Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » multiple alternatives error during the generation of the artifacts
multiple alternatives error during the generation of the artifacts [message #1800361] Tue, 25 December 2018 22:09 Go to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Hi all
When I try to generate the grammar have the error.
It happens because of the question in the rule
Atomic returns Expression:
	{IntConstant} value=INT |
	{StringConstant} value=STRING |
	{BoolConstant} value=('true' | 'false') |
	{VariableRef} "."? value=VariableDeclarationRef | //Error because of this string
	{SelectOp} value=AtOperator |
	{MemberDefinition} value=ClassMemberDefinition|
	{CreateAtom} value=Create;


But, when I remove the question everything is fine. I know why this error is happening in main but don't understand this particular case.


My grammar is

grammar org.blockchain.rell.Rell with org.eclipse.xtext.common.Terminals

generate rell "http://www.blockchain.org/rell/Rell"

Model:
	entities+=ClassDefinition*
	operations+=Operation*;

ClassDefinition:
	'class' name=ID ('extends' superType=[ClassDefinition])? '{'
	attributeListField+=AttributeListField*
	'}';

AttributeListField:
	mutable=Mutable? key=Key? index=Index? attributeList+=RelAttrubutesList ';';

Operation:
	"operation" name=ID "(" parameters=RelAttrubutesList? ")" "{" statements+=Statement* "}";

Statement:
	(relation=Relational | variable=OperationVariable) ';';

OperationVariable:
	assessModificator=(Var | Val) variable=Variable;

Variable:
	name=VariableDeclaration (('=' expression=Expression)?);

Relational:
	Update | Delete | Create | AtOperator;

Update:
	'update' entity=[ClassDefinition] '(' conditions+=Expression* ')' '{' variableList+=VariableInit
	(',' variableList+=VariableInit*)? '}';

Delete:
	'delete' entity=[ClassDefinition] '(' conditions+=Expression (',' conditions+=Expression)* ')';

Create:
	'create' (entity=[ClassDefinition]) '(' (createWhatPart+=CreateWhatPart  (','
	createWhatPart+=CreateWhatPart)*)? ')';

CreateWhatPart:
	(varDeclRef=VariableDeclarationRef '=')?
	condition+=Expression;

AtOperator:
	(tableNameWithAlias+=TableNameWithAlias | '(' tableNameWithAlias+=TableNameWithAlias (','
	tableNameWithAlias+=TableNameWithAlias)* ')') Ampersand ampersandModificator=AmpersandModificator? '{'
	conditions+=Expression (',' conditions+=Expression)* '}';

ClassMemberDefinition:
	classRef=ClassRef "." variableDeclarationRef=VariableDeclarationRef;

ClassRef:
	value=[TableNameWithAlias];

TableNameWithAlias:
	{ClassRefDecl} (name=ID ':' classDef=[ClassDefinition]) |
	{JustNameDecl} name=[ClassDefinition];


VariableDeclarationRef:
	 decl=[VariableDeclaration|ValuableID];

VariableInit:
	name=[VariableDeclaration] '=' expression=Expression;

Expression:
	or=Or;

Or returns Expression:
	And ({Or.left=current} "or" right=And)*;

And returns Expression:
	Equality ({And.left=current} "and" right=Equality)*;

Equality returns Expression:
	Comparison ({Equality.left=current} op=("==" | "!=")
	right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} op=(">=" | "<=" | ">" | "<")
	right=PlusOrMinus)*;

PlusOrMinus returns Expression:
	MulOrDiv (({Plus.left=current} PlusChar | {Minus.left=current} MinusChar)
	right=MulOrDiv)*;

MulOrDiv returns Expression:
	Primary ({MulOrDiv.left=current} op=(MulChar | DivChar)
	right=Primary)*;

Primary returns Expression:
	'(' Expression ')' |
	{Not} "not" expression=Primary |
	Atomic;

