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!]]>

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 )]]>