[antlr-interest] Article against TreeWalkers

Andy Tripp antlr at jazillian.com
Fri Mar 10 07:27:45 PST 2006


Micheal J wrote:

>
>Leaving the Treewalking vs TreeGrammer issue to one side for a moment, what
>advantage does manually developing your own treewalking code (a la
>JavaEmitter.java) have over using a tool like TreeDL and one of the Visitor
>pattern variants?
>  
>
I'm not sure, as I haven't tried TreeDL, or even writing a significant 
amount of "hand-code" to
manipulate ASTs. The JavaEmitter example I talk about in the article is 
obviously just printing out
the AST (i.e. walking only), not manipulating it.

But my general feeling is that yes, using TreeDL or some other 
AST-manipulation-tool would be better
than "hand-coding". I had looked into TXL in detail a long time ago, and 
also looked into DMS
from Semantic Designs.

 From what I remember about TXL, I thought it didn't go nearly far
enough in functionality. The examples where all completely trivial (e.g. 
"here's how to insert a typecast")
compared to what I needed ("Look at each variable reference to see if 
it's being used as a boolean
and if it's usually used as a boolean, change it's type to boolean, and 
at each reference where
it's not used as a boolean, change the expression so that the expression 
still works"). Yes, you could
"jump out" and do anything you want by hand-coding, but it seemed like 
I'd have to do that everywhere,
and thus not get much benefit from the tool.

DMS sounded like a nice, sophisticated framework that might be a good 
"engine" for building an
AST-maniplulating application on top of. But it was hard to evaluate it 
further without paying
tens of thousands of dollars to buy it or take a week-long course.

My test for any of these tools would be "Does it make it easier for me 
to change
'printf("%s\n", "Hello, World");'   to 'System.out.println("Hello, 
World");'  ?
If the tool isn't making stuff like that easier, then it's not helping.
(Take a few moments here and picture the two AST's here: it's not a 
trivial AST manipulation!)

So, in summary, my feeling is "If you're just going to walk the tree, 
just write the code to do it,
check out these tools first". But if I looked into TreeDL, I may end up 
saying "nah, just write your
own handful of tree-manipulation functions", I don't know.

Andy



More information about the antlr-interest mailing list