Parentheses for grouping.

This commit is contained in:
Bob Nystrom
2013-10-31 21:49:15 -07:00
parent 8e6ce2bb2a
commit 46c0fe87e6
2 changed files with 17 additions and 0 deletions

View File

@ -583,6 +583,14 @@ void primary(Compiler* compiler)
string(compiler);
return;
}
// Parentheses.
if (match(compiler, TOKEN_LEFT_PAREN))
{
expression(compiler);
consume(compiler, TOKEN_RIGHT_PAREN);
return;
}
}
void number(Compiler* compiler)

9
test/grammar.wren Normal file
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