[antlr-interest] Change type of current AST
Gavin Lambert
antlr at mirality.co.nz
Sat Jun 7 00:37:51 PDT 2008
At 11:51 7/06/2008, Dimitrios Kolovos wrote:
>I've found that the following works (in case anyone faces a
>similar issue in the future):
>
>additiveExpression
> : multiplicativeExpression (('+'^|'-'^)
multiplicativeExpression
> {if (root_0.getToken() != null)
>root_0.getToken().setType(Operator);})*
> ;
>
>I'm sure there is a more elegant way but this will do for now...
How about this:
additiveExpression
: multiplicativeExpression ((o='+'^|o='-'^)
multiplicativeExpression
{ $o.setType(Operator); } )*
;
(You might need to rearrange the = and ^ a bit.)
Though I'm not entirely sure how either of these will react with
backtracking.
More information about the antlr-interest
mailing list