1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
|
// Generated by Bisonc++ V6.05.00 on Sat, 15 Jul 2023 12:26:48 -0700
// base/comment
// $insert class.ih
#include "parser.ih"
// The FIRST element of SR arrays shown below uses `d_type', defining the
// state's type, and `d_lastIdx' containing the last element's index. If
// d_lastIdx contains the REQ_TOKEN bitflag (see below) then the state needs
// a token: if in this state d_token is Reserved_::UNDETERMINED_, nextToken() will be
// called
// The LAST element of SR arrays uses `d_token' containing the last retrieved
// token to speed up the (linear) seach. Except for the first element of SR
// arrays, the field `d_action' is used to determine what to do next. If
// positive, it represents the next state (used with SHIFT); if zero, it
// indicates `ACCEPT', if negative, -d_action represents the number of the
// rule to reduce to.
// `lookup()' tries to find d_token in the current SR array. If it fails, and
// there is no default reduction UNEXPECTED_TOKEN_ is thrown, which is then
// caught by the error-recovery function.
// The error-recovery function will pop elements off the stack until a state
// having bit flag ERR_ITEM is found. This state has a transition on errTok_
// which is applied. In this errTok_ state, while the current token is not a
// proper continuation, new tokens are obtained by nextToken(). If such a
// token is found, error recovery is successful and the token is
// handled according to the error state's SR table and parsing continues.
// During error recovery semantic actions are ignored.
// A state flagged with the DEF_RED flag will perform a default
// reduction if no other continuations are available for the current token.
// The ACCEPT STATE never shows a default reduction: when it is reached the
// parser returns ACCEPT(). During the grammar
// analysis phase a default reduction may have been defined, but it is
// removed during the state-definition phase.
// So:
// s_x[] =
// {
// [_field_1_] [_field_2_]
//
// First element: {state-type, idx of last element},
// Other elements: {required token, action to perform},
// ( < 0: reduce,
// 0: ACCEPT,
// > 0: next state)
// }
// base/declarations
namespace // anonymous
{
char const author[] = "Frank B. Brokken (f.b.brokken@rug.nl)";
enum Reserved_
{
UNDETERMINED_ = -2,
EOF_ = -1,
errTok_ = 256
};
enum StateType // modify statetype/data.cc when this enum changes
{
NORMAL,
ERR_ITEM,
REQ_TOKEN,
ERR_REQ, // ERR_ITEM | REQ_TOKEN
DEF_RED, // state having default reduction
ERR_DEF, // ERR_ITEM | DEF_RED
REQ_DEF, // REQ_TOKEN | DEF_RED
ERR_REQ_DEF // ERR_ITEM | REQ_TOKEN | DEF_RED
};
inline bool operator&(StateType lhs, StateType rhs)
{
return (static_cast<int>(lhs) & rhs) != 0;
}
enum StateTransition
{
ACCEPT_ = 0, // `ACCEPT' TRANSITION
};
struct PI_ // Production Info
{
size_t d_nonTerm; // identification number of this production's
// non-terminal
size_t d_size; // number of elements in this production
};
struct SR_ // Shift Reduce info, see its description above
{
union
{
int _field_1_; // initializer, allowing initializations
// of the SR s_[] arrays
StateType d_type;
int d_token;
};
union
{
int _field_2_;
int d_lastIdx; // if negative, the state uses SHIFT
int d_action; // may be negative (reduce),
// postive (shift), or 0 (accept)
};
};
// $insert staticdata
enum // size to expand the state-stack with when
{ // full
STACK_EXPANSION_ = 10
};
// Productions Info Records:
PI_ const s_productionInfo[] =
{
{0, 0}, // not used: reduction values are negative
{267, 2}, // 1: grammar -> grammar ifStmnt
{267, 0}, // 2: grammar -> <empty>
{269, 1}, // 3: optNot (NOT) -> NOT
{269, 0}, // 4: optNot -> <empty>
{270, 1}, // 5: eMatchMode (LETTER) -> LETTER
{271, 1}, // 6: eRegex (REGEX) -> REGEX
{272, 3}, // 7: expression -> eMatchMode optNot eRegex
{272, 3}, // 8: expression (AND) -> expression AND expression
{273, 1}, // 9: rNr (NR) -> NR
{274, 1}, // 10: rDate (DATE) -> DATE
{275, 4}, // 11: rule ('\x0a') -> rNr rDate expression '\x0a'
{275, 2}, // 12: rule (errTok_) -> errTok_ '\x0a'
{275, 1}, // 13: rule ('\x0a') -> '\x0a'
{276, 2}, // 14: rules -> rules rule
{276, 1}, // 15: rules -> rule
{277, 1}, // 16: cRulesFile (FILE) -> FILE
{278, 2}, // 17: cFile -> cRulesFile rules
{278, 1}, // 18: cFile (FILE) -> FILE
{279, 1}, // 19: cHdr (HDR) -> HDR
{280, 2}, // 20: condTerm -> cHdr cFile
{281, 3}, // 21: condition (AND) -> condition AND condTerm
{281, 1}, // 22: condition -> condTerm
{282, 1}, // 23: if (IF) -> IF
{268, 3}, // 24: ifStmnt (ACTION) -> if condition ACTION
{268, 2}, // 25: ifStmnt (errTok_) -> errTok_ ACTION
{268, 1}, // 26: ifStmnt ('\x0a') -> '\x0a'
{283, 1}, // 27: grammar_$ -> grammar
};
// State info and SR_ transitions for each state.
SR_ s_0[] =
{
{ { DEF_RED}, { 2} },
{ { 267}, { 1} }, // grammar
{ { 0}, { -2} },
};
SR_ s_1[] =
{
{ { ERR_REQ}, { 7} },
{ { 268}, { 2} }, // ifStmnt
{ { 282}, { 3} }, // if
{ { errTok_}, { 4} }, // errTok_
{ { 10}, { 5} }, // '\x0a'
{ { 257}, { 6} }, // IF
{ { EOF_}, { ACCEPT_} },
{ { 0}, { 0} },
};
SR_ s_2[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -1} },
};
SR_ s_3[] =
{
{ { REQ_TOKEN}, { 5} },
{ { 281}, { 7} }, // condition
{ { 280}, { 8} }, // condTerm
{ { 279}, { 9} }, // cHdr
{ { 261}, { 10} }, // HDR
{ { 0}, { 0} },
};
SR_ s_4[] =
{
{ { REQ_TOKEN}, { 2} },
{ { 258}, { 11} }, // ACTION
{ { 0}, { 0} },
};
SR_ s_5[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -26} },
};
SR_ s_6[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -23} },
};
SR_ s_7[] =
{
{ { REQ_TOKEN}, { 3} },
{ { 258}, { 12} }, // ACTION
{ { 266}, { 13} }, // AND
{ { 0}, { 0} },
};
SR_ s_8[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -22} },
};
SR_ s_9[] =
{
{ { REQ_TOKEN}, { 4} },
{ { 278}, { 14} }, // cFile
{ { 277}, { 15} }, // cRulesFile
{ { 260}, { 16} }, // FILE
{ { 0}, { 0} },
};
SR_ s_10[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -19} },
};
SR_ s_11[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -25} },
};
SR_ s_12[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -24} },
};
SR_ s_13[] =
{
{ { REQ_TOKEN}, { 4} },
{ { 280}, { 17} }, // condTerm
{ { 279}, { 9} }, // cHdr
{ { 261}, { 10} }, // HDR
{ { 0}, { 0} },
};
SR_ s_14[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -20} },
};
SR_ s_15[] =
{
{ { ERR_REQ}, { 7} },
{ { 276}, { 18} }, // rules
{ { 275}, { 19} }, // rule
{ { 273}, { 20} }, // rNr
{ { errTok_}, { 21} }, // errTok_
{ { 10}, { 22} }, // '\x0a'
{ { 264}, { 23} }, // NR
{ { 0}, { 0} },
};
SR_ s_16[] =
{
{ { REQ_DEF}, { 3} },
{ { 258}, { -18} }, // ACTION
{ { 266}, { -18} }, // AND
{ { 0}, { -16} },
};
SR_ s_17[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -21} },
};
SR_ s_18[] =
{
{ { ERR_REQ_DEF}, { 6} },
{ { 275}, { 24} }, // rule
{ { 273}, { 20} }, // rNr
{ { errTok_}, { 21} }, // errTok_
{ { 10}, { 22} }, // '\x0a'
{ { 264}, { 23} }, // NR
{ { 0}, { -17} },
};
SR_ s_19[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -15} },
};
SR_ s_20[] =
{
{ { REQ_TOKEN}, { 3} },
{ { 274}, { 25} }, // rDate
{ { 259}, { 26} }, // DATE
{ { 0}, { 0} },
};
SR_ s_21[] =
{
{ { REQ_TOKEN}, { 2} },
{ { 10}, { 27} }, // '\x0a'
{ { 0}, { 0} },
};
SR_ s_22[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -13} },
};
SR_ s_23[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -9} },
};
SR_ s_24[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -14} },
};
SR_ s_25[] =
{
{ { REQ_TOKEN}, { 4} },
{ { 272}, { 28} }, // expression
{ { 270}, { 29} }, // eMatchMode
{ { 262}, { 30} }, // LETTER
{ { 0}, { 0} },
};
SR_ s_26[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -10} },
};
SR_ s_27[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -12} },
};
SR_ s_28[] =
{
{ { REQ_TOKEN}, { 3} },
{ { 10}, { 31} }, // '\x0a'
{ { 266}, { 32} }, // AND
{ { 0}, { 0} },
};
SR_ s_29[] =
{
{ { REQ_DEF}, { 3} },
{ { 269}, { 33} }, // optNot
{ { 263}, { 34} }, // NOT
{ { 0}, { -4} },
};
SR_ s_30[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -5} },
};
SR_ s_31[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -11} },
};
SR_ s_32[] =
{
{ { REQ_TOKEN}, { 4} },
{ { 272}, { 35} }, // expression
{ { 270}, { 29} }, // eMatchMode
{ { 262}, { 30} }, // LETTER
{ { 0}, { 0} },
};
SR_ s_33[] =
{
{ { REQ_TOKEN}, { 3} },
{ { 271}, { 36} }, // eRegex
{ { 265}, { 37} }, // REGEX
{ { 0}, { 0} },
};
SR_ s_34[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -3} },
};
SR_ s_35[] =
{
{ { REQ_DEF}, { 1} },
{ { 0}, { -8} },
};
SR_ s_36[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -7} },
};
SR_ s_37[] =
{
{ { DEF_RED}, { 1} },
{ { 0}, { -6} },
};
// State array:
SR_ *s_state[] =
{
s_0, s_1, s_2, s_3, s_4, s_5, s_6, s_7, s_8, s_9,
s_10, s_11, s_12, s_13, s_14, s_15, s_16, s_17, s_18, s_19,
s_20, s_21, s_22, s_23, s_24, s_25, s_26, s_27, s_28, s_29,
s_30, s_31, s_32, s_33, s_34, s_35, s_36, s_37,
};
} // anonymous namespace ends
// If the parsing function call (i.e., parse()' needs arguments, then provide
// an overloaded function. The code below doesn't rely on parameters, so no
// arguments are required. Furthermore, parse uses a function try block to
// allow us to do ACCEPT and ABORT from anywhere, even from within members
// called by actions, simply throwing the appropriate exceptions.
// base/base1
ParserBase::ParserBase()
:
d_token(Reserved_::UNDETERMINED_),
// $insert baseclasscode
d_requiredTokens_(0)
{
}
// base/clearin
void ParserBase::clearin_()
{
d_nErrors_ = 0;
d_stackIdx = -1;
d_stateStack.clear();
d_token = Reserved_::UNDETERMINED_;
d_next = TokenPair{ Reserved_::UNDETERMINED_, STYPE_{} };
d_recovery = false;
d_acceptedTokens_ = d_requiredTokens_;
d_val_ = STYPE_{};
push_(0);
}
// base/debugfunctions
void ParserBase::setDebug(bool mode)
{
d_actionCases_ = false;
d_debug_ = mode;
}
void ParserBase::setDebug(DebugMode_ mode)
{
d_actionCases_ = mode & ACTIONCASES;
d_debug_ = mode & ON;
}
// base/lex
void ParserBase::lex_(int token)
{
d_token = token;
if (d_token <= 0)
d_token = Reserved_::EOF_;
d_terminalToken = true;
}
// base/lookup
int ParserBase::lookup_() const
{
// if the final transition is negative, then we should reduce by the rule
// given by its positive value.
SR_ const *sr = s_state[d_state];
SR_ const *last = sr + sr->d_lastIdx;
for ( ; ++sr != last; ) // visit all but the last SR entries
{
if (sr->d_token == d_token)
return sr->d_action;
}
if (sr == last) // reached the last element
{
if (sr->d_action < 0) // default reduction
{
return sr->d_action;
}
// No default reduction, so token not found, so error.
throw UNEXPECTED_TOKEN_;
}
// not at the last element: inspect the nature of the action
// (< 0: reduce, 0: ACCEPT, > 0: shift)
int action = sr->d_action;
return action;
}
// base/pop
void ParserBase::pop_(size_t count)
{
if (d_stackIdx < static_cast<int>(count))
{
ABORT();
}
d_stackIdx -= count;
d_state = d_stateStack[d_stackIdx].first;
d_vsp = &d_stateStack[d_stackIdx];
}
// base/poptoken
void ParserBase::popToken_()
{
d_token = d_next.first;
d_val_ = std::move(d_next.second);
d_next.first = Reserved_::UNDETERMINED_;
}
// base/push
void ParserBase::push_(size_t state)
{
size_t currentSize = d_stateStack.size();
if (stackSize_() == currentSize)
{
size_t newSize = currentSize + STACK_EXPANSION_;
d_stateStack.resize(newSize);
}
++d_stackIdx;
d_stateStack[d_stackIdx] =
StatePair{ d_state = state, std::move(d_val_) };
d_vsp = &d_stateStack[d_stackIdx];
if (d_stackIdx == 0)
{
}
else
{
}
}
// base/pushtoken
void ParserBase::pushToken_(int token)
{
d_next = TokenPair{ d_token, std::move(d_val_) };
d_token = token;
}
// base/redotoken
void ParserBase::redoToken_()
{
if (d_token != Reserved_::UNDETERMINED_)
pushToken_(d_token);
}
// base/reduce
void ParserBase::reduce_(int rule)
{
PI_ const &pi = s_productionInfo[rule];
d_token = pi.d_nonTerm;
pop_(pi.d_size);
d_terminalToken = false;
}
// base/shift
void ParserBase::shift_(int action)
{
push_(action);
popToken_(); // token processed
if (d_recovery and d_terminalToken)
{
d_recovery = false;
d_acceptedTokens_ = 0;
}
}
// base/startrecovery
void ParserBase::startRecovery_()
{
int lastToken = d_token; // give the unexpected token a
// chance to be processed
// again.
pushToken_(Reserved_::errTok_); // specify errTok_ as next token
push_(lookup_()); // push the error state
d_token = lastToken; // reactivate the unexpected
// token (we're now in an
// ERROR state).
d_recovery = true;
}
// base/top
inline size_t ParserBase::top_() const
{
return d_stateStack[d_stackIdx].first;
}
// derived/errorrecovery
void Parser::errorRecovery_()
{
// When an error has occurred, pop elements off the stack until the top
// state has an error-item. If none is found, the default recovery
// mode (which is to abort) is activated.
//
// If EOF is encountered without being appropriate for the current state,
// then the error recovery will fall back to the default recovery mode.
// (i.e., parsing terminates)
if (d_acceptedTokens_ >= d_requiredTokens_)// only generate an error-
{ // message if enough tokens
++d_nErrors_; // were accepted. Otherwise
error(); // simply skip input
}
// get the error state
while (not (s_state[top_()][0].d_type & ERR_ITEM))
{
pop_();
}
// In the error state, looking up a token allows us to proceed.
// Continuation may be require multiple reductions, but eventually a
// terminal-token shift is used. See nextCycle_ for details.
startRecovery_();
}
// derived/executeaction
void Parser::executeAction_(int production)
try
{
if (token_() != Reserved_::UNDETERMINED_)
pushToken_(token_()); // save an already available token
switch (production)
{
// $insert actioncases
case 1:
#line 31 "grammar"
{
d_val_ = vs_(-1);
}
break;
case 3:
#line 3 "inc/opt"
{
d_val_ = REVERSE;
}
break;
case 4:
#line 7 "inc/opt"
{
d_val_ = USE;
}
break;
case 5:
#line 3 "inc/expression"
{
matchMode();
}
break;
case 6:
#line 10 "inc/expression"
{
regex();
}
break;
case 7:
#line 17 "inc/expression"
{
expression(vs_(-1));
}
break;
case 8:
#line 22 "inc/expression"
{
d_val_ = vs_(-2);
}
break;
case 9:
#line 3 "inc/rules"
{
addRule();
}
break;
case 10:
#line 10 "inc/rules"
{
date();
}
break;
case 11:
#line 17 "inc/rules"
{
endRule();
}
break;
case 12:
#line 23 "inc/rules"
{
d_val_ = vs_(-1);
}
break;
case 13:
#line 25 "inc/rules"
{
d_val_ = vs_(0);
}
break;
case 14:
#line 29 "inc/rules"
{
d_val_ = vs_(-1);
}
break;
case 15:
#line 31 "inc/rules"
{
d_val_ = vs_(0);
}
break;
case 16:
#line 3 "inc/condition"
{
beginRules();
}
break;
case 17:
#line 10 "inc/condition"
{
d_val_ = vs_(-1);
}
break;
case 18:
#line 12 "inc/condition"
{
d_val_ = vs_(0);
}
break;
case 19:
#line 16 "inc/condition"
{
hdr();
}
break;
case 20:
#line 23 "inc/condition"
{
condTerm();
}
break;
case 21:
#line 30 "inc/condition"
{
d_val_ = vs_(-2);
}
break;
case 22:
#line 32 "inc/condition"
{
d_val_ = vs_(0);
}
break;
case 23:
#line 42 "grammar"
{
startIf();
}
break;
case 24:
#line 50 "grammar"
{
action();
}
break;
case 25:
#line 55 "inc/condition"
{
d_val_ = vs_(-1);
}
break;
case 26:
#line 57 "inc/condition"
{
d_val_ = vs_(0);
}
break;
}
}
catch (std::exception const &exc)
{
exceptionHandler(exc);
}
// derived/nextcycle
void Parser::nextCycle_()
try
{
if (s_state[state_()]->d_type & REQ_TOKEN)
nextToken_(); // obtain next token
int action = lookup_(); // lookup d_token in d_state
if (action > 0) // SHIFT: push a new state
{
shift_(action);
return;
}
if (action < 0) // REDUCE: execute and pop.
{
if (recovery_())
redoToken_();
else
executeAction_(-action);
// next token is the rule's LHS
reduce_(-action);
return;
}
if (recovery_())
ABORT();
else
ACCEPT();
}
catch (ErrorRecovery_)
{
if (not recovery_())
errorRecovery_();
else
{
if (token_() == Reserved_::EOF_)
ABORT();
popToken_(); // skip the failing token
}
}
// derived/nexttoken
void Parser::nextToken_()
{
// If d_token is Reserved_::UNDETERMINED_ then if savedToken_() is
// Reserved_::UNDETERMINED_ another token is obtained from lex(). Then
// savedToken_() is assigned to d_token.
// no need for a token: got one already
if (token_() != Reserved_::UNDETERMINED_)
{
return;
}
if (savedToken_() != Reserved_::UNDETERMINED_)
{
popToken_(); // consume pending token
}
else
{
++d_acceptedTokens_; // accept another token (see
// errorRecover())
lex_(lex());
print_();
}
print();
}
// derived/print
void Parser::print_()
{
// $insert print
}
// derived/parse
int Parser::parse()
try
{
// The parsing algorithm:
// Initially, state 0 is pushed on the stack, and all relevant variables
// are initialized by Base::clearin_.
//
// Then, in an eternal loop:
//
// 1. If a state is a REQ_TOKEN type, then the next token is obtained
// from nextToken(). This may very well be the currently available
// token. When retrieving a terminal token d_terminal is set to true.
//
// 2. lookup() is called, d_token is looked up in the current state's
// SR_ array.
//
// 4. Depending on the result of the lookup() function the next state is
// shifted on the parser's stack, a reduction by some rule is applied,
// or the parsing function returns ACCEPT(). When a reduction is
// called for, any action that may have been defined for that
// reduction is executed.
//
// 5. An error occurs if d_token is not found, and the state has no
// default reduction.
clearin_(); // initialize, push(0)
while (true)
{
// $insert prompt
nextCycle_();
}
}
catch (Return_ retValue)
{
return retValue or d_nErrors_;
}
// derived/tail
|