1#line 10196 "../../doc/bison.texi" 2%skeleton "lalr1.cc" /* -*- C++ -*- */ 3%require "2.6.90.8-d4fe" 4%defines 5%define parser_class_name "calcxx_parser" 6#line 10214 "../../doc/bison.texi" 7%code requires { 8# include <string> 9class calcxx_driver; 10} 11#line 10227 "../../doc/bison.texi" 12// The parsing context. 13%parse-param { calcxx_driver& driver } 14%lex-param { calcxx_driver& driver } 15#line 10240 "../../doc/bison.texi" 16%locations 17%initial-action 18{ 19 // Initialize the initial location. 20 @$.begin.filename = @$.end.filename = &driver.file; 21}; 22#line 10255 "../../doc/bison.texi" 23%debug 24%error-verbose 25#line 10265 "../../doc/bison.texi" 26// Symbols. 27%union 28{ 29 int ival; 30 std::string *sval; 31}; 32#line 10280 "../../doc/bison.texi" 33%code { 34# include "calc++-driver.hh" 35} 36#line 10295 "../../doc/bison.texi" 37%token END 0 "end of file" 38%token ASSIGN ":=" 39%token <sval> IDENTIFIER "identifier" 40%token <ival> NUMBER "number" 41%type <ival> exp 42#line 10309 "../../doc/bison.texi" 43%printer { yyoutput << *$$; } "identifier" 44%destructor { delete $$; } "identifier" 45 46%printer { yyoutput << $$; } <ival> 47#line 10320 "../../doc/bison.texi" 48%% 49%start unit; 50unit: assignments exp { driver.result = $2; }; 51 52assignments: 53 /* Nothing. */ {} 54| assignments assignment {}; 55 56assignment: 57 "identifier" ":=" exp 58 { driver.variables[*$1] = $3; delete $1; }; 59 60%left '+' '-'; 61%left '*' '/'; 62exp: exp '+' exp { $$ = $1 + $3; } 63 | exp '-' exp { $$ = $1 - $3; } 64 | exp '*' exp { $$ = $1 * $3; } 65 | exp '/' exp { $$ = $1 / $3; } 66 | "identifier" { $$ = driver.variables[*$1]; delete $1; } 67 | "number" { $$ = $1; }; 68%% 69#line 10349 "../../doc/bison.texi" 70void 71yy::calcxx_parser::error (const yy::calcxx_parser::location_type& l, 72 const std::string& m) 73{ 74 driver.error (l, m); 75} 76