Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Ambiguity detected but why?
Ambiguity detected but why? [message #1770745] Wed, 16 August 2017 16:53 Go to next message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
Can you please explain why I get ambiguity between the edit and add alternatives in the Reuse parser rule in the grammar below. Everything works fine if the reuse assignment in the Link parser rule is just an optional (?), but if I change the cardinality to a multiple containment I get the error. I guess the parser doesn't take note of the diff keywords preceding the alternatives in Reuse- or is something else going on?? And also how do I fix it?? Would very muchprefer to do it with as little change to the grammar as possible :)

ReUseAbleReduced returns ReUseAble:
	Visual | Inertial | Collision
;

ReUseAbleReduce returns ReUseAble:
	Origin | Axis | Limit | Calibration | Dynamics | SafetyController
;

Link:
	{Link} 'Link' name=ID
	(('def' (inertial=Inertial | visual+=Visual | collision+=Collision)+)	 
		| ('reuse' isReuseOf=[Link] (reuse=Reuse)?)
	)?
;

Reuse:
	{Reuse} AddToReuse add=ReUseAbleReduced | EditReuse edit=AssignNewValue
	
;

AddToReuse:
	'Add' 'to' 'current' 'reuse'
;

EditReuse:
	'Edit' 'item' 'in' 'current' 'reuse'
;


AssignNewValue:
	{AssignNewValue} getRef=DotExpression '=' newReuseable=ReUseAble
;


DotExpression returns Ref:
    ReUsableRef ({DotExpression.ref=current}  "." tail=[ReUseAble])*
;

ReUsableRef returns Ref: 
	{ReUsableRef} reuseable=[ReUseAble]
;

Inertial:
	{Inertial} 'Inertial' (name=ID)?
;

Visual:
	{Visual} 'Visual' (name=ID)? 
;

Collision:
	'Collision' (name=ID)?
;

Re: Ambiguity detected but why? [message #1770748 is a reply to message #1770745] Wed, 16 August 2017 17:29 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11603
Registered: July 2009
Senior Member
can you please share a complete grammar

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Ambiguity detected but why? [message #1770809 is a reply to message #1770748] Thu, 17 August 2017 09:40 Go to previous messageGo to next message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
Thanks :) Here you go:


Robot:
	'Robot' name=ID
	 ('Topology' topologies+=Topology | 
	 	         links+=Link | 
	 	         joint+=Joint |
	 	         addto+=AddTo
	 )*
;

Topology:
	parent=[Link] (joint=JointRef child=Topology)?
;  

JointRef:
	 fix = '->' | rev = 'r->' | pris = 'p->' | cont = 'c->'  
;

ReUseAble: 
 	Link | Visual | Inertial | Collision
;

ReUseAbleReduced returns ReUseAble:
	Visual | Inertial | Collision
;

ReUseAbleReduce returns ReUseAble:
	Origin | Axis | Limit | Calibration | Dynamics | SafetyController
;
  
Link:
	{Link} 'Link' name=ID
	(('def' (inertial=Inertial | visual+=Visual | collision+=Collision)+)	 
		| ('reuse' isReuseOf=[Link] (reuse+=Reuse)*)
	)?
;

AddTo:
	(AddToLink link=[Link] 
		add = ReUseAbleReduced ) | 
	(AddToJoint joint=[Joint]
		add = ReUseAbleReduce   
	)
;

AddToLink:
	'Add' 'attributes' 'to' 'existing' 'link'
;

AddToJoint:
	'Add' 'attributes' 'to' 'existing' 'joint'
;

Reuse:
	{Reuse}  AddToReuse add=ReUseAbleReduced | EditReuse edit=AssignNewValue
;

AddToReuse:
	'Add' 'to' 'current' 'reuse'
;

EditReuse:
	'Edit' 'item' 'in' 'current' 'reuse'
;


AssignNewValue:
	{AssignNewValue} getRef=DotExpression '=' newReuseable=ReUseAble
;


DotExpression returns Ref:
    ReUsableRef ({DotExpression.ref=current}  "." tail=[ReUseAble])*
;

ReUsableRef returns Ref: 
	{ReUsableRef} reuseable=[ReUseAble]
;

Inertial:
	{Inertial} 'Inertial' (name=ID)?
	inertia=Inertia
	mass=Mass
	(origin=Origin)?
;

Inertia:
	{Inertia} 'Inertia' (name=ID)?
	'ixx' ixx=URDFAttrSignedNumeric 
	'ixy' ixy=URDFAttrSignedNumeric
	'ixz' ixz=URDFAttrSignedNumeric
	'iyy' iyy=URDFAttrSignedNumeric
	'iyz' iyz=URDFAttrSignedNumeric
	'izz' izz=URDFAttrSignedNumeric
;


Visual:
	{Visual} 'Visual' (name=ID)? 
	'Geometry' geometry=Geometry
	(origin=Origin)?               //problem: Kan ikke definere material uden origin pt
	('Material' material=Material)? //problem: Kan ikke definere material uden origin pt
	
;

Origin:
    {Origin} 'Origin' (name=ID)?
    'x' x=URDFAttrSignedNumeric 
	'y' y=URDFAttrSignedNumeric
	'z' z=URDFAttrSignedNumeric
    ('roll' roll=URDFAttrSignedNumeric | 'pitch' pitch=URDFAttrSignedNumeric | 'yaw' yaw=URDFAttrSignedNumeric)*
;

Mass:
	{Mass} 'Mass' (name=ID)?
	'massKilogram' massKilogram=URDFAttrSignedNumeric
;

Collision:
	'Collision' (name=ID)?
	'Geometry' geometry=Geometry
	(origin=Origin)?
;

Geometry:
	Box | Cylinder | Mesh | Sphere
	
;

//Tjek spec: order listing of dimensions?
Box:
	'Box' (name=ID)?
	'height' height=URDFAttrNumeric 
	'length' length=URDFAttrNumeric
	'width' width=URDFAttrNumeric 
;

Cylinder:
	'Cylinder' (name=ID)?
	'radius' radius=URDFAttrNumeric
	'length' length=URDFAttrNumeric	
;

//TODO: create ValueConverter to convert scale to Box
Mesh:
	'Mesh' (name=ID)?
	'pathToFile' pathToFile=URDFAttrSTRING
	//('scale' dimension=Box)?
;

Sphere:
	'Sphere' (name=ID)?
	'radius' radius=URDFAttrNumeric	
;

Material:
	Texture | Color 
;


Texture:
	'Texture' (name=ID)?
	'pathToFile' pathToFile=URDFAttrSTRING
;


// RGBA values must be floats between 0 and 1 incl 
Color:
	'Color' (name=ID)?
	'red' red=URDFAttrFloat 
	'green' green=URDFAttrFloat 
	'blue' blue=URDFAttrFloat 
	'alpha' alpha=URDFAttrFloat	
;

Joint:
	'Joint' name=ID
	(('def'  'ChildOf' childOf=[Link] 
			 'ParentOf' parentOf=[Link] 
			 'Type' type=JointType) 
			 ( origin=Origin | axis=Axis | limit=Limit | calibration=Calibration | dynamics=Dynamics | safetycontroller=SafetyController)* | 
	 //HOW TO REUSE: CHANGE PARENT AND CHILD LINKS??
	 ('reuse' isReuseOf=[Joint] 
	 	'ChildOf' childOf=[Link] 
		'ParentOf' parentOf=[Link] 
	 	(reuse=Reuse)?
	 )
	)
;

enum JointType:
		fixed = 'fixed' |revolute = 'revolute' |  prismatic = 'prismatic' | continuous = 'continuous'
;

/* Binary values must be 0 or 1 - digitsum must be 1, WHY NEED TO DEFINE ALL THREE?? */
//keyword aliases: 'xyz' or 'x', 'y', 'z'
Axis:
	'Axis' (name=ID)?
	'x' x=URDFAttrINT
	'y' y=URDFAttrINT
	'z' z=URDFAttrINT 
;

Limit:
	'Limit' (name=ID)?
	'effort' effort=URDFAttrSignedNumeric 
	'velocity' velocity=URDFAttrSignedNumeric 
	('lower' lower=URDFAttrSignedNumeric | 'upper' upper=URDFAttrSignedNumeric)* 
;

Calibration:
	 {Calibration} 'Calibration' (name=ID)?
	 ('rising' rising=URDFAttrSignedNumeric | 'falling' falling=URDFAttrSignedNumeric) 
;

Dynamics:
	{Dynamics} 'Dynamics' (name=ID)?
	('friction' friction=URDFAttrSignedNumeric | 'damping' damping=URDFAttrSignedNumeric)+
;


SafetyController:
	'SafetyController' (name=ID)?
	'k_velocity' k_velocity=URDFAttrSignedNumeric
	('k_position' k_position=URDFAttrSignedNumeric |
	 'softLowerLimit' softLowerLimit=URDFAttrSignedNumeric | 
	 'softUpperLimit' softUpperLimit=URDFAttrSignedNumeric)*
;


//Should we cut Mimic from the spec - NEED TO GET INTERPRETATION OF ATTRS??
/*Mimic:
	'Mimic' (name=ID)?
	'mimics' mimics=[Joint]
	('multiplier' multiplier=URDFAttrSignedNumeric)?
	('offSet' offSet=URDFAttrSignedNumeric)?
;*/


/*Constant:
;*/

URDFAttrSignedNumeric:
	value = SIGNED_NUMERIC
;

URDFAttrFloat:
	value = FLOAT
;

URDFAttrINT:
	value = INT
;

URDFAttrNumeric:
	value = NUMERIC
;

URDFAttrSTRING:
	value = STRING
;

FLOAT returns ecore::EFloat: 
	INT '.' INT
;

SCIENTIFIC returns ecore::EBigDecimal:
	FLOAT 'e' ('+' | '-')? INT 
;

SIGNED_NUMERIC:
	('-')? (INT | FLOAT | SCIENTIFIC)
;

NUMERIC:
	INT | FLOAT | SCIENTIFIC
;



Re: Ambiguity detected but why? [message #1770815 is a reply to message #1770809] Thu, 17 August 2017 10:37 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11603
Registered: July 2009
Senior Member
a few remarks upfront: you should take the warnings the grammar editor gives serious =>




with

			parserGenerator = {
				debugGrammar = true
			}


you can generate a debug grammar to be opened with antlrworks

the problem is:

if you have multiple links. do they to the link list in robot, or into the links

giving the parser a small hint might help e.g.

Link:
	{Link} 'Link' name=ID
	(('def' (inertial+=Inertial | visual+=Visual | collision+=Collision)+)	 
		| ('reuse' isReuseOf=[Link] (->reuse+=Reuse)*)
	)?
;



Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Ambiguity detected but why? [message #1770817 is a reply to message #1770815] Thu, 17 August 2017 10:53 Go to previous messageGo to next message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
Okay I think I get it. Thank you very much for your help :)
Re: Ambiguity detected but why? [message #1770870 is a reply to message #1770815] Fri, 18 August 2017 06:26 Go to previous messageGo to next message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
The arrow did the trick :D Thanks again! I'll try out antrlworks as well. I have tried to find documentation for the arrow in the Xtext grammar but with little luck. Can you refer me something, so I can read up on exactly whats happening here?
Re: Ambiguity detected but why? [message #1770871 is a reply to message #1770870] Fri, 18 August 2017 06:28 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11603
Registered: July 2009
Senior Member
keyword in documentation is "First Token Set Predicates"

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Ambiguity detected but why? [message #1770874 is a reply to message #1770871] Fri, 18 August 2017 08:17 Go to previous message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
Great, you just made my life a lot easier :D Thanks a lot!!
Previous Topic:implement Xpath using Xtext
Next Topic:Problem faced with Xtext when running in headless application
Goto Forum:
  


Current Time: Fri Jan 19 17:50:59 GMT 2018

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

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