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 Doe is currently offline John DoeFriend
Messages: 138
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 online Christian DietrichFriend
Messages: 13939
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] ;


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
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 May 14 10:42:25 GMT 2021

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

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

Back to the top