- private Node(Node parent, Forest pending, Parser.Table.State state, Phase start) {
- this.state = state;
- if (pending != null) this.holder().merge(pending);
- if (parent != null) parents.add(parent, true);
- if (Phase.this.hash.get(code(state, start)) != null) throw new Error("severe problem!");
- Phase.this.hash.put(code(state, start), this);
- Phase.this.numNodes++;
- if (parent==null) holder().valid = true; // hack to make sure that the "base" node is always considered valid
- }
- }
-
- public void newReduct(Node n, Node n2, Parser.Table.Reduction r) {
- new Reduct(n, n2, r)/*.go()*/;
- }
-
- // Forest / Completed Reductions //////////////////////////////////////////////////////////////////////////////
-
- /** a pending or completed reduction */
- class Reduct {
-
- /** the node from which the reduction should begin */
- public Node n = null;
-
- /** the node on the other end of the edge to be reduced along (either: null, the second node of the reduction,
- * or the parent of the result of a length-one reduction)
- */
- public Node n2 = null;
-
- /** true iff the reduction has already been performed */
- private boolean done = false;
-
- /** the reduction to be applied */
- public Parser.Table.Reduction r;
-
- public Tree<String> result = null;
-
- public Reduct(Node n, Node n2, Parser.Table.Reduction r) {
- this.n = n;
- this.n2 = n2;
- this.r = r;
- if (reductions.contains(this)) { done = true; return; }
- reductions.add(this);
- pendingReduct.addFirst(this);
- pendingReductions++;
- }
-
- /** perform the reduction */
- public void go() {
- if (done) return;
- done = true;
- pendingReduct.remove(this);
- pendingReductions--;
-
- if (r==null)
- for(Parser.Table.Reduction r : token==null ? n.state.getEofReductions() : n.state.getReductions(token)) {
-
- // currently we have this weird problem where we
- // have to do an individual reduct for each child
- // when the reduction length is one (ie the
- // children wind up being children of the newly
- // created node rather than part of the popped
- // sequence
-
- if (r.numPop == 1) new Reduct(n, n2, r).go();
+ public void reduce(Position r, int pos, Phase target, Forest[] holder) {
+ Forest old = holder[pos];
+ holder[pos] = this.pending();
+ if (pos==0) {
+ System.arraycopy(holder, 0, r.holder, 0, holder.length);
+ for(int i=0; i<r.pos; i++) if (r.holder[i]==null) throw new Error("realbad");
+ Forest rex = null;
+ if (r.pos==1) rex = singularReductions.get(this, r);
+ if (rex==null) {
+ rex = r.rewrite(phase().getLocation());
+ if (r.pos==1) singularReductions.put(this, r, rex);