while (queuedStates.size() > 0) {
ParserState current = queuedStates.remove(0);
OperationResult opres = OperationResult.CONTINUE;
while (opres == OperationResult.CONTINUE) {
int ip = current.getNextInstructionAndIncrement();
Operation op = template.getOperation(ip);
try {
opres = op.execute(current);
} catch (RuntimeException ex) {
throw new RuntimeException("Cannot execute operation at template position:\n\t" + op.getTemplatePosition(), ex);
}
if (opres == null)
throw new RuntimeException(op.getClass().toString() + " returned invalid operation result");
switch (opres) {
case CONTINUE:
// everything fine
break;
case NEXTPASS:
lastFailOffset = -1;
lastFailTemplatePositions.clear();
sideEffectBlockedTemplatePositions.clear();
opres = OperationResult.CONTINUE;
break;
case DIE:
if (queuedStates.size() == 0)
throw new RuntimeException("Last state died");
break;
case FAIL_BLOCKED:
sideEffectBlockedTemplatePositions.add(op.getTemplatePosition());
// fall through
case FAIL:
if (current.getOffset() > lastFailOffset) {
lastFailOffset = current.getOffset();
lastFailTemplatePositions.clear();
}
if (current.getOffset() == lastFailOffset) {
String cmd = op.getTemplatePosition();
if (!lastFailTemplatePositions.contains(cmd)) {
lastFailTemplatePositions.add(cmd);
}
}
break;