Reputation: 15375
I have the following rules in a grammar:
CCExpression
: LiteralExpression
| CCParenthesizedExpression
| CCSimpleNameExpression
| CCCastExpression
| CCOperatorExpression
| CCConditionalExpression
;
CCOperatorExpression
: CCUnaryOperator CCExpression
| CCExpression CCBinaryOperator CCExpression
;
and I am getting the following error:
The following sets of rules are mutually left-recursive [CCExpression, CCOperatorExpression]
I tried to fold the CCOperatorExpression
rule into the CCExpression
rule:
CCExpression
: CCExpression CCBinaryOperator CCExpression
| CCUnaryOperator CCExpression
| '(' CCExpression ')'
| LiteralExpression
| CCSimpleNameExpression
| CCCastExpression
| CCConditionalExpression
;
but that didn't seem to help. I still get:
The following sets of rules are mutually left-recursive [CCExpression]
How can I fix this?
Upvotes: 0
Views: 62
Reputation: 170298
That is because lexer rules can’t be left recursive, only parser rules can.
See: Practical difference between parser rules and lexer rules in ANTLR?
Upvotes: 0