0

I am having a problem with an ambiguous Xtext grammar, but I just cannot find the correct solution.

Program: (statements+=Statement)+
Statement: (AssignmentStatement | ResetStatement);
ResetStatement returns Statement:
  'RESET' (fields+=Identifier)+
;

AssignStatement returns Statement:
  target=Identifier ':=' object=Identifier
;

The problem I get is that the RESET statement may have several fields to RESET; however, when a ':=' token is located, the parser should detect the beginning of an AssignmentStatement instead. I have tried using syntactic predicates, but I was only able to disambiguate the grammar doing:

ResetStatement returns Statement:
  'RESET' =>(fields+=Identifier)+
;

However, as you might notice that is not the expected behavior, as:

RESET ID1 ID2
ID3 := ID1

Returns an error at the ':=' token. I tried adding the predicate marker to the AssignmentStatement:

Statement: (=>AssignmentStatement | ResetStatement);

And also:

AssignStatement returns Statement:
  =>(target=Identifier ':=') object=Identifier
;

But with no success. The error is in all the cases:

[fatal] rule ruleResetStatement has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.

I am quite lost so any hints are well appreciated.

0 Answers0