say 'Hello World!';grammar AdventExpressionGrammar {
rule TOP {
<expr>
}
token value { \d+ }
token operators { '+' | '-' | '*' | '/' }
rule expr {
'(' <expr> ')'
|
<value> <operators> [ <expr> | <value> ]
}
}
say AdventExpressionGrammar.parse('1 + 2');
say AdventExpressionGrammar.parse('(1 + 2)');
say AdventExpressionGrammar.parse('1 + 2 * 3 + 4 * 5 + 6').gist;
say AdventExpressionGrammar.parse('1 + (2 * 3) + (4 * (5 + 6))').gist;