Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText suggests left-factoring. Why?
XText suggests left-factoring. Why? [message #1743084] Sun, 11 September 2016 19:47 Go to next message
Eric Salemi is currently offline Eric SalemiFriend
Messages: 35
Registered: September 2016
Location: Belgium
Member
I have the following model:

grammar com.septentrio.infrastructure.smf.Model with org.eclipse.xtext.common.Terminals

generate language "http://www.septentrio.com/infrastructure/smf/Model"

Model:
    ('package' name=QualifiedName)?
    (imports+=Import)*
    (entities+=Entity)*;

Import:
    'import' importedNamespace=QualifiedNameWithWildcard;

QualifiedName:
    ID ('.' ID)*;

QualifiedNameWithWildcard:
    QualifiedName '.*'?;

Entity:
    Class|Test;

Class:
	'class' name=ID
	( '<' (params+=ID','?)+ '>' )?
	( 'extends' (parents+=[Class|QualifiedName]','?)+ )?
	( '{' (members+=Member)* '}' )?;

Member:
	Attribute|Method;

Attribute:
	type=ElementType (array='['(length=INT)?']')? name=ID;

Method:
	type=ElementType name=ID '()';

ElementType:
	BasicType|ClassType;

BasicType:
	type=('any'|'enum'|'logical'|'string'|'integer'|'float');

ClassType:
	type=[Class|QualifiedName] ( '<' (params+=[Class|QualifiedName]','?)+ '>' )?;

Test:
	'test' name=ID '{' (expressions+=Expression)* '}';

Expression:
    Primary ({SubscriptReference.operand=current} (indices+=SubscriptIndex)*)?;

Primary returns Expression:
    '(' Expression ')' |
    {Instance} class=[Class] |
    {Metaclass} '?' class=[Class] |
    {Identifier} name=ID;

SubscriptIndex:
    {DotIndex} '.' name=[Member] |
    {ParenthesisIndex} '(' (argument=Expression)? ')';


I get the following error:

[fatal] rule ruleExpression 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.


What's wrong?
Re: XText suggests left-factoring. Why? [message #1743087 is a reply to message #1743084] Mon, 12 September 2016 03:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13888
Registered: July 2009
Senior Member
the problem is here

test t1 { // multiple expressions
a
(b)
(c)
}

vs

test t1 {
a(b)(c) // subscripts
}

the next problem is

{Instance} class=[Class] vs {Identifier} name=ID;

which is ambigous cause it is parsed like class=ID


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText suggests left-factoring. Why? [message #1743176 is a reply to message #1743087] Tue, 13 September 2016 02:18 Go to previous messageGo to next message
Eric Salemi is currently offline Eric SalemiFriend
Messages: 35
Registered: September 2016
Location: Belgium
Member
Thanks!

Problem 1:
I solved in a different way

Problem 2:
I had assumed that the parser would only perform the "Instance" action if the string corresponds to an existing "Class". If not it would fallback to the "Identifier" action with any other string. Can I achieve something like that?

Re: XText suggests left-factoring. Why? [message #1743177 is a reply to message #1743176] Tue, 13 September 2016 03:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13888
Registered: July 2009
Senior Member
You would have to fiddle around the the metamodel and maybe linker on that. The parser does not do linking at all. I have never implemented such a thing myself

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText suggests left-factoring. Why? [message #1743219 is a reply to message #1743177] Tue, 13 September 2016 11:13 Go to previous message
Eric Salemi is currently offline Eric SalemiFriend
Messages: 35
Registered: September 2016
Location: Belgium
Member
Ok, I will move the logic in the linking phase then.
Previous Topic:XBase language + Matlab code generation?
Next Topic:How to bind Formatter2
Goto Forum:
  


Current Time: Wed Apr 21 13:37:03 GMT 2021

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

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

Back to the top