-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·57 lines (48 loc) · 1.15 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
53
54
55
56
57
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "driver.hh"
#include "preprocessor.hpp"
#include <sstream>
#include "writer.h"
using namespace std;
string stream_to_string(istream &i) {
i.seekg(0, std::ios::end);
size_t size = i.tellg();
std::string buffer(size, ' ');
i.seekg(0);
i.read(&buffer[0], size);
return buffer;
}
int main(int argc, char *argv[]) {
if (argc < 5) {
cerr << "Usage: " << argv[0] << " -i <input> -o <output>" << endl;
return 1;
}
ofstream output_file(argv[4]);
ifstream input_file(argv[2]);
string i = stream_to_string(input_file);
string preprocessed = preprocess(i);
ofstream tmp("tmp.txt");
tmp << preprocessed;
tmp.flush();
tmp.close();
writer::set(&output_file);
driver drv;
int result;
try {
result = drv.parse("tmp.txt");
} catch (const runtime_error& e){
cout << "Semantic Error" << endl;
cerr << e.what() << endl;
return 2;
}
if (!result) {
cout << "OK" << endl;
} else {
cout << "Syntax Error" << endl;
return 1;
}
return 0;
}