Skip to content

Commit

Permalink
Implement expression with parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
leewei05 authored and Lai-YT committed Sep 12, 2023
1 parent e23df98 commit 0f0918a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ expr: ID { $$ = std::make_unique<IdExprNode>($1); }
| expr '-' expr { $$ = std::make_unique<SubExprNode>($1, $3); }
| expr '*' expr { $$ = std::make_unique<MulExprNode>($1, $3); }
| expr '/' expr { $$ = std::make_unique<DivExprNode>($1, $3); }
| '(' expr ')' { $$ = $2; }
;

epsilon: /* empty */ ;
Expand Down
6 changes: 6 additions & 0 deletions test/paren_expr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main() {
4 * (5 - 2);
10 / ((5 + 1) * 3);

return 0;
}
20 changes: 20 additions & 0 deletions test/paren_expr.exp
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 0f0918a

Please sign in to comment.