-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
52 lines (44 loc) · 1.12 KB
/
main.cpp
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
#include "src/scanner.h"
#include "src/parser.h"
#include "src/ast/SeleniumASTVisitor.h"
#include <fstream>
#define NUM_ARGS (3)
using namespace std;
int main(int argc, const char** argv) {
if(argc != NUM_ARGS) {
cerr << "You must provide two arguments." << endl
<< " e.g. ./restricted-nl in.txt out.txt" << endl;
return -1;
}
string in_path = argv[1];
string out_path = argv[2];
ifstream infile = ifstream(in_path);
ofstream outfile = ofstream(out_path);
string line;
string file;
if (infile.is_open()) {
while (getline(infile, line)) {
file += line + "\n";
}
infile.close();
}
else {
cerr << "Unable to open file!" << endl;
return -1;
}
parser p(std::move(file));
auto res = p.parse();
if(res.has_value()) {
const auto& tree = res.value();
SeleniumASTVisitor visitor;
string code = tree.accept(visitor);
outfile << code;
cout << "Compiled Successfully" << endl;
} else{
for(const auto& err : res.error()) {
cout << err << endl;
}
cerr << "Compilation failed";
}
return 0;
}