protected Parser(Table<Tok> pt) { this.pt = pt; }
/** implement this method to create the output forest corresponding to a lone shifted input token */
- public abstract Forest<Result> shiftToken(Input.Location oldloc, Tok t, Input.Location newloc);
+ protected abstract Forest<Result> shiftToken(Tok t, Input.Location newloc);
- public boolean helpgc = true;
+ boolean helpgc = true;
public String toString() { return pt.toString(); }
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<Tok>(current, this, current, input.next(), loc, forest);
if (!helpgc) {
FileOutputStream fos = new FileOutputStream("out-"+idx+".dot");
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<Element> 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 */
// Helpers //////////////////////////////////////////////////////////////////////////////
+ private static void reachable(Sequence s, HashSet<Position> 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<Position> 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<Position> h) {
if (h.contains(p)) return;