Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools JavaCC > testing AST nod...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 452 of 549
Post > Topic >>

testing AST nodes

by "mwnorman@[EMAIL PROTECTED] " <mwnorman@[EMAIL PROTECTED] > Mar 30, 2007 at 09:57 AM

In SimpleNode, there is a protected field (id) that I wish to use to
compare against the
constants generated on the XXXTreeConstants interface

Right now I have to do: ...

public class MyVisitor implements XXXVisitor {

    public Object visit(ASTDeclarativeSection node, Object data)
throws Exception {
        ArrayList<Node> types = new ArrayList<Node>();
        ArrayList<Node> programUnits = new ArrayList<Node>();
        for (int i=0; i < node.jjtGetNumChildren(); i++ ) {
            Node n = node.jjtGetChild(i);
            if (n instanceof ASTProgramUnit) {
                programUnits.add(n);
            }
            else if (n instanceof ASTTypeDefinition) {
                types.add(n);
            }
        }
        // visit types before programUnits
        for (int i=0; i < types.size(); i++ ) {
            Node n = types.get(i);
            n.jjtAccept(this, data);
        }
        for (int i=0; i < programUnits.size(); i++ ) {
            Node n = programUnits.get(i);
            Object o = n.jjtAccept(this, data);
        }
        return data;
    }

It would be a lot nicer if one could do something like:

            if (n.getId() == XXXTreeConstants.JJTPROGRAMUNIT) {
                programUnits.add(n);
            }
            else if (n.getId() == XXXTreeConstants.JJTTYPEDEFINITION)
{
                types.add(n);
            }

instead of the instanceof check
 




 3 Posts in Topic:
testing AST nodes
"mwnorman@[EMAIL PRO  2007-03-30 09:57:35 
Re: testing AST nodes
Quintria <mikronik@[EM  2007-03-31 13:48:40 
Re: testing AST nodes
"mwnorman@[EMAIL PRO  2007-04-02 09:56:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 20:10:51 CDT 2008.