summaryrefslogtreecommitdiff
path: root/jlox/app
diff options
context:
space:
mode:
Diffstat (limited to 'jlox/app')
-rw-r--r--jlox/app/build.gradle10
-rw-r--r--jlox/app/src/main/java/org/example/App.java14
-rw-r--r--jlox/app/src/main/java/org/example/lox.java43
3 files changed, 52 insertions, 15 deletions
diff --git a/jlox/app/build.gradle b/jlox/app/build.gradle
index 87365b8..799620d 100644
--- a/jlox/app/build.gradle
+++ b/jlox/app/build.gradle
@@ -34,10 +34,18 @@ java {
application {
// Define the main class for the application.
- mainClass = 'org.example.App'
+ mainClass = 'org.example.lox'
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
+
+tasks.named('jar') {
+ manifest {
+ attributes(
+ 'Main-Class': 'org.example.lox'
+ )
+ }
+}
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);
+ }
+}