src/parser.cc

Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.3.  */
00002 
00003 /* Skeleton implementation for Bison LALR(1) parsers in C++
00004 
00005    Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.  */
00021 
00022 /* As a special exception, you may create a larger work that contains
00023    part or all of the Bison parser skeleton and distribute that work
00024    under terms of your choice, so long as that work isn't itself a
00025    parser generator using the skeleton or a modified version thereof
00026    as a parser skeleton.  Alternatively, if you modify or redistribute
00027    the parser skeleton itself, you may (at your option) remove this
00028    special exception, which will cause the skeleton and the resulting
00029    Bison output files to be licensed under the GNU General Public
00030    License without this special exception.
00031 
00032    This special exception was added by the Free Software Foundation in
00033    version 2.2 of Bison.  */
00034 
00035 // Take the name prefix into account.
00036 #define yylex   examplelex
00037 
00038 #include "y.tab.h"
00039 
00040 /* User implementation prologue.  */
00041 #line 78 "parser.yy"
00042 
00043 
00044 #include "driver.h"
00045 #include "scanner.h"
00046 
00047 /* this "connects" the bison parser in the driver to the flex scanner class
00048  * object. it defines the yylex() function call to pull the next token from the
00049  * current lexer object of the driver context. */
00050 #undef yylex
00051 #define yylex driver.lexer->lex
00052 
00053 
00054 
00055 /* Line 317 of lalr1.cc.  */
00056 #line 57 "parser.cc"
00057 
00058 #ifndef YY_
00059 # if YYENABLE_NLS
00060 #  if ENABLE_NLS
00061 #   include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
00062 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
00063 #  endif
00064 # endif
00065 # ifndef YY_
00066 #  define YY_(msgid) msgid
00067 # endif
00068 #endif
00069 
00070 /* Suppress unused-variable warnings by "using" E.  */
00071 #define YYUSE(e) ((void) (e))
00072 
00073 /* A pseudo ostream that takes yydebug_ into account.  */
00074 # define YYCDEBUG                                                       \
00075   for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false)        \
00076     (*yycdebug_)
00077 
00078 /* Enable debugging if requested.  */
00079 #if YYDEBUG
00080 
00081 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)  \
00082 do {                                                    \
00083   if (yydebug_)                                         \
00084     {                                                   \
00085       *yycdebug_ << Title << ' ';                       \
00086       yy_symbol_print_ ((Type), (Value), (Location));   \
00087       *yycdebug_ << std::endl;                          \
00088     }                                                   \
00089 } while (false)
00090 
00091 # define YY_REDUCE_PRINT(Rule)          \
00092 do {                                    \
00093   if (yydebug_)                         \
00094     yy_reduce_print_ (Rule);            \
00095 } while (false)
00096 
00097 # define YY_STACK_PRINT()               \
00098 do {                                    \
00099   if (yydebug_)                         \
00100     yystack_print_ ();                  \
00101 } while (false)
00102 
00103 #else /* !YYDEBUG */
00104 
00105 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
00106 # define YY_REDUCE_PRINT(Rule)
00107 # define YY_STACK_PRINT()
00108 
00109 #endif /* !YYDEBUG */
00110 
00111 #define YYACCEPT        goto yyacceptlab
00112 #define YYABORT         goto yyabortlab
00113 #define YYERROR         goto yyerrorlab
00114 
00115 namespace example
00116 {
00117 #if YYERROR_VERBOSE
00118 
00119   /* Return YYSTR after stripping away unnecessary quotes and
00120      backslashes, so that it's suitable for yyerror.  The heuristic is
00121      that double-quoting is unnecessary unless the string contains an
00122      apostrophe, a comma, or backslash (other than backslash-backslash).
00123      YYSTR is taken from yytname.  */
00124   std::string
00125   Parser::yytnamerr_ (const char *yystr)
00126   {
00127     if (*yystr == '"')
00128       {
00129         std::string yyr = "";
00130         char const *yyp = yystr;
00131 
00132         for (;;)
00133           switch (*++yyp)
00134             {
00135             case '\'':
00136             case ',':
00137               goto do_not_strip_quotes;
00138 
00139             case '\\':
00140               if (*++yyp != '\\')
00141                 goto do_not_strip_quotes;
00142               /* Fall through.  */
00143             default:
00144               yyr += *yyp;
00145               break;
00146 
00147             case '"':
00148               return yyr;
00149             }
00150       do_not_strip_quotes: ;
00151       }
00152 
00153     return yystr;
00154   }
00155 
00156 #endif
00157 
00159   Parser::Parser (class Driver& driver_yyarg)
00160     : yydebug_ (false),
00161       yycdebug_ (&std::cerr),
00162       driver (driver_yyarg)
00163   {
00164   }
00165 
00166   Parser::~Parser ()
00167   {
00168   }
00169 
00170 #if YYDEBUG
00171   /*--------------------------------.
00172   | Print this symbol on YYOUTPUT.  |
00173   `--------------------------------*/
00174 
00175   inline void
00176   Parser::yy_symbol_value_print_ (int yytype,
00177                            const semantic_type* yyvaluep, const location_type* yylocationp)
00178   {
00179     YYUSE (yylocationp);
00180     YYUSE (yyvaluep);
00181     switch (yytype)
00182       {
00183          default:
00184           break;
00185       }
00186   }
00187 
00188 
00189   void
00190   Parser::yy_symbol_print_ (int yytype,
00191                            const semantic_type* yyvaluep, const location_type* yylocationp)
00192   {
00193     *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
00194                << ' ' << yytname_[yytype] << " ("
00195                << *yylocationp << ": ";
00196     yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
00197     *yycdebug_ << ')';
00198   }
00199 #endif /* ! YYDEBUG */
00200 
00201   void
00202   Parser::yydestruct_ (const char* yymsg,
00203                            int yytype, semantic_type* yyvaluep, location_type* yylocationp)
00204   {
00205     YYUSE (yylocationp);
00206     YYUSE (yymsg);
00207     YYUSE (yyvaluep);
00208 
00209     YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
00210 
00211     switch (yytype)
00212       {
00213         case 6: /* "\"string\"" */
00214 #line 72 "parser.yy"
00215         { delete (yyvaluep->stringVal); };
00216 #line 217 "parser.cc"
00217         break;
00218       case 18: /* "constant" */
00219 #line 73 "parser.yy"
00220         { delete (yyvaluep->calcnode); };
00221 #line 222 "parser.cc"
00222         break;
00223       case 19: /* "variable" */
00224 #line 73 "parser.yy"
00225         { delete (yyvaluep->calcnode); };
00226 #line 227 "parser.cc"
00227         break;
00228       case 20: /* "atomexpr" */
00229 #line 74 "parser.yy"
00230         { delete (yyvaluep->calcnode); };
00231 #line 232 "parser.cc"
00232         break;
00233       case 21: /* "powexpr" */
00234 #line 74 "parser.yy"
00235         { delete (yyvaluep->calcnode); };
00236 #line 237 "parser.cc"
00237         break;
00238       case 22: /* "unaryexpr" */
00239 #line 74 "parser.yy"
00240         { delete (yyvaluep->calcnode); };
00241 #line 242 "parser.cc"
00242         break;
00243       case 23: /* "mulexpr" */
00244 #line 74 "parser.yy"
00245         { delete (yyvaluep->calcnode); };
00246 #line 247 "parser.cc"
00247         break;
00248       case 24: /* "addexpr" */
00249 #line 74 "parser.yy"
00250         { delete (yyvaluep->calcnode); };
00251 #line 252 "parser.cc"
00252         break;
00253       case 25: /* "expr" */
00254 #line 74 "parser.yy"
00255         { delete (yyvaluep->calcnode); };
00256 #line 257 "parser.cc"
00257         break;
00258 
00259         default:
00260           break;
00261       }
00262   }
00263 
00264   void
00265   Parser::yypop_ (unsigned int n)
00266   {
00267     yystate_stack_.pop (n);
00268     yysemantic_stack_.pop (n);
00269     yylocation_stack_.pop (n);
00270   }
00271 
00272   std::ostream&
00273   Parser::debug_stream () const
00274   {
00275     return *yycdebug_;
00276   }
00277 
00278   void
00279   Parser::set_debug_stream (std::ostream& o)
00280   {
00281     yycdebug_ = &o;
00282   }
00283 
00284 
00285   Parser::debug_level_type
00286   Parser::debug_level () const
00287   {
00288     return yydebug_;
00289   }
00290 
00291   void
00292   Parser::set_debug_level (debug_level_type l)
00293   {
00294     yydebug_ = l;
00295   }
00296 
00297 
00298   int
00299   Parser::parse ()
00300   {
00302     int yychar = yyempty_;
00303     int yytoken = 0;
00304 
00305     /* State.  */
00306     int yyn;
00307     int yylen = 0;
00308     int yystate = 0;
00309 
00310     /* Error handling.  */
00311     int yynerrs_ = 0;
00312     int yyerrstatus_ = 0;
00313 
00315     semantic_type yylval;
00317     location_type yylloc;
00319     location yyerror_range[2];
00320 
00322     semantic_type yyval;
00324     location_type yyloc;
00325 
00326     int yyresult;
00327 
00328     YYCDEBUG << "Starting parse" << std::endl;
00329 
00330 
00331     /* User initialization code.  */
00332     #line 41 "/tdata/home/Desktop/flex-bison-cpp-example/trunk/src/parser.yy"
00333 {
00334     // initialize the initial location object
00335     yylloc.begin.filename = yylloc.end.filename = &driver.streamname;
00336 }
00337   /* Line 547 of yacc.c.  */
00338 #line 339 "parser.cc"
00339     /* Initialize the stacks.  The initial state will be pushed in
00340        yynewstate, since the latter expects the semantical and the
00341        location values to have been already stored, initialize these
00342        stacks with a primary value.  */
00343     yystate_stack_ = state_stack_type (0);
00344     yysemantic_stack_ = semantic_stack_type (0);
00345     yylocation_stack_ = location_stack_type (0);
00346     yysemantic_stack_.push (yylval);
00347     yylocation_stack_.push (yylloc);
00348 
00349     /* New state.  */
00350   yynewstate:
00351     yystate_stack_.push (yystate);
00352     YYCDEBUG << "Entering state " << yystate << std::endl;
00353     goto yybackup;
00354 
00355     /* Backup.  */
00356   yybackup:
00357 
00358     /* Try to take a decision without look-ahead.  */
00359     yyn = yypact_[yystate];
00360     if (yyn == yypact_ninf_)
00361       goto yydefault;
00362 
00363     /* Read a look-ahead token.  */
00364     if (yychar == yyempty_)
00365       {
00366         YYCDEBUG << "Reading a token: ";
00367         yychar = yylex (&yylval, &yylloc);
00368       }
00369 
00370 
00371     /* Convert token to internal form.  */
00372     if (yychar <= yyeof_)
00373       {
00374         yychar = yytoken = yyeof_;
00375         YYCDEBUG << "Now at end of input." << std::endl;
00376       }
00377     else
00378       {
00379         yytoken = yytranslate_ (yychar);
00380         YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
00381       }
00382 
00383     /* If the proper action on seeing token YYTOKEN is to reduce or to
00384        detect an error, take that action.  */
00385     yyn += yytoken;
00386     if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
00387       goto yydefault;
00388 
00389     /* Reduce or error.  */
00390     yyn = yytable_[yyn];
00391     if (yyn <= 0)
00392       {
00393         if (yyn == 0 || yyn == yytable_ninf_)
00394         goto yyerrlab;
00395         yyn = -yyn;
00396         goto yyreduce;
00397       }
00398 
00399     /* Accept?  */
00400     if (yyn == yyfinal_)
00401       goto yyacceptlab;
00402 
00403     /* Shift the look-ahead token.  */
00404     YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
00405 
00406     /* Discard the token being shifted unless it is eof.  */
00407     if (yychar != yyeof_)
00408       yychar = yyempty_;
00409 
00410     yysemantic_stack_.push (yylval);
00411     yylocation_stack_.push (yylloc);
00412 
00413     /* Count tokens shifted since error; after three, turn off error
00414        status.  */
00415     if (yyerrstatus_)
00416       --yyerrstatus_;
00417 
00418     yystate = yyn;
00419     goto yynewstate;
00420 
00421   /*-----------------------------------------------------------.
00422   | yydefault -- do the default action for the current state.  |
00423   `-----------------------------------------------------------*/
00424   yydefault:
00425     yyn = yydefact_[yystate];
00426     if (yyn == 0)
00427       goto yyerrlab;
00428     goto yyreduce;
00429 
00430   /*-----------------------------.
00431   | yyreduce -- Do a reduction.  |
00432   `-----------------------------*/
00433   yyreduce:
00434     yylen = yyr2_[yyn];
00435     /* If YYLEN is nonzero, implement the default value of the action:
00436        `$$ = $1'.  Otherwise, use the top of the stack.
00437 
00438        Otherwise, the following line sets YYVAL to garbage.
00439        This behavior is undocumented and Bison
00440        users should not rely upon it.  */
00441     if (yylen)
00442       yyval = yysemantic_stack_[yylen - 1];
00443     else
00444       yyval = yysemantic_stack_[0];
00445 
00446     {
00447       slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
00448       YYLLOC_DEFAULT (yyloc, slice, yylen);
00449     }
00450     YY_REDUCE_PRINT (yyn);
00451     switch (yyn)
00452       {
00453           case 2:
00454 #line 96 "parser.yy"
00455     {
00456                (yyval.calcnode) = new CNConstant((yysemantic_stack_[(1) - (1)].integerVal));
00457            }
00458     break;
00459 
00460   case 3:
00461 #line 100 "parser.yy"
00462     {
00463                (yyval.calcnode) = new CNConstant((yysemantic_stack_[(1) - (1)].doubleVal));
00464            }
00465     break;
00466 
00467   case 4:
00468 #line 105 "parser.yy"
00469     {
00470                if (!driver.calc.existsVariable(*(yysemantic_stack_[(1) - (1)].stringVal))) {
00471                    error(yyloc, std::string("Unknown variable \"") + *(yysemantic_stack_[(1) - (1)].stringVal) + "\"");
00472                    delete (yysemantic_stack_[(1) - (1)].stringVal);
00473                    YYERROR;
00474                }
00475                else {
00476                    (yyval.calcnode) = new CNConstant( driver.calc.getVariable(*(yysemantic_stack_[(1) - (1)].stringVal)) );
00477                    delete (yysemantic_stack_[(1) - (1)].stringVal);
00478                }
00479            }
00480     break;
00481 
00482   case 5:
00483 #line 118 "parser.yy"
00484     {
00485                (yyval.calcnode) = (yysemantic_stack_[(1) - (1)].calcnode);
00486            }
00487     break;
00488 
00489   case 6:
00490 #line 122 "parser.yy"
00491     {
00492                (yyval.calcnode) = (yysemantic_stack_[(1) - (1)].calcnode);
00493            }
00494     break;
00495 
00496   case 7:
00497 #line 126 "parser.yy"
00498     {
00499                (yyval.calcnode) = (yysemantic_stack_[(3) - (2)].calcnode);
00500            }
00501     break;
00502 
00503   case 8:
00504 #line 131 "parser.yy"
00505     {
00506               (yyval.calcnode) = (yysemantic_stack_[(1) - (1)].calcnode);
00507           }
00508     break;
00509 
00510   case 9:
00511 #line 135 "parser.yy"
00512     {
00513               (yyval.calcnode) = new CNPower((yysemantic_stack_[(3) - (1)].calcnode), (yysemantic_stack_[(3) - (3)].calcnode));
00514           }
00515     break;
00516 
00517   case 10:
00518 #line 140 "parser.yy"
00519     {
00520                 (yyval.calcnode) = (yysemantic_stack_[(1) - (1)].calcnode);
00521             }
00522     break;
00523 
00524   case 11:
00525 #line 144 "parser.yy"
00526     {
00527                 (yyval.calcnode) = (yysemantic_stack_[(2) - (2)].calcnode);
00528             }
00529     break;
00530 
00531   case 12:
00532 #line 148 "parser.yy"
00533     {
00534                 (yyval.calcnode) = new CNNegate((yysemantic_stack_[(2) - (2)].calcnode));
00535             }
00536     break;
00537 
00538   case 13:
00539 #line 153 "parser.yy"
00540     {
00541               (yyval.calcnode) = (yysemantic_stack_[(1) - (1)].calcnode);
00542           }
00543     break;
00544 
00545   case 14:
00546 #line 157 "parser.yy"
00547     {
00548               (yyval.calcnode) = new CNMultiply((yysemantic_stack_[(3) - (1)].calcnode), (yysemantic_stack_[(3) - (3)].calcnode));
00549           }
00550     break;
00551 
00552   case 15:
00553 #line 161 "parser.yy"
00554     {
00555               (yyval.calcnode) = new CNDivide((yysemantic_stack_[(3) - (1)].calcnode), (yysemantic_stack_[(3) - (3)].calcnode));
00556           }
00557     break;
00558 
00559   case 16:
00560 #line 165 "parser.yy"
00561     {
00562               (yyval.calcnode) = new CNModulo((yysemantic_stack_[(3) - (1)].calcnode), (yysemantic_stack_[(3) - (3)].calcnode));
00563           }
00564     break;
00565 
00566   case 17:
00567 #line 170 "parser.yy"
00568     {
00569               (yyval.calcnode) = (yysemantic_stack_[(1) - (1)].calcnode);
00570           }
00571     break;
00572 
00573   case 18:
00574 #line 174 "parser.yy"
00575     {
00576               (yyval.calcnode) = new CNAdd((yysemantic_stack_[(3) - (1)].calcnode), (yysemantic_stack_[(3) - (3)].calcnode));
00577           }
00578     break;
00579 
00580   case 19:
00581 #line 178 "parser.yy"
00582     {
00583               (yyval.calcnode) = new CNSubtract((yysemantic_stack_[(3) - (1)].calcnode), (yysemantic_stack_[(3) - (3)].calcnode));
00584           }
00585     break;
00586 
00587   case 20:
00588 #line 183 "parser.yy"
00589     {
00590               (yyval.calcnode) = (yysemantic_stack_[(1) - (1)].calcnode);
00591           }
00592     break;
00593 
00594   case 21:
00595 #line 188 "parser.yy"
00596     {
00597                  driver.calc.variables[*(yysemantic_stack_[(3) - (1)].stringVal)] = (yysemantic_stack_[(3) - (3)].calcnode)->evaluate();
00598                  std::cout << "Setting variable " << *(yysemantic_stack_[(3) - (1)].stringVal)
00599                            << " = " << driver.calc.variables[*(yysemantic_stack_[(3) - (1)].stringVal)] << "\n";
00600                  delete (yysemantic_stack_[(3) - (1)].stringVal);
00601                  delete (yysemantic_stack_[(3) - (3)].calcnode);
00602              }
00603     break;
00604 
00605   case 28:
00606 #line 203 "parser.yy"
00607     {
00608               driver.calc.expressions.push_back((yysemantic_stack_[(3) - (2)].calcnode));
00609           }
00610     break;
00611 
00612   case 29:
00613 #line 207 "parser.yy"
00614     {
00615               driver.calc.expressions.push_back((yysemantic_stack_[(3) - (2)].calcnode));
00616           }
00617     break;
00618 
00619   case 30:
00620 #line 211 "parser.yy"
00621     {
00622               driver.calc.expressions.push_back((yysemantic_stack_[(3) - (2)].calcnode));
00623           }
00624     break;
00625 
00626 
00627     /* Line 675 of lalr1.cc.  */
00628 #line 629 "parser.cc"
00629         default: break;
00630       }
00631     YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
00632 
00633     yypop_ (yylen);
00634     yylen = 0;
00635     YY_STACK_PRINT ();
00636 
00637     yysemantic_stack_.push (yyval);
00638     yylocation_stack_.push (yyloc);
00639 
00640     /* Shift the result of the reduction.  */
00641     yyn = yyr1_[yyn];
00642     yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
00643     if (0 <= yystate && yystate <= yylast_
00644         && yycheck_[yystate] == yystate_stack_[0])
00645       yystate = yytable_[yystate];
00646     else
00647       yystate = yydefgoto_[yyn - yyntokens_];
00648     goto yynewstate;
00649 
00650   /*------------------------------------.
00651   | yyerrlab -- here on detecting error |
00652   `------------------------------------*/
00653   yyerrlab:
00654     /* If not already recovering from an error, report this error.  */
00655     if (!yyerrstatus_)
00656       {
00657         ++yynerrs_;
00658         error (yylloc, yysyntax_error_ (yystate, yytoken));
00659       }
00660 
00661     yyerror_range[0] = yylloc;
00662     if (yyerrstatus_ == 3)
00663       {
00664         /* If just tried and failed to reuse look-ahead token after an
00665          error, discard it.  */
00666 
00667         if (yychar <= yyeof_)
00668           {
00669           /* Return failure if at end of input.  */
00670           if (yychar == yyeof_)
00671             YYABORT;
00672           }
00673         else
00674           {
00675             yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
00676             yychar = yyempty_;
00677           }
00678       }
00679 
00680     /* Else will try to reuse look-ahead token after shifting the error
00681        token.  */
00682     goto yyerrlab1;
00683 
00684 
00685   /*---------------------------------------------------.
00686   | yyerrorlab -- error raised explicitly by YYERROR.  |
00687   `---------------------------------------------------*/
00688   yyerrorlab:
00689 
00690     /* Pacify compilers like GCC when the user code never invokes
00691        YYERROR and the label yyerrorlab therefore never appears in user
00692        code.  */
00693     if (false)
00694       goto yyerrorlab;
00695 
00696     yyerror_range[0] = yylocation_stack_[yylen - 1];
00697     /* Do not reclaim the symbols of the rule which action triggered
00698        this YYERROR.  */
00699     yypop_ (yylen);
00700     yylen = 0;
00701     yystate = yystate_stack_[0];
00702     goto yyerrlab1;
00703 
00704   /*-------------------------------------------------------------.
00705   | yyerrlab1 -- common code for both syntax error and YYERROR.  |
00706   `-------------------------------------------------------------*/
00707   yyerrlab1:
00708     yyerrstatus_ = 3;   /* Each real token shifted decrements this.  */
00709 
00710     for (;;)
00711       {
00712         yyn = yypact_[yystate];
00713         if (yyn != yypact_ninf_)
00714         {
00715           yyn += yyterror_;
00716           if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
00717             {
00718               yyn = yytable_[yyn];
00719               if (0 < yyn)
00720                 break;
00721             }
00722         }
00723 
00724         /* Pop the current state because it cannot handle the error token.  */
00725         if (yystate_stack_.height () == 1)
00726         YYABORT;
00727 
00728         yyerror_range[0] = yylocation_stack_[0];
00729         yydestruct_ ("Error: popping",
00730                      yystos_[yystate],
00731                      &yysemantic_stack_[0], &yylocation_stack_[0]);
00732         yypop_ ();
00733         yystate = yystate_stack_[0];
00734         YY_STACK_PRINT ();
00735       }
00736 
00737     if (yyn == yyfinal_)
00738       goto yyacceptlab;
00739 
00740     yyerror_range[1] = yylloc;
00741     // Using YYLLOC is tempting, but would change the location of
00742     // the look-ahead.  YYLOC is available though.
00743     YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
00744     yysemantic_stack_.push (yylval);
00745     yylocation_stack_.push (yyloc);
00746 
00747     /* Shift the error token.  */
00748     YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
00749                    &yysemantic_stack_[0], &yylocation_stack_[0]);
00750 
00751     yystate = yyn;
00752     goto yynewstate;
00753 
00754     /* Accept.  */
00755   yyacceptlab:
00756     yyresult = 0;
00757     goto yyreturn;
00758 
00759     /* Abort.  */
00760   yyabortlab:
00761     yyresult = 1;
00762     goto yyreturn;
00763 
00764   yyreturn:
00765     if (yychar != yyeof_ && yychar != yyempty_)
00766       yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
00767 
00768     /* Do not reclaim the symbols of the rule which action triggered
00769        this YYABORT or YYACCEPT.  */
00770     yypop_ (yylen);
00771     while (yystate_stack_.height () != 1)
00772       {
00773         yydestruct_ ("Cleanup: popping",
00774                    yystos_[yystate_stack_[0]],
00775                    &yysemantic_stack_[0],
00776                    &yylocation_stack_[0]);
00777         yypop_ ();
00778       }
00779 
00780     return yyresult;
00781   }
00782 
00783   // Generate an error message.
00784   std::string
00785   Parser::yysyntax_error_ (int yystate, int tok)
00786   {
00787     std::string res;
00788     YYUSE (yystate);
00789 #if YYERROR_VERBOSE
00790     int yyn = yypact_[yystate];
00791     if (yypact_ninf_ < yyn && yyn <= yylast_)
00792       {
00793         /* Start YYX at -YYN if negative to avoid negative indexes in
00794            YYCHECK.  */
00795         int yyxbegin = yyn < 0 ? -yyn : 0;
00796 
00797         /* Stay within bounds of both yycheck and yytname.  */
00798         int yychecklim = yylast_ - yyn + 1;
00799         int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
00800         int count = 0;
00801         for (int x = yyxbegin; x < yyxend; ++x)
00802           if (yycheck_[x + yyn] == x && x != yyterror_)
00803             ++count;
00804 
00805         // FIXME: This method of building the message is not compatible
00806         // with internationalization.  It should work like yacc.c does it.
00807         // That is, first build a string that looks like this:
00808         // "syntax error, unexpected %s or %s or %s"
00809         // Then, invoke YY_ on this string.
00810         // Finally, use the string as a format to output
00811         // yytname_[tok], etc.
00812         // Until this gets fixed, this message appears in English only.
00813         res = "syntax error, unexpected ";
00814         res += yytnamerr_ (yytname_[tok]);
00815         if (count < 5)
00816           {
00817             count = 0;
00818             for (int x = yyxbegin; x < yyxend; ++x)
00819               if (yycheck_[x + yyn] == x && x != yyterror_)
00820                 {
00821                   res += (!count++) ? ", expecting " : " or ";
00822                   res += yytnamerr_ (yytname_[x]);
00823                 }
00824           }
00825       }
00826     else
00827 #endif
00828       res = YY_("syntax error");
00829     return res;
00830   }
00831 
00832 
00833   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
00834      STATE-NUM.  */
00835   const signed char Parser::yypact_ninf_ = -15;
00836   const signed char
00837   Parser::yypact_[] =
00838   {
00839        -15,     0,   -15,   -15,   -15,   -15,   -14,    16,    27,    27,
00840      -15,   -15,   -15,   -15,    -1,   -15,    23,     8,     9,    14,
00841       16,   -15,     5,    -1,    -1,    27,    16,    16,    16,    16,
00842       16,   -15,   -15,   -15,   -15,   -15,   -15,   -15,   -15,   -15,
00843      -15,   -15,   -15,    23,    23
00844   };
00845 
00846   /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
00847      doesn't specify something else to do.  Zero means the default is an
00848      error.  */
00849   const unsigned char
00850   Parser::yydefact_[] =
00851   {
00852         22,     0,     1,    24,     2,     3,     4,     0,     0,     0,
00853       23,     5,     6,     8,    10,    13,    17,    20,     0,     0,
00854        0,     4,     0,    11,    12,     0,     0,     0,     0,     0,
00855        0,    30,    29,    28,    27,    26,    25,    21,     7,     9,
00856       14,    15,    16,    18,    19
00857   };
00858 
00859   /* YYPGOTO[NTERM-NUM].  */
00860   const signed char
00861   Parser::yypgoto_[] =
00862   {
00863        -15,   -15,   -15,    19,    20,    12,    13,   -15,    -5,   -15,
00864      -15
00865   };
00866 
00867   /* YYDEFGOTO[NTERM-NUM].  */
00868   const signed char
00869   Parser::yydefgoto_[] =
00870   {
00871         -1,    11,    12,    13,    14,    15,    16,    17,    18,    19,
00872        1
00873   };
00874 
00875   /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
00876      positive, shift that token.  If negative, reduce the rule which
00877      number is the opposite.  If zero, do what YYDEFACT says.  */
00878   const signed char Parser::yytable_ninf_ = -1;
00879   const unsigned char
00880   Parser::yytable_[] =
00881   {
00882          2,    20,    22,     3,     4,     5,     6,     7,    25,    31,
00883        8,     9,    32,    38,    34,    37,    10,    35,    29,    30,
00884        4,     5,    21,     7,     0,    33,     8,     9,    23,    24,
00885       36,     4,     5,    21,     7,    26,    27,    28,    40,    41,
00886       42,     0,    43,    44,    39
00887   };
00888 
00889   /* YYCHECK.  */
00890   const signed char
00891   Parser::yycheck_[] =
00892   {
00893          0,    15,     7,     3,     4,     5,     6,     7,     9,     0,
00894       10,    11,     3,     8,     0,    20,    16,     3,    10,    11,
00895        4,     5,     6,     7,    -1,    16,    10,    11,     8,     9,
00896       16,     4,     5,     6,     7,    12,    13,    14,    26,    27,
00897       28,    -1,    29,    30,    25
00898   };
00899 
00900   /* STOS_[STATE-NUM] -- The (internal number of the) accessing
00901      symbol of state STATE-NUM.  */
00902   const unsigned char
00903   Parser::yystos_[] =
00904   {
00905          0,    27,     0,     3,     4,     5,     6,     7,    10,    11,
00906       16,    18,    19,    20,    21,    22,    23,    24,    25,    26,
00907       15,     6,    25,    21,    21,     9,    12,    13,    14,    10,
00908       11,     0,     3,    16,     0,     3,    16,    25,     8,    20,
00909       22,    22,    22,    23,    23
00910   };
00911 
00912 #if YYDEBUG
00913   /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
00914      to YYLEX-NUM.  */
00915   const unsigned short int
00916   Parser::yytoken_number_[] =
00917   {
00918          0,   256,   257,   258,   259,   260,   261,    40,    41,    94,
00919       43,    45,    42,    47,    37,    61,    59
00920   };
00921 #endif
00922 
00923   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
00924   const unsigned char
00925   Parser::yyr1_[] =
00926   {
00927          0,    17,    18,    18,    19,    20,    20,    20,    21,    21,
00928       22,    22,    22,    23,    23,    23,    23,    24,    24,    24,
00929       25,    26,    27,    27,    27,    27,    27,    27,    27,    27,
00930       27
00931   };
00932 
00933   /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
00934   const unsigned char
00935   Parser::yyr2_[] =
00936   {
00937          0,     2,     1,     1,     1,     1,     1,     3,     1,     3,
00938        1,     2,     2,     1,     3,     3,     3,     1,     3,     3,
00939        1,     3,     0,     2,     2,     3,     3,     3,     3,     3,
00940        3
00941   };
00942 
00943 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
00944   /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
00945      First, the terminals, then, starting at \a yyntokens_, nonterminals.  */
00946   const char*
00947   const Parser::yytname_[] =
00948   {
00949     "\"end of file\"", "error", "$undefined", "\"end of line\"",
00950   "\"integer\"", "\"double\"", "\"string\"", "'('", "')'", "'^'", "'+'",
00951   "'-'", "'*'", "'/'", "'%'", "'='", "';'", "$accept", "constant",
00952   "variable", "atomexpr", "powexpr", "unaryexpr", "mulexpr", "addexpr",
00953   "expr", "assignment", "start", 0
00954   };
00955 #endif
00956 
00957 #if YYDEBUG
00958   /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
00959   const Parser::rhs_number_type
00960   Parser::yyrhs_[] =
00961   {
00962         27,     0,    -1,     4,    -1,     5,    -1,     6,    -1,    18,
00963       -1,    19,    -1,     7,    25,     8,    -1,    20,    -1,    21,
00964        9,    20,    -1,    21,    -1,    10,    21,    -1,    11,    21,
00965       -1,    22,    -1,    23,    12,    22,    -1,    23,    13,    22,
00966       -1,    23,    14,    22,    -1,    23,    -1,    24,    10,    23,
00967       -1,    24,    11,    23,    -1,    24,    -1,     6,    15,    25,
00968       -1,    -1,    27,    16,    -1,    27,     3,    -1,    27,    26,
00969       16,    -1,    27,    26,     3,    -1,    27,    26,     0,    -1,
00970       27,    25,    16,    -1,    27,    25,     3,    -1,    27,    25,
00971        0,    -1
00972   };
00973 
00974   /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
00975      YYRHS.  */
00976   const unsigned char
00977   Parser::yyprhs_[] =
00978   {
00979          0,     0,     3,     5,     7,     9,    11,    13,    17,    19,
00980       23,    25,    28,    31,    33,    37,    41,    45,    47,    51,
00981       55,    57,    61,    62,    65,    68,    72,    76,    80,    84,
00982       88
00983   };
00984 
00985   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
00986   const unsigned char
00987   Parser::yyrline_[] =
00988   {
00989          0,    95,    95,    99,   104,   117,   121,   125,   130,   134,
00990      139,   143,   147,   152,   156,   160,   164,   169,   173,   177,
00991      182,   187,   196,   197,   198,   199,   200,   201,   202,   206,
00992      210
00993   };
00994 
00995   // Print the state stack on the debug stream.
00996   void
00997   Parser::yystack_print_ ()
00998   {
00999     *yycdebug_ << "Stack now";
01000     for (state_stack_type::const_iterator i = yystate_stack_.begin ();
01001          i != yystate_stack_.end (); ++i)
01002       *yycdebug_ << ' ' << *i;
01003     *yycdebug_ << std::endl;
01004   }
01005 
01006   // Report on the debug stream that the rule \a yyrule is going to be reduced.
01007   void
01008   Parser::yy_reduce_print_ (int yyrule)
01009   {
01010     unsigned int yylno = yyrline_[yyrule];
01011     int yynrhs = yyr2_[yyrule];
01012     /* Print the symbols being reduced, and their result.  */
01013     *yycdebug_ << "Reducing stack by rule " << yyrule - 1
01014                << " (line " << yylno << "), ";
01015     /* The symbols being reduced.  */
01016     for (int yyi = 0; yyi < yynrhs; yyi++)
01017       YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",
01018                        yyrhs_[yyprhs_[yyrule] + yyi],
01019                        &(yysemantic_stack_[(yynrhs) - (yyi + 1)]),
01020                        &(yylocation_stack_[(yynrhs) - (yyi + 1)]));
01021   }
01022 #endif // YYDEBUG
01023 
01024   /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
01025   Parser::token_number_type
01026   Parser::yytranslate_ (int t)
01027   {
01028     static
01029     const token_number_type
01030     translate_table[] =
01031     {
01032            0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01033        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01034        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01035        2,     2,     2,     2,     2,     2,     2,    14,     2,     2,
01036        7,     8,    12,    10,     2,    11,     2,    13,     2,     2,
01037        2,     2,     2,     2,     2,     2,     2,     2,     2,    16,
01038        2,    15,     2,     2,     2,     2,     2,     2,     2,     2,
01039        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01040        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01041        2,     2,     2,     2,     9,     2,     2,     2,     2,     2,
01042        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01043        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01044        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01045        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01046        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01047        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01048        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01049        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01050        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01051        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01052        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01053        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01054        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01055        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01056        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
01057        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
01058        5,     6
01059     };
01060     if ((unsigned int) t <= yyuser_token_number_max_)
01061       return translate_table[t];
01062     else
01063       return yyundef_token_;
01064   }
01065 
01066   const int Parser::yyeof_ = 0;
01067   const int Parser::yylast_ = 44;
01068   const int Parser::yynnts_ = 11;
01069   const int Parser::yyempty_ = -2;
01070   const int Parser::yyfinal_ = 2;
01071   const int Parser::yyterror_ = 1;
01072   const int Parser::yyerrcode_ = 256;
01073   const int Parser::yyntokens_ = 17;
01074 
01075   const unsigned int Parser::yyuser_token_number_max_ = 261;
01076   const Parser::token_number_type Parser::yyundef_token_ = 2;
01077 
01078 } // namespace example
01079 
01080 #line 217 "parser.yy"
01081  /*** Additional Code ***/
01082 
01083 void example::Parser::error(const Parser::location_type& l,
01084                             const std::string& m)
01085 {
01086     driver.error(l, m);
01087 }
01088 

Generated on Mon Aug 20 13:34:21 2007 for Flex Bison C++ Example by  doxygen 1.5.2