[antlr-interest] AST algorithm stuck in infinite loop?

jw9315 jw9315 at bris.ac.uk
Mon May 5 06:29:22 PDT 2003


Hi,
I implemented the following algorithm to walk an AST as suggested by 
a member of this group:

// Start
void visit( AST tree )
 {
         AST child = tree.getFirstChild();
         System.out.println("_" + child);
         // Test to see if node has a child
         if( child != null) 
	 {
		 System.out.println(child);
                 // Call method recursively
		 visit( child ); 
	 }
         // Else there were no children
         AST sibling = tree.getNextSibling();
         while( sibling != null)
	 {
	 	System.out.println(sibling);
		visit( sibling );
		sibling = sibling .getNextSibling();
 }
// End

However, I find that this enters an infinite loop and prints the tree 
out over and over again. Have I implemented the algorithm correctly, 
and if so, could someone tell me how to test for the fact that I have 
walked the whole tree? Is there a special command for this?
Thanks in advance,
Jon


 

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




More information about the antlr-interest mailing list