-
- Node n = new Node(parent, pending, state, start); // ALLOC
- n.queueEmptyReductions();
- if (!fromEmptyReduction) n.queueReductions(parent);
- }
-
-
- /** perform all reduction operations */
- public void reduce() {
- reducing = true;
- if (reducing_list==null || reducing_list.length < hash.size())
- reducing_list = new Phase.Node[hash.size() * 4];
- Collection<Node> hv = hash.values();
- hv.toArray(reducing_list);
- int num = hv.size();
- for(int i=0; i<num; i++) {
- Node n = reducing_list[i];
- n.queueEmptyReductions();
- // INVARIANT: we never "see" a node until its parent-set is complete, modulo merges
- }
- for(int i=0; i<num; i++) {
- Node n = reducing_list[i];
- reducing_list[i] = null;
- n.queueReductions();
- }
- }
-
- public void invoke(Parser.Table.State st, Forest result, Node n) {
- next.newNode(n, result, st, true, this);
- }
- private Phase next = null;
-
- /** perform all shift operations, adding promoted nodes to <tt>next</tt> */
- public void shift(Phase next, Forest result) {
- this.next = next;
- closed = true;
- Forest res = null;
- boolean ok = false;
- for(Phase.Node n : hash.values()) {
- if (n.holder==null) continue;
- n.holder.resolve();
- if (token == null && n.state.isAccepting()) {
- ok = true;
- if (finalResult==null) finalResult = new Forest.Ref();
- finalResult.merge(n.holder);
- }
- if (!n.holder.valid()) continue;
- if (token == null) continue;
- n.state.invokeShifts(token, this, result, n);
- /*
- for(Parser.Table.State st : n.state.getShifts(token)) {
- if (res == null) res = result;
- next.newNode(n, res, st, true, this);
- ok = true;
- }
- */
- }
-
- if (!ok && token != null) {
- StringBuffer error = new StringBuffer();
- error.append("error: unable to shift token \"" + token + "\"\n");
- //error.append(" before: " +pendingReductions+ "\n");
- //error.append(" before: " +totalReductions+ "\n");
- //for(Phase.Node n : hash.values()) {
- //n.queueReductions();
- //n.queueEmptyReductions();
- //}
- //error.append(" after: " +pendingReductions+ "\n");
- //error.append(" candidate states:\n");
- //for(Phase.Node n : hash.values()) {
- //for(Sequence.Position p : n.state) error.append(" " + p + "\n");
- //error.append(" --\n");
- //for(Parser.Table.Reduction r : n.state.getReductions(token)) error.append(" " + r + "\n");
- //error.append(" ==\n");
- //}
- next.error = error.toString();
- }
-
- // this massively improves GC performance
- hash = null;