Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » OneOf
OneOf [message #1790616] Wed, 13 June 2018 15:14 Go to next message
David Horacek is currently offline David HoracekFriend
Messages: 3
Registered: June 2018
Junior Member
for few days I'm still struggling with the basics of grammar, so I hope someone can help me out.

I' trying very simple example of constants and variables:
const a = 1;
const b = "asd";
var c = "asd";
var d = a;
var e = c;

The Grammar I've come up with looks like this:
Domainmodel: (elements+=Type)*;

terminal FLOAT: ('+' | '-')? INT ('.' (INT)?)?;

PrimitiveValue: value=(STRING|FLOAT);

	ConstantDeclaration | VariableDeclaration
	'const' name=ID '=' value=PrimitiveValue ';'

	'var' name=ID ('=' value=[VariableValue])? ';'

	PrimitiveValue | VariableReference

	(ref=[VariableDeclaration] | ref=[ConstantDeclaration])

Error says that the problem is two possible results... which I guess comes from VariableReference where ConstantDeclaration can fit into both because it fits inside value property of VariableDeclaration? ... I'm not really sure though.

Can someone please explain it a little bit more in depth or provide and example how to write a grammar for such language case?

Thanks in advance.
Re: OneOf [message #1790821 is a reply to message #1790616] Mon, 18 June 2018 14:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14079
Registered: July 2009
Senior Member
the problem is

ref=[VariableDeclaration] is short for ref=[VariableDeclaration|ID] which says: refer to VariableDeclaration, parse ID

so it is parsed as if there is a ref=ID

so in your case

(ref=ID | ref=ID)

which is obviously ambigious

=> you either need to disabigue the both syntax wise or you need to make the one reference


Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:Keyword/name=ID conflicts
Next Topic:Syntax Error in lambda implementing Xtext quickfixes
Goto Forum:

Current Time: Tue Oct 26 13:20:13 GMT 2021

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

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

Back to the top