- public void newNode(Node parent, Forest pending, Parser.Table.State state, boolean fromEmptyReduction, Phase start) {
- Node p = hash.get(code(state, start));
- if (p != null) newNode2(p, parent, pending, state, fromEmptyReduction, start);
- else newNode3(parent, pending, state, fromEmptyReduction, start);
+ public boolean newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction) {
+ return newNode(parent, pending, state, fromEmptyReduction, null); }
+ public boolean newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction, Reduction reduction) {
+ int pos = parent==null?0:parent.phase()==null?0:parent.phase().pos;
+ if (reduction!=null) {
+ if (inhibited.contains(pos, reduction.position.owner())) return false;
+ if (reduction.position.owner().needs != null) {
+ for(Sequence s : reduction.position.owner().needs) {
+ if (!performed.contains(pos, s)) {
+ waiting.add(s, new Waiting(parent, pending, state, fromEmptyReduction, reduction));
+ return false;
+ }
+ }
+ }
+ if ((reduction.position.owner().needed != null && reduction.position.owner().needed.size()>0) ||
+ (reduction.position.owner().hated != null && reduction.position.owner().hated.size()>0) ||
+ (reduction.position.owner().hates != null && reduction.position.owner().hates.size()>0))
+ performed.add(pos, reduction.position.owner());
+ }
+ Node p = hash.get(code(state, parent==null?null:parent.phase()));
+ boolean ret;
+ if (reduction!=null) inhibit(reduction, parent==null?0:parent.phase().pos);
+ if (p != null) ret = newNode2(p, parent, pending, state, fromEmptyReduction, reduction);
+ else ret = newNode3(parent, pending, state, fromEmptyReduction, reduction);
+ if (reduction != null) {
+ boolean redo = true;
+ while(redo) {
+ redo = false;
+ for(Waiting w : waiting.getAll(reduction.position.owner())) {
+ if (w.parent==parent || (parent!=null&&w.parent!=null&&w.parent.phase()==parent.phase())) {
+ waiting.remove(reduction.position.owner(), w);
+ w.perform();
+ redo = true;
+ break;
+ }
+ }
+ }
+ }
+ return ret;