return null;
}
private static Token evalLoop(AbstractClass<?> caller, ArrayList<Token> lines, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
Token line = lines.remove(0);
frame = new Frame(frame);
if (line.getCar().equals("for")) {
if (!line.getNextToken().getCarType().equals(parenthesesType))
throw new UnexpectedTokenException("Expected a parenthesis, got a " + line.getNextToken().getCarType() + ". " + line.toString());
ArrayList<Token> inner = splitLines((Token) line.getNextToken().getCar());
Token block = line.getNextToken().getNextToken();
if (block.getCarType().equals(curlyBracesType))
block = (Token) block.getCar();
else
block = null;
eval(caller, inner.remove(0), frame);
if (inner.size() < 2)
throw new UnendedLineException("A for loop requires three arguments, got " + inner.size() + 1 + ".");
Token incrementer = inner.remove(1);
while (!incrementer.isNull()) {
Token item = new Token();
do {
item = item.append(incrementer.singular());
} while (!(incrementer = incrementer.getNextToken()).getCarType().equals(separatorType) && !incrementer.isNull());
if (!incrementer.isNull())
incrementer = incrementer.getNextToken();
inner.add(item.getFirstToken());
}
while (((PrimitiveObject<Boolean>) eval(caller, inner.get(0), frame).getCar()).getSource()) {
if (block != null) {
Token result = eval(caller, block.clone(), new Frame(frame));
if (result.getCarType().equals(breakType))
if (result.getCar().equals("continue"))
continue;
else
return result.getCar().equals("break") ? null : result;
}
for (int i = 0; i < inner.size(); i++)
eval(caller, inner.get(i).clone(), frame);
}
}
else {
Token block = null;
if (line.getCar().equals("do")) {
if (!line.getNextToken().getCarType().equals(curlyBracesType))
throw new UnexpectedTokenException("Expected a curly brace, got a " + line.getNextToken().getCarType() + ". " + line.toString());
block = (Token) line.getNextToken().getCar();
Token result = eval(caller, block.clone(), new Frame(frame));
if (result.getCarType().equals(breakType) && !result.getCar().equals("continue"))
return result.getCar().equals("break") ? null : result;
line = lines.remove(0);
}
else
block = (Token) line.getNextToken().getNextToken().getCar();
if (!line.getNextToken().getCarType().equals(parenthesesType))
throw new UnexpectedTokenException("Expected a parenthesis, got a " + line.getNextToken().getCarType() + ". " + line.toString());
Token condition = (Token) line.getNextToken().getCar();
while (((PrimitiveObject<Boolean>) eval(caller, condition.clone(), frame).getCar()).getSource()) {
if (block != null) {
Token result = eval(caller, block.clone(), new Frame(frame));
if (result.getCarType().equals(breakType))
if (result.getCar().equals("continue"))
continue;
else
return result.getCar().equals("break") ? null : result;