In my grammar I have Variables and Objects (Objects are just a name (ID)). Now I want that a variable can be a reference to another declared variable or an object.
So I want to parse the following input:
var = 3;
var2 = var;
objVar = MyObject;
I've implemented like that:
Declaration:
name = ID "=" Content ";"
;
Content:
INT
| reference = [Declaration]
| object = ID
But the parser can't differentiate between a simple ID and a reference to a declaration (because name is also an ID).
Is there a way to solve my problem?
I tried syntactic predicates but then I can as well delete either the reference or the object from my rule because the parser only see an ID and not a reference. In ANTLR I would use semantic predicates but as far as I know they don't exist in Xtext.
Is there a way to let the parser recognize if the ID is a reference or not and then let it either choose the ID to match the reference or the object?
Greeting Krzmbrzl