From 97a75622f9803c35e6d9fecce207a9184c05514f Mon Sep 17 00:00:00 2001 From: Darkress Date: Tue, 9 May 2023 22:44:59 +0200 Subject: [PATCH] Implemented Program Parser --- .gitignore | 3 ++- HelloWorld.java | 4 +--- Parser.java | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 Parser.java diff --git a/.gitignore b/.gitignore index 70c3d64..211967f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ hs_err_pid* #IntelliJ Files .idea -out \ No newline at end of file +out +*.iml \ No newline at end of file diff --git a/HelloWorld.java b/HelloWorld.java index c202db0..ea520bc 100644 --- a/HelloWorld.java +++ b/HelloWorld.java @@ -2,8 +2,6 @@ class HelloWorld { public static void main(String[] args) { - System.out.println("Hello, World!"); - int input = Integer.decode("0x0070"); - CommandDecoder commandDecoder = new CommandDecoder(input); + System.out.println(Parser.parser("TPicSim2.LST")); } } \ No newline at end of file diff --git a/Parser.java b/Parser.java new file mode 100644 index 0000000..b92475b --- /dev/null +++ b/Parser.java @@ -0,0 +1,30 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Parser +{ + public static ArrayList parser(String filePath) + { + ArrayList program = new ArrayList<>(); + try { + File file = new File(filePath); + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + String data = scanner.nextLine(); + if(!data.startsWith(" ")) + { + String commandAndParametersString = "0x" + data.split(" ")[1]; + int commandAndParameters = Integer.decode(commandAndParametersString); + program.add(commandAndParameters); + } + } + scanner.close(); + } catch (FileNotFoundException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + return program; + } +}