diff options
Diffstat (limited to 'src/com/craftinginterpreters/lox/Interpreter.java')
-rw-r--r-- | src/com/craftinginterpreters/lox/Interpreter.java | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/com/craftinginterpreters/lox/Interpreter.java b/src/com/craftinginterpreters/lox/Interpreter.java index 9d0cfb3..22c8d4a 100644 --- a/src/com/craftinginterpreters/lox/Interpreter.java +++ b/src/com/craftinginterpreters/lox/Interpreter.java @@ -161,14 +161,23 @@ class Interpreter implements Expr.Visitor<Object>, Stmt.Visitor<Void> { @Override public Void visitWhileStmt(Stmt.While stmt) { - while (isTruthy(evaluate(stmt.condition))) { - execute(stmt.body); + try { + while (isTruthy(evaluate(stmt.condition))) { + execute(stmt.body); + } + } catch (Break ex) { + // We continue on. } return null; } @Override + public Void visitBreakStmt(Stmt.Break stmt) { + throw new Break(); + } + + @Override public Object visitAssignExpr(Expr.Assign expr) { Object value = evaluate(expr.value); environment.assign(expr.name, value); |