Create interp.l

This commit is contained in:
Chen, Chien-ting 2018-05-21 00:12:41 +08:00 committed by GitHub
parent 40bee9ebbc
commit 50d5fc9a3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

41
interp.l Normal file
View file

@ -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;
}