How to define recursive arithmetical expression with optional parenthesis in Lezer?
I try this:
@top Template { statement* }
statement {
ArithExpr
}
ArithExpr {
ArithExpr ArithOp ArithExpr |
'(' ArithExpr ')' |
number
}
ArithOp { '+' | '-' | '*' | '/' }
@tokens {
number { @digit+ }
}
@detectDelim
but got an error:
shift/reduce conflict between
ArithOp -> · "+"
and
ArithExpr -> ArithExpr ArithOp ArithExpr
With input:
ArithExpr ArithOp ArithExpr · "+" …
The reduction of ArithExpr is allowed before "+" because of this rule:
ArithExpr -> ArithExpr · ArithOp ArithExpr
Shared origin: statement+ -> · ArithExpr
via ArithExpr -> ArithExpr ArithOp · ArithExpr
via ArithExpr -> ArithExpr · ArithOp ArithExpr
ArithOp -> · "+"
and don’t understand how to resolve that.
Could you please help?
BTW, the similar grammar works in ANTLR v4.