Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Ambiguous grammar
Ambiguous grammar [message #1838923] Tue, 09 March 2021 16:44 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi all,

I have the following grammar:

Machine:

("A" a+=A ("," a+=A )*)*
("B" b+=B ("," b+=B )*)*
goto+=GoTo
;

A:
name=ID;

B:
name=ID;

GoTo:
name=ID ":" (as=[A] | bs=[B]) "to" (as=[A] | bs=[B]) ;

I get the following error: Decision can match input such as RULE_ID using multiple alternatives 1,2 .

I understand that happens because the parser will not understand if it belongs to A or B, but I cannot find a way around it.

Any help is appreciated!

Thank you!
Re: Ambiguous grammar [message #1838924 is a reply to message #1838923] Tue, 09 March 2021 16:47 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you cant. the only way is either to use a different syntax/keyword for the cases
or introduce a common superType e.g.

AorB:A|B; // UNCALLED

GoTo:
name=ID ":" from=[AorB] "to" to=[AorB] ;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Alternatives can never be matched
Next Topic:Migrating from ANTLR3 to ANTLR4
Goto Forum:
  


Current Time: Fri Apr 26 10:20:42 GMT 2024

Powered by FUDForum. Page generated in 0.05353 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top