Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext vs ANTLR syntactic predicates
Xtext vs ANTLR syntactic predicates [message #880977] Sun, 03 June 2012 14:56 Go to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
This grammar works in antlr (with backtrack = false) but doesn't work in Xtext with "non LL(*)decision" error. What's wrong?
model:
	((declarator '{') => func = function) 
	| decl = declarator 
;

declarator:
	name = ID
	| '('declarator ')' 
;

function:
	decl = declarator
	'{' id= ID '}'
;


Unfortunately, Xtext documentation lacks information about syntactic predicates. They seem to differ from those in antlr. In Xtext there is just one example on how to use them. The question is - Can I use syntactic predicates xpressions without creating features? (in my example: "(declarator '{' => func = function)" will not force Xtext to wait for one more declaration and '{' before a function?

Xtext gives an error "no viable alternative at input" when trying to manually create an object after predicate symbol:
=> {someobject.left = curent}
. but it works without '=>' symbol

[Updated on: Sun, 03 June 2012 15:08]

Report message to a moderator

Re: Xtext vs ANTLR syntactic predicates [message #880989 is a reply to message #880977] Sun, 03 June 2012 15:21 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Oleg,

did you try to move the predicate into the rule 'function'?

function: =>(decl = declarator '{') id = ID '}’;

Xtext will propagate predicates that are at the start of a parser rule
to all the callers.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 03.06.12 16:56, schrieb Oleg Bolshakov:
> This grammar works in antlr (with backtrack = false) but doesn't work in
> Xtext with "non LL(*)decision" error. What's wrong?
> model:
> ((declarator '{') => func = function) | decl = declarator ;
>
> declarator:
> name = ID
> | '('declarator ')' ;
>
> function:
> decl = declarator
> '{' id= ID '}'
> ;
>
> Unfortunately, Xtext documentation lacks information about syntactic
> predicates. They seem to differ from those in antlr. In Xtext there is
> just one example on how to use them.
Re: Xtext vs ANTLR syntactic predicates [message #880992 is a reply to message #880989] Sun, 03 June 2012 15:31 Go to previous messageGo to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
works now

[Updated on: Sun, 03 June 2012 15:39]

Report message to a moderator

Re: Xtext vs ANTLR syntactic predicates [message #880994 is a reply to message #880992] Sun, 03 June 2012 15:32 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
That's why I used parenthesis in the example:

function: => ( decl = declarator '{' ) id = ID '}’;

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 03.06.12 17:31, schrieb Oleg Bolshakov:
> model:
> ((declarator '{') func = function) | decl = declarator ;
>
> declarator:
> name = ID
> | '('declarator ')' ;
>
> function:
> => decl = declarator
> '{' id= ID '}'
> ;
> The result is the same: "non-LL(*) decision". The generated antlr
> grammar is rather big and difficult to understand for me because I'm new
> to antlr I can't understand why it force this error.
Re: Xtext vs ANTLR syntactic predicates [message #881001 is a reply to message #880994] Sun, 03 June 2012 15:58 Go to previous messageGo to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
function: => ( decl = declarator '{' ) id = ID '}';

That works even like this:
function:
	(=> decl = declarator) '{' id= ID '}'
;

I don't understand how does it work? Smile
Please, correct me if I am mistaken. I suppose syntactic predicates to work in case of ambiguities to show the parser what it must do (without any suggestions or apprehensions) if next symbols are <...> (I checked - almost the same said in documentation within dangling else example explanation). In antlr this expression precedes the predicate symbol:
(...)=> 
where ... is a grammar fragment.
What about Xtext? This expression follows the predicate symbols? Then what really changes this expression?:
(=> decl = declarator)
(there is no '{' in parenthesis). declarator may still refer to either declarator rule or function rule - why do parser now know what rule to apply?

[Updated on: Sun, 03 June 2012 15:59]

Report message to a moderator

Re: Xtext vs ANTLR syntactic predicates [message #881024 is a reply to message #881001] Sun, 03 June 2012 17:39 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You can read => as "grammar, if you are here and you can parse the next
expression, then take this path even if there are other paths that you
could take".

Does that help?

- henrik


On 2012-03-06 17:58, Oleg Bolshakov wrote:
> function: => ( decl = declarator '{' ) id = ID '}';
>
> That works even like this:
> function:
> (=> decl = declarator) '{' id= ID '}'
> ;
> I don't understand how does it work? :)
> Please, correct me if I am mistaken. I suppose syntactic predicates to
> work in case of ambiguities to show the parser what it must do (without
> any suggestions or apprehensions) if next symbols are <...> (I checked -
> almost the same said in documentation within dangling else example
> explanation). In antlr this expression precedes the predicate symbol:
> (...)=> where ... is a grammar fragment
> What about Xtext? This expression follows the predicate symbols? Then
> what really changes this expression?:
> (=> decl = declarator)(there is no '{' in parenthesis). declarator may
> refer to either declarator rule or function rule.
>
Re: Xtext vs ANTLR syntactic predicates [message #881030 is a reply to message #881024] Sun, 03 June 2012 18:07 Go to previous messageGo to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
Thank you, Henrik, very good explanation of what syntactic predicates do in Xtext. But I think antlr syntactic predicates work in another way, I suppose like this: "grammar, if you are here and you can parse the previous expression, then take the following (after sign '=>') path even if there are other paths that you could take". I want to have one more rule:
compound_expresion:
    '{' id= ID '}'

But the first sign from it ('{') must be used in a predicate expression to be able to distinct declaration from
function. So while in antlr I say : "if there is a declaration and a '{' then go next path" and I can then describe this path - in Xtext I suppose that this path was already parsed and I can't use compound_expresion because it was already parsed, if I will use it, I will have to use double '{'. Is there a solution to it?

UPD:
function:
	 => (decl = declarator cmp = compound_expresion)
;
and
function:
	 decl = declarator (=> cmp = compound_expresion)
;

still cause an non-LL(*) error. (why???)

UPD2:
function:
	 => decl = declarator cmp = compound_expresion
;

seems to be the same as
function:
	 => (decl = declarator) cmp = compound_expresion
;

and it compiles, but of course, in this way I can't parse declarations in the model rule:
model:
	func = function
	| decl = declarator 
;


UPD3:
I don't know why this didn't work (bug?):
function:
	 => (decl = declarator cmp = compound_expresion)
;
But I found the solution!!:
Model:
	(=> func = function)
	| decl = declarator 
;

declarator:
	name = ID
	| '('declarator ')' 
;

function:
	decl = declarator cmp = compound_expresion
;

compound_expresion:
	'{' id= ID '}'
;

[Updated on: Sun, 03 June 2012 18:27]

Report message to a moderator

Re: Xtext vs ANTLR syntactic predicates [message #881052 is a reply to message #881030] Sun, 03 June 2012 19:23 Go to previous message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
When trying to insert one more rule (with unordered group) to my function rule I got Xtext syntax error message: "can not use unordered groups in syntactic predicates" (I tell it here because I have not found such a limitation on using predicates neither in the Xtext documention, nor in blogs, like this one: http://dslmeinte.wordpress.com/2011/12/05/using-syntactic-predicates-in-xtext-part-1/).
Previous Topic:Whats the meaning of isPreIndexingPhase
Next Topic:Final variable not getting injected
Goto Forum:
  


Current Time: Wed Apr 24 20:36:05 GMT 2024

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

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

Back to the top