[antlr-interest] Template rewrite of assignment to List set function call

Mark Gressett Mark.Gressett at sas.com
Mon Jun 25 08:57:21 PDT 2012


Hi all,

Using ANTLR V3.1, I'm trying to rewrite something like
x = y = z = a+1;
to
x.put(y.put(z.put(a+1)));

My grammar recognizes assignment right at the top of the expression rules
assignment_expression
      :     logical_or_expression (OP_EQ logical_or_expression)*
      ;

Much further down, I recognize array dereference
id_expression
      :     ID
      |     ID LBRACKET additive_expression RBRACKET
      ;

I'm trying to get by with simple template rewrite, leaving the base grammar unchanged. Any ideas about how to proceed?

Am I going to have to construct an AST and walk it to achieve this rewrite?

Thanks,
Mark


More information about the antlr-interest mailing list