aboutsummaryrefslogtreecommitdiff
path: root/12
diff options
context:
space:
mode:
Diffstat (limited to '12')
-rw-r--r--12/input11
-rw-r--r--12/main.l5
-rw-r--r--12/main.y9
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 @@
1int main(int a, int b, int c) { 1int main(int a, int b, int c) {
2 if (a > b) { 2 if (a > b) {
3 for(;;); 3 int i = 1;
4 a++; 4 float j = 2;
5 } else if (a < b) {
6 b++;
7 while(a > b) {
8 a++;
9 }
10 } else {
11 c++;
5 } 12 }
6} 13}
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;
12"long" return LONG; 12"long" return LONG;
13"return" return RET; 13"return" return RET;
14"for" return FOR; 14"for" return FOR;
15"while" return WHILE;
15"if" return IF; 16"if" return IF;
16"else" return ELSE; 17"else" return ELSE;
17"," return COMMA; 18"," return COMMA;
@@ -33,6 +34,10 @@ extern int yylval;
33">" return GT; 34">" return GT;
34"<=" return LTE; 35"<=" return LTE;
35">=" return GTE; 36">=" return GTE;
37[0-9]+ {
38 yylval = atoi(yytext);
39 return NUM;
40};
36[a-zA-Z_][a-zA-Z_0-9]* return ID; 41[a-zA-Z_][a-zA-Z_0-9]* return ID;
37. ; 42. ;
38\n ; 43\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
58 | unary_expr NEQ unary_expr 58 | unary_expr NEQ unary_expr
59 ; 59 ;
60 60
61assignment_expr: unary_expr ASSIGN unary_expr 61assignment_expr: argument ASSIGN unary_expr
62 | unary_expr ASSIGN boolean_expr 62 | argument ASSIGN boolean_expr
63 ; 63 ;
64 64
65expression: unary_expr 65expression: unary_expr
@@ -67,12 +67,11 @@ expression: unary_expr
67 | assignment_expr 67 | assignment_expr
68 ; 68 ;
69 69
70for_expr: FOR LPAREN statement statement expression RPAREN statement 70for_expr: FOR LPAREN statement statement expression RPAREN block
71 | FOR LPAREN statement statement RPAREN statement 71 | FOR LPAREN statement statement RPAREN block
72 ; 72 ;
73 73
74while_expr: WHILE LPAREN expression RPAREN block 74while_expr: WHILE LPAREN expression RPAREN block
75 | WHILE LPAREN RPAREN block
76 ; 75 ;
77 76
78if_expr: IF LPAREN expression RPAREN block 77if_expr: IF LPAREN expression RPAREN block