X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FWalk.java;h=e2ac662a0e18da8aefd37b46087809e60c7cf875;hp=0b19cd49b2fee38880592f3a350b7874795a875c;hb=a2008a0c57702f49ed7f8be682e4e29484fded38;hpb=778717ec55a53ceab4847f2a0922478d6c06e4e1 diff --git a/src/edu/berkeley/sbp/Walk.java b/src/edu/berkeley/sbp/Walk.java index 0b19cd4..e2ac662 100644 --- a/src/edu/berkeley/sbp/Walk.java +++ b/src/edu/berkeley/sbp/Walk.java @@ -39,13 +39,8 @@ abstract class Walk { else if (e instanceof Sequence) return walkSequence((Sequence)e); else if (e instanceof Union) { T ret = bottom(e); - for(Sequence s : (Union)e) { + for(Sequence s : (Union)e) ret = union((Union)e, ret, walk(s)); - - // FIXME - for(Sequence ss : s.needs()) ret = union((Union)e, ret, walk(ss)); - for(Sequence ss : s.hates()) ret = union((Union)e, ret, walk(ss)); - } return ret; } else { throw new Error("unknown element of class " + e.getClass().getName() + ": " + e); @@ -62,6 +57,27 @@ abstract class Walk { c.atoms.put(e, c.atoms.get(e)==null ? r : c.atoms.get(e).union(r)); return super.walkAtom(r); } + protected HashSet walk2(SequenceOrElement e) { + HashSet ret = super.walk2(e); + if (e instanceof Union) + for(Sequence s : (Union)e) { + for(Sequence ss : s.needs()) ret = union((Union)e, ret, walk(ss)); + for(Sequence ss : s.hates()) ret = union((Union)e, ret, walk(ss)); + } + return ret; + } + } + + static class YieldSet2 extends Walk> { + private final SequenceOrElement e; + public final HashSet walk() { return walk(e); } + public YieldSet2(SequenceOrElement e, Cache c) { super(c); this.e = e; } + public HashSet bottom(SequenceOrElement e) { return acc; } + public HashSet walkSequence(Sequence seq) { return bottom(seq); } + public HashSet walkAtom(Atom r) { + c.atoms.put(e, c.atoms.get(e)==null ? r : c.atoms.get(e).union(r)); + return super.walkAtom(r); + } } static class EquivalentTo extends Walk> { @@ -149,6 +165,7 @@ abstract class Walk { public Topology walkAtom(Atom r) { cs = cs.union(r.getTokenTopology()); return cs; } } + // feature: intersect with "first" set of all positive conjuncts static class First extends WalkTokenSet { public First(Topology cs, Walk.Cache cache) { super(cs, cache); } public Topology walkSequence(Sequence seq) { @@ -236,6 +253,7 @@ abstract class Walk { public HashMap eof = new HashMap(); public HashMap follow = new HashMap(); public HashMapBag ys = new HashMapBag(); + public HashMapBag ys2 = new HashMapBag(); public HashMap atoms = new HashMap(); public Topology first(SequenceOrElement e, Topology empty) { return new Walk.First(empty, this).walk(e);