[antlr-interest] Need some help with AST creation
Luis Pureza
pureza at gmail.com
Fri Aug 6 08:41:59 PDT 2010
Hi,
I need some help from the ANTLR wizards :)
I'm trying to match expressions with field accesses and array indexes.
For example:
costumers.length
costumers[0].address
costumers[costumers.length - 1].orders[0].total
The following rule seems to work:
fieldExpr : atom ('.'^ identifier | ('['^ expr ']'!))*;
However, it creates trees with notes annotated with '[', and I'd
prefer to have a dummy token like INDEX. For example, costumers[0] now
returns
([ (ID costumers) (INT 0))
But I'd like it to return
(INDEX (ID costumers) (INT 0))
I tried to create the AST manually with -> ^(...), but I ended up
nowhere. Maybe I should've tried to refactor the grammar, but that
would make it a little less readable, so I didn't do it.
How do you suggest I do this?
Thank you!
More information about the antlr-interest
mailing list