-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParser.java
More file actions
47 lines (39 loc) · 1.09 KB
/
Parser.java
File metadata and controls
47 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
public class Parser{
private HashMap<Integer,ArrayList<String>> instructions = new HashMap<Integer,ArrayList<String>>();
//CONSTRUCTOR
public Parser(String inputFile){
readFile(inputFile);
}
//READ INPUT FILE AND PARSE
public void readFile(String inputFile) {
ArrayList<String> row = new ArrayList<String>();
int count = 1;
try {
//file reading should be dynamic
BufferedReader in = new BufferedReader(new FileReader(inputFile));
String line = null;
//parsing
while ((line = in.readLine()) != null) {
for (String token : line.split(" ")) {
token = token.replace(",","");
token = token.toUpperCase();
row.add(token);
}
//add one line of instruction in the hashmap
instructions.put(count, new ArrayList<String>(row));
row.clear();
count++;
}
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
//GETTER
public HashMap<Integer,ArrayList<String>> getInstructions() {
return instructions;
}
}