for(int i=0; i<num; i++) {
Node n = reducing_list[i];
reducing_list[i] = null;
- n.queueEmptyReductions();
n.queueReductions();
}
}
if (allqueued) return;
allqueued = true;
int where = parents().size();
- for(Parser.Table.Reduction r : token==null ? state.getEofReductions() : state.getReductions(token))
+ for(Parser.Table.Reduction r : state.getReductions(token))
if (r.numPop >= 1)
r.reduce(this, null, null);
}
/** FIXME */
- public void queueReductions(Node n2) { queueReductions(n2, true); }
- public void queueReductions(Node n2, boolean includeLongs) {
+ public void queueReductions(Node n2) {
if (!allqueued) { queueReductions(); return; }
- Node n = this;
- for(Parser.Table.Reduction r : token==null ? n.state.getEofReductions() : n.state.getReductions(token)) {
-
- // UGLY HACK
- // The problem here is that a "reduction of length 1"
- // performed twice with different values of n2 needs
- // to only create a *single* new result, but must add
- // multiple parents to the node holding that result.
- // The current reducer doesn't differentiate between
- // the next node of an n-pop reduction and the
- // ultimate parent of the last pop, so we need to
- // cache instances here as a way of avoiding
- // recreating them.
- if (r.numPop <= 0) continue;
- if (r.numPop == 1) {
- Forest ret = n.cache().get(r);
- if (ret != null) r.reduce(this, n2, ret);
- else n.cache().put(r, r.reduce(this, n2, null));
- } else {
+ for(Parser.Table.Reduction r : state.getReductions(token))
+ if (r.numPop > 0)
r.reduce(this, n2, null);
- }
- }
}
public boolean canShift(Token t) { return shifts.contains(t); }
public Iterable<State> getShifts(Token t) { return shifts.get(t); }
public boolean isAccepting() { return accept; }
- public Iterable<Reduction> getReductions(Token t) { return reductions.get(t); }
+ public Iterable<Reduction> getReductions(Token t) { return t==null ? eofReductions : reductions.get(t); }
public Iterable<Reduction> getEofReductions() { return eofReductions; }
public Iterator<Position> iterator() { return hs.iterator(); }
Union mg = gram.done();
System.out.println("\nparsing " + s[1]);
- res = new CharToken.CharToStringParser(mg).parse1(new Tib(new FileInputStream(s[1])));
- System.out.println(((Tree)walk(res)).toString(0, 0, 120));
+ Forest f = new CharToken.CharToStringParser(mg).parse(new Tib(new FileInputStream(s[1])));
+ System.out.println(f);
+ System.out.println(((Tree)walk(f.expand1())).toString(0, 0, 120));
}
public static Tree<String> walk(Tree<String> tree) {
+x::="x"
// indentation styling...
// literal blocks [[need to ignore bracing]] double-colon style?
// definition -- by prior line indentation, like headings in the original structured text
//////////////////////////////////////////////////////////////////////////////
-s ::= {Doc} => top
+s ::= { Doc } => "top"
Doc ::= Header Body /ws => doc
Header ::= "header" { kv */ ws } /ws => header