summaryrefslogtreecommitdiffstats
path: root/src/com/craftinginterpreters/lox/Lox.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/craftinginterpreters/lox/Lox.java')
-rw-r--r--src/com/craftinginterpreters/lox/Lox.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/com/craftinginterpreters/lox/Lox.java b/src/com/craftinginterpreters/lox/Lox.java
index 586442d..a3334e3 100644
--- a/src/com/craftinginterpreters/lox/Lox.java
+++ b/src/com/craftinginterpreters/lox/Lox.java
@@ -9,7 +9,9 @@ import java.nio.file.Paths;
import java.util.List;
public class Lox {
- private static boolean hadError = false;
+ private static final Interpreter interpreter = new Interpreter();
+ public static boolean hadError = false;
+ public static boolean hadRuntimeError = false;
public static void main(String[] args) throws IOException {
if (args.length > 1) {
@@ -29,6 +31,8 @@ public class Lox {
// Indicate an error in the exit code.
if (hadError)
System.exit(65);
+ if (hadRuntimeError)
+ System.exit(70);
}
private static void runPrompt() throws IOException {
@@ -52,9 +56,10 @@ public class Lox {
Expr expression = parser.parse();
// Stop if there was a syntax error
- if (hadError) return;
+ if (hadError)
+ return;
- System.out.println(new AstPrinter().print(expression));
+ interpreter.interpret(expression);
}
public static void error(int line, String message) {
@@ -73,4 +78,9 @@ public class Lox {
report(token.line, " at '" + token.lexeme + "'", message);
}
}
+
+ public static void runtimeError(RuntimeError error) {
+ System.err.println(error.getMessage() + "\n[line " + error.token.line + "]");
+ hadRuntimeError = true;
+ }
}