diff options
Diffstat (limited to 'src/frontend/lexer.l')
-rw-r--r-- | src/frontend/lexer.l | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/frontend/lexer.l b/src/frontend/lexer.l index 5b72086..40f6196 100644 --- a/src/frontend/lexer.l +++ b/src/frontend/lexer.l @@ -9,7 +9,8 @@ %option yylineno DIGIT [0-9] -ALPHA [[:alpha:]_] +PREID [a-zA-Z_] +PSTID [a-zA-Z0-9_] /*** rules section ***/ %% @@ -30,12 +31,18 @@ ALPHA [[:alpha:]_] "void" {return VOID;} "return" {return RET;} -{DIGIT}+ {yylval.ival = atol(yytext); return NUMBER;} -{ALPHA}+ { +{PREID}{PSTID}* { yylval.sval = strdup(yytext); return WORD; } +{DIGIT}+ {yylval.ival = atol(yytext); return NUMBER;} + +{PSTID}+ { + printf("Error at line %d: invalid identifier \"%s\"\n", yylineno, yytext); + return YYerror; +} + [[:space:]]+ {/* discard */} . { printf("Error at line %d: unrecognized symbol \"%s\"\n", yylineno, yytext); |