removed illegal use of double-star
[sbp.git] / src / edu / berkeley / sbp / Union.java
index 7370a68..a7a7630 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); }
 
 
     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 (a==null) continue;
+            if (ret==null) ret = a.dup();
+            else           ret.add(a.dup());
+        }
+        return ret;
+    }
+
     /** adds an alternative */
     public void add(Sequence s) { alternatives.add(s); }
 
     /** adds an alternative */
     public void add(Sequence s) { alternatives.add(s); }
 
@@ -36,6 +48,9 @@ public class Union extends Element implements Iterable<Sequence> {
         this.synthetic = synthetic;
     }
 
         this.synthetic = synthetic;
     }
 
+    public static Union epsilon = new Union("()");
+    static { epsilon.add(Sequence.empty); }
+
     private Forest.Ref epsilonForm = null;
     Forest epsilonForm() {
         if (epsilonForm != null) return epsilonForm;
     private Forest.Ref epsilonForm = null;
     Forest epsilonForm() {
         if (epsilonForm != null) return epsilonForm;