[antlr-interest] Tree Operators vs. Tree Rewrite Rules
Simon
cocoa at gmx.ch
Sun Oct 26 14:25:43 PDT 2008
>
> Ok, thank you very much, that did it.
>
> The answer leads to the next question. I've tried to split the rule
> into an additional selector subrule, but without success.
>
> expr
> : primary selector*
> ;
>
> selector
> : '.' ID
> | '[' expr ']'
> ;
>
> I went one step further and added array access to the selector (to
> make the example a bit more realistic).
>
> My head is starting to spin from all those tree rewrite rules. If I'm
> again missing the obvious, please just send me a link to the correct
> information. This time, I've at least searched the list archive and
> read the manual... Or even better, if somebody has a tree grammar for
> Java expressions (that builds the tree as laid out in my original
> post), could you please send it to me?
Here is the answer to my own question. After many unsuccessful tries I
got it...
expr
: (primary -> primary)
(selector[$expr.tree] -> ^(selector))*
;
primary
: identifier
;
selector[Object ast]
: '.' identifier -> ^(CALL {$ast} identifier)
| '[' INT ']' -> ^(ARRIDX {$ast} INT)
;
... I need some additional time to figure out how exactly the tree is
constructed. Again, any help is appreciated.
Thanks
Simon
More information about the antlr-interest
mailing list