1

This is part of the grammar of the NuSMV language:

BasicExpression:
Constant | '(' BasicExpression ')' | '!' BasicExpression | BasicExpression '&' BasicExpression;
Constant:
BooleanConstant
BooleanConstant: 
'TRUE' | 'FALSE';

Unfortunately XText is throwing an exception that states there is left recursion in this grammar. How can I fix it?

Thanks.

Shevach
  • 717
  • 9
  • 25

2 Answers2

1

You could simply introduce a new rule (a new tier) like that:

BasicExpression:
    firstContent=ExpressionContent ("&" secondContent=ExpressionContent)?
;

ExpressionContent:
    Constant 
    | '(' BasicExpression ')' 
    | '!' BasicExpression 
;

That way the rule is not left recursive anymore.

Greeting Krzmbrzl

Raven
  • 2,951
  • 2
  • 26
  • 42
0

Have a look at this article or the official documentation, it will explain in detail how to handle recursion in language, and taking into account operator precedence.

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45