Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Rule has non-LL(*) decision even tho its copied from a lecture
Rule has non-LL(*) decision even tho its copied from a lecture [message #1811127] Tue, 27 August 2019 05:05 Go to next message
Eclipse UserFriend
Hi
I need to parse Expressions in my DSL and copied the grammar pretty much exactly from here: http://dsl-course.org/

But when I parse it I get two errors:


Quote:

InternalXtextTest.g:6065:3: [fatal] rule ruleOr has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.

InternalXtextTest.g:6131:3: [fatal] rule ruleAnd has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.


I'm really confused why this is happening since my version is practically 1 to 1 what is used everywhere else.

Heres my code for the expressions:

Expression:
	Or;

Or returns Expression:
	And ({Or.left=current} ('OR' | 'or') right=And)*;

And returns Expression:
	Equality ({And.left=current} ('AND' | 'and') right=Equality)*;

Equality returns Expression:
	Comparison ({Equality.left=current} ('!=' | '==') right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} ('>=' | '<=' | '<' | '>') right=PlusOrMinus)*;

PlusOrMinus returns Expression:
	MultiOrDivide ({PlusOrMinus.left=current} ('+' | '-') right=MultiOrDivide)*;

MultiOrDivide returns Expression:
	Primary ({MultiOrDivide.left=current} ('*' | '/') right=Primary)*;

Primary returns Expression:
	'(' Expression ')' | '!' expression=Primary | '-' expression=Primary | Atomic;

Atomic returns Expression:
	{Expression} DOUBLE | {Expression} INT | {Expression} STRING | var=[VariableName];


Update:
I found out that it has to do with my VariableName definition. If I exclude that part of the expression that says " | var=[VariableName]" it works fine.
This confuses me even more.
This is my code for VariableAssignments:

  
VariableAssignment:
	name=VariableName '=' value=Expression ';';

VariableName:
	name=(ID | TERMINAL_CONSTANT);

[Updated on: Tue, 27 August 2019 05:11] by Moderator

Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1811128 is a reply to message #1811127] Tue, 27 August 2019 05:27 Go to previous messageGo to next message
Eclipse UserFriend
Hello Jakob,

a nice introduction to expression languages in Xtext is available under https://youtu.be/d3JymwcB_TM

Maybe it helps you further.

Tamás
Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1811132 is a reply to message #1811128] Tue, 27 August 2019 06:06 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, tho I already watched that twice.. :/
Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1811137 is a reply to message #1811132] Tue, 27 August 2019 07:59 Go to previous messageGo to next message
Eclipse UserFriend
can you please provide a complete grammar. for me it looks more like a problem with double.


Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1811144 is a reply to message #1811137] Tue, 27 August 2019 09:26 Go to previous messageGo to next message
Eclipse UserFriend
Uhm I don't think to post my whole grammar is gonna help much cause its 750 lines.. and most of it is string literal constants.

So I'm gonna post the actual "logic" of my grammar without all the constants.

grammar com.me.XtextTest with org.eclipse.xtext.common.Terminals

generate xtextTest 'http://www.me.com/XtextTest'

Model:
	statements+=Statement*;

terminal DOUBLE:
	('0'..'9')+ '.' ('0'..'9')*;

terminal COMMENT:
	'#' !('\n' | '\r')* ('\r'? '\n')?;

terminal LiteralBoolean:
	'true' | 'false' | 'TRUE' | 'FALSE';


Statement:
	{Statement} ('RETURN' | 'return') ';' |
	VariableAssignment |
	IfStatement |
	('PRINT' | 'print') '(' Expression ')' ';' |
	('print_reset' | 'PRINT_RESET') ';'
	("setaddressbook"|"SETADDRESSBOOK") '(' Expression (',' exps+=Expression ',' exps+=Expression ','
	exps+=Expression)? ')' ';' ;

IfStatement:
	('if' | 'IF') '(' condition=Expression ')' '{' statements+=Statement* '}' (=> 'else' (('if' | 'IF') '('
	else_condition=Expression ')')? '{'
	elseStatements+=Statement* '}')*;

VariableAssignment:
	name=VariableName '=' value=Expression ';';

VariableName:
	name=ID ;

Expression:
	Or;

Or returns Expression:
	And ({Or.left=current} ('OR' | 'or') right=And)*;

And returns Expression:
	Equality ({And.left=current} ('AND' | 'and') right=Equality)*;

Equality returns Expression:
	Comparison ({Equality.left=current} ('!=' | '==') right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} ('>=' | '<=' | '<' | '>') right=PlusOrMinus)*;

PlusOrMinus returns Expression:
	MultiOrDivide ({PlusOrMinus.left=current} ('+' | '-') right=MultiOrDivide)*;

MultiOrDivide returns Expression:
	Primary ({MultiOrDivide.left=current} ('*' | '/') right=Primary)*;

Primary returns Expression:
	'(' Expression ')' | '!' expression=Primary | '-' expression=Primary | Atomic;

Atomic returns Expression:
	{VarRef} var=[VariableName] | {Expression} DOUBLE | {Expression} INT | {Expression} STRING
	| ('strlen' | 'STRLEN') '(' Expression ')'
	| ('trim' | 'TRIM') '(' exps+=Expression (',' exps+=Expression (',' exps+=Expression (',' TrimKeyword)?)?)? ')';

Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1811145 is a reply to message #1811144] Tue, 27 August 2019 09:36 Go to previous messageGo to next message
Eclipse UserFriend
this is still incomplete and generates fine with an improvised

TrimKeyword:
'TRIM'
;

