-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.h
59 lines (45 loc) · 1.57 KB
/
parser.h
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
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef PARSER_H
#define PARSER_H
#include "helper_funcs.h"
/*
Given an input path, the parser should return a vector of strings where each string is a RISCV instruction, or a label
- Take out all comments
*/
class Parser{
public:
Parser () {}
void SetPathToFile(const fs::path& path){
current_path = path;
}
std::vector<std::string> GetInstrs(){
return instructions;
}
void Parse(){
instructions = {};
std::ifstream infile;
infile.open(current_path);
if(!infile.is_open()){
std::cout << "Error opening file at path : " << current_path << std::endl;
}
std::string line, part;
while(std::getline(infile, line)){
if(!removeWhiteSpace(line).empty() && line[0] != '#'){ // ignore newlines and starting comments
//std::cout << line << std::endl;
if(line.find("#") != std::string::npos){
part = splitString(removeWhiteSpace(line), "#")[0];
if(!part.empty()){instructions.push_back(removeWhiteSpace(part));}
} else {
instructions.push_back(removeWhiteSpace(line));
}
}
}
/*
for(auto i : instructions){
std::cout << i << std::endl;
}*/
}
private:
fs::path current_path;
std::vector<std::string> instructions;
};
#endif