diff options
| author | physick <mynameisgennadiy@vk.com> | 2026-08-20 18:08:25 +0500 |
|---|---|---|
| committer | physick <mynameisgennadiy@vk.com> | 2026-08-20 18:08:25 +0500 |
| commit | 6e7f0e0ae9c57f76bb57a23004819b8cb49589da (patch) | |
| tree | 43abc05566f75e1a7bbfd4238d8498ae31c21336 /jlox/app/src/main/java/org/example/lox.java | |
| parent | 61e1651e5ce526d4a9fcfdf44f3d6e5578f78ba8 (diff) | |
Diffstat (limited to 'jlox/app/src/main/java/org/example/lox.java')
| -rw-r--r-- | jlox/app/src/main/java/org/example/lox.java | 43 |
1 files changed, 43 insertions, 0 deletions
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); + } +} |
