Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Why this grammar is not LL(*)?
Why this grammar is not LL(*)? [message #880568] Sat, 02 June 2012 09:58 Go to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
Why this grammar is not LL(*)?
Model:
	(elem=assignment_expression);

assignment_expression: 
	(left = expression 'end')
	| alone = expression
;

expression:
	"a" {expression1} right = expression
	| "b" {expression2}
;


I decided to check on LL(*) from www.antlr.org/wiki/display/~admin/LL%28*%29+grammar+analysis:

Model:
(elem=rules_s);

rules_s :
rule_e 'X'
| rule_e 'Y'
;

rule_e : 'L' rule_e 'R'
| 'I'
;

Xtext tells it's not LL(*) too. Why?

[Updated on: Sat, 02 June 2012 10:21]

Report message to a moderator

Re: Why this grammar is not LL(*)? [message #880576 is a reply to message #880568] Sat, 02 June 2012 10:33 Go to previous messageGo to next message
Phil R is currently offline Phil RFriend
Messages: 99
Registered: September 2011
Member
edit: was a bit confused.
In both antlr and xtext the assignment_expression has expression on it left side for 2 times. Which path will it take if you know that the antlr parser does not backtrack by default..

[Updated on: Sat, 02 June 2012 11:07]

Report message to a moderator

Re: Why this grammar is not LL(*)? [message #880578 is a reply to message #880576] Sat, 02 June 2012 10:37 Go to previous messageGo to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
But what about the second grammar?
Re: Why this grammar is not LL(*)? [message #880600 is a reply to message #880568] Sat, 02 June 2012 11:51 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-02-06 11:58, Oleg Bolshakov wrote:
> Why this grammar is not LL(*)?
> Model:
> (elems+=assignment_expression)*;
>
> assignment_expression: (left = expression '=' => right = expression)
> | alone = expression
> ;
>
> expression:
> "a" {expression1} right = expression
> | "b" {expression2}
> ;

I can recommend reading this:
http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html

It shows how to write a grammar for Expressions, deal with precedence
and left/right associativity.

- henrik
Re: Why this grammar is not LL(*)? [message #880661 is a reply to message #880600] Sat, 02 June 2012 16:03 Go to previous message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
This grammar works with backtrack = true. My problem was that I checked this option in XtextAntlrUiGeneratorFragment instead of XtextAntlrGeneratorFragment
Previous Topic:Xtext hangs
Next Topic:Objects' types in outline
Goto Forum:
  


Current Time: Tue Nov 24 18:57:25 GMT 2020

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

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

Back to the top