[antlr-interest] Tree walking Q

Andy Tripp atripp at comcast.net
Fri Jun 10 09:14:45 PDT 2005


Yes, we had a lengthy discussion on this list about whether translators 
should use treewalkers
when Terence wrote that article. I wasn't convinced that treewalkers 
were always better,
and I think this is probably a good example of such a case. If you want 
to walk a tree and only
do actions at a few nodes, I think hand-written Java code is cleaner and 
simpler than
creating an ANTLR treewalker. And even when you have to do an action at 
every node,
I prefer "hand-written" code.

See my JavaEmitter vs. Terence's JavaEmitter in the File Sharing section 
for a good example of
the two approaches to doing the same thing.

Andy


Mark Bednarczyk wrote:

>I'm no expert, but the following article from a real expert
>addresses your question:
>
>http://www.antlr.org/article/1100569809276/use.tree.grammars.tml
>
>Cheers,
>mark...
>
>  
>
>>-----Original Message-----
>>From: antlr-interest-bounces at antlr.org
>>[mailto:antlr-interest-bounces at antlr.org]On Behalf Of
>>Andy Tripp
>>Sent: Friday, June 10, 2005 11:08 AM
>>To: antlr-interest at antlr.org
>>Subject: [antlr-interest] Tree walking Q
>>
>>
>>Sorry for trolling, but...
>>Why not just walk the tree "by hand"? Just have a
>>method that takes an
>>AST parameter,
>>and checks its type. If it's a type you want to
>>handle, do your thing.
>>If not, make recursive calls
>>for each of the children. That seems like the cleanest
>>and easiest
>>solution to me.
>>
>>Andy
>>
>>
>>
>>    
>>
>
>
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050610/aff447c2/attachment.html


More information about the antlr-interest mailing list