From 50d5fc9a3a002cf147fd588a84b61ccdcf2cf51b Mon Sep 17 00:00:00 2001 From: "Chen, Chien-ting" Date: Mon, 21 May 2018 00:12:41 +0800 Subject: [PATCH] Create interp.l --- interp.l | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 interp.l diff --git a/interp.l b/interp.l new file mode 100644 index 0000000..e60771a --- /dev/null +++ b/interp.l @@ -0,0 +1,41 @@ +%option yylineno +%{ +#include "y.tab.h" +int yycharno = 0; +%} + + +str \"([^\n]|\\\")+\" +ws [ \t]+ +newline [\n] +alpha [a-zA-Z] +dig [0-9] +float1 {dig}+[.]{dig}+ +int {dig}+ +float2 {float1}[eE][-+]?{dig}+ +float {float1}|{float2} +number {int}|{float} +var ([_]|{alpha})([_]|{alpha}|{dig})* +%% + +{newline} {yylineno = yylineno + 1;return T_NEWLINE;} +{ws} {yycharno = yycharno + yyleng;} +{var} {yylval.strVal = strdup(yytext); + yycharno = yycharno + yyleng; + printf("yyval.strVal = %s",yylval.strVal); + return T_VAR;} +{number} {yylval.floatVal = atof(yytext); + yycharno = yycharno + yyleng; + return T_NUM;} +"-" {yycharno += 1;return T_SUB;} +"+" {yycharno += 1;return T_ADD;} +"*" {yycharno += 1;return T_MUL;} +"/" {yycharno += 1; return T_DIV;} +"(" {yycharno += 1; return T_LPATH;} +")" {yycharno += 1; return T_RPATH;} +. {yycharno += 1;} + +%% +int yywrap(void){ + return 1; +}