X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FWalk.java;h=0d4233a0f80c590cf49bec0586efcebbc5e6b214;hp=8b6eae61fab9c8f933c81636b950cc0238999af5;hb=888e9ccbab5f458a727c16da9d9291fd8951d909;hpb=0516ea34996c86664928ef948013b749876b87ec diff --git a/src/edu/berkeley/sbp/Walk.java b/src/edu/berkeley/sbp/Walk.java index 8b6eae6..0d4233a 100644 --- a/src/edu/berkeley/sbp/Walk.java +++ b/src/edu/berkeley/sbp/Walk.java @@ -52,7 +52,7 @@ abstract class Walk { public HashSet bottom(Element e) { return acc; } public HashSet sequence(Sequence seq) { return bottom(seq); } public HashSet walkAtom(Atom r) { - c.atoms.put(e, c.atoms.get(e)==null ? r.dup() : c.atoms.get(e).union(r.dup())); + c.atoms.put(e, c.atoms.get(e)==null ? r : c.atoms.get(e).union(r)); return super.walkAtom(r); } } @@ -83,7 +83,7 @@ abstract class Walk { public WalkTokenSet(Topology cs) { this.cs = cs; } public WalkTokenSet(Topology cs, Cache c) { super(c); this.cs = cs; } public Topology bottom(Element e) { return cs; } - public Topology walkAtom(Atom r) { cs.add(r.dup()); return cs; } + public Topology walkAtom(Atom r) { cs = cs.union(r); return cs; } } class First extends WalkTokenSet { @@ -97,20 +97,6 @@ abstract class Walk { } } - class Last extends WalkTokenSet { - public Last(Topology cs, Walk.Cache cache) { super(cs, cache); } - public Topology sequence(Sequence seq) { sequence(seq.firstp()); return cs; } - private Topology sequence(Position p) { - if (p==null) return null; - Topology ret = sequence(p.next()); - if (ret!=null) return ret; - if (p.isLast()) return null; - if (p.element().possiblyEpsilon(c)) return null; - if (p.element()==null) return null; - return walk(p.element()); - } - } - static class Follow extends WalkTokenSet { private final Element me; private final HashSet all; @@ -127,7 +113,7 @@ abstract class Walk { if (c != null) { Topology cached = (Topology)c.follow.get(e); if (cached != null) { - cs.add(cached); + cs = cs.union(cached); eof |= c.eof.get(e); return cs; } @@ -135,24 +121,22 @@ abstract class Walk { Topology cso = cs; boolean eofo = eof; - eof = false; - cs = cso.fresh(); + eof = c.eof.get(e) != null && c.eof.get(e).booleanValue(); + cs = cso.empty(); - if (e instanceof Parser.Table.Top) eof = true; for(Element x : all) { boolean matched = false; - if (x instanceof Parser.Table.Top) walk(x); // because this symbol might not appear in any other Sequence if (!(x instanceof Sequence)) continue; Sequence a = (Sequence)x; Position mp = null; for(Position pos = a.firstp(); pos != null && !pos.isLast(); pos = pos.next()) { - if (matched) cs.add(new First(cs.fresh(), c).walk(pos.element())); + if (matched) cs = cs.union(new First(cs.empty(), c).walk(pos.element())); if (pos.isLast()) { matched = (matched && pos.element().possiblyEpsilon(c)); continue; } boolean good = false; if (e instanceof Atom) { Topology top = c.atoms.get(pos.element()); if (top==null) continue; - if (!(top.containsAll(((Atom)e).dup()))) continue; + if (!(top.containsAll(((Atom)e)))) continue; } else { if (c.ys.get(pos.element()).contains(e)) good = true; } @@ -166,15 +150,15 @@ abstract class Walk { if (e instanceof Sequence) { Sequence s = (Sequence)e; - if (s.noFollow() != null) cs.remove(s.noFollow().dup()); + if (s.noFollow() != null) cs = cs.minus(s.noFollow()); } if (c != null && e==me) { - c.follow.put(e, cs.dup()); + c.follow.put(e, cs); c.eof.put(e, eof); } - cso.add(cs); + cso = cso.union(cs); cs = cso; eofo |= eof; eof = eofo;