- 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) {
+ 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;
+ }
+ }
+ }
+ if (!owner.lame)
+ newNode(parent, pending, state, fromEmptyReduction);
+ if (reduction != null) {
+ boolean redo = true;
+ while(redo) {
+ redo = false;
+ for(Waiting w : waiting.getAll(owner)) {
+ if (w.parent==parent || (parent!=null&&w.parent!=null&&w.parent.phase()==parent.phase())) {
+ waiting.remove(owner, w);
+ w.perform();
+ redo = true;
+ break;
+ }
+ }
+ }
+ }