Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext: Trying to check for cross references but get ambiguous grammar
Xtext: Trying to check for cross references but get ambiguous grammar [message #1028653] Thu, 28 March 2013 14:58 Go to next message
Anja Liro is currently offline Anja LiroFriend
Messages: 3
Registered: March 2013
Junior Member
Hi,

I am trying to implement something like this:
I have two types, individuals and groups. I can assign one individual to another individual and one group to another. Now I want to be able to assign an individual to a group, but it should be forbidden to assign a group to an individual.

Here is an example:

individual ind1;
individual ind2;
group gr1;
group gr2;

ind2 = ind1; //ok
gr2 = gr1; //ok
gr2 = ind2; //ok
ind2 = gr2; //forbidden


I tried to realize this with the following grammar:

VanillaModel:
	statements+=Statement*;
	
Statement:
	Group | Individual | Assignment;
	
Group:
	'group' name=ID ';' ;

Individual:
	'individual' name=ID ';' ;

Assignment:
	left=[Group] '=' right=[Group] ';'
	| left=[Group] '=' right=[Individual] ';'
	| left=[Individual] '=' right=[Individual] ';'
;


However, this grammar is ambiguous and ANTLR complains, which makes sense

warning(200): ../org.xtext.example.vanilladsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalVanillaDsl.g:232:1: Decision can match input such as "RULE_ID '=' RULE_ID ';'" using multiple alternatives: 1, 2, 3
As a result, alternative(s) 3,2 were disabled for that input


However, shouldn't there be a way to somehow realize this setting? I'm pretty new to Xtext, so I might be just missing something. Does anybody have an idea what I could do?

Thanks a lot

-anja
Re: Xtext: Trying to check for cross references but get ambiguous grammar [message #1028701 is a reply to message #1028653] Thu, 28 March 2013 16:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,


introduce a supertype

GoI: Group | Individual;
Assignment:
	left=[GoI] '=' right=[GoI] ';'
;


the rest can be done with a semantic validaton


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext: Trying to check for cross references but get ambiguous grammar [message #1033424 is a reply to message #1028701] Thu, 04 April 2013 08:07 Go to previous messageGo to next message
Anja Liro is currently offline Anja LiroFriend
Messages: 3
Registered: March 2013
Junior Member
Hi,

Thanks for the reply.
The solution looks good so far.
Just one more question: What is a semantic validation? Where does it happen (in which class/file)? When googling this, I only found semantic predicates which is not the same, is it?

Thanks

-anja
Re: Xtext: Trying to check for cross references but get ambiguous grammar [message #1033434 is a reply to message #1033424] Thu, 04 April 2013 08:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi have a look at MyDslJavaValidator

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext: Trying to check for cross references but get ambiguous grammar [message #1033463 is a reply to message #1033434] Thu, 04 April 2013 08:49 Go to previous message
Anja Liro is currently offline Anja LiroFriend
Messages: 3
Registered: March 2013
Junior Member
Awesome, this works!
Thanks a lot for the quick help!
Previous Topic:DSLs targetting non-Java languages
Next Topic:Problem when generating Xtext problem from different EMF models
Goto Forum:
  


Current Time: Thu Apr 25 22:18:40 GMT 2024

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

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

Back to the top