[antlr-interest] ANTLR3 Pruning the AST
Loring Craymer
lgcraymer at yahoo.com
Fri Mar 30 11:07:21 PDT 2007
That's a parse tree; your problem is with the
"imaginary" nodes that you have inserted into the tree
to get a parse tree instead of building a more
efficient AST. As a general rule, only insert
"imaginary" nodes when it simplifies recognition for
the next tree walker stage.
Remove the node insertions (at least those under EXPR)
in your grammar; after-the-fact pruning of inserted
nodes is something to avoid.
--Loring
--- Kailey Joanette <kaileyjo at bigbluebubble.com>
wrote:
> 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
>
>
____________________________________________________________________________________
Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
http://farechase.yahoo.com/promo-generic-14795097
More information about the antlr-interest
mailing list