Addlw instruction (#4)
* Added addlw command * Write to program list * Included CommandUtils as helpter class. Sorted classes into packages * Revert changes on HelloWorld * Revert "Revert changes on HelloWorld" This reverts commit a08a336864fb2aa2bbc5a4e37ca360765774965e. * Added example execution of Addlw command
This commit is contained in:
33
parser/Parser.java
Normal file
33
parser/Parser.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package parser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Parser
|
||||
{
|
||||
public static List<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