[antlr-interest] AST rewrite query

John B. Brodie jbb at acm.org
Tue Jun 12 09:54:56 PDT 2012


Greetings!


On 06/12/2012 12:18 PM, Richard Kenyon wrote:
> Hi all,
>
> I have a rule:
>
> exp	:	term ((PLUS^ | MINUS^) term)*;

Just off the top of my head, untested....

exp : exp_helper -> ^(EXP exp_helper) ;

exp_helper :	term ((PLUS^ | MINUS^) term)*;


assuming the EXP is defined in your tokens{...} section

> My current AST would look something like, for example,
>
> (PLUS (term) (MINUS (term) (term)))
>
> I would prefer to have something like
>
> (EXP (PLUS (term) (EXP (MINUS (term) (term)))))
>
> Essentially I want to make the EXP token the parent of any expression,
> I've tried a few different approaches, but not work fully and now I'm
> at a dead end. :(
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list