Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar rules ordering
Grammar rules ordering [message #757603] Sun, 20 November 2011 09:59 Go to next message
Mahmoud Moneeb is currently offline Mahmoud MoneebFriend
Messages: 15
Registered: October 2011
Junior Member
Hi,

I wondering does the ordering of two ORed rules make a difference ?!

for example:

Rule: rule_1 | rule_2 ;

Is it supposed to work the same as

Rule: rule_2 | rule_1 ;

I have tried implementing some grammar rules and I found that the ordering of the ORed rules matters.

Best regards,
Mahmoud
Re: Grammar rules ordering [message #757604 is a reply to message #757603] Sun, 20 November 2011 10:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13409
Registered: July 2009
Senior Member
Hi,

can you elaborate a bit on what happens when you change the order in a real world example.
it should not matter if there are not any ambiguities in your grammar.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammar rules ordering [message #757606 is a reply to message #757604] Sun, 20 November 2011 10:28 Go to previous messageGo to next message
Mahmoud Moneeb is currently offline Mahmoud MoneebFriend
Messages: 15
Registered: October 2011
Junior Member
At first I had this rule and it was not working as expected

primary :
prim_res = ID
| literal
| function_call
| aggregate
| qualified_expression
| name
| allocator
;

On changing the order of the rules It works fine now
primary :
function_call
| prim_res = ID
| literal
| aggregate
| qualified_expression
| name
| allocator
;

Another example :

the second rule here is always not working. Only the first one get recognized by the generated IDE

logical_expression :
LHS_relation = relation ( Multiple_logical_operators REST_RHS_relation += relation )*
| LH_relation = relation ( Single_logical_operators RH_relation = relation )?
;
Re: Grammar rules ordering [message #757608 is a reply to message #757606] Sun, 20 November 2011 10:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13409
Registered: July 2009
Senior Member
As i said: you grammar is ambigous => first come first serve

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 20 November 2011 10:44]

Report message to a moderator

Re: Grammar rules ordering [message #757612 is a reply to message #757608] Sun, 20 November 2011 10:51 Go to previous messageGo to next message
Mahmoud Moneeb is currently offline Mahmoud MoneebFriend
Messages: 15
Registered: October 2011
Junior Member
So how can I detect the ambiguous points in my grammar exactly and there no warning and the building went smoothly ?!

I'm talking in general. Maybe I face other problems with the grammar later and need a way to resolve these ambiguity issues

Thanks,
Mahmoud
Re: Grammar rules ordering [message #757613 is a reply to message #757612] Sun, 20 November 2011 10:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13409
Registered: July 2009
Senior Member
Hi,

you have to enable backtracking to get the grammar built - so you actually get warned

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 20 November 2011 10:58]

Report message to a moderator

Re: Grammar rules ordering [message #757614 is a reply to message #757613] Sun, 20 November 2011 10:57 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13409
Registered: July 2009
Senior Member
P.S: you might have a look at assigend actions to build proper expressions see http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Xtext 2.1.1][SOLVED] create custom loop scope
Next Topic:a type serializer for JvmType
Goto Forum:
  


Current Time: Sat Mar 28 17:04:34 GMT 2020

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

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

Back to the top