Finish chapter 7
This commit is contained in:
@@ -9,7 +9,9 @@ import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public class Lox {
|
||||
private static final Interpreter interpreter = new Interpreter();
|
||||
static boolean hadError = false;
|
||||
static boolean hadRuntimeError = false;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length > 1) {
|
||||
@@ -27,6 +29,8 @@ public class Lox {
|
||||
run(new String(bytes, Charset.defaultCharset()));
|
||||
if (hadError)
|
||||
System.exit(65);
|
||||
if (hadRuntimeError)
|
||||
System.exit(70);
|
||||
}
|
||||
|
||||
private static void runPrompt() throws IOException {
|
||||
@@ -53,7 +57,7 @@ public class Lox {
|
||||
if (hadError)
|
||||
return;
|
||||
|
||||
System.out.println(new AstPrinter().print(expression));
|
||||
interpreter.interpret(expression);
|
||||
}
|
||||
|
||||
static void error(int line, String message) {
|
||||
@@ -73,4 +77,9 @@ public class Lox {
|
||||
report(token.line, " at '" + token.lexeme + "'", message);
|
||||
}
|
||||
}
|
||||
|
||||
static void runtimeError(RuntimeError error) {
|
||||
System.err.println(error.getMessage() + "\n[line " + error.token.line + "]");
|
||||
hadRuntimeError = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user