make ANSI.clreol()
[sbp.git] / src / edu / berkeley / sbp / Forest.java
index bdaedca..b2f4a22 100644 (file)
@@ -129,7 +129,6 @@ public abstract class Forest<NodeType> implements GraphViz.ToGraphViz {
     /** An "ambiguity node"; this is immutable once it has been "looked at" */
     static class Many<NodeType> extends Forest<NodeType> {
 
-        HashSet<GSS.Phase.Node> parents = new HashSet<GSS.Phase.Node>();
         private FastSet<Forest<NodeType>> hp = new FastSet<Forest<NodeType>>();
         private boolean touched = false;
 
@@ -158,6 +157,14 @@ public abstract class Forest<NodeType> implements GraphViz.ToGraphViz {
         
         void gather(HashSet<Forest<NodeType>> ht) {
             touched();
+
+            // FIXME: do something more sensible here
+            if (ht.contains(this)) {
+                System.err.println("WARNING: grammar produced a circular forest\n" + this);
+                //throw new Error("grammar produced a circular forest:\n" + this);
+                return;
+            }
+
             ht.add(this);
             for(Forest<NodeType> f : hp) f.gather(ht);
         }