Implemented Program Parser
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,3 +25,4 @@ hs_err_pid*
|
||||
#IntelliJ Files
|
||||
.idea
|
||||
out
|
||||
*.iml
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
30
Parser.java
Normal file
30
Parser.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user