[antlr-interest] Re: AST algorithm stuck in infinite loop?
jw9315
jw9315 at bris.ac.uk
Mon May 5 06:56:59 PDT 2003
Apologies, the algorithm was not stuck in a loop, it was just taking
so long to complete that I did not notice! It still seems to go
through the same branch many times though, I was wondering if it was
meant to do this, or it was an error in the implementation of the
algorithm?
Thanks,
Jon
--- In antlr-interest at yahoogroups.com, "jw9315" <jw9315 at b...> wrote:
> 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