- /** 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 boolean newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction) {
- Node p = hash.get(state, parent==null?null:parent.phase());
- if (p != null) return newNode2(p, parent, pending, state, fromEmptyReduction);
- else return newNode3(parent, pending, state, fromEmptyReduction);
- }
- public void newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction, Position reduction) {
- int pos = parent==null?0:parent.phase()==null?0:parent.phase().pos;
- Sequence owner = reduction==null ? null : reduction.owner();
- if (reduction!=null) {
- if (owner.hates!=null) {
- for (Sequence s : performed.getAll(pos))
- if (owner.hates.contains(s))
- return;
- for (Sequence s : lastperformed.getAll(pos))
- if (owner.hates.contains(s)) {
- //System.out.println("now expecting ["+pos+"] => " + s);
- expected.add(pos, s);
- return;
- }
- }
- if (owner.needs != null)
- for(Sequence s : owner.needs)
- if (!performed.contains(pos, s)) {
- waiting.add(s, new Waiting(parent, pending, state, fromEmptyReduction, reduction));
- return;
- }
- if (!performed.contains(pos, owner)) {
- performed.add(pos, owner);
- if (owner.hated != null)
- for(Sequence seq : owner.hated)
- if (performed.contains(pos, seq)) {
- performed.remove(pos, seq);
- reset = true;
- }
+ /** perform all shift operations, adding promoted nodes to <tt>next</tt> */
+ private void shift(Phase next, Forest result) throws ParseFailed {
+ this.next = next;
+ // this massively improves GC performance
+ if (prev != null) {
+ IntPairMap<Node> h = prev.hash;
+ prev.hash = null;
+ prev.performed = null;
+ for(Node n : h) n.check();
+ }
+ numOldNodes = hash.size();
+ for(Node n : hash.values()) {
+ if (token == null && n.state().isAccepting()) {
+ if (finalResult==null) finalResult = new Forest.Many();
+ for(Result r : n)
+ finalResult.merge(r.getForest());