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