X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=d4d5415972c984141db742da684e523a41e4736d;hp=300ff27fd31156ea7a4daf2f3914fe6a7fce15b2;hb=24112db237318c030b4d4f457d90c34fd69d652b;hpb=a26089cd0d7c95cad657b745e836cb4cba35a97a diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index 300ff27..d4d5415 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -15,9 +15,9 @@ public abstract class Parser { protected Parser(Table pt) { this.pt = pt; } /** implement this method to create the output forest corresponding to a lone shifted input token */ - public abstract Forest shiftToken(Input.Location oldloc, Tok t, Input.Location newloc); + protected abstract Forest shiftToken(Tok t, Input.Location newloc); - public boolean helpgc = true; + boolean helpgc = true; public String toString() { return pt.toString(); } @@ -32,7 +32,7 @@ public abstract class Parser { Input.Location oldloc = loc; loc = input.getLocation(); current.reduce(); - Forest forest = current.token==null ? null : shiftToken(oldloc, (Tok)current.token, loc); + Forest forest = current.token==null ? null : shiftToken((Tok)current.token, loc); GSS.Phase next = gss.new Phase(current, this, current, input.next(), loc, forest); if (!helpgc) { FileOutputStream fos = new FileOutputStream("out-"+idx+".dot"); @@ -82,11 +82,15 @@ public abstract class Parser { if (hs.contains(e)) return; hs.add(e); if (e instanceof Atom) return; - for(Sequence s : (Union)e) { - hs.add(s); - for(Position p = s.firstp(); p != null; p = p.next()) - walk(p.element(), hs); - } + for(Sequence s : (Union)e) + walk(s, hs); + } + private void walk(Sequence s, HashSet hs) { + hs.add(s); + for(Position p = s.firstp(); p != null; p = p.next()) + walk(p.element(), hs); + for(Sequence ss : s.needs()) walk(ss, hs); + for(Sequence ss : s.hates()) walk(ss, hs); } /** the start state */ @@ -287,10 +291,15 @@ public abstract class Parser { // Helpers ////////////////////////////////////////////////////////////////////////////// + private static void reachable(Sequence s, HashSet h) { + reachable(s.firstp(), h); + for(Sequence ss : s.needs()) reachable(ss, h); + for(Sequence ss : s.hates()) reachable(ss, h); + } private static void reachable(Element e, HashSet h) { if (e instanceof Atom) return; for(Sequence s : ((Union)e)) - reachable(s.firstp(), h); + reachable(s, h); } private static void reachable(Position p, HashSet h) { if (h.contains(p)) return;