Implemented Program Parser

This commit is contained in:
Darkress
2023-05-09 22:44:59 +02:00
committed by DarkressX
parent 3cda4057ac
commit 97a75622f9
3 changed files with 33 additions and 4 deletions

30
Parser.java Normal file
View File

@@ -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<Integer> parser(String filePath)
{
ArrayList<Integer> 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;
}
}