diff options
Diffstat (limited to '12')
-rw-r--r-- | 12/input | 11 | ||||
-rw-r--r-- | 12/main.l | 5 | ||||
-rw-r--r-- | 12/main.y | 9 |
3 files changed, 18 insertions, 7 deletions
@@ -1,6 +1,13 @@ | |||
1 | int main(int a, int b, int c) { | 1 | int 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 | } |
@@ -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 ; |
@@ -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 | ||
61 | assignment_expr: unary_expr ASSIGN unary_expr | 61 | assignment_expr: argument ASSIGN unary_expr |
62 | | unary_expr ASSIGN boolean_expr | 62 | | argument ASSIGN boolean_expr |
63 | ; | 63 | ; |
64 | 64 | ||
65 | expression: unary_expr | 65 | expression: unary_expr |
@@ -67,12 +67,11 @@ expression: unary_expr | |||
67 | | assignment_expr | 67 | | assignment_expr |
68 | ; | 68 | ; |
69 | 69 | ||
70 | for_expr: FOR LPAREN statement statement expression RPAREN statement | 70 | for_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 | ||
74 | while_expr: WHILE LPAREN expression RPAREN block | 74 | while_expr: WHILE LPAREN expression RPAREN block |
75 | | WHILE LPAREN RPAREN block | ||
76 | ; | 75 | ; |
77 | 76 | ||
78 | if_expr: IF LPAREN expression RPAREN block | 77 | if_expr: IF LPAREN expression RPAREN block |