Home | History | Annotate | Download | only in calc++
      1 /* A Bison parser, made by GNU Bison 2.6.90.8-d4fe.  */
      2 
      3 /* Skeleton implementation for Bison LALR(1) parsers in C++
      4 
      5       Copyright (C) 2002-2012 Free Software Foundation, Inc.
      6 
      7    This program is free software: you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation, either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 /* As a special exception, you may create a larger work that contains
     21    part or all of the Bison parser skeleton and distribute that work
     22    under terms of your choice, so long as that work isn't itself a
     23    parser generator using the skeleton or a modified version thereof
     24    as a parser skeleton.  Alternatively, if you modify or redistribute
     25    the parser skeleton itself, you may (at your option) remove this
     26    special exception, which will cause the skeleton and the resulting
     27    Bison output files to be licensed under the GNU General Public
     28    License without this special exception.
     29 
     30    This special exception was added by the Free Software Foundation in
     31    version 2.2 of Bison.  */
     32 
     33 
     34 /* First part of user declarations.  */
     35 
     36 /* Line 279 of lalr1.cc  */
     37 #line 38 "../../../../examples/calc++/calc++-parser.cc"
     38 
     39 
     40 #include "calc++-parser.hh"
     41 
     42 /* User implementation prologue.  */
     43 
     44 /* Line 285 of lalr1.cc  */
     45 #line 46 "../../../../examples/calc++/calc++-parser.cc"
     46 /* Unqualified %code blocks.  */
     47 /* Line 286 of lalr1.cc  */
     48 #line 10280 "../../doc/bison.texi"
     49 
     50 # include "calc++-driver.hh"
     51 
     52 
     53 /* Line 286 of lalr1.cc  */
     54 #line 55 "../../../../examples/calc++/calc++-parser.cc"
     55 
     56 
     57 # ifndef YY_NULL
     58 #  if defined __cplusplus && 201103L <= __cplusplus
     59 #   define YY_NULL nullptr
     60 #  else
     61 #   define YY_NULL 0
     62 #  endif
     63 # endif
     64 
     65 #ifndef YY_
     66 # if defined YYENABLE_NLS && YYENABLE_NLS
     67 #  if ENABLE_NLS
     68 #   include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
     69 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
     70 #  endif
     71 # endif
     72 # ifndef YY_
     73 #  define YY_(msgid) msgid
     74 # endif
     75 #endif
     76 
     77 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
     78 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
     79    If N is 0, then set CURRENT to the empty location which ends
     80    the previous symbol: RHS[0] (always defined).  */
     81 
     82 # ifndef YYLLOC_DEFAULT
     83 #  define YYLLOC_DEFAULT(Current, Rhs, N)                               \
     84     do                                                                  \
     85       if (N)                                                            \
     86         {                                                               \
     87           (Current).begin  = YYRHSLOC (Rhs, 1).begin;                   \
     88           (Current).end    = YYRHSLOC (Rhs, N).end;                     \
     89         }                                                               \
     90       else                                                              \
     91         {                                                               \
     92           (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;      \
     93         }                                                               \
     94     while (/*CONSTCOND*/ false)
     95 # endif
     96 
     97 
     98 /* Suppress unused-variable warnings by "using" E.  */
     99 #define YYUSE(e) ((void) (e))
    100 
    101 /* Enable debugging if requested.  */
    102 #if YYDEBUG
    103 
    104 /* A pseudo ostream that takes yydebug_ into account.  */
    105 # define YYCDEBUG if (yydebug_) (*yycdebug_)
    106 
    107 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)	\
    108 do {							\
    109   if (yydebug_)						\
    110     {							\
    111       *yycdebug_ << Title << ' ';			\
    112       yy_symbol_print_ ((Type), (Value), (Location));	\
    113       *yycdebug_ << std::endl;				\
    114     }							\
    115 } while (false)
    116 
    117 # define YY_REDUCE_PRINT(Rule)		\
    118 do {					\
    119   if (yydebug_)				\
    120     yy_reduce_print_ (Rule);		\
    121 } while (false)
    122 
    123 # define YY_STACK_PRINT()		\
    124 do {					\
    125   if (yydebug_)				\
    126     yystack_print_ ();			\
    127 } while (false)
    128 
    129 #else /* !YYDEBUG */
    130 
    131 # define YYCDEBUG if (false) std::cerr
    132 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) YYUSE(Type)
    133 # define YY_REDUCE_PRINT(Rule)        static_cast<void>(0)
    134 # define YY_STACK_PRINT()             static_cast<void>(0)
    135 
    136 #endif /* !YYDEBUG */
    137 
    138 #define yyerrok		(yyerrstatus_ = 0)
    139 #define yyclearin	(yychar = yyempty_)
    140 
    141 #define YYACCEPT	goto yyacceptlab
    142 #define YYABORT		goto yyabortlab
    143 #define YYERROR		goto yyerrorlab
    144 #define YYRECOVERING()  (!!yyerrstatus_)
    145 
    146 
    147 namespace yy {
    148 /* Line 353 of lalr1.cc  */
    149 #line 150 "../../../../examples/calc++/calc++-parser.cc"
    150 
    151   /* Return YYSTR after stripping away unnecessary quotes and
    152      backslashes, so that it's suitable for yyerror.  The heuristic is
    153      that double-quoting is unnecessary unless the string contains an
    154      apostrophe, a comma, or backslash (other than backslash-backslash).
    155      YYSTR is taken from yytname.  */
    156   std::string
    157   calcxx_parser::yytnamerr_ (const char *yystr)
    158   {
    159     if (*yystr == '"')
    160       {
    161         std::string yyr = "";
    162         char const *yyp = yystr;
    163 
    164         for (;;)
    165           switch (*++yyp)
    166             {
    167             case '\'':
    168             case ',':
    169               goto do_not_strip_quotes;
    170 
    171             case '\\':
    172               if (*++yyp != '\\')
    173                 goto do_not_strip_quotes;
    174               /* Fall through.  */
    175             default:
    176               yyr += *yyp;
    177               break;
    178 
    179             case '"':
    180               return yyr;
    181             }
    182       do_not_strip_quotes: ;
    183       }
    184 
    185     return yystr;
    186   }
    187 
    188 
    189   /// Build a parser object.
    190   calcxx_parser::calcxx_parser (calcxx_driver& driver_yyarg)
    191     :
    192 #if YYDEBUG
    193       yydebug_ (false),
    194       yycdebug_ (&std::cerr),
    195 #endif
    196       driver (driver_yyarg)
    197   {
    198   }
    199 
    200   calcxx_parser::~calcxx_parser ()
    201   {
    202   }
    203 
    204 #if YYDEBUG
    205   /*--------------------------------.
    206   | Print this symbol on YYOUTPUT.  |
    207   `--------------------------------*/
    208 
    209   inline void
    210   calcxx_parser::yy_symbol_value_print_ (int yytype,
    211 			   const semantic_type* yyvaluep, const location_type* yylocationp)
    212   {
    213     YYUSE (yylocationp);
    214     YYUSE (yyvaluep);
    215     std::ostream& yyo = debug_stream ();
    216     std::ostream& yyoutput = yyo;
    217     YYUSE (yyoutput);
    218     switch (yytype)
    219       {
    220         case 4: /* "identifier" */
    221 /* Line 423 of lalr1.cc  */
    222 #line 10309 "../../doc/bison.texi"
    223         { yyoutput << *((*yyvaluep).sval); };
    224 /* Line 423 of lalr1.cc  */
    225 #line 226 "../../../../examples/calc++/calc++-parser.cc"
    226         break;
    227       case 5: /* "number" */
    228 /* Line 423 of lalr1.cc  */
    229 #line 10312 "../../doc/bison.texi"
    230         { yyoutput << ((*yyvaluep).ival); };
    231 /* Line 423 of lalr1.cc  */
    232 #line 233 "../../../../examples/calc++/calc++-parser.cc"
    233         break;
    234       case 14: /* exp */
    235 /* Line 423 of lalr1.cc  */
    236 #line 10312 "../../doc/bison.texi"
    237         { yyoutput << ((*yyvaluep).ival); };
    238 /* Line 423 of lalr1.cc  */
    239 #line 240 "../../../../examples/calc++/calc++-parser.cc"
    240         break;
    241        default:
    242 	  break;
    243       }
    244   }
    245 
    246 
    247   void
    248   calcxx_parser::yy_symbol_print_ (int yytype,
    249 			   const semantic_type* yyvaluep, const location_type* yylocationp)
    250   {
    251     *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
    252 	       << ' ' << yytname_[yytype] << " ("
    253 	       << *yylocationp << ": ";
    254     yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
    255     *yycdebug_ << ')';
    256   }
    257 #endif
    258 
    259   void
    260   calcxx_parser::yydestruct_ (const char* yymsg,
    261 			   int yytype, semantic_type* yyvaluep, location_type* yylocationp)
    262   {
    263     YYUSE (yylocationp);
    264     YYUSE (yymsg);
    265     YYUSE (yyvaluep);
    266 
    267     if (yymsg)
    268       YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
    269 
    270     switch (yytype)
    271       {
    272         case 4: /* "identifier" */
    273 /* Line 455 of lalr1.cc  */
    274 #line 10310 "../../doc/bison.texi"
    275         { delete ((*yyvaluep).sval); };
    276 /* Line 455 of lalr1.cc  */
    277 #line 278 "../../../../examples/calc++/calc++-parser.cc"
    278         break;
    279 
    280 	default:
    281 	  break;
    282       }
    283   }
    284 
    285   void
    286   calcxx_parser::yypop_ (unsigned int n)
    287   {
    288     yystate_stack_.pop (n);
    289     yysemantic_stack_.pop (n);
    290     yylocation_stack_.pop (n);
    291   }
    292 
    293 #if YYDEBUG
    294   std::ostream&
    295   calcxx_parser::debug_stream () const
    296   {
    297     return *yycdebug_;
    298   }
    299 
    300   void
    301   calcxx_parser::set_debug_stream (std::ostream& o)
    302   {
    303     yycdebug_ = &o;
    304   }
    305 
    306 
    307   calcxx_parser::debug_level_type
    308   calcxx_parser::debug_level () const
    309   {
    310     return yydebug_;
    311   }
    312 
    313   void
    314   calcxx_parser::set_debug_level (debug_level_type l)
    315   {
    316     yydebug_ = l;
    317   }
    318 #endif
    319 
    320   inline bool
    321   calcxx_parser::yy_pact_value_is_default_ (int yyvalue)
    322   {
    323     return yyvalue == yypact_ninf_;
    324   }
    325 
    326   inline bool
    327   calcxx_parser::yy_table_value_is_error_ (int yyvalue)
    328   {
    329     return yyvalue == yytable_ninf_;
    330   }
    331 
    332   int
    333   calcxx_parser::parse ()
    334   {
    335     /// Lookahead and lookahead in internal form.
    336     int yychar = yyempty_;
    337     int yytoken = 0;
    338 
    339     // State.
    340     int yyn;
    341     int yylen = 0;
    342     int yystate = 0;
    343 
    344     // Error handling.
    345     int yynerrs_ = 0;
    346     int yyerrstatus_ = 0;
    347 
    348     /// Semantic value of the lookahead.
    349     static semantic_type yyval_default;
    350     semantic_type yylval = yyval_default;
    351     /// Location of the lookahead.
    352     location_type yylloc;
    353     /// The locations where the error started and ended.
    354     location_type yyerror_range[3];
    355 
    356     /// $$.
    357     semantic_type yyval;
    358     /// @$.
    359     location_type yyloc;
    360 
    361     int yyresult;
    362 
    363     // FIXME: This shoud be completely indented.  It is not yet to
    364     // avoid gratuitous conflicts when merging into the master branch.
    365     try
    366       {
    367     YYCDEBUG << "Starting parse" << std::endl;
    368 
    369 
    370 /* User initialization code.  */
    371 /* Line 545 of lalr1.cc  */
    372 #line 10242 "../../doc/bison.texi"
    373 {
    374   // Initialize the initial location.
    375   yylloc.begin.filename = yylloc.end.filename = &driver.file;
    376 }
    377 /* Line 545 of lalr1.cc  */
    378 #line 379 "../../../../examples/calc++/calc++-parser.cc"
    379 
    380     /* Initialize the stacks.  The initial state will be pushed in
    381        yynewstate, since the latter expects the semantical and the
    382        location values to have been already stored, initialize these
    383        stacks with a primary value.  */
    384     yystate_stack_ = state_stack_type (0);
    385     yysemantic_stack_ = semantic_stack_type (0);
    386     yylocation_stack_ = location_stack_type (0);
    387     yysemantic_stack_.push (yylval);
    388     yylocation_stack_.push (yylloc);
    389 
    390     /* New state.  */
    391   yynewstate:
    392     yystate_stack_.push (yystate);
    393     YYCDEBUG << "Entering state " << yystate << std::endl;
    394 
    395     /* Accept?  */
    396     if (yystate == yyfinal_)
    397       goto yyacceptlab;
    398 
    399     goto yybackup;
    400 
    401     /* Backup.  */
    402   yybackup:
    403 
    404     /* Try to take a decision without lookahead.  */
    405     yyn = yypact_[yystate];
    406     if (yy_pact_value_is_default_ (yyn))
    407       goto yydefault;
    408 
    409     /* Read a lookahead token.  */
    410     if (yychar == yyempty_)
    411       {
    412         YYCDEBUG << "Reading a token: ";
    413         yychar = yylex (&yylval, &yylloc, driver);
    414       }
    415 
    416     /* Convert token to internal form.  */
    417     if (yychar <= yyeof_)
    418       {
    419 	yychar = yytoken = yyeof_;
    420 	YYCDEBUG << "Now at end of input." << std::endl;
    421       }
    422     else
    423       {
    424 	yytoken = yytranslate_ (yychar);
    425 	YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    426       }
    427 
    428     /* If the proper action on seeing token YYTOKEN is to reduce or to
    429        detect an error, take that action.  */
    430     yyn += yytoken;
    431     if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
    432       goto yydefault;
    433 
    434     /* Reduce or error.  */
    435     yyn = yytable_[yyn];
    436     if (yyn <= 0)
    437       {
    438 	if (yy_table_value_is_error_ (yyn))
    439 	  goto yyerrlab;
    440 	yyn = -yyn;
    441 	goto yyreduce;
    442       }
    443 
    444     /* Shift the lookahead token.  */
    445     YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
    446 
    447     /* Discard the token being shifted.  */
    448     yychar = yyempty_;
    449 
    450     yysemantic_stack_.push (yylval);
    451     yylocation_stack_.push (yylloc);
    452 
    453     /* Count tokens shifted since error; after three, turn off error
    454        status.  */
    455     if (yyerrstatus_)
    456       --yyerrstatus_;
    457 
    458     yystate = yyn;
    459     goto yynewstate;
    460 
    461   /*-----------------------------------------------------------.
    462   | yydefault -- do the default action for the current state.  |
    463   `-----------------------------------------------------------*/
    464   yydefault:
    465     yyn = yydefact_[yystate];
    466     if (yyn == 0)
    467       goto yyerrlab;
    468     goto yyreduce;
    469 
    470   /*-----------------------------.
    471   | yyreduce -- Do a reduction.  |
    472   `-----------------------------*/
    473   yyreduce:
    474     yylen = yyr2_[yyn];
    475     /* If YYLEN is nonzero, implement the default value of the action:
    476        `$$ = $1'.  Otherwise, use the top of the stack.
    477 
    478        Otherwise, the following line sets YYVAL to garbage.
    479        This behavior is undocumented and Bison
    480        users should not rely upon it.  */
    481     if (yylen)
    482       yyval = yysemantic_stack_[yylen - 1];
    483     else
    484       yyval = yysemantic_stack_[0];
    485 
    486     // Compute the default @$.
    487     {
    488       slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
    489       YYLLOC_DEFAULT (yyloc, slice, yylen);
    490     }
    491 
    492     // Perform the reduction.
    493     YY_REDUCE_PRINT (yyn);
    494     switch (yyn)
    495       {
    496           case 2:
    497 /* Line 670 of lalr1.cc  */
    498 #line 10322 "../../doc/bison.texi"
    499     { driver.result = (yysemantic_stack_[(2) - (2)].ival); }
    500     break;
    501 
    502   case 3:
    503 /* Line 670 of lalr1.cc  */
    504 #line 10325 "../../doc/bison.texi"
    505     {}
    506     break;
    507 
    508   case 4:
    509 /* Line 670 of lalr1.cc  */
    510 #line 10326 "../../doc/bison.texi"
    511     {}
    512     break;
    513 
    514   case 5:
    515 /* Line 670 of lalr1.cc  */
    516 #line 10330 "../../doc/bison.texi"
    517     { driver.variables[*(yysemantic_stack_[(3) - (1)].sval)] = (yysemantic_stack_[(3) - (3)].ival); delete (yysemantic_stack_[(3) - (1)].sval); }
    518     break;
    519 
    520   case 6:
    521 /* Line 670 of lalr1.cc  */
    522 #line 10334 "../../doc/bison.texi"
    523     { (yyval.ival) = (yysemantic_stack_[(3) - (1)].ival) + (yysemantic_stack_[(3) - (3)].ival); }
    524     break;
    525 
    526   case 7:
    527 /* Line 670 of lalr1.cc  */
    528 #line 10335 "../../doc/bison.texi"
    529     { (yyval.ival) = (yysemantic_stack_[(3) - (1)].ival) - (yysemantic_stack_[(3) - (3)].ival); }
    530     break;
    531 
    532   case 8:
    533 /* Line 670 of lalr1.cc  */
    534 #line 10336 "../../doc/bison.texi"
    535     { (yyval.ival) = (yysemantic_stack_[(3) - (1)].ival) * (yysemantic_stack_[(3) - (3)].ival); }
    536     break;
    537 
    538   case 9:
    539 /* Line 670 of lalr1.cc  */
    540 #line 10337 "../../doc/bison.texi"
    541     { (yyval.ival) = (yysemantic_stack_[(3) - (1)].ival) / (yysemantic_stack_[(3) - (3)].ival); }
    542     break;
    543 
    544   case 10:
    545 /* Line 670 of lalr1.cc  */
    546 #line 10338 "../../doc/bison.texi"
    547     { (yyval.ival) = driver.variables[*(yysemantic_stack_[(1) - (1)].sval)]; delete (yysemantic_stack_[(1) - (1)].sval); }
    548     break;
    549 
    550   case 11:
    551 /* Line 670 of lalr1.cc  */
    552 #line 10339 "../../doc/bison.texi"
    553     { (yyval.ival) = (yysemantic_stack_[(1) - (1)].ival); }
    554     break;
    555 
    556 
    557 /* Line 670 of lalr1.cc  */
    558 #line 559 "../../../../examples/calc++/calc++-parser.cc"
    559       default:
    560         break;
    561       }
    562 
    563     /* User semantic actions sometimes alter yychar, and that requires
    564        that yytoken be updated with the new translation.  We take the
    565        approach of translating immediately before every use of yytoken.
    566        One alternative is translating here after every semantic action,
    567        but that translation would be missed if the semantic action
    568        invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
    569        yychar.  In the case of YYABORT or YYACCEPT, an incorrect
    570        destructor might then be invoked immediately.  In the case of
    571        YYERROR, subsequent parser actions might lead to an incorrect
    572        destructor call or verbose syntax error message before the
    573        lookahead is translated.  */
    574     YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
    575 
    576     yypop_ (yylen);
    577     yylen = 0;
    578     YY_STACK_PRINT ();
    579 
    580     yysemantic_stack_.push (yyval);
    581     yylocation_stack_.push (yyloc);
    582 
    583     /* Shift the result of the reduction.  */
    584     yyn = yyr1_[yyn];
    585     yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
    586     if (0 <= yystate && yystate <= yylast_
    587 	&& yycheck_[yystate] == yystate_stack_[0])
    588       yystate = yytable_[yystate];
    589     else
    590       yystate = yydefgoto_[yyn - yyntokens_];
    591     goto yynewstate;
    592 
    593   /*------------------------------------.
    594   | yyerrlab -- here on detecting error |
    595   `------------------------------------*/
    596   yyerrlab:
    597     /* Make sure we have latest lookahead translation.  See comments at
    598        user semantic actions for why this is necessary.  */
    599     yytoken = yytranslate_ (yychar);
    600 
    601     /* If not already recovering from an error, report this error.  */
    602     if (!yyerrstatus_)
    603       {
    604 	++yynerrs_;
    605 	if (yychar == yyempty_)
    606 	  yytoken = yyempty_;
    607 	error (yylloc, yysyntax_error_ (yystate, yytoken));
    608       }
    609 
    610     yyerror_range[1] = yylloc;
    611     if (yyerrstatus_ == 3)
    612       {
    613         /* If just tried and failed to reuse lookahead token after an
    614            error, discard it.  */
    615         if (yychar <= yyeof_)
    616           {
    617             /* Return failure if at end of input.  */
    618             if (yychar == yyeof_)
    619               YYABORT;
    620           }
    621         else
    622           {
    623             yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
    624             yychar = yyempty_;
    625           }
    626       }
    627 
    628     /* Else will try to reuse lookahead token after shifting the error
    629        token.  */
    630     goto yyerrlab1;
    631 
    632 
    633   /*---------------------------------------------------.
    634   | yyerrorlab -- error raised explicitly by YYERROR.  |
    635   `---------------------------------------------------*/
    636   yyerrorlab:
    637 
    638     /* Pacify compilers like GCC when the user code never invokes
    639        YYERROR and the label yyerrorlab therefore never appears in user
    640        code.  */
    641     if (false)
    642       goto yyerrorlab;
    643 
    644     yyerror_range[1] = yylocation_stack_[yylen - 1];
    645     /* Do not reclaim the symbols of the rule which action triggered
    646        this YYERROR.  */
    647     yypop_ (yylen);
    648     yylen = 0;
    649     yystate = yystate_stack_[0];
    650     goto yyerrlab1;
    651 
    652   /*-------------------------------------------------------------.
    653   | yyerrlab1 -- common code for both syntax error and YYERROR.  |
    654   `-------------------------------------------------------------*/
    655   yyerrlab1:
    656     yyerrstatus_ = 3;	/* Each real token shifted decrements this.  */
    657 
    658     for (;;)
    659       {
    660 	yyn = yypact_[yystate];
    661 	if (!yy_pact_value_is_default_ (yyn))
    662 	{
    663 	  yyn += yyterror_;
    664 	  if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
    665 	    {
    666 	      yyn = yytable_[yyn];
    667 	      if (0 < yyn)
    668 		break;
    669 	    }
    670 	}
    671 
    672 	/* Pop the current state because it cannot handle the error token.  */
    673 	if (yystate_stack_.height () == 1)
    674 	  YYABORT;
    675 
    676 	yyerror_range[1] = yylocation_stack_[0];
    677 	yydestruct_ ("Error: popping",
    678 		     yystos_[yystate],
    679 		     &yysemantic_stack_[0], &yylocation_stack_[0]);
    680 	yypop_ ();
    681 	yystate = yystate_stack_[0];
    682 	YY_STACK_PRINT ();
    683       }
    684 
    685     yyerror_range[2] = yylloc;
    686     // Using YYLLOC is tempting, but would change the location of
    687     // the lookahead.  YYLOC is available though.
    688     YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
    689     yysemantic_stack_.push (yylval);
    690     yylocation_stack_.push (yyloc);
    691 
    692     /* Shift the error token.  */
    693     YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
    694 		     &yysemantic_stack_[0], &yylocation_stack_[0]);
    695 
    696     yystate = yyn;
    697     goto yynewstate;
    698 
    699     /* Accept.  */
    700   yyacceptlab:
    701     yyresult = 0;
    702     goto yyreturn;
    703 
    704     /* Abort.  */
    705   yyabortlab:
    706     yyresult = 1;
    707     goto yyreturn;
    708 
    709   yyreturn:
    710     if (yychar != yyempty_)
    711       {
    712         /* Make sure we have latest lookahead translation.  See comments
    713            at user semantic actions for why this is necessary.  */
    714         yytoken = yytranslate_ (yychar);
    715         yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval,
    716                      &yylloc);
    717       }
    718 
    719     /* Do not reclaim the symbols of the rule which action triggered
    720        this YYABORT or YYACCEPT.  */
    721     yypop_ (yylen);
    722     while (1 < yystate_stack_.height ())
    723       {
    724         yydestruct_ ("Cleanup: popping",
    725                      yystos_[yystate_stack_[0]],
    726                      &yysemantic_stack_[0],
    727                      &yylocation_stack_[0]);
    728         yypop_ ();
    729       }
    730 
    731     return yyresult;
    732     }
    733     catch (...)
    734       {
    735         YYCDEBUG << "Exception caught: cleaning lookahead and stack"
    736                  << std::endl;
    737         // Do not try to display the values of the reclaimed symbols,
    738         // as their printer might throw an exception.
    739         if (yychar != yyempty_)
    740           {
    741             /* Make sure we have latest lookahead translation.  See
    742                comments at user semantic actions for why this is
    743                necessary.  */
    744             yytoken = yytranslate_ (yychar);
    745             yydestruct_ (YY_NULL, yytoken, &yylval, &yylloc);
    746           }
    747 
    748         while (1 < yystate_stack_.height ())
    749           {
    750             yydestruct_ (YY_NULL,
    751                          yystos_[yystate_stack_[0]],
    752                          &yysemantic_stack_[0],
    753                          &yylocation_stack_[0]);
    754             yypop_ ();
    755           }
    756         throw;
    757       }
    758   }
    759 
    760   // Generate an error message.
    761   std::string
    762   calcxx_parser::yysyntax_error_ (int yystate, int yytoken)
    763   {
    764     std::string yyres;
    765     // Number of reported tokens (one for the "unexpected", one per
    766     // "expected").
    767     size_t yycount = 0;
    768     // Its maximum.
    769     enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
    770     // Arguments of yyformat.
    771     char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
    772 
    773     /* There are many possibilities here to consider:
    774        - If this state is a consistent state with a default action, then
    775          the only way this function was invoked is if the default action
    776          is an error action.  In that case, don't check for expected
    777          tokens because there are none.
    778        - The only way there can be no lookahead present (in yytoken) is
    779          if this state is a consistent state with a default action.
    780          Thus, detecting the absence of a lookahead is sufficient to
    781          determine that there is no unexpected or expected token to
    782          report.  In that case, just report a simple "syntax error".
    783        - Don't assume there isn't a lookahead just because this state is
    784          a consistent state with a default action.  There might have
    785          been a previous inconsistent state, consistent state with a
    786          non-default action, or user semantic action that manipulated
    787          yychar.
    788        - Of course, the expected token list depends on states to have
    789          correct lookahead information, and it depends on the parser not
    790          to perform extra reductions after fetching a lookahead from the
    791          scanner and before detecting a syntax error.  Thus, state
    792          merging (from LALR or IELR) and default reductions corrupt the
    793          expected token list.  However, the list is correct for
    794          canonical LR with one exception: it will still contain any
    795          token that will not be accepted due to an error action in a
    796          later state.
    797     */
    798     if (yytoken != yyempty_)
    799       {
    800         yyarg[yycount++] = yytname_[yytoken];
    801         int yyn = yypact_[yystate];
    802         if (!yy_pact_value_is_default_ (yyn))
    803           {
    804             /* Start YYX at -YYN if negative to avoid negative indexes in
    805                YYCHECK.  In other words, skip the first -YYN actions for
    806                this state because they are default actions.  */
    807             int yyxbegin = yyn < 0 ? -yyn : 0;
    808             /* Stay within bounds of both yycheck and yytname.  */
    809             int yychecklim = yylast_ - yyn + 1;
    810             int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
    811             for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
    812               if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
    813                   && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
    814                 {
    815                   if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
    816                     {
    817                       yycount = 1;
    818                       break;
    819                     }
    820                   else
    821                     yyarg[yycount++] = yytname_[yyx];
    822                 }
    823           }
    824       }
    825 
    826     char const* yyformat = YY_NULL;
    827     switch (yycount)
    828       {
    829 #define YYCASE_(N, S)                         \
    830         case N:                               \
    831           yyformat = S;                       \
    832         break
    833         YYCASE_(0, YY_("syntax error"));
    834         YYCASE_(1, YY_("syntax error, unexpected %s"));
    835         YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
    836         YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
    837         YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
    838         YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
    839 #undef YYCASE_
    840       }
    841 
    842     // Argument number.
    843     size_t yyi = 0;
    844     for (char const* yyp = yyformat; *yyp; ++yyp)
    845       if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
    846         {
    847           yyres += yytnamerr_ (yyarg[yyi++]);
    848           ++yyp;
    849         }
    850       else
    851         yyres += *yyp;
    852     return yyres;
    853   }
    854 
    855 
    856   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    857      STATE-NUM.  */
    858   const signed char calcxx_parser::yypact_ninf_ = -9;
    859   const signed char
    860   calcxx_parser::yypact_[] =
    861   {
    862         -9,    13,     5,    -9,    14,    -9,    -9,    -1,     7,     7,
    863        7,     7,     7,    -9,    -1,     6,     6,    -9,    -9
    864   };
    865 
    866   /* YYDEFACT[S] -- default reduction number in state S.  Performed when
    867      YYTABLE doesn't specify something else to do.  Zero means the
    868      default is an error.  */
    869   const unsigned char
    870   calcxx_parser::yydefact_[] =
    871   {
    872          3,     0,     0,     1,    10,    11,     4,     2,     0,     0,
    873        0,     0,     0,    10,     5,     6,     7,     8,     9
    874   };
    875 
    876   /* YYPGOTO[NTERM-NUM].  */
    877   const signed char
    878   calcxx_parser::yypgoto_[] =
    879   {
    880         -9,    -9,    -9,    -9,    -8
    881   };
    882 
    883   /* YYDEFGOTO[NTERM-NUM].  */
    884   const signed char
    885   calcxx_parser::yydefgoto_[] =
    886   {
    887         -1,     1,     2,     6,     7
    888   };
    889 
    890   /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
    891      positive, shift that token.  If negative, reduce the rule which
    892      number is the opposite.  If YYTABLE_NINF_, syntax error.  */
    893   const signed char calcxx_parser::yytable_ninf_ = -1;
    894   const unsigned char
    895   calcxx_parser::yytable_[] =
    896   {
    897         14,    15,    16,    17,    18,     9,    10,    11,    12,     4,
    898        5,    13,     5,     3,    11,    12,     0,     8
    899   };
    900 
    901   /* YYCHECK.  */
    902   const signed char
    903   calcxx_parser::yycheck_[] =
    904   {
    905          8,     9,    10,    11,    12,     6,     7,     8,     9,     4,
    906        5,     4,     5,     0,     8,     9,    -1,     3
    907   };
    908 
    909   /* STOS_[STATE-NUM] -- The (internal number of the) accessing
    910      symbol of state STATE-NUM.  */
    911   const unsigned char
    912   calcxx_parser::yystos_[] =
    913   {
    914          0,    11,    12,     0,     4,     5,    13,    14,     3,     6,
    915        7,     8,     9,     4,    14,    14,    14,    14,    14
    916   };
    917 
    918 #if YYDEBUG
    919   /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
    920      to YYLEX-NUM.  */
    921   const unsigned short int
    922   calcxx_parser::yytoken_number_[] =
    923   {
    924          0,   256,   257,   258,   259,   260,    43,    45,    42,    47
    925   };
    926 #endif
    927 
    928   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
    929   const unsigned char
    930   calcxx_parser::yyr1_[] =
    931   {
    932          0,    10,    11,    12,    12,    13,    14,    14,    14,    14,
    933       14,    14
    934   };
    935 
    936   /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
    937   const unsigned char
    938   calcxx_parser::yyr2_[] =
    939   {
    940          0,     2,     2,     0,     2,     3,     3,     3,     3,     3,
    941        1,     1
    942   };
    943 
    944 
    945   /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
    946      First, the terminals, then, starting at \a yyntokens_, nonterminals.  */
    947   const char*
    948   const calcxx_parser::yytname_[] =
    949   {
    950     "\"end of file\"", "error", "$undefined", "\":=\"", "\"identifier\"",
    951   "\"number\"", "'+'", "'-'", "'*'", "'/'", "$accept", "unit",
    952   "assignments", "assignment", "exp", YY_NULL
    953   };
    954 
    955 #if YYDEBUG
    956   /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
    957   const calcxx_parser::rhs_number_type
    958   calcxx_parser::yyrhs_[] =
    959   {
    960         11,     0,    -1,    12,    14,    -1,    -1,    12,    13,    -1,
    961        4,     3,    14,    -1,    14,     6,    14,    -1,    14,     7,
    962       14,    -1,    14,     8,    14,    -1,    14,     9,    14,    -1,
    963        4,    -1,     5,    -1
    964   };
    965 
    966   /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
    967      YYRHS.  */
    968   const unsigned char
    969   calcxx_parser::yyprhs_[] =
    970   {
    971          0,     0,     3,     6,     7,    10,    14,    18,    22,    26,
    972       30,    32
    973   };
    974 
    975   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
    976   const unsigned short int
    977   calcxx_parser::yyrline_[] =
    978   {
    979          0, 10322, 10322, 10325, 10326, 10329, 10334, 10335, 10336, 10337,
    980    10338, 10339
    981   };
    982 
    983   // Print the state stack on the debug stream.
    984   void
    985   calcxx_parser::yystack_print_ ()
    986   {
    987     *yycdebug_ << "Stack now";
    988     for (state_stack_type::const_iterator i = yystate_stack_.begin ();
    989 	 i != yystate_stack_.end (); ++i)
    990       *yycdebug_ << ' ' << *i;
    991     *yycdebug_ << std::endl;
    992   }
    993 
    994   // Report on the debug stream that the rule \a yyrule is going to be reduced.
    995   void
    996   calcxx_parser::yy_reduce_print_ (int yyrule)
    997   {
    998     unsigned int yylno = yyrline_[yyrule];
    999     int yynrhs = yyr2_[yyrule];
   1000     /* Print the symbols being reduced, and their result.  */
   1001     *yycdebug_ << "Reducing stack by rule " << yyrule - 1
   1002 	       << " (line " << yylno << "):" << std::endl;
   1003     /* The symbols being reduced.  */
   1004     for (int yyi = 0; yyi < yynrhs; yyi++)
   1005       YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",
   1006 		       yyrhs_[yyprhs_[yyrule] + yyi],
   1007 		       &(yysemantic_stack_[(yynrhs) - (yyi + 1)]),
   1008 		       &(yylocation_stack_[(yynrhs) - (yyi + 1)]));
   1009   }
   1010 #endif // YYDEBUG
   1011 
   1012   /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
   1013   calcxx_parser::token_number_type
   1014   calcxx_parser::yytranslate_ (int t)
   1015   {
   1016     static
   1017     const token_number_type
   1018     translate_table[] =
   1019     {
   1020            0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1021        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1022        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1023        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1024        2,     2,     8,     6,     2,     7,     2,     9,     2,     2,
   1025        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1026        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1027        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1028        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1029        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1030        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1031        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1032        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1033        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1034        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1035        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1036        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1037        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1038        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1039        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1040        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1041        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1042        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1043        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1044        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
   1045        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
   1046        5
   1047     };
   1048     if ((unsigned int) t <= yyuser_token_number_max_)
   1049       return translate_table[t];
   1050     else
   1051       return yyundef_token_;
   1052   }
   1053 
   1054   const int calcxx_parser::yyeof_ = 0;
   1055   const int calcxx_parser::yylast_ = 17;
   1056   const int calcxx_parser::yynnts_ = 5;
   1057   const int calcxx_parser::yyempty_ = -2;
   1058   const int calcxx_parser::yyfinal_ = 3;
   1059   const int calcxx_parser::yyterror_ = 1;
   1060   const int calcxx_parser::yyerrcode_ = 256;
   1061   const int calcxx_parser::yyntokens_ = 10;
   1062 
   1063   const unsigned int calcxx_parser::yyuser_token_number_max_ = 260;
   1064   const calcxx_parser::token_number_type calcxx_parser::yyundef_token_ = 2;
   1065 
   1066 
   1067 } // yy
   1068 /* Line 1141 of lalr1.cc  */
   1069 #line 1070 "../../../../examples/calc++/calc++-parser.cc"
   1070 /* Line 1142 of lalr1.cc  */
   1071 #line 10340 "../../doc/bison.texi"
   1072 
   1073 #line 10349 "../../doc/bison.texi"
   1074 void
   1075 yy::calcxx_parser::error (const yy::calcxx_parser::location_type& l,
   1076                           const std::string& m)
   1077 {
   1078   driver.error (l, m);
   1079 }
   1080