[antlr-interest] Difference between toStringList() and toStringTree()?

jw9315 jw9315 at bris.ac.uk
Tue May 6 07:19:57 PDT 2003


Hi,
I found the following methods in BaseAST.java that walk AST's; I was 
wondering what the difference between them is, as they seem to print 
the same thing? In addition does anyone know why the BaseAST cast is 
needed in the methods? Lastly, is there a name for the method used to 
walk the trees; are they depth-first or breadth-first etc..?
Thanks in advance,
Jon

Methods - toStringList() and toStringTree():
'
    /** Print out a child-sibling tree in LISP notation */
    public String toStringList() {
        AST t = this;
        String ts = "";
        if (t.getFirstChild() != null) ts += " (";
        ts += " " + this.toString();
        if (t.getFirstChild() != null) {
            ts += ((BaseAST)t.getFirstChild()).toStringList();
        }
        if (t.getFirstChild() != null) ts += " )";
        if (t.getNextSibling() != null) {
            ts += ((BaseAST)t.getNextSibling()).toStringList();
        }
        return ts;
    }

    public String toStringTree() {
        AST t = this;
        String ts = "";
        if (t.getFirstChild() != null) ts += " (";
        ts += " " + this.toString();
        if (t.getFirstChild() != null) {
            ts += ((BaseAST)t.getFirstChild()).toStringList();
        }
        if (t.getFirstChild() != null) ts += " )";
        return ts;
    }

'


 

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




More information about the antlr-interest mailing list