=> please try to create a really minified grammar that actually has the problem.
otherwise i cannot / wont help
Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1811146 is a reply to message #1811145] Tue, 27 August 2019 09:47 Go to previous messageGo to next message
Eclipse UserFriend
Huh okay, I'm sorry.
I'll try to get the smallest version which shows the problem.

Thanks for the help sofar
Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1814041 is a reply to message #1811146] Mon, 02 September 2019 05:49 Go to previous messageGo to next message
Eclipse UserFriend
Okay, I found the smallest Version of my grammar that still produces the error::

grammar com.me.XtextTest with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate xtextTest 'http://www.me.com/XtextTest'

Model:
	statements+=Statement*;

terminal DOUBLE:
	('0'..'9')+ '.' ('0'..'9')*;

@Override
terminal INT returns ecore::EInt:
	('0'..'9')+;
terminal COMMENT:
	'#' !('\n' | '\r')* ('\r'? '\n')?;
terminal LiteralBoolean:
	'true' | 'false' | 'TRUE' | 'FALSE'; OR_KEYWORD:
	'OR' | 'or';

AND_KEYWORD:
	'AND' | 'and';

COMPARISON_OPERATOR:
	'==' | '<=' | '>=' | '!=' | '<' | '>';

Statement:
	{Statement} ('RETURN' | 'return') ';' |
	VariableAssignment |
	SelectTableEntry;

SelectTableEntry:
	('selecttableentry' | 'SELECTTABLEENTRY') ('from' | 'FROM') tableName=ID ('WITH' | 'with')
	'(' selCond=GeneralSelectionCondition ')';

GeneralSelectionCondition:
	'!' GeneralSelectionCondition | '(' GeneralSelectionCondition ')' | GeneralSelectionComposition
	({GeneralSelectionCondition.left=current} op=(OR_KEYWORD | AND_KEYWORD) right=GeneralSelectionComposition)*;

GeneralSelectionComposition:
	tableFieldName=GeneralTableFieldName op=(COMPARISON_OPERATOR | 'LIKE' | 'like' | '!LIKE' | '!like') expr=Expression;

GeneralTableFieldName:
	ID;

VariableAssignment:
	name=VariableName '=' value=Expression ';';

VariableName:
	name=(ID);

Expression:
	Or;

Or returns Expression:
	And ({Or.left=current} OR_KEYWORD right=And)*;

And returns Expression:
	Equality ({And.left=current} AND_KEYWORD right=Equality)*;

Equality returns Expression:
	Comparison ({Equality.left=current} ('!=' | '==') right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} ('>=' | '<=' | '<' | '>') right=PlusOrMinus)*;

PlusOrMinus returns Expression:
	MultiOrDivide ({PlusOrMinus.left=current} ('+' | '-') right=MultiOrDivide)*;

MultiOrDivide returns Expression:
	Primary ({MultiOrDivide.left=current} ('*' | '/') right=Primary)*;

Primary returns Expression:
	'(' Expression ')' | '!' expression=Primary | '-' expression=Primary | Atomic;

Atomic returns Expression:
	{VarRef} var=[VariableName] | {Expression} DOUBLE | {Expression} INT | {Expression} STRING';




It is definitely related to the rule: GeneralFieldName

I couldn't find out how to fix this tho.
Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1814051 is a reply to message #1814041] Mon, 02 September 2019 06:24 Go to previous messageGo to next message
Eclipse UserFriend
here is a much more minified version of the grammar

Model:
	statements+=SelectTableEntry;
	
OR_KEYWORD:
	'OR' | 'or';


COMPARISON_OPERATOR:
	'==' | '<=' | '>=' | '!=' | '<' | '>';

SelectTableEntry:
	
	'(' selCond=GeneralSelectionCondition ')';

GeneralSelectionCondition:
	'!' GeneralSelectionCondition
	({GeneralSelectionCondition.left=current} op=(OR_KEYWORD ) right=GeneralSelectionComposition)*;

GeneralSelectionComposition:
	tableFieldName=ID op=(COMPARISON_OPERATOR) expr=Expression;

Expression:
	Or;

Or returns Expression:
	Comparison ({Or.left=current} OR_KEYWORD right=Comparison)*;

Comparison returns Expression:
	Primary ({Comparison.left=current} ('>=' | '<=' | '<' | '>') right=Primary)*;

Primary returns Expression:
	'!' expression=Primary | Atomic;

Atomic returns Expression:
	{VarRef} var=ID;

[Updated on: Mon, 02 September 2019 06:27] by Moderator

Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1814053 is a reply to message #1814051] Mon, 02 September 2019 06:38 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, yeah true this is even smaller and still generates the Error.
Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1814054 is a reply to message #1814053] Mon, 02 September 2019 06:45 Go to previous messageGo to next message
Eclipse UserFriend
you might use predicates => to help the parser if the OR belongs to inner our outer like

Or returns Expression:
Comparison =>({Or.left=current} OR_KEYWORD right=Comparison)*;

GeneralSelectionCondition:
'!' GeneralSelectionCondition
=>({GeneralSelectionCondition.left=current} op=(OR_KEYWORD ) right=GeneralSelectionCompositio
Re: Rule has non-LL(*) decision even tho its copied from a lecture [message #1814055 is a reply to message #1814054] Mon, 02 September 2019 08:07 Go to previous message
Eclipse UserFriend
Thanks that works well ^^

Thank you very much
Previous Topic:Getting java.lang.OutOfMemoryError: GC overhead limit exceeded exception
Next Topic:Couldn't resolve reference to Field 'x'
Goto Forum:
  


Current Time: Mon Apr 21 09:00:38 EDT 2025

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

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

Back to the top