mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-12 14:48:40 +01:00
Parentheses for grouping.
This commit is contained in:
@ -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
9
test/grammar.wren
Normal 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
|
||||
Reference in New Issue
Block a user