Skip to main content



      Home
Home » Modeling » TMF (Xtext) » XText suggests left-factoring. Why?
XText suggests left-factoring. Why? [message #1743084] Sun, 11 September 2016 15:47 Go to next message
Eclipse UserFriend
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] Sun, 11 September 2016 23:45 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: XText suggests left-factoring. Why? [message #1743176 is a reply to message #1743087] Mon, 12 September 2016 22:18 Go to previous messageGo to next message
Eclipse UserFriend
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] Mon, 12 September 2016 23:00 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: XText suggests left-factoring. Why? [message #1743219 is a reply to message #1743177] Tue, 13 September 2016 07:13 Go to previous message
Eclipse UserFriend
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: Sat Jul 05 07:02:25 EDT 2025

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

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

Back to the top