package calculator.interpreter.ast.logic;
import calculator.interpreter.Cell;
import calculator.interpreter.Environment;
import calculator.interpreter.EvalException;
import calculator.interpreter.Variable;
import calculator.interpreter.ast.Statement;
/**
* The loop goto statement
*/
public abstract class LoopGotoStatement extends Statement {
/** the label of loop (may be null) */
public String label;
@Override
public Environment eval(Environment env, Cell result) {
Variable var = env.find(WhileStatement.tokenName(label));
if (var == null) {
throw new EvalException(this, "The break and continue statements "
+ "must happen only in the lexical scope of the loop.");
}
if (var.value == null) {
throw new EvalException(this, "The break and continue statements "
+ "must happen only while loop is acitve.");
}
throw new WhileStatement.LoopGotoException(var.value, isBreak());
}
/**
* @return true if it is break statement, false if continue
*/
protected abstract boolean isBreak();
}