- private Forest.Ref epsilonForm = null;
- Forest epsilonForm() {
- if (epsilonForm != null) return epsilonForm;
- epsilonForm = new Forest.Ref();
- for(Sequence s : this)
- if (s.possiblyEpsilon(null))
- epsilonForm.merge(s.epsilonForm());
+ public boolean contains(Sequence s) {
+ viewed = true;
+ return alternatives.contains(s);
+ }
+
+ /** iterator over this Union's Sequences */
+ public Iterator<Sequence> iterator() {
+ viewed = true;
+ return alternatives.iterator();
+ }
+
+ /** adds an alternative */
+ public void add(Sequence s) {
+ /*
+ FIXME
+ if (viewed)
+ throw new RuntimeException("attempt to add a Sequence to a Union that has already been examined:\n "+this);
+ */
+ if (alternatives.contains(s)) return;
+ alternatives.add(s);
+ }
+
+ /** adds a one-element sequence */
+ public void add(Element e) {
+ add(Sequence.create(e));
+ }
+
+
+ // Epsilon Form //////////////////////////////////////////////////////////////////////////////
+
+ // FIXME
+ //private Forest.Many epsilonForm = null;
+ Forest epsilonForm(Input.Region loc) {
+ //if (epsilonForm != null) return epsilonForm;
+ Forest.Many epsilonForm = new Forest.Many();
+ for(Sequence s : this) {
+ // FIXME FIXME FIXME
+ if (new Walk.Cache().possiblyEpsilon(s))
+ epsilonForm.merge(s.epsilonForm(loc));
+ }