private void processExpansion(NodeInstance nodeInstance) { if (nodeInstance != null) { result.append("\n["); result.append(nodeInstance.getRuleInstance().getRule()); result.append("]"); } else { result.append("[initial]"); } result.append("\t\t"); for (NodeInstance doneInstance : done) { result.append(' '); result.append(doneInstance.getNode()); } if (!todo.isEmpty()) { result.append(" *"); for (NodeInstance todoInstance : todo) { result.append(' '); result.append(todoInstance.getNode()); } } }
@Override public void visit(NodeInstance nodeInstance) { if (todo.remove(0) != nodeInstance) { throw new RuntimeException("Inconsistent generation"); } List<NodeInstance> childInstances = nodeInstance.getChildren(); for (int childIdx = childInstances.size() - 1; childIdx >= 0; childIdx--) { todo.add(0, childInstances.get(childIdx)); } while (todo.size() > 0 && todo.get(0).isOnLimit()) { done.add(todo.remove(0)); } processExpansion(nodeInstance); }
@Override public boolean prune(NodeInstance nodeInstance) { return nodeInstance.isOnLimit(); }