|
Re: non-LL(*) decision due to recursive rule invocations [message #893605 is a reply to message #893397] |
Wed, 04 July 2012 19:39 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
Your Statements rule has multiple entries that could start with ID.
You can use a predicate to pick how much the parser should see before
picking that path, or use backtracking (where this is done
automatically, but sometimes with surprising results when you have
imperfections in your spec).
Also look at Left factoring in an expression grammar.
Have not looked at your grammar in detail so don't know which approach
would work best for you as you build out your language), but as a
general advice (IMO) left factoring (when possible) gives you the least
surprises, and then only use syntactic predicates when you have a true
language ambiguity (e.g. typical if-if-else).
Regards
- henrik
On 2012-03-07 13:45, Andrew A wrote:
> Hello!
>
> I have a grammar:
>
>
> grammar org.xtext.example.mydsl.MyDsl
>
> generate myDsl "megaurl"
>
> Model:
> statements+=Statement*;
>
> Statement: Text | Var | Braced | Macro;
>
> Text: val = (WSP | ID | PUNCTUATION | '$');
>
> Braced: {Braced} '{' statements+=Statement* '}';
>
> Var: '${' name=ID '}';
>
> Macro: spec=ID body=Braced;
>
> terminal PUNCTUATION : ('(' | ')' | ',' | '.' | ';' | ':' | '[' | ']' |
> '+' | '-' | '*' | '/' );
>
>
> terminal ID: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
> terminal WSP: (' '|'\t'|'\r'|'\n')+;
>
>
> Generating language artifacts results in error:
>
> error(211):
> ../org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyDsl.g:119:1:
> [fatal] rule ruleStatement has non-LL(*) decision due to recursive rule
> invocations reachable from alts 1,4. Resolve by left-factoring or using
> syntactic predicates or using backtrack=true option.
>
> Could you give me a hint, please, how to fix that?
> And what is "backtrack=true option"?
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03022 seconds