X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fsbp%2FUnion.java;h=4de0bb4969c58512982b7977fda60c9c6eaeac05;hb=1a249057cbfd2180910e46672eafee3af46ae470;hp=db0db7dca1a322625895ee88f6d338a7934623ba;hpb=0516ea34996c86664928ef948013b749876b87ec;p=sbp.git diff --git a/src/edu/berkeley/sbp/Union.java b/src/edu/berkeley/sbp/Union.java index db0db7d..4de0bb4 100644 --- a/src/edu/berkeley/sbp/Union.java +++ b/src/edu/berkeley/sbp/Union.java @@ -10,28 +10,24 @@ import java.lang.ref.*; /** an element which can produce one of several alternatives */ public class Union extends Element implements Iterable { + /** 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 alternatives = new ArrayList(); public Iterator iterator() { return alternatives.iterator(); } - - void reachable(HashSet 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; - } + public boolean contains(Sequence s) { return alternatives.contains(s); } /** adds an alternative */ - public void add(Sequence s) { alternatives.add(s); } + public void add(Sequence s) { + alternatives.add(s); + for(Sequence n : s.needs) add(n); + for(Sequence n : s.hates) add(n); + } /** * Since every cycle in a non-degenerate grammar contains at