X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FUnion.java;h=8f3ea2e428b6cbc8f1cc3da0d9cc6b7b7b6bb14c;hp=1843a4620cb5dd2ca96b92636ce4c332883230e9;hb=HEAD;hpb=b9228a7c1bd98e514e6a5c0483c2e539ee777992 diff --git a/src/edu/berkeley/sbp/Union.java b/src/edu/berkeley/sbp/Union.java index 1843a46..8f3ea2e 100644 --- a/src/edu/berkeley/sbp/Union.java +++ b/src/edu/berkeley/sbp/Union.java @@ -1,4 +1,4 @@ -// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license +// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license package edu.berkeley.sbp; import edu.berkeley.sbp.util.*; @@ -26,7 +26,8 @@ public class Union extends Element implements Iterable { private final List alternatives = new ArrayList(); public Union(String name) { this(name, false); } - public Union(String name, Sequence s) { this(name, false); add(s); } + public Union(String name, Sequence s) { this(name, s, false); } + public Union(String name, Sequence s, boolean synthetic) { this(name, synthetic); add(s); } /** * Since every cycle in a non-degenerate grammar contains at @@ -72,19 +73,13 @@ public class Union extends Element implements Iterable { add(Sequence.create(e)); } - - // Epsilon Form ////////////////////////////////////////////////////////////////////////////// - - private Forest.Many epsilonForm = null; - Forest epsilonForm(Input.Region loc) { - // FIXME: this is pretty ugly... + /** the Forest which results from matching this Union against the empty string at region region */ + Forest epsilonForm(Input.Region region) { viewed = true; - if (epsilonForm != null) return epsilonForm; Forest.Many epsilonForm = new Forest.Many(); - Cache cache = new Cache(null, null); for(Sequence s : this) - if (cache.possiblyEpsilon(s)) - epsilonForm.merge(s.epsilonForm(loc)); + if (Element.possiblyEpsilon(s)) + epsilonForm.merge(s.epsilonForm(region)); return epsilonForm; }