driver.cc 816 Bytes
Newer Older
1
2
3
4
5
6
7
// See https://www.gnu.org/software/bison/manual/html_node/Calc_002b_002b-Parsing-Driver.html
#include "driver.hh"
#include "parser.hh"

driver::driver ()
  : trace_parsing (false), trace_scanning (false)
{
8
9
  // These are hardcoded variables that are now available inside expressions you write
  // e.g. 'y = one + 1'
10
11
12
13
14
15
16
17
  variables["one"] = 1;
  variables["two"] = 2;
}

int
driver::parse (const std::string &f)
{
  file = f;
18
  location.initialize (&file);  // set location to beginning of file or stdin
19
  scan_begin ();
20
  yy::parser parse (*this);     // set the parsing context to *this (remember, we are inside driver.cc class)
21
  parse.set_debug_level (trace_parsing);
22
  int res = parse ();   //this evaluates the file (or stdin, see scan_begin() definition at the end of scanner.ll)
23
24
25
  scan_end ();
  return res;
}