diff --git a/parser.y b/parser.y index bc59a8a6..898e42d5 100644 --- a/parser.y +++ b/parser.y @@ -104,6 +104,7 @@ expr: ID { $$ = std::make_unique($1); } | expr '-' expr { $$ = std::make_unique($1, $3); } | expr '*' expr { $$ = std::make_unique($1, $3); } | expr '/' expr { $$ = std::make_unique($1, $3); } + | '(' expr ')' { $$ = $2; } ; epsilon: /* empty */ ; diff --git a/test/paren_expr.c b/test/paren_expr.c new file mode 100644 index 00000000..ae4866e0 --- /dev/null +++ b/test/paren_expr.c @@ -0,0 +1,6 @@ +int main() { + 4 * (5 - 2); + 10 / ((5 + 1) * 3); + + return 0; +} diff --git a/test/paren_expr.exp b/test/paren_expr.exp new file mode 100644 index 00000000..8d398c5a --- /dev/null +++ b/test/paren_expr.exp @@ -0,0 +1,20 @@ +(* + 4: int + (- + 5: int + 2: int + ): int +): int +(/ + 10: int + (* + (+ + 5: int + 1: int + ): int + 3: int + ): int +): int +(ret + 0: int +)