calc++.cc 740 Bytes
Newer Older
1
2
3
4
5
6
7
8
// See https://www.gnu.org/software/bison/manual/html_node/Calc_002b_002b-Top-Level.html
#include <iostream>
#include "driver.hh"


int
main (int argc, char *argv[])
{
9
10
  // we build an interpreter, 
  // hence we return an int as the result of the expressions we evaluate
11
12
13
14
15
16
17
18
  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]))
19
20
      // parse() returns 1 if it ran into an error
      // so with !drv.parse we are here if everything was fine
21
22
      std::cout << drv.result << '\n';
    else
23
      // error while parsing
24
25
26
27
      res = 1;
  return res;
}