Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can't understand why one rule are recognized as another
Can't understand why one rule are recognized as another [message #1804963] Wed, 03 April 2019 20:33 Go to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Hi all, I have the grammar(see it below) it's simplified variant of some bigger.
And two peases of code

In this one everything is fine
class user {}
query q2() = (user,user) @ { } ;


As well as in this:
Quote:
class user {}
query q2() = (u:user) @ { } ;


But in this one, I have the problem
class user {}
query q2() = (user) @ { } ;


I assume it because the first part of AtOperator is recognized as a tuple value. But I need the tuple value in my grammar.

So, how to fix my grammar?

Regards,
Vladimir

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

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

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

ClassDefinition:
	'class' name=ID LEFT_BRACE
	attributeListField+=AttributeListField*
	RIGHT_BRACE;

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

Query:
	"query" name=ID LEFT_BRACKET parameters=RelAttrubutesList? RIGHT_BRACKET
	(DOUBLE_QUOTE type=TypeReference)?
	((ASSIGNMENT returnExr=Expression ';') |
	(LEFT_BRACE
	statements+=Statement*
	(('return' returnExr=Expression ';')?)
	RIGHT_BRACE));

Statement:
	(relation=Relational | methodCall=DotValue) ';';

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

Relational:
	AtOperator;

AtOperator:
	(tableNameWithAlias+=TableNameWithAlias |
	(LEFT_BRACKET
	tableNameWithAlias+=TableNameWithAlias (',' tableNameWithAlias+=TableNameWithAlias)*
	RIGHT_BRACKET))
	Ampersand
	(ampersandModificator=AmpersandModificator?)
	LEFT_BRACE
	(ASSIGNMENT? conditions+=Expression (',' ASSIGNMENT? conditions+=Expression)*)?
	RIGHT_BRACE
	(tupleValue=TupleValue?);

TupleValue:
	LEFT_BRACKET members+=TupleValueMember (',' tuplePart+=TupleValueMember)* RIGHT_BRACKET;

TupleValueMember:
	(name=ValuableID ASSIGNMENT)? value=Expression;

TableNameWithAlias:
	classRefDecl=ClassRefDecl |
	justNameDecl=JustNameDecl;

ClassRefDecl:
	name=ID DOUBLE_QUOTE classDef=[ClassDefinition];

JustNameDecl:
	name=[ClassDefinition];

VariableDeclarationRef:
	name=[VariableDeclaration|ValuableID];

AccessToList:
	LEFT_SQUARE_BRACE expr=Expression RIGHT_SQUARE_BRACE;

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=EQUALS
	right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} op=IN
	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)
	right=Primary)*;

Primary returns Expression:
	prefixChar=MinusChar expression=Primary |
	DotValue;

DotValue:
	(LEFT_BRACKET DotValue RIGHT_BRACKET) | ((atom=Atomic (accesToList=AccessToList?) (DOT dotPart=DotValue)?));

Atomic returns Expression:
	{SelectOp} value=AtOperator
	| {TupleRes} value=TupleValue
	| {VariableDeclarationRef} value=VariableDeclarationRef;

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

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

TypeReference:
	type=PrimitiveType;

PrimitiveType:
	Text;

ValuableID:
	PrimitiveType | ID;

AmpersandModificator:
	PlusChar | MulChar | QuestionChar;

Text:
	'text';

Key:
	'key';

Index:
	'index';

Mutable:
	'mutable';

Ampersand:
	'@';

QuestionChar:
	'?';

PlusChar:
	'+';

MinusChar:
	'-';

MulChar:
	'*';

terminal IN:
	'in';

terminal RIGHT_SQUARE_BRACE:
	']';

terminal LEFT_SQUARE_BRACE:
	'[';

terminal RIGHT_BRACE:
	'}';

terminal LEFT_BRACE:
	'{';

terminal RIGHT_BRACKET:
	')';

terminal LEFT_BRACKET:
	'(';

terminal ASSIGNMENT:
	'=';

terminal EQUALS:
	'==';

terminal DOUBLE_QUOTE:
	':';

terminal DOT:
	'.';


Re: Can't understand why one rule are recognized as another [message #1804965 is a reply to message #1804963] Wed, 03 April 2019 20:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13164
Registered: July 2009
Senior Member
error(211): ../org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl1/parser/antlr/internal/InternalMyDsl.g:486:3: [fatal] rule ruleStatement has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl1/parser/antlr/internal/InternalMyDsl.g:1723:2: [fatal] rule ruleDotValue has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.


=> did you enable backtracking?

=> you really should solve the left recursion an ambiguities there


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 03 April 2019 20:56]

Report message to a moderator

Re: Can't understand why one rule are recognized as another [message #1804991 is a reply to message #1804965] Thu, 04 April 2019 11:38 Go to previous messageGo to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Quote:

=> did you enable backtracking?

Yes

options = {
					backtrack = true
				}


Quote:

you really should solve the left recursion an ambiguities there


Well, as I understand backtracking will help. But still, have this problem.
Trace of my error is

Quote:

java.lang.AssertionError: Unexpected errors: XtextSyntaxDiagnostic: null:2 mismatched input '@' expecting ';'
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.blockchain.rell.tests.WorkingTests.assertParsingTrue(WorkingTests.java:2124)
at org.blockchain.rell.tests.WorkingTests.testOneClassInTheBrackets(WorkingTests.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.eclipse.xtext.testing.XtextRunner$1.evaluate(XtextRunner.java:49)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)


Re: Can't understand why one rule are recognized as another [message #1805005 is a reply to message #1804991] Thu, 04 April 2019 14:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13164
Registered: July 2009
Senior Member
as i said: you should fix the grammar problem (e.g. configure workflow to create debug grammar and use antlrworks to analyze)
instead of using backtracking.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't understand why one rule are recognized as another [message #1805033 is a reply to message #1805005] Thu, 04 April 2019 17:14 Go to previous messageGo to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Quote:
use antlrworks to analyze

I have already created the test antlr grammar, but what do you mean on quoted? Is it some framework?
Re: Can't understand why one rule are recognized as another [message #1805035 is a reply to message #1805033] Thu, 04 April 2019 17:21 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13164
Registered: July 2009
Senior Member
There is a tool called antlrworks that helps you to debug problems with antlr grammars

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to add LSP support in existing Xtext project
Next Topic:Hello I'm new in this technology
Goto Forum:
  


Current Time: Wed Oct 23 00:28:07 GMT 2019

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

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

Back to the top