Implemented Program Parser
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -24,4 +24,5 @@ hs_err_pid*
|
|||||||
|
|
||||||
#IntelliJ Files
|
#IntelliJ Files
|
||||||
.idea
|
.idea
|
||||||
out
|
out
|
||||||
|
*.iml
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
class HelloWorld {
|
class HelloWorld {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello, World!");
|
System.out.println(Parser.parser("TPicSim2.LST"));
|
||||||
int input = Integer.decode("0x0070");
|
|
||||||
CommandDecoder commandDecoder = new CommandDecoder(input);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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