[antlr-interest] Code bloat for mulitple passes with point changes.
pganelin
ganelin at mail.com
Mon Jun 13 12:50:12 PDT 2005
Problem Summary: multiple transformations passes with small changes
results in code bloat. Nodes to be changed are located deeply within tree.
Description:
In ANTLR documentation (Tree Parser Chapter) there is an example of tree
transformation (optimizing identity operations) and I will use this
example for illustration.
X+0 -> X
X*1 -> X
I have multiphase transformation. During stage number N I want to do
"identity optimization". I can easily implement the transformation
using visitor pattern without TreeWalker with a few lines of code. If I
want to use TreeWalker instead I will need to duplicate (really inherit)
the whole tree grammar file for phase N with most rules without any
action. Only two rules (plus and multiply) have the explicit
transformation action. The generated file would be huge, because it
creates duplicate tree for all these grammar rules without action. As a
result the code would be bloated and very ineffective compare with
visitor pattern.
Do I miss something or Tree Walker is not appropriate tool for such job?
Sincerely,
Pavel
More information about the antlr-interest
mailing list