Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar ambiguity only when using external references
Grammar ambiguity only when using external references [message #1057783] Wed, 08 May 2013 17:09 Go to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Hello everybody,

I followed this blog post to reference one language from another.
http://christiandietrich.wordpress.com/2012/08/07/xtext-referencing-elements-of-one-dsl-from-another-dsl/

My problem is the following.
I have three grammars: A,B,C
In grammar A I am both referencing grammars B and C
If I compile A I obtain error 201 because it says the grammar is ambiguous.

What is driving me crazy is that if I copy and paste the body of grammar
B (or C) inside A, then the ambiguity is magically resolved and the
compilation succeed.

What could be the problem? Below are my three grammars.
Thank you for your time and help.

============================

Grammar A
Model:
         trigger=Trigger;
Trigger:
	event=[events::Event] |
	timeConstraint=[timeconstraints::TimeConstraint]


Grammar B
Model:
	event=Event;

Event:
	'@' (eventName=ID ('(' parameters=Parameters ')')? '.' 
eventExtension=EventExtensions) | (nowEvent ?= 'now')
;

Parameters :
	param=ID | param=ID ',' parameters=Parameters
;

EventExtensions :
	'exit' | 'enter' | 'start'  | 'end' | 'tick' | 'sig' | 'call' | 'send' 
| 'receive'
;


Grammar C
Model:
	timeconstraint=TimeConstraint;
	
TimeConstraint:
	(event2=[events::Event] '-' event1=[events::Event] op=RELATIONS value=INT)
;

terminal RELATIONS:
	('<'| '>'| '==' | '<=' |'>=' | '!=')
;	
Re: Grammar ambiguity only when using external references [message #1057784 is a reply to message #1057783] Wed, 08 May 2013 17:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi

The solutions are

Introduce a Common supertype ( e.g through a Base grammar) and reference that One
Or to solve the Ambiguität on Syntax level
Re: Grammar ambiguity only when using external references [message #1057839 is a reply to message #1057784] Thu, 09 May 2013 08:41 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Hi Christian and thank you for your help

I read some of the advices around the forum about using a
supertype or solving at syntaxt level and I will give it a try.

But my doubt is the following:
if there is an ambiguity in the grammar, why if I simply copy and paste
the grammar and I use a unique file (instead of separate project files
with imports) the ambiguity is resolved?

Am I missing something? To me this makes no sense.

Thank you


On 05/08/2013 07:18 PM, Christian Dietrich wrote:
> Hi
>
> The solutions are
>
> Introduce a Common supertype ( e.g through a Base grammar) and reference
> that One
> Or to solve the Ambiguität on Syntax level
Re: Grammar ambiguity only when using external references [message #1057854 is a reply to message #1057839] Thu, 09 May 2013 10:40 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Since I am new to XText I think that my fault is that I confused the
role of imports and the role of mixins (explained here
http://www.eclipse.org/Xtext/documentation.html#grammarMixins)

More in detail when I was using the operators like this one

timeConstraint=[timeconstraints::TimeConstraint]

I thought it is equivalent to refer to the grammar-rule defined in the
other language, while it seems it is not (as you may notice from this
article http://blogs.itemis.de/stundzig/archives/776 or the first one I
posted
http://christiandietrich.wordpress.com/2012/08/07/xtext-referencing-elements-of-one-dsl-from-another-dsl/)

I will go through that to understand if I am correct or not


On 05/09/2013 10:41 AM, Alfredo Motta wrote:
> Hi Christian and thank you for your help
>
> I read some of the advices around the forum about using a
> supertype or solving at syntaxt level and I will give it a try.
>
> But my doubt is the following:
> if there is an ambiguity in the grammar, why if I simply copy and paste
> the grammar and I use a unique file (instead of separate project files
> with imports) the ambiguity is resolved?
>
> Am I missing something? To me this makes no sense.
>
> Thank you
>
>
> On 05/08/2013 07:18 PM, Christian Dietrich wrote:
>> Hi
>>
>> The solutions are
>>
>> Introduce a Common supertype ( e.g through a Base grammar) and reference
>> that One
>> Or to solve the Ambiguität on Syntax level
>
>
Re: Grammar ambiguity only when using external references [message #1057861 is a reply to message #1057854] Thu, 09 May 2013 12:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
HI,

what do you mean with "copy and paste"
Re: Grammar ambiguity only when using external references [message #1057865 is a reply to message #1057861] Thu, 09 May 2013 12:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
And:

timeConstraint=[timeconstraints::TimeConstraint]

is short for:

timeConstraint=[timeconstraints::TimeConstraint|ID] which means "by ID" => an ID will be parsed.
Re: Grammar ambiguity only when using external references [message #1057868 is a reply to message #1057865] Thu, 09 May 2013 12:45 Go to previous message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Exactly, this was my error.
I believed that using such expression the corresponding imported rule
was invoked.

Thank you

On 05/09/2013 02:16 PM, Christian Dietrich wrote:
> And:
>
> timeConstraint=[timeconstraints::TimeConstraint]
>
> is short for:
>
> timeConstraint=[timeconstraints::TimeConstraint|ID] which means "by ID"
> => an ID will be parsed.
Previous Topic:global scope and importedURI
Next Topic:Using both AbstractModelInferrer and IGenerator implementations
Goto Forum:
  


Current Time: Sat Dec 20 06:39:29 GMT 2014

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

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