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

Terence Parr parrt at jguru.com
Wed May 7 12:09:38 PDT 2003


toStringList considers t.getNextSibling() where t is the root tree node 
passed in whereas toStringTree() does not: it goes straight down and 
then does a toStringList() ;)

There should be some "find" type methods in there you can use for depth 
first walking etc...

Ter
On Tuesday, May 6, 2003, at 07:19  AM, jw9315 wrote:

> 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/
>
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Co-founder, http://www.peerscope.com link sharing, pure-n-simple
Lecturer in Comp. Sci., University of San Francisco


 

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




More information about the antlr-interest mailing list