@Override
public boolean writeVariable(String variable, Token value, boolean isNew) throws InterpreterException {
if (isNew) {
if (variables.containsKey(variable))
throw new InvalidAssignmentException("The a variable called " + variable + " already exists in this frame.");
variables.put(variable, new Pair<AbstractClass<?>, Token>(((Variable<?>) value.getCar()).getType(), value));
return true;
}
if (variables.containsKey(variable)) {
Pair<AbstractClass<?>, Token> pair = variables.get(variable);
if (((Variable<?>) value.getCar()).getType().extend(pair.getX()) != -1) {
pair.setY(value);
return true;
}
throw new InvalidAssignmentException("Cannot assign a value of the type, " + ((Variable<?>) value.getCar()).getType() + ", to the type " + pair.getX());
}
else if (previous != null && !(previous instanceof RootFrame))
return previous.writeVariable(variable, value, false); //Cannot be a first assignment
throw new VariableNotFoundException(variable + " has not been declared in this frame or scope.");
}