Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Problem parsing expression(Problem parsing expressions)
Problem parsing expression [message #1790650] Wed, 13 June 2018 18:06 Go to next message
Eclipse UserFriend
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 00:50 Go to previous messageGo to next message
Eclipse UserFriend
can you please provide a complete but minimal reproducing grammar?
Re: Problem parsing expression [message #1790655 is a reply to message #1790653] Thu, 14 June 2018 02:05 Go to previous messageGo to next message
Eclipse UserFriend
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 02:27 Go to previous message
Eclipse UserFriend
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.

Previous Topic: importURI with Xtext 2.14 and the new generator
Next Topic:Caches in Code Generator
Goto Forum:
  


Current Time: Fri Jun 20 16:41:37 EDT 2025

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

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

Back to the top