X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FUnion.java;h=c1642627c0dac9d744973d40a0c904f7369ceea4;hp=1843a4620cb5dd2ca96b92636ce4c332883230e9;hb=dc9bb3a45ed306e2e35549076842b3e74efecb48;hpb=449c39e0dafd7c736bfcd8d56bbd08b7a99e25a4 diff --git a/src/edu/berkeley/sbp/Union.java b/src/edu/berkeley/sbp/Union.java index 1843a46..c164262 100644 --- a/src/edu/berkeley/sbp/Union.java +++ b/src/edu/berkeley/sbp/Union.java @@ -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, Cache cache) { 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)); + epsilonForm.merge(s.epsilonForm(region, cache)); return epsilonForm; }