Left recursive grammars

When moving on to a more complex expression, such as addition, we need to write a recursive rule since the left and right parts of an addition are expressions themselves. It would be natural to express such a rule as follows:

Expression:
  ... as above
  {Plus} left=Expression '+' right=Expression;

However, this results in an error from the Xtext editor as shown in the following screenshot:

Left recursive grammars

Xtext uses a parser algorithm that is suitable for use for interactive editing due to its better handling of error recovery. Unfortunately this parser algorithm does not deal with left recursive rules. A rule is left recursive when the first ...

Get Implementing Domain-Specific Languages with Xtext and Xtend now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.