Xtext vs ANTLR syntactic predicates [message #880977] |
Sun, 03 June 2012 14:56 |
Oleg Bolshakov 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 #881030 is a reply to message #881024] |
Sun, 03 June 2012 18:07 |
Oleg Bolshakov 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03857 seconds