[antlr-interest] AST Generation - Order of Children
Liehann Loots
liehannl at gmail.com
Thu Jul 3 12:24:10 PDT 2008
Ok, I think I figured it out. My solution looks like this:
expr
: (IDENT -> IDENT) // set return tree
( deref -> ^(DEREF $expr deref)
| invoke -> ^(INVOKE $expr invoke)
)*
;
- Liehann
On Thu, Jul 3, 2008 at 8:46 PM, Liehann Loots <liehannl at gmail.com> wrote:
> Hi,
>
> I have three rules that look something like this:
>
> expr : IDENT (deref^ | invoke^)*;
> deref : (PERIOD)! IDENT -> ^(DEREF IDENT);
> invoke : (PERIOD)! IDENT (LEFT_BRKT)! (RIGHT_BRKT)! -> ^(INVOKE IDENT);
>
> That produce an AST like this:
>
> INVOKE
> | |
> c DEREF
> | |
> b a
>
> What I want to get is a tree like this:
>
> INVOKE
> | |
> DEREF c
> | |
> a b
>
> But I'm not sure how to specify a rewrite rule to make the current tree the
> first child of the new parent, opposed to appending it to the end.
> Any assistance would be appreciated.
>
> Regards,
> Liehann
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080703/b224fbd1/attachment.html
More information about the antlr-interest
mailing list