How to suppress ambiguity

To not have alternative for ambiguity in parse result there is two solution:

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

rejecting rule match in match manager class, see match manager class.



© 2008-2009, parser4j