Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » "Decision can match input such as "')'" using multiple alternatives: 1, 2"
icon5.gif  "Decision can match input such as "')'" using multiple alternatives: 1, 2" [message #639748] Wed, 17 November 2010 16:28 Go to next message
Kai Maschke is currently offline Kai MaschkeFriend
Messages: 16
Registered: October 2010
Junior Member
Hi,

I'm trying to define a language which should be used for definig transformation.
So I defined my transformation operations like this:
PrimitiveTransformation:
	GetNthChar | GetDelimited | GetSubstring | 
	Concat | AddType | SubstractType |
	MultiplyType | DivideType | Constant;

TransVal:
	{PrimitiveTransformation} | {STRING};

GetNthChar returns STRING:
	{GetNthChar} 'get_nth_char(' val=TransVal ',' pos=INT ')';

GetDelimited returns STRING:
	{GetDelimited} 'get_delimited(' val=TransVal ',' char=STRING ')';
	
GetSubstring returns STRING:
	{GetSubstring} 'get_substring(' val=TransVal ',' lolimit=INT ',' hilimit=INT ')';
	
Concat returns STRING:
	{Concat} 'concat(' val1=TransVal ',' val2=TransVal ')';
	
AddType returns STRING:
	{AddType} 'add_type(' val1=TransVal ',' val2=TransVal ')';

SubstractType returns STRING:
	{SubstractType} 'substract_type(' val1=TransVal ',' val2=TransVal ')';
	
MultiplyType returns STRING:
	{MultiplyType} 'multiply_type(' val1=TransVal ',' val2=TransVal ')';
	
DivideType returns STRING:
	{DivideType} 'divide_type(' val1=TransVal ',' val2=TransVal ')';

Constant returns STRING:
	constant=STRING;


While generating the code I get the following warnings:
Quote:

...:1459:1: Decision can match input such as "')'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:1459:1: Decision can match input such as "EOF" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ...:1459:1: Decision can match input such as "','" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(201):...:1459:1: The following alternatives are unreachable: 2



I am new to XText. Maybe I didn't figure out yet how to define a grammar well.
Can you see the problem in my grammar?

Here an example how it should look:
concat(
  GetSubstring('Attr1',0,3),
  'Attr2'
)


Re: "Decision can match input such as "')'" using multiple alternatives: 1, 2" [message #639788 is a reply to message #639748] Wed, 17 November 2010 19:16 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
The Transval rule looks...weird. (So much so that I'm surprised the grammar even validates.) Also, what is the STRING rule in this case: the default terminal rule or something else?

In any case, be sure to read the ultimate explanation of expression parsing with Xtext: http://blog.efftinge.de/2010/08/parsing-expressions-with-xte xt.html

The basic problem of your grammar is that the parser (apparently) can't decide whether some ')' belongs to an expression (PrimitiveTransformation) which is an argument to a method call or is the closing parenthesis of that method call. (Ditto for the other ones.) The error actually come from the Antlr parser generator.

You're already quite far with your grammar but be sure to read Sven's blog and rework the grammar to follow that pattern and you should have it working in no-time.


Re: "Decision can match input such as "')'" using multiple alternatives: 1, 2" [message #639943 is a reply to message #639748] Thu, 18 November 2010 13:47 Go to previous message
Kai Maschke is currently offline Kai MaschkeFriend
Messages: 16
Registered: October 2010
Junior Member
Hi,

thanks Meinte! I think that I now understand the definition of a grammar a bit more and I solved the problem with reworking the grammar.

Thanks!
Previous Topic:xtext parser node
Next Topic:importURI Resource Path
Goto Forum:
  


Current Time: Fri Mar 29 09:41:36 GMT 2024

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

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

Back to the top