diff options
author | Tom Willemse | 2020-11-11 21:33:02 -0800 |
---|---|---|
committer | Tom Willemse | 2020-11-11 21:33:02 -0800 |
commit | ee63307aee839c7ce5e7bf032402a3b05809c51e (patch) | |
tree | feccbfc402460125b3182f504eabb153dc24e762 /src/com/craftinginterpreters/lox/Lox.java | |
parent | a78fe97f60c2ad39d3d6335c1d058bd8ee4921bb (diff) | |
download | crafting-interpreters-ee63307aee839c7ce5e7bf032402a3b05809c51e.tar.gz crafting-interpreters-ee63307aee839c7ce5e7bf032402a3b05809c51e.zip |
Add the interpreter
Diffstat (limited to 'src/com/craftinginterpreters/lox/Lox.java')
-rw-r--r-- | src/com/craftinginterpreters/lox/Lox.java | 16 |
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; + } } |