-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.h
84 lines (66 loc) · 2.83 KB
/
driver.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// $Id: driver.h 17 2007-08-19 18:51:39Z tb $
/** \file driver.h Declaration of the example::Driver class. */
#ifndef EXAMPLE_DRIVER_H
#define EXAMPLE_DRIVER_H
#include <string>
#include <vector>
// forward declaration
class CudfDoc;
/** The example namespace is used to encapsulate the three parser classes
* example::Parser, example::Scanner and example::Driver */
namespace example {
/** The Driver class brings together all components. It creates an instance of
* the Parser and Scanner classes and connects them. Then the input stream is
* fed into the scanner object and the parser gets it's token
* sequence. Furthermore the driver object is available in the grammar rules as
* a parameter. Therefore the driver class contains a reference to the
* structure into which the parsed data is saved. */
class Driver
{
public:
/// construct a new parser driver context
Driver(class CudfDoc& doc);
/// enable debug output in the flex scanner
bool trace_scanning;
/// enable debug output in the bison parser
bool trace_parsing;
/// stream name (file or input stream) used for error messages.
std::string streamname;
/** Invoke the scanner and parser for a stream.
* @param in input stream
* @param sname stream name for error messages
* @return true if successfully parsed
*/
bool parse_stream(std::istream& in,
const std::string& sname = "stream input");
/** Invoke the scanner and parser on an input string.
* @param input input string
* @param sname stream name for error messages
* @return true if successfully parsed
*/
bool parse_string(const std::string& input,
const std::string& sname = "string stream");
/** Invoke the scanner and parser on a file. Use parse_stream with a
* std::ifstream if detection of file reading errors is required.
* @param filename input file name
* @return true if successfully parsed
*/
bool parse_file(const std::string& filename);
// To demonstrate pure handling of parse errors, instead of
// simply dumping them on the standard error output, we will pass
// them to the driver using the following two member functions.
/** Error handling with associated line number. This can be modified to
* output the error e.g. to a dialog box. */
void error(const class location& l, const std::string& m);
/** General error handling. This can be modified to output the error
* e.g. to a dialog box. */
void error(const std::string& m);
/** Pointer to the current lexer instance, this is used to connect the
* parser to the scanner. It is used in the yylex macro. */
class Scanner* lexer;
/** Reference to the calculator context filled during parsing of the
* expressions. */
class CudfDoc& doc;
};
} // namespace example
#endif // EXAMPLE_DRIVER_H