convered maximal to use character lookahead
[sbp.git] / src / edu / berkeley / sbp / Union.java
index 1d4841f..db0db7d 100644 (file)
@@ -18,6 +18,18 @@ public class Union extends Element implements Iterable<Sequence> {
 
     void reachable(HashSet<Sequence.Position> h) { for(Sequence s : alternatives) s.reachable(h); }
 
+    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.dup();
+            else           ret = ret.union(a.dup());
+        }
+        if (ret==null) throw new RuntimeException("confusion on " + this);
+        return ret;
+    }
+
     /** adds an alternative */
     public void add(Sequence s) { alternatives.add(s); }