aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/craftinginterpreters/lox/Interpreter.java
diff options
context:
space:
mode:
authorGravatar Tom Willemse2021-01-16 22:16:31 -0800
committerGravatar Tom Willemse2021-01-16 22:16:31 -0800
commit3b9c44434e8bc395068eb8c3e319e384b66ed72e (patch)
tree929dd1c6151a606397a92836e01fb9f8e4bd715b /src/com/craftinginterpreters/lox/Interpreter.java
parentc62b73a2477b9fa625285e9c2ca1e51c2bcb8024 (diff)
downloadcrafting-interpreters-3b9c44434e8bc395068eb8c3e319e384b66ed72e.tar.gz
crafting-interpreters-3b9c44434e8bc395068eb8c3e319e384b66ed72e.zip
Add while statement
Diffstat (limited to 'src/com/craftinginterpreters/lox/Interpreter.java')
-rw-r--r--src/com/craftinginterpreters/lox/Interpreter.java9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/com/craftinginterpreters/lox/Interpreter.java b/src/com/craftinginterpreters/lox/Interpreter.java
index 6c32233..6b3e409 100644
--- a/src/com/craftinginterpreters/lox/Interpreter.java
+++ b/src/com/craftinginterpreters/lox/Interpreter.java
@@ -158,6 +158,15 @@ class Interpreter implements Expr.Visitor<Object>, Stmt.Visitor<Void> {
}
@Override
+ public Void visitWhileStmt(Stmt.While stmt) {
+ while (isTruthy(evaluate(stmt.condition))) {
+ execute(stmt.body);
+ }
+
+ return null;
+ }
+
+ @Override
public Object visitAssignExpr(Expr.Assign expr) {
Object value = evaluate(expr.value);
environment.assign(expr.name, value);