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