summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frontend/lexer.l13
-rw-r--r--src/frontend/parser.y9
2 files changed, 14 insertions, 8 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);
diff --git a/src/frontend/parser.y b/src/frontend/parser.y
index aa58f64..bd5d127 100644
--- a/src/frontend/parser.y
+++ b/src/frontend/parser.y
@@ -66,10 +66,6 @@ exp: term {
add_child($$, $1);
add_child($$, $3);
}
-| un_op exp {
- $$ = create_expr($1);
- add_child($$, $2);
- }
;
term: factor {
@@ -90,6 +86,10 @@ term: factor {
add_child($$, $1);
add_child($$, $3);
}
+| un_op exp {
+ $$ = create_expr($1);
+ add_child($$, $2);
+ }
;
factor: NUMBER {
@@ -113,4 +113,3 @@ un_op: COMP {
void yyerror(Node **root, const char *msg) {
printf("** Line %d: %s\n", yylineno, msg);
}
-