// See https://www.gnu.org/software/bison/manual/html_node/Calc_002b_002b-Parsing-Driver.html #ifndef DRIVER_HH # define DRIVER_HH # include # include # include "parser.hh" // Give Flex the prototype of yylex we want: // because of %define api.value.type variant and %define api.token.constructor in parser.yy // the parser defines the type symbol_type, and expects yylex to have the following prototype. # define YY_DECL \ yy::parser::symbol_type yylex (driver& drv) // ... and declare it for the parser's sake. // yylex now returns a complete symbol, aggregating its type (i.e., the traditional value returned by yylex), // its semantic value, and possibly its location. // see https://www.gnu.org/software/bison/manual/html_node/Complete-Symbols.html YY_DECL; // Conducting the whole scanning and parsing of Calc++. // This is the parsing context, an interface to the parser and scanner // Contains all the data to exchange -> opens file to scan, instantiates the parser etc. class driver { public: driver (); std::map variables; // this holds the variables and their values we find on the way int result; // the evaluated expession result // Run the parser on file F. Return 0 on success and 1 on failure. int parse (const std::string& f); // The name of the file being parsed. std::string file; // Whether to generate parser debug traces. bool trace_parsing; // Handling the scanner. // These functions are declared at the end of scanner.ll void scan_begin (); void scan_end (); // Whether to generate scanner debug traces. bool trace_scanning; // The token's location used by the scanner. // made available by 'yy::location& loc = drv.location;' in scanner.ll yy::location location; }; #endif // ! DRIVER_HH