Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » non-LL(*) decision due to recursive rule invocations
non-LL(*) decision due to recursive rule invocations [message #893397] Tue, 03 July 2012 20:45 Go to next message
Andrew A is currently offline Andrew AFriend
Messages: 9
Registered: June 2012
Junior Member
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"?


Re: non-LL(*) decision due to recursive rule invocations [message #893605 is a reply to message #893397] Wed, 04 July 2012 19:39 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
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"?
>
>
>
Previous Topic:Introduction to OCL
Next Topic:Cross-reference mistake
Goto Forum:
  


Current Time: Wed Feb 26 17:12:56 GMT 2020

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

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

Back to the top