File indexing completed on 2024-06-16 04:29:43

0001 /*
0002  * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 #ifndef DRIVER_HH
0007 #define DRIVER_HH
0008 #include "parser.hh"
0009 #include <map>
0010 #include <string>
0011 // Give Flex the prototype of yylex we want ...
0012 #define YY_DECL yy::parser::symbol_type yylex(driver &drv)
0013 // ... and declare it for the parser's sake.
0014 YY_DECL;
0015 
0016 // Conducting the whole scanning and parsing of Calc++.
0017 class driver
0018 {
0019 public:
0020     driver();
0021     std::map<std::string, int> variables;
0022 
0023     KNumber result;
0024 
0025     int parse(const std::string expr);
0026     // Whether to generate parser debug traces.
0027     bool trace_parsing;
0028 
0029     // Handling the scanner.
0030     void scan_begin(std::string s);
0031     // Whether to generate scanner debug traces.
0032     bool trace_scanning;
0033     // The token's location used by the scanner.
0034     yy::location location;
0035     bool syntaxError = false;
0036 };
0037 #endif // ! DRIVER_HH