// See https://www.gnu.org/software/bison/manual/html_node/Calc_002b_002b-Top-Level.html #include #include "driver.hh" int main (int argc, char *argv[]) { // we build an interpreter, // hence we return an int as the result of the expressions we evaluate int res = 0; driver drv; for (int i = 1; i < argc; ++i) if (argv[i] == std::string ("-p")) drv.trace_parsing = true; else if (argv[i] == std::string ("-s")) drv.trace_scanning = true; else if (!drv.parse (argv[i])) // parse() returns 1 if it ran into an error // so with !drv.parse we are here if everything was fine std::cout << drv.result << '\n'; else // error while parsing res = 1; return res; }