-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.cc
56 lines (44 loc) · 1.15 KB
/
driver.cc
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
// $Id: driver.cc 39 2008-08-03 10:07:15Z tb $
/** \file driver.cc Implementation of the example::Driver class. */
#include <fstream>
#include <sstream>
#include "driver.h"
#include "scanner.h"
namespace example {
Driver::Driver(class CudfDoc& _doc)
: trace_scanning(false),
trace_parsing(false),
doc(_doc)
{
}
bool Driver::parse_stream(std::istream& in, const std::string& sname)
{
streamname = sname;
Scanner scanner(&in);
scanner.set_debug(trace_scanning);
this->lexer = &scanner;
Parser parser(*this);
parser.set_debug_level(trace_parsing);
return (parser.parse() == 0);
}
bool Driver::parse_file(const std::string &filename)
{
std::ifstream in(filename.c_str());
if (!in.good()) return false;
return parse_stream(in, filename);
}
bool Driver::parse_string(const std::string &input, const std::string& sname)
{
std::istringstream iss(input);
return parse_stream(iss, sname);
}
void Driver::error(const class location& l,
const std::string& m)
{
std::cerr << l << ": " << m << std::endl;
}
void Driver::error(const std::string& m)
{
std::cerr << m << std::endl;
}
} // namespace example