Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Language allows for operator definition
Language allows for operator definition [message #645039] Wed, 15 December 2010 10:22
No real name is currently offline No real nameFriend
Messages: 25
Registered: April 2010
Junior Member
Hi,

Im currently trying to write the grammar for language which allows for operator definition, and defines its own operators in a base file. Unfortunately, I cannot change any design choices since I am just writing the plugin for an existing language.

Now the problem comes in when I want to accommodate for postfix expressions. My code looks as follows:

Expression:
	expr+=UniraryExpression ( op+=[OperatorDeclaration | OperationSymbol] expr+=UniraryExpression)*;

UniraryExpression:
	  PreOperatorExpression 
	| PostOperatorExpression
	;

PreOperatorExpression:
	{PreOperatorExpression} op=[PreOperatorDeclaration | OperationSymbol] expression=PrimaryExpression;

PostOperatorExpression:
	{PostOperatorExpression} expression=PrimaryExpression (op=[PostOperatorDeclaration | OperationSymbol])? ;

PrimaryExpression:
	  {NumberLiteral} value=NumberLiteral 
	| {BooleanLiteral} value=BooleanLiteral
	| {FloatLiteral} value=FloatLiteral
	| {NameLiteral} value=NameLiteral
	| {StringLiteral} value=StringLiteral
	| '(' Expression ')'
	;


This doesnt work, because once the parser gets to a PrimaryExpression and sees a OperationSymbol, it doesnt know if that symbol is part of the Expression or PostExpression.

Is there any walkaround or should I just bite the bullet and hardcode the standard operators?
Previous Topic:Help writing EBNF - With statement
Next Topic: retrieving crossreferences from external file
Goto Forum:
  


Current Time: Fri Apr 26 03:04:53 GMT 2024

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

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

Back to the top