From df51b2bb52628d48bb6822ead13a7cc9c84b89b5 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 7 May 2021 11:41:11 +0530 Subject: fix assignment exprs --- 12/input | 11 +++++++++-- 12/main.l | 5 +++++ 12/main.y | 9 ++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/12/input b/12/input index fa64ab2..b35b023 100644 --- a/12/input +++ b/12/input @@ -1,6 +1,13 @@ int main(int a, int b, int c) { if (a > b) { - for(;;); - a++; + int i = 1; + float j = 2; + } else if (a < b) { + b++; + while(a > b) { + a++; + } + } else { + c++; } } diff --git a/12/main.l b/12/main.l index 2fa1b44..5641fad 100644 --- a/12/main.l +++ b/12/main.l @@ -12,6 +12,7 @@ extern int yylval; "long" return LONG; "return" return RET; "for" return FOR; +"while" return WHILE; "if" return IF; "else" return ELSE; "," return COMMA; @@ -33,6 +34,10 @@ extern int yylval; ">" return GT; "<=" return LTE; ">=" return GTE; +[0-9]+ { + yylval = atoi(yytext); + return NUM; +}; [a-zA-Z_][a-zA-Z_0-9]* return ID; . ; \n ; diff --git a/12/main.y b/12/main.y index 5431c55..319b2d9 100644 --- a/12/main.y +++ b/12/main.y @@ -58,8 +58,8 @@ boolean_expr: unary_expr LT unary_expr | unary_expr NEQ unary_expr ; -assignment_expr: unary_expr ASSIGN unary_expr - | unary_expr ASSIGN boolean_expr +assignment_expr: argument ASSIGN unary_expr + | argument ASSIGN boolean_expr ; expression: unary_expr @@ -67,12 +67,11 @@ expression: unary_expr | assignment_expr ; -for_expr: FOR LPAREN statement statement expression RPAREN statement - | FOR LPAREN statement statement RPAREN statement +for_expr: FOR LPAREN statement statement expression RPAREN block + | FOR LPAREN statement statement RPAREN block ; while_expr: WHILE LPAREN expression RPAREN block - | WHILE LPAREN RPAREN block ; if_expr: IF LPAREN expression RPAREN block -- cgit v1.2.3