summaryrefslogtreecommitdiff
path: root/jlox/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'jlox/app/src/main')
-rw-r--r--jlox/app/src/main/java/org/example/App.java14
-rw-r--r--jlox/app/src/main/java/org/example/lox.java43
2 files changed, 43 insertions, 14 deletions
diff --git a/jlox/app/src/main/java/org/example/App.java b/jlox/app/src/main/java/org/example/App.java
deleted file mode 100644
index e7e1af9..0000000
--- a/jlox/app/src/main/java/org/example/App.java
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * This source file was generated by the Gradle 'init' task
- */
-package org.example;
-
-public class App {
- public String getGreeting() {
- return "Hello World!";
- }
-
- public static void main(String[] args) {
- System.out.println(new App().getGreeting());
- }
-}
diff --git a/jlox/app/src/main/java/org/example/lox.java b/jlox/app/src/main/java/org/example/lox.java
new file mode 100644
index 0000000..e15f8ad
--- /dev/null
+++ b/jlox/app/src/main/java/org/example/lox.java
@@ -0,0 +1,43 @@
+package org.example;
+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;
+
+public class lox {
+ public static void main(String[] args) throws IOException {
+ switch (args.length) {
+ case 0:
+ RunPropmt();
+ return;
+ case 1:
+ InerpritFile(args[0]);
+ return;
+ default:
+ System.out.println("Invalid arguments");
+ }
+ }
+
+ private static void RunPropmt() throws IOException {
+ InputStreamReader inp = new InputStreamReader(System.in);
+ BufferedReader reader= new BufferedReader(inp);
+
+ while (true) {
+ System.out.print("$ ");
+ String prompt = reader.readLine();
+ if (prompt == null) break;
+ run(prompt);
+ }
+ }
+
+ private static void InerpritFile(String fileName) throws IOException {
+ byte[] bytes = Files.readAllBytes(Paths.get(fileName));
+ run(new String(bytes, Charset.defaultCharset()));
+ }
+
+ private static void run(String program) {
+ System.out.println(program);
+ }
+}