How to suppress ambiguity
To not have alternative for ambiguity in parse result there is two solution:
- use unambiguous grammar
- programmatocally rejecting rule match in match manager class
disambiguate grammar
The ambiguous grammar:
Start : Expression
Expression : 'a'
| Expression '+' Expression
| Expression '*' Expression
The disambiguate grammar ( operator precedence is managed at syntax level even if it is a semantic level concern )
Start : Expression
Expression : ExpressionMul
| Expression '+' ExpressionMul
ExpressionMul : PrimaryExpression
| ExpressionMul '*' PrimaryExpression
PrimaryExpression : 'a'
programmatically
© 2008-2009, parser4j