[antlr-interest] TreeDL news: tutorial, new releases, mailing lists

Tiller, Michael (M.M.) mtiller at ford.com
Fri Oct 29 06:16:26 PDT 2004


> From: Alexey Demakov [mailto:demakov at ispras.ru]
> Subject: Re: [antlr-interest] TreeDL news: tutorial, new releases,
mailing
> lists
> 
> > Well, regarding the visitor pattern there are really two issues
here.
> > First is the interface of the visitor.  The interface defines what
> > operations are involved.  This is where I think the "enter" and
"leave"
> > methods would be preferable to a "visit" method for anything that
has
> > children.  This has nothing to do with the tree walking itself (i.e.
the
> > 'accept' method invocations), it just provides a comprehensive list
of
> > methods associated with each node type.  Looking at the
documentation
> > you mentioned I see that TreeDL appears to do this part (although it
is
> > restricted to 'visit' methods).
> 
> If you don't mind to write enter/leave in different classes, this
pattern
> can be
> implemented using two visitors. Generated tree walker will be like
this:
> 
> class EnterLeaveTreeWalker implements TreeVisitor
> {
>     TreeVisitor enterVisitor;
>     TreeVisitor leaveVisitor;
> 
>     // for each node
>     void visitNode( Node node )
>     {
>         node.accept( enterVisitor );
>         // walk children
>         node.accept( leaveVisitor );
>     }
> }

This isn't really what I had in mind.  I don't want two visitors, I want
the traversal (using only one visitor) to include actions for both
entering and leaving the same node.  For information on how SableCC
handles the visitor pattern, you might take a look at:

http://sablecc.org/thesis/thesis.html#PAGE52

They use the terms "in" and "out" instead of "enter" and "leave".  You
can see some discussion of this specifically at:

http://sablecc.org/thesis/thesis.html#PAGE60

> > The second part is the tree walking part.  Here it is possible to
write
> > tree walkers automatically but you have to choose a pattern (e.g.
> > depth-first).

Discussion of the AST walkers in SableCC can be found here:

http://sablecc.org/thesis/thesis.html#PAGE58

--
Mike



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list