checkpoint
[sbp.git] / src / edu / berkeley / sbp / Union.java
index ea2e2db..4de0bb4 100644 (file)
@@ -10,32 +10,23 @@ import java.lang.ref.*;
 /** an element which can produce one of several alternatives */
 public class Union extends Element implements Iterable<Sequence> {
 
+    /** display form for the Union (ie not including the RHS) */
     final String shortForm;
+
+    /** this is just a hint to use when printing out the grammar in visual form */
     final boolean synthetic;
+
+    /** the actual alternatives */
     private final List<Sequence> alternatives = new ArrayList<Sequence>();
 
     public Iterator<Sequence> iterator() { return alternatives.iterator(); }
     public boolean contains(Sequence s) { return alternatives.contains(s); }
 
-    Topology toAtom() {
-        if (alternatives.size()==0) throw new RuntimeException("cannot build an Atom from a Union with no productions");
-        Topology ret = null;
-        for(Sequence s : this) {
-            Topology a = s.toAtom();
-            if (ret==null) ret = a;
-            else           ret = ret.union(a);
-        }
-        if (ret==null) throw new RuntimeException("confusion on " + this);
-        return ret;
-    }
-
     /** adds an alternative */
     public void add(Sequence s) {
         alternatives.add(s);
-        if (/*!synthetic &&*/ shortForm!=null
-            && Character.isUpperCase(shortForm.charAt(0))
-            )
-            s.setName(toString());
+        for(Sequence n : s.needs) add(n);
+        for(Sequence n : s.hates) add(n);
     }
 
     /**