-
Notifications
You must be signed in to change notification settings - Fork 17
/
driver.cpp
51 lines (40 loc) · 981 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
46
47
48
49
50
#include "driver.hh"
#include "parser.hh"
#include "visitors/Interpreter.h"
#include "visitors/PrintVisitor.h"
Driver::Driver() :
trace_parsing(false),
trace_scanning(false),
scanner(*this), parser(scanner, *this) {
}
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 << "parser " << res << std::endl;
scan_end();
return res;
}
int Driver::Evaluate() {
Interpreter interpreter;
return interpreter.GetResult(program);
}
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();
}
void Driver::PrintTree(const std::string& filename) {
SymbolTreeVisitor visitor(filename);
visitor.Visit(program);
}