- public Token.Location getLocation() { return location; }
-
- /** add a new node (merging with existing nodes if possible)
- * @param parent the parent of the new node
- * @param result the SPPF result corresponding to the new node
- * @param state the state that the new node is in
- * @param fromEmptyReduction true iff this node is being created as a result of a reduction of length zero (see GRMLR paper)
- * @param start the earliest part of the input contributing to this node (used to make merging decisions)
- */
- public void newNode(Node parent, Forest pending, Parser.Table.State state, boolean fromEmptyReduction) {
- Node p = hash.get(code(state, parent==null?null:parent.phase()));
- if (p != null) newNode2(p, parent, pending, state, fromEmptyReduction);
- else newNode3(parent, pending, state, fromEmptyReduction);
- }
- private void newNode2(Node p, Node parent, Forest pending, Parser.Table.State state, boolean fromEmptyReduction) {
- p.holder.merge(pending);
- if (p.parents().contains(parent)) return;
- //if (p.fe && p.phase() != parent.phase()) throw new Error("yep yep");
- //if (!p.fe && p.phase() == parent.phase()) throw new Error("yep yep2");
- p.parents().add(parent, true);
- if (p!=parent && !fromEmptyReduction) p.queueReductions(parent);
- }
- private void newNode3(Node parent, Forest pending, Parser.Table.State state, boolean fromEmptyReduction) {
- do {
- if (token != null && state.canShift(token)) break;
- if (state.isAccepting()) break;
- if (token==null) break;
- if (!state.canReduce(token)) return;
- //if (count > 1) break;
- //if (r.numPop == 0) break;
- //r.reduce(pending, parent, null, Phase.this, null);
- //return;
- } while(false);
-
- Node n = new Node(parent, pending, state, fromEmptyReduction); // 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, false);
- }
- private Phase next = null;