[antlr-interest] Re: JavaTreeParser? What does it do?

Nick Collier nick.collier at verizon.net
Wed Apr 30 05:52:46 PDT 2003


Hi,

I agree that Tree Walkers certainly give you finer control, but the
double dispatch at the heart of the visitor patter does allow for some
context dependent operations, I think. For example, last I checked,
jython (python in java) uses the visitor pattern as a kind of "tree
walker" during compilation / interpretation.

Nick

On Tue, 2003-04-29 at 19:10, lgcraymer wrote:
> Micheal--
> 
> The Visitor pattern is good when you do not have context-dependent 
> operations on AST nodes.  One example of this is in printing 
> trees--all that you need to know is depth (for indenting) and AST node 
> properties.  Another is "change all AST nodes of type FOO to type BAR 
> in my tree".  I find Visitors convenient for quick-and-dirty tools 
> that work on any tree that I can construct.
> 
> Tree walkers give you finer control, but require knowledge of tree 
> structure and force you into node-by-node processing (if you want do 
> do "action()" whenever you encounter a FOO node, then you will have to 
> insert " { action(); }" everywhere in your tree grammar that you 
> specify FOO).
> 
> --Loring
> 
> 
> --- In antlr-interest at yahoogroups.com, "micheal_jor" <open.zone at v...> 
> wrote:
> > > Tree parsers do the "getFirstChild()" and "getNextSibling()" for 
> > > you as well as matching a tree pattern--the whole idea is to 
> extend 
> > > the ANTLR parsing concept to trees.  About the only case where you 
> > > might want to walk a tree without a tree parser is when 
> > the "Visitor" 
> > > pattern is appropriate.
> > 
> > Hi Loring,
> > 
> > Do you have any guidelines/advise on choosing between an 
> architecture 
> > using the Visitor pattern or TreeParsers?
> > 
> > Having made full support of hetero-ASTs a priority in the C# codegen 
> -
> >  to support the use of Visitors with ANTLR-built trees - we now 
> often 
> > need to choose between both architectures.
> > 
> > Cheers,
> > 
> > Micheal
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
-- 
Nick Collier <nick.collier at verizon.net>


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list