#include <driver.h>
Public Member Functions | |
Driver (class CalcContext &calc) | |
construct a new parser driver context | |
bool | parse_stream (std::istream &in, const std::string &sname="stream input") |
Invoke the scanner and parser for a stream. | |
bool | parse_string (const std::string &input, const std::string &sname="string stream") |
Invoke the scanner and parser on an input string. | |
bool | parse_file (const std::string &filename) |
Invoke the scanner and parser on a file. | |
void | error (const class location &l, const std::string &m) |
Error handling with associated line number. | |
void | error (const std::string &m) |
General error handling. | |
Public Attributes | |
bool | trace_scanning |
enable debug output in the flex scanner | |
bool | trace_parsing |
enable debug output in the bison parser | |
std::string | streamname |
stream name (file or input stream) used for error messages. | |
class Scanner * | lexer |
Pointer to the current lexer instance, this is used to connect the parser to the scanner. | |
class CalcContext & | calc |
Reference to the calculator context filled during parsing of the expressions. |
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.
Definition at line 23 of file driver.h.
example::Driver::Driver | ( | class CalcContext & | calc | ) |
bool example::Driver::parse_stream | ( | std::istream & | in, | |
const std::string & | sname = "stream input" | |||
) |
Invoke the scanner and parser for a stream.
in | input stream | |
sname | stream name for error messages |
Definition at line 19 of file driver.cc.
References lexer, example::Parser::parse(), example::Scanner::set_debug(), example::Parser::set_debug_level(), streamname, trace_parsing, and trace_scanning.
Referenced by main(), parse_file(), and parse_string().
bool example::Driver::parse_string | ( | const std::string & | input, | |
const std::string & | sname = "string stream" | |||
) |
Invoke the scanner and parser on an input string.
input | input string | |
sname | stream name for error messages |
Definition at line 39 of file driver.cc.
References parse_stream().
Referenced by main().
bool example::Driver::parse_file | ( | const std::string & | filename | ) |
Invoke the scanner and parser on a file.
Use parse_stream with a std::ifstream if detection of file reading errors is required.
filename | input file name |
Definition at line 32 of file driver.cc.
References parse_stream().
void example::Driver::error | ( | const class location & | l, | |
const std::string & | m | |||
) |
Error handling with associated line number.
This can be modified to output the error e.g. to a dialog box.
Definition at line 45 of file driver.cc.
Referenced by example::Parser::error().
void example::Driver::error | ( | const std::string & | m | ) |
enable debug output in the flex scanner
Definition at line 30 of file driver.h.
Referenced by main(), and parse_stream().
enable debug output in the bison parser
Definition at line 33 of file driver.h.
Referenced by main(), and parse_stream().
std::string example::Driver::streamname |
stream name (file or input stream) used for error messages.
Definition at line 36 of file driver.h.
Referenced by example::Parser::parse(), and parse_stream().
class Scanner* example::Driver::lexer |
Pointer to the current lexer instance, this is used to connect the parser to the scanner.
It is used in the yylex macro.
Definition at line 75 of file driver.h.
Referenced by parse_stream().
class CalcContext& example::Driver::calc |
Reference to the calculator context filled during parsing of the expressions.
Definition at line 79 of file driver.h.
Referenced by example::Parser::parse().