feat: add parentheses grouping support in expression parser

Implement parenthesized expression parsing in the primary() function by matching TOKEN_LEFT_PAREN, recursively calling expression(), and consuming TOKEN_RIGHT_PAREN. Add grammar test cases in test/grammar.wren verifying correct operator precedence with parentheses, including nested grouping expressions.
This commit is contained in:
Bob Nystrom
2013-11-01 04:49:15 +00:00
parent 66961a3c1a
commit d3cffd521d
2 changed files with 17 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
// * has higher precedence than +.
io.write(2 + 3 * 4) // expect: 14
// * has higher precedence than -.
io.write(20 - 3 * 4) // expect: 8
// Using () for grouping.
io.write((2 * (6 - (2 + 2)))) // expect: 4