diff options
Diffstat (limited to 'simple-c/lexer.l')
-rw-r--r-- | simple-c/lexer.l | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/simple-c/lexer.l b/simple-c/lexer.l new file mode 100644 index 0000000..be983d1 --- /dev/null +++ b/simple-c/lexer.l @@ -0,0 +1,37 @@ +%{ +#include "parser.h" +#define YY_USER_ACTION yylloc.first_line = yylloc.last_line = yylineno; +%} + +%option noyywrap + +DIGIT [0-9] + +%% + +"-" { return MINUS; } +"+" { return PLUS; } +"*" { return MULT; } +"/" { return DIV; } +"=" { return EQUAL; } +"(" { return L_PAREN; } +")" { return R_PAREN; } + +(\.{DIGIT}+)|({DIGIT}+(\.{DIGIT}*)?([eE][+-]?[0-9]+)?) { + yylval.dval = atof(yytext); + return NUMBER; +} + +[ \t]+ { /* ignore spaces */ } + +"\n" { return END; } + +. { + printf( + "Error at line %d: unrecognized symbol \"%s\"\n", + yylloc.first_line, + yytext); + exit(0); +} + +%% |