[antlr-interest] ANTLR3 Pruning the AST

Kailey Joanette kaileyjo at bigbluebubble.com
Fri Mar 30 06:45:58 PDT 2007


Is there any way to prune an AST so that things like :

           EXPR 
            EXPR_COND 
             COND_OR_EXPR 
              COND_AND_EXPR 
               INCL_OR_EXPR 
                EXCL_OR_EXPR 
                 AND_EXPR 
                  EQUA_EXPR 
                   INSTANCEOF_EXPR 
                    RELA_EXPR 
                     SHIFT_EXPR 
                      ADDIT_EXPR 
                       MULIT_EXPR 
                        UNARY_EXPR 
                         UNARY_EXPR_NPM 
                          PRIMARY System out println

Will turn into just 

EXPR
 PRIMARY System out println

I don't care about whats in between unless something actually happens there.
Would it work if I didn't add the EXPR_COND or whatever based on a
predicate?  So say ADDIT_EXPR is an expression that looks like 4+5, if only
4 is present then I don't build ADDIT I just keep going down the list.

Kailey



More information about the antlr-interest mailing list