[antlr-interest] Manually creating tree - infinite loop
Edward Povazan
epovazan at telus.net
Thu Nov 6 15:59:39 PST 2003
> I can't really follow what rule was getting you into trouble, but infinite
> loops are usually caused because people forget that trees and nodes are
the
> same object. A node contains the down and right pointers. So if you were
> to do something like #(a1, a2, a1) you would create an infinite loop.
Often
> people forget to copy a node if they want something like the above.
>
> Monty
Thanks for the input,
The loop is gone now by excluding nodes from the auto tree contruction. They
were as indicated below.
You mention copying nodes? Is there a shortcut for this?
a1:add_op
(
gt1:GT! a2:add_op!
{ ## = #(#gt1, #a1, #a2); } <----loop
(
gt2:GT! a3:add_op!
{ ## = #([AND, "and"], ##, #(#gt2, #a2, #a3)); #a2 = #a3; } <----loop
)*
)?
;
The tree is now correct with this code, I still don't see how adding child
## results in a bad tree.
{
AST childroot = astFactory.dupTree(##);
## = #([AND, "and"], childroot, #(#gt2, #a2, #a3));
#a2 = #a3;
}
vs
{
## = #([AND, "and"], ##, #(#gt2, #a2, #a3));
#a2 = #a3;
}
Thanks - it works now, but I don't like when I don't know why something
works.
-Ed
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list