Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Help with Actions
Help with Actions [message #756726] Mon, 14 November 2011 20:18 Go to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi,

I'm having a little trouble with my grammar. Here I show a sample of my code.

Model:
	'expression' expression=Expression
;

Expression:
	Multiplication (({Plus.left=current} '+' | {Minus.left=current} '-') right=Multiplication)*
;

Multiplication:
	Power (({Multi.left=current} '*'  | {Div.left=current} '/')  right=Power)*
;

Power:
	PrimaryExpression (({Power.left=current} '^') right=PrimaryExpression)*
;

PrimaryExpression:
	(  FieldReference | MethodInvocation)
	| Something
;

MethodInvocation : 
	method=[ecore::EObject]
;

FieldReference:
	field=[ecore::EObject]
;


Something:
	st='some rule'
;


I need to be able to place a sign "+" or "-" as prefix for FieldReference and MethodInvocation. I cannot write something like "sign=('+' | '-')" inside any of those rules because I use them in different parts of the grammar where the sign would make no sense. For example, with the recursive dot :

     variable.FieldReference.MethodInvocation()



Also, I cannot place the sing before ( FieldReference | MethodInvocation) in the PrimaryExpression rule because I get "An unassigned rule call is not allowed, when the 'current' was already created".


How would you do this?

Thanks!
Re: Help with Actions [message #756822 is a reply to message #756726] Tue, 15 November 2011 09:50 Go to previous message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
First some links which might be helpful:
http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html
http://dslmeinte.wordpress.com/2011/03/21/pre-and-postfix-operators-in-xtext/
http://dslmeinte.wordpress.com/2011/03/24/more-on-pre-and-postfix-operators-in-xtext/

In essence, your sign (+|-) is a prefix operator with a FieldReference or MethodInvocation as operand and which is probably non-associative.

For the dot operator, you might want to look into: http://dslmeinte.wordpress.com/2010/08/16/path-expressions-in-entity-models/

(And sorry about the shameless plugs Wink)


Previous Topic:Xtext 2: problem with workflow
Next Topic:problems with the tutorial "Five simple steps to your JVM language"
Goto Forum:
  


Current Time: Fri Apr 26 02:29:06 GMT 2024

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

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

Back to the top