[antlr-interest] oops got that backwards (was is there a way to decompose ASTs)

Josh Scholar joshscholar at nightstudies.net
Wed Aug 8 23:19:12 PDT 2007


At the last minute I decided to edit my example rule to make CAR and
CDR lower case so they wouldn't look like tokens - and at that point
reversed the two.  I meant:

It would be helpful to be able to CAR and CDR your way through subrule
AST trees inside of rewrite rules, or for other things like making an
imaginary token that has the line and column information of a token
from a subrule (or replacing a token from a subrule match).

For instance inside of this rule:

arg1    :    (argScope -> argScope)
        ( biop=('.'|'->') argScope -> ^($biop $arg1  argScope)

*** LOOK HERE ****
           | b  ( l=list -> ^(AT[car($l)] $arg1 cdr($l))
                    | app='(' (expr (',' expr)*)? ')' )
->^(APPLY[$app] $arg1 expr+)
           | post=('++'|'--') ->^(POSTOP[$post] $post $arg1)
         )*
        ;


More information about the antlr-interest mailing list