-
Notifications
You must be signed in to change notification settings - Fork 17
/
driver.cpp
46 lines (36 loc) · 880 Bytes
/
driver.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
#include "driver.hh"
#include "parser.hh"
Driver::Driver() :
trace_parsing(false),
trace_scanning(false),
scanner(*this), parser(scanner, *this) {
// variables["one"] = 1;
// variables["two"] = 2;
}
int Driver::parse(const std::string& f) {
file = f;
location.initialize(&file);
scan_begin();
parser.set_debug_level(trace_parsing);
int res = parser();
std::cout << program << std::endl;
result = program->eval(*this);
for (const auto& [name, value]: variables) {
std::cerr << name << " " << value << std::endl;
}
scan_end();
return res;
}
void Driver::scan_begin() {
scanner.set_debug(trace_scanning);
if (file.empty () || file == "-") {
} else {
stream.open(file);
std::cout << file << std::endl;
scanner.yyrestart(&stream);
}
}
void Driver::scan_end()
{
stream.close();
}