started chapter 1 scanning
This commit is contained in:
parent
164814ca9d
commit
bc70468db2
39
jlox/Lox.java
Normal file
39
jlox/Lox.java
Normal file
@ -0,0 +1,39 @@
|
||||
package com.craftinginterpreters.lox;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public class Lox {
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length > 1) {
|
||||
System.out.println("Usage: jlox [script]");
|
||||
System.exit(64);
|
||||
} else if (args.length == 1) {
|
||||
runFile(args[0]);
|
||||
} else {
|
||||
runPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
private static void runFile(String path) throws IOException {
|
||||
byte[] bytes =Files.readAllBytes(Paths.get(path));
|
||||
run(new String(bytes, Charset.defaultCharset()));
|
||||
}
|
||||
|
||||
private static void runPrompt() throws IOException {
|
||||
InputStreamReader input = new InputStreamReader(System.in);
|
||||
BufferedReader reader = new BufferedReader(input);
|
||||
|
||||
for (;;) {
|
||||
System.out.print("> ");
|
||||
String line = reader.readLine();
|
||||
if (line == null) break;
|
||||
run(line);
|
||||
}
|
||||
}
|
||||
}
|
10
jlox/Makefile
Normal file
10
jlox/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
##
|
||||
# jlox
|
||||
#
|
||||
# @file
|
||||
# @version 0.1
|
||||
all:
|
||||
javac -d . Lox.java
|
||||
|
||||
|
||||
# end
|
Loading…
Reference in New Issue
Block a user