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
Hello,
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);

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

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

VariableValue:
	PrimitiveValue | VariableReference
;

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: 12239
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

VariableReference:
(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

VariableReference:
(ref=[Type])
;


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Keyword/name=ID conflicts
Next Topic:Syntax Error in lambda implementing Xtext quickfixes
Goto Forum:
  


Current Time: Tue Sep 25 00:51:24 GMT 2018

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

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

Back to the top