Atomic returns Expression:
	{IntConstant} value=INT |
	{StringConstant} value=STRING |
	{BoolConstant} value=('true' | 'false') |
	{VariableRef} "."? value=VariableDeclarationRef | //Error because of this string
	{SelectOp} value=AtOperator |
	{MemberDefinition} value=ClassMemberDefinition|
	{CreateAtom} value=Create;

RelAttrubutesList:
	value+=Variable (',' value+=Variable)*;

VariableDeclaration:
	name=ValuableID ((':' type=TypeReference)?);

TypeReference:
	primitive=PrimitiveType | entityType=ClassType;

ClassType:
	type=[ClassDefinition];

PrimitiveType:
	Text | Tuid | Pubkey | Name | Timestamp | Integer | Json | ByteArray | Boolean;

ValuableID:
	PrimitiveType | ID;

AmpersandModificator:
	PlusChar | MulChar | QuestionChar;

Name:
	'name';

Pubkey:
	'pubkey';

Timestamp:
	'timestamp';

Tuid:
	'tuid';

Boolean:
	'bool';

Json:
	'json';

Integer:
	'integer';

Text:
	'text';

ByteArray:
	'byte_array';

List:
	'list';

Key:
	'key';

Index:
	'index';

Mutable:
	'mutable';

Var:
	'var';

Val:
	'val';

Ampersand:
	'@';

QuestionChar:
	'?';

PlusChar:
	'+';

MinusChar:
	'-';

MulChar:
	'*';

DivChar:
	'/';


Error log is

Quote:

warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'name'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'byte_array'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'bool'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'text'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'tuid'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'timestamp'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'integer'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'pubkey'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' 'json'" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
warning(200): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: Decision can match input such as "RULE_ID '.' RULE_ID" using multiple alternatives: 4, 6
As a result, alternative(s) 6 were disabled for that input
error(201): ../org.blockchain.rell/src-gen/org/blockchain/rell/parser/antlr/internal/InternalRell.g:2062:2: The following alternatives can never be matched: 6


p.s. Sorry for the too long grammar, but I'm not sure how to simplify it



Re: multiple alternatives error during the generation of the artifacts [message #1800380 is a reply to message #1800361] Wed, 26 December 2018 08:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
did you try to create a debug grammar

parserGenerator={debugGrammar=true}

an analyze with antlrworks?

here is at least one minimal grammar that shows at least one of the problems

Model:
'update' entity=ID '(' conditions+=Atomic* ')' '{' '}';

Atomic returns Expression:
{VariableRef} "."? value=ValuableID | //Error because of this string
{MemberDefinition} value=ClassMemberDefinition
;

ValuableID:ID;

ClassMemberDefinition:
classRef=ClassRef "." variableDeclarationRef=ValuableID;

ClassRef:
value=ID;

is update x (a .b) a ClassMemberDefinition or two VariableRefs?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: multiple alternatives error during the generation of the artifacts [message #1800396 is a reply to message #1800380] Wed, 26 December 2018 15:17 Go to previous messageGo to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Thank you for the reply, very useful.
There are two questions:
1. Is there some tutorial of the antlr generation? I didn't know about this possibility
2. How to fix this? You see there can be three alternatives 1. <ClassName>.<FieldName>(link on the database field) 2. .<FieldName> link on default database table field(in case select only from one table) 3. <VariableName> - link on the variable, or the constant.
So, how to process these three variables, maybe you know?
Re: multiple alternatives error during the generation of the artifacts [message #1800398 is a reply to message #1800396] Wed, 26 December 2018 15:45 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No tutorial

How shall this be resolved? The ambiguity?
Since parsing does not know anything about types
You need to merge all the stuff into one rule. I wonder why there is no comma to separate the elements


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:BUILD Failed for 2.10.0 version of Xtext
Next Topic:Unit test MyDslProposalProvider
Goto Forum:
  


Current Time: Fri Apr 26 09:12:33 GMT 2024

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

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

Back to the top