[antlr-interest] add a tree visitor?
Terence Parr
parrt at cs.usfca.edu
Tue Oct 28 10:28:53 PDT 2008
On Oct 28, 2008, at 8:15 AM, Andy Tripp wrote:
> Yep, that's the Visitor design pattern...seems like a good thing to
> add.
> The TreeVisitorAction method is usually called "accept()", though.
I decided to allow both pre-and post:
/** How to execute code for node t when a visitor visits node t.
Execute
* pre() before visiting children and execute post() after visiting
children.
*/
public interface TreeVisitorAction {
/** Execute an action before visiting children of t. Return t or
* a rewritten t. Children of returned value will be visited.
*/
public Object pre(Object t);
/** Execute an action after visiting children of t. Return t or
* a rewritten t. It is up to the visitor to decide what to do
* with the return value.
*/
public Object post(Object t);
}
> And the Java 1.5 foreach and generics would make the code cleaner.
I hate that syntax because it looks so nice, but crashes if you have a
null list. stupidest thing I've ever seen in my life. plus, I can't
rely on 1.5 yet.
I agree it would be nice if that syntax did something nice. :) don't
get me started on how bad the generic stuff works when you want
List<AST> to work with List<MyAST>. blech. renders it useless. sorry
to be so negative on a Tuesday morning. Just getting sick of all of
these Java "enhancements".
Ter
More information about the antlr-interest
mailing list