Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Alternatives can never be matched
Alternatives can never be matched [message #1838868] Sun, 07 March 2021 14:40 Go to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi all,

I am having some issues with Xtext.

Lets say that I have the following rules.

Node:
Circle | Square | Triangle

Circle:
Name = ID ;

Square:
Name = ID ;

Triangle:
Name=ID

I get an error saying:
Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2, 3. Alternatives 2,3 can never be matched.

I understand why this happens. being that the name is ID in all of them while creating a node there will be no way to know if it is a circle, square or triangle.

I know that I can add a keyword before the name to distinct them, but I do not want to do that because I have the following statement:

circle+=Circle ("," circle+=Circle)* ";" )*

And if I add a keyword I will get:
Circle c1;
Circle c2;

while I want

Circle c1, c2;

And I also do not want to change ID.

Any way around this?

Many thanks!
Re: Alternatives can never be matched [message #1838870 is a reply to message #1838868] Sun, 07 March 2021 15:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
you can either move the keyword or

CircleList: "Circle" circles+=Circle (","circles+=Circle)*;
Circle: name=ID

use m2m / IDerivedStateComputer http://xtextcasts.org/episodes/18-model-optimization


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Alternatives can never be matched [message #1838871 is a reply to message #1838868] Sun, 07 March 2021 15:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7220
Registered: July 2009
Senior Member
HI

What you have programmed has excatly zero difference between Circl/Triangle/Square so you cannot expect Xtext to telepathically decide which you mean.

Consider something more familiar such as Java where you have PackageName/ClassName/FieldName with a declaration that clarifies the intent of the name so that subsequent usage does not confuse Package and Field references.

You need to introduce shape declarations such as

CircleDef := 'Circle' ID (',' ID)*;
SquareDef := 'Square' ID (',' ID)*;

ShapeDef := CircleDef | SquareDef;

circle += CircleDef ...

Regards

Ed Willink
Re: Alternatives can never be matched [message #1838874 is a reply to message #1838871] Sun, 07 March 2021 17:09 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi Ed,

Thank you for your answer. However, when I try your approach, CircleDef is in light gray, and it is not reachable. So when I try to write the grammar, circle will not show up at all.

If I change it to
CircleDef := 'Circle' name=ID (',' name=ID)*;

It fixes that, but then I get:
This assignment will probably overwrite the previously assigned value of name, so I cannot do that either.

Any other option?

Thanks!
Re: Alternatives can never be matched [message #1838875 is a reply to message #1838874] Sun, 07 March 2021 18:38 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7220
Registered: July 2009
Senior Member
Hi

LIght gray means not referenced.

I suggest you follow an Xtext tutorial so that you learn the basic concepts before you ask for them all to be explained .

Regards

Ed Willink
Previous Topic:Begginer on Xtext Validation
Next Topic:Ambiguous grammar
Goto Forum:
  


Current Time: Thu Jul 29 18:35:29 GMT 2021

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

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

Back to the top