[antlr-interest] AST Generation - Order of Children
Raphael Reitzig
r_reitzi at cs.uni-kl.de
Thu Jul 3 12:48:29 PDT 2008
Hi!
I had a similar problem; for me, replacing '*'/'+' by a recursive rule and
declare rewrite rules there helped to override ANTLRs default way to build
an AST from such subrules.
Regards
Raphael
On Thu, 3 Jul 2008 20:46:47 +0200, "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
More information about the antlr-interest
mailing list