我遇到了一个模棱两可的 Xtext 语法问题,但我找不到正确的解决方案。
Program: (statements+=Statement)+
Statement: (AssignmentStatement | ResetStatement);
ResetStatement returns Statement:
'RESET' (fields+=Identifier)+
;
AssignStatement returns Statement:
target=Identifier ':=' object=Identifier
;
我得到的问题是 RESET 语句可能有几个要 RESET 的字段;然而,当一个 ':=' 标记被定位时,解析器应该检测一个 AssignmentStatement 的开始。我曾尝试使用句法谓词,但我只能消除语法的歧义:
ResetStatement returns Statement:
'RESET' =>(fields+=Identifier)+
;
但是,您可能会注意到这不是预期的行为,例如:
RESET ID1 ID2
ID3 := ID1
在 ':=' 标记处返回错误。我尝试将谓词标记添加到 AssignmentStatement:
Statement: (=>AssignmentStatement | ResetStatement);
并且:
AssignStatement returns Statement:
=>(target=Identifier ':=') object=Identifier
;
但没有成功。在所有情况下都会出现错误:
[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.
我很迷茫,所以任何提示都非常感谢。