Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem parsing expression(Problem parsing expressions)
Problem parsing expression [message #1790650] Wed, 13 June 2018 22:06 Go to next message
Eyck Jentzsch is currently offline Eyck JentzschFriend
Messages: 21
Registered: August 2012
Junior Member
Hi,
I have the following (partial) grammar:
ParamInstantiation : 
	'#(' instances+=ParamInstance (',' instances+=ParamInstance)* ')'
;
ParamInstance:
	 '.' param=ID '(' value=ConstantExpression ')' 
;
ConstantExpression: PlusOrMinus;

PlusOrMinus returns ConstantExpression:
	MulOrDiv (
		=>({PlusOrMinus.left=current} op=AddSubOperator) right=MulOrDiv
	)*
;

MulOrDiv returns ConstantExpression:
	Primary (
		=>({MulOrDiv.left=current} op=MulOperator) right=Primary
	)*
;

Primary returns ConstantExpression:
	'(' ConstantExpression ')' |
	Atomic
;

Atomic returns ConstantExpression:
	{IntConstant} value=INT |
	{StringConstant} value=STRING |
;

when trying to match this against:
#( .SIZE(16) ) 

I get 'mismatched input ')' expecting '('' at the end of '(16)'. And I do not understand why...
If I change the ParamInstance rule to:
ParamInstance:
	 '.' param=ID '{' value=PlusOrMinus '}' 
;

and the input accordingly, it works. Anyone an idea why? I guess it relates to the first part of the Primary rule but I don't know in which way and how to work around,
Best

-Eyck
Re: Problem parsing expression [message #1790653 is a reply to message #1790650] Thu, 14 June 2018 04:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you please provide a complete but minimal reproducing grammar?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem parsing expression [message #1790655 is a reply to message #1790653] Thu, 14 June 2018 06:05 Go to previous messageGo to next message
Eyck Jentzsch is currently offline Eyck JentzschFriend
Messages: 21
Registered: August 2012
Junior Member
Hi Christian,
THX for kicking my butt, the root cause seems to be somewhere else as it works in a stand alone example. So it must come from the context.

Is there a way to debug/see what parser sees and which rules it chooses?

Best regards

-Eyck
Re: Problem parsing expression [message #1790657 is a reply to message #1790655] Thu, 14 June 2018 06:27 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes and no. you would need to debug the lexer and parser
or you change the workflow to create a debug grammar (parserGenerator={debugGrammar=true} // if i remember correct)
and then use antlrworks to analyze.



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic: importURI with Xtext 2.14 and the new generator
Next Topic:Caches in Code Generator
Goto Forum:
  


Current Time: Wed Apr 24 16:19:24 GMT 2024

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

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

Back to the top