From ee63307aee839c7ce5e7bf032402a3b05809c51e Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 11 Nov 2020 21:33:02 -0800 Subject: Add the interpreter --- src/com/craftinginterpreters/lox/Lox.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/com/craftinginterpreters/lox/Lox.java') 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; + } } -- cgit v1.2.3-54-g00ecf