diff options
author | bd <bdunahu@operationnull.com> | 2025-01-28 16:22:49 -0500 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-01-28 16:22:49 -0500 |
commit | ce7189464a302872634d949cf06e9071b625bfcb (patch) | |
tree | adadc344f518642a009a2c12215e90bda420fc67 /src/frontend/lexer.l | |
parent | 9e09767e23a4edb6b31540195bfe885f83e080d7 (diff) |
Fix various lexer/parser bugs, pass all tests for binary ops
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); |