1 # C++ skeleton for Bison 2 3 # Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc. 4 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 m4_include(b4_skeletonsdir/[c++.m4]) 19 20 # api.value.type=variant is valid. 21 m4_define([b4_value_type_setup_variant]) 22 23 # Check the value of %define parse.lac, where LAC stands for lookahead 24 # correction. 25 b4_percent_define_default([[parse.lac]], [[none]]) 26 b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) 27 b4_define_flag_if([lac]) 28 m4_define([b4_lac_flag], 29 [m4_if(b4_percent_define_get([[parse.lac]]), 30 [none], [[0]], [[1]])]) 31 32 33 # b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED) 34 # ------------------------------------------- 35 m4_define([b4_tname_if], 36 [m4_case(b4_percent_define_get([[parse.error]]), 37 [verbose], [$1], 38 [b4_token_table_if([$1], 39 [$2])])]) 40 41 42 # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT) 43 # -------------------------------------------------------------- 44 # Declare "parser::yy<TABLE-NAME>_" whose contents is CONTENT. 45 m4_define([b4_integral_parser_table_declare], 46 [m4_ifval([$3], [b4_comment([$3], [ ]) 47 ])dnl 48 static const b4_int_type_for([$2]) yy$1_[[]];dnl 49 ]) 50 51 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) 52 # ------------------------------------------------------------- 53 # Define "parser::yy<TABLE-NAME>_" whose contents is CONTENT. 54 m4_define([b4_integral_parser_table_define], 55 [ const b4_int_type_for([$2]) 56 b4_parser_class::yy$1_[[]] = 57 { 58 $2 59 };dnl 60 ]) 61 62 63 # b4_symbol_kind(NUM) 64 # ------------------- 65 m4_define([b4_symbol_kind], 66 [symbol_kind::b4_symbol_kind_base($@)]) 67 68 69 # b4_symbol_value_template(VAL, SYMBOL-NUM, [TYPE]) 70 # ------------------------------------------------- 71 # Same as b4_symbol_value, but used in a template method. It makes 72 # a difference when using variants. Note that b4_value_type_setup_union 73 # overrides b4_symbol_value, so we must override it again. 74 m4_copy([b4_symbol_value], [b4_symbol_value_template]) 75 m4_append([b4_value_type_setup_union], 76 [m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])]) 77 78 # b4_lhs_value(SYMBOL-NUM, [TYPE]) 79 # -------------------------------- 80 # See README. 81 m4_define([b4_lhs_value], 82 [b4_symbol_value([yylhs.value], [$1], [$2])]) 83 84 85 # b4_lhs_location() 86 # ----------------- 87 # Expansion of @$. 88 m4_define([b4_lhs_location], 89 [yylhs.location]) 90 91 92 # b4_rhs_data(RULE-LENGTH, POS) 93 # ----------------------------- 94 # See README. 95 m4_define([b4_rhs_data], 96 [yystack_@{b4_subtract($@)@}]) 97 98 99 # b4_rhs_state(RULE-LENGTH, POS) 100 # ------------------------------ 101 # The state corresponding to the symbol #POS, where the current 102 # rule has RULE-LENGTH symbols on RHS. 103 m4_define([b4_rhs_state], 104 [b4_rhs_data([$1], [$2]).state]) 105 106 107 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) 108 # -------------------------------------------------- 109 # See README. 110 m4_define([_b4_rhs_value], 111 [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3], [$4])]) 112 113 m4_define([b4_rhs_value], 114 [b4_percent_define_ifdef([api.value.automove], 115 [YY_MOVE (_b4_rhs_value($@))], 116 [_b4_rhs_value($@)])]) 117 118 119 # b4_rhs_location(RULE-LENGTH, POS) 120 # --------------------------------- 121 # Expansion of @POS, where the current rule has RULE-LENGTH symbols 122 # on RHS. 123 m4_define([b4_rhs_location], 124 [b4_rhs_data([$1], [$2]).location]) 125 126 127 # b4_symbol_action(SYMBOL-NUM, KIND) 128 # ---------------------------------- 129 # Run the action KIND (destructor or printer) for SYMBOL-NUM. 130 # Same as in C, but using references instead of pointers. 131 m4_define([b4_symbol_action], 132 [b4_symbol_if([$1], [has_$2], 133 [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl 134 b4_dollar_pushdef([yysym.value], 135 [$1], 136 [], 137 [yysym.location])dnl 138 _b4_symbol_case([$1])[]dnl 139 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl 140 b4_symbol([$1], [$2]) 141 b4_syncline([@oline@], [@ofile@])dnl 142 break; 143 144 m4_popdef([b4_symbol_value])[]dnl 145 b4_dollar_popdef[]dnl 146 ])]) 147 148 149 # b4_lex 150 # ------ 151 # Call yylex. 152 m4_define([b4_lex], 153 [b4_token_ctor_if( 154 [b4_function_call([yylex], 155 [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))], 156 [b4_function_call([yylex], [int], 157 [b4_api_PREFIX[STYPE*], [&yyla.value]][]dnl 158 b4_locations_if([, [[location*], [&yyla.location]]])dnl 159 m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) 160 161 162 m4_pushdef([b4_copyright_years], 163 [2002-2015, 2018-2021]) 164 165 m4_define([b4_parser_class], 166 [b4_percent_define_get([[api.parser.class]])]) 167 168 b4_bison_locations_if([# Backward compatibility. 169 m4_define([b4_location_constructors]) 170 m4_include(b4_skeletonsdir/[location.cc])]) 171 m4_include(b4_skeletonsdir/[stack.hh]) 172 b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])]) 173 174 175 # b4_shared_declarations(hh|cc) 176 # ----------------------------- 177 # Declaration that might either go into the header (if --defines, $1 = hh) 178 # or in the implementation file. 179 m4_define([b4_shared_declarations], 180 [b4_percent_code_get([[requires]])[ 181 ]b4_parse_assert_if([# include <cassert>])[ 182 # include <cstdlib> // std::abort 183 # include <iostream> 184 # include <stdexcept> 185 # include <string> 186 # include <vector> 187 188 ]b4_cxx_portability[ 189 ]m4_ifdef([b4_location_include], 190 [[# include ]b4_location_include])[ 191 ]b4_variant_if([b4_variant_includes])[ 192 193 ]b4_attribute_define[ 194 ]b4_cast_define[ 195 ]b4_null_define[ 196 197 ]b4_YYDEBUG_define[ 198 199 ]b4_namespace_open[ 200 201 ]b4_bison_locations_if([m4_ifndef([b4_location_file], 202 [b4_location_define])])[ 203 204 /// A Bison parser. 205 class ]b4_parser_class[ 206 { 207 public: 208 ]b4_public_types_declare[ 209 ]b4_symbol_type_define[ 210 /// Build a parser object. 211 ]b4_parser_class[ (]b4_parse_param_decl[); 212 virtual ~]b4_parser_class[ (); 213 214 #if 201103L <= YY_CPLUSPLUS 215 /// Non copyable. 216 ]b4_parser_class[ (const ]b4_parser_class[&) = delete; 217 /// Non copyable. 218 ]b4_parser_class[& operator= (const ]b4_parser_class[&) = delete; 219 #endif 220 221 /// Parse. An alias for parse (). 222 /// \returns 0 iff parsing succeeded. 223 int operator() (); 224 225 /// Parse. 226 /// \returns 0 iff parsing succeeded. 227 virtual int parse (); 228 229 #if ]b4_api_PREFIX[DEBUG 230 /// The current debugging stream. 231 std::ostream& debug_stream () const YY_ATTRIBUTE_PURE; 232 /// Set the current debugging stream. 233 void set_debug_stream (std::ostream &); 234 235 /// Type for debugging levels. 236 typedef int debug_level_type; 237 /// The current debugging level. 238 debug_level_type debug_level () const YY_ATTRIBUTE_PURE; 239 /// Set the current debugging level. 240 void set_debug_level (debug_level_type l); 241 #endif 242 243 /// Report a syntax error.]b4_locations_if([[ 244 /// \param loc where the syntax error is found.]])[ 245 /// \param msg a description of the syntax error. 246 virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); 247 248 /// Report a syntax error. 249 void error (const syntax_error& err); 250 251 ]b4_parse_error_bmatch( 252 [custom\|detailed], 253 [[ /// The user-facing name of the symbol whose (internal) number is 254 /// YYSYMBOL. No bounds checking. 255 static const char *symbol_name (symbol_kind_type yysymbol);]], 256 [simple], 257 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 258 /// The user-facing name of the symbol whose (internal) number is 259 /// YYSYMBOL. No bounds checking. 260 static const char *symbol_name (symbol_kind_type yysymbol); 261 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 262 ]], 263 [verbose], 264 [[ /// The user-facing name of the symbol whose (internal) number is 265 /// YYSYMBOL. No bounds checking. 266 static std::string symbol_name (symbol_kind_type yysymbol);]])[ 267 268 ]b4_token_constructor_define[ 269 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ 270 class context 271 { 272 public: 273 context (const ]b4_parser_class[& yyparser, const symbol_type& yyla); 274 const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; } 275 symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[ 276 const location_type& location () const YY_NOEXCEPT { return yyla_.location; } 277 ]])[ 278 /// Put in YYARG at most YYARGN of the expected tokens, and return the 279 /// number of tokens stored in YYARG. If YYARG is null, return the 280 /// number of expected tokens (guaranteed to be less than YYNTOKENS). 281 int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; 282 283 private: 284 const ]b4_parser_class[& yyparser_; 285 const symbol_type& yyla_; 286 }; 287 ]])[ 288 private: 289 #if YY_CPLUSPLUS < 201103L 290 /// Non copyable. 291 ]b4_parser_class[ (const ]b4_parser_class[&); 292 /// Non copyable. 293 ]b4_parser_class[& operator= (const ]b4_parser_class[&); 294 #endif 295 ]b4_lac_if([[ 296 /// Check the lookahead yytoken. 297 /// \returns true iff the token will be eventually shifted. 298 bool yy_lac_check_ (symbol_kind_type yytoken) const; 299 /// Establish the initial context if no initial context currently exists. 300 /// \returns true iff the token will be eventually shifted. 301 bool yy_lac_establish_ (symbol_kind_type yytoken); 302 /// Discard any previous initial lookahead context because of event. 303 /// \param event the event which caused the lookahead to be discarded. 304 /// Only used for debbuging output. 305 void yy_lac_discard_ (const char* event);]])[ 306 307 /// Stored state numbers (used for stacks). 308 typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type; 309 ]b4_parse_error_bmatch( 310 [custom], [[ 311 /// Report a syntax error 312 /// \param yyctx the context in which the error occurred. 313 void report_syntax_error (const context& yyctx) const;]], 314 [detailed\|verbose], [[ 315 /// The arguments of the error message. 316 int yy_syntax_error_arguments_ (const context& yyctx, 317 symbol_kind_type yyarg[], int yyargn) const; 318 319 /// Generate an error message. 320 /// \param yyctx the context in which the error occurred. 321 virtual std::string yysyntax_error_ (const context& yyctx) const;]])[ 322 /// Compute post-reduction state. 323 /// \param yystate the current state 324 /// \param yysym the nonterminal to push on the stack 325 static state_type yy_lr_goto_state_ (state_type yystate, int yysym); 326 327 /// Whether the given \c yypact_ value indicates a defaulted state. 328 /// \param yyvalue the value to check 329 static bool yy_pact_value_is_default_ (int yyvalue); 330 331 /// Whether the given \c yytable_ value indicates a syntax error. 332 /// \param yyvalue the value to check 333 static bool yy_table_value_is_error_ (int yyvalue); 334 335 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; 336 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; 337 338 /// Convert a scanner token kind \a t to a symbol kind. 339 /// In theory \a t should be a token_kind_type, but character literals 340 /// are valid, yet not members of the token_type enum. 341 static symbol_kind_type yytranslate_ (int t); 342 343 ]b4_parse_error_bmatch( 344 [simple], 345 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 346 /// For a symbol, its name in clear. 347 static const char* const yytname_[]; 348 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 349 ]], 350 [verbose], 351 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic. 352 static std::string yytnamerr_ (const char *yystr); 353 354 /// For a symbol, its name in clear. 355 static const char* const yytname_[]; 356 ]])[ 357 358 // Tables. 359 ]b4_parser_tables_declare[ 360 361 #if ]b4_api_PREFIX[DEBUG 362 ]b4_integral_parser_table_declare([rline], [b4_rline], 363 [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ 364 /// Report on the debug stream that the rule \a r is going to be reduced. 365 virtual void yy_reduce_print_ (int r) const; 366 /// Print the state stack on the debug stream. 367 virtual void yy_stack_print_ () const; 368 369 /// Debugging level. 370 int yydebug_; 371 /// Debug stream. 372 std::ostream* yycdebug_; 373 374 /// \brief Display a symbol kind, value and location. 375 /// \param yyo The output stream. 376 /// \param yysym The symbol. 377 template <typename Base> 378 void yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const; 379 #endif 380 381 /// \brief Reclaim the memory associated to a symbol. 382 /// \param yymsg Why this token is reclaimed. 383 /// If null, print nothing. 384 /// \param yysym The symbol. 385 template <typename Base> 386 void yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const; 387 388 private: 389 /// Type access provider for state based symbols. 390 struct by_state 391 { 392 /// Default constructor. 393 by_state () YY_NOEXCEPT; 394 395 /// The symbol kind as needed by the constructor. 396 typedef state_type kind_type; 397 398 /// Constructor. 399 by_state (kind_type s) YY_NOEXCEPT; 400 401 /// Copy constructor. 402 by_state (const by_state& that) YY_NOEXCEPT; 403 404 /// Record that this symbol is empty. 405 void clear () YY_NOEXCEPT; 406 407 /// Steal the symbol kind from \a that. 408 void move (by_state& that); 409 410 /// The symbol kind (corresponding to \a state). 411 /// \a ]b4_symbol(-2, kind)[ when empty. 412 symbol_kind_type kind () const YY_NOEXCEPT; 413 414 /// The state number used to denote an empty symbol. 415 /// We use the initial state, as it does not have a value. 416 enum { empty_state = 0 }; 417 418 /// The state. 419 /// \a empty when empty. 420 state_type state; 421 }; 422 423 /// "Internal" symbol: element of the stack. 424 struct stack_symbol_type : basic_symbol<by_state> 425 { 426 /// Superclass. 427 typedef basic_symbol<by_state> super_type; 428 /// Construct an empty symbol. 429 stack_symbol_type (); 430 /// Move or copy construction. 431 stack_symbol_type (YY_RVREF (stack_symbol_type) that); 432 /// Steal the contents from \a sym to build this. 433 stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) sym); 434 #if YY_CPLUSPLUS < 201103L 435 /// Assignment, needed by push_back by some old implementations. 436 /// Moves the contents of that. 437 stack_symbol_type& operator= (stack_symbol_type& that); 438 439 /// Assignment, needed by push_back by other implementations. 440 /// Needed by some other old implementations. 441 stack_symbol_type& operator= (const stack_symbol_type& that); 442 #endif 443 }; 444 445 ]b4_stack_define[ 446 447 /// Stack type. 448 typedef stack<stack_symbol_type> stack_type; 449 450 /// The stack. 451 stack_type yystack_;]b4_lac_if([[ 452 /// The stack for LAC. 453 /// Logically, the yy_lac_stack's lifetime is confined to the function 454 /// yy_lac_check_. We just store it as a member of this class to hold 455 /// on to the memory and to avoid frequent reallocations. 456 /// Since yy_lac_check_ is const, this member must be mutable. 457 mutable std::vector<state_type> yylac_stack_; 458 /// Whether an initial LAC context was established. 459 bool yy_lac_established_; 460 ]])[ 461 462 /// Push a new state on the stack. 463 /// \param m a debug message to display 464 /// if null, no trace is output. 465 /// \param sym the symbol 466 /// \warning the contents of \a s.value is stolen. 467 void yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym); 468 469 /// Push a new look ahead token on the state on the stack. 470 /// \param m a debug message to display 471 /// if null, no trace is output. 472 /// \param s the state 473 /// \param sym the symbol (for its value and location). 474 /// \warning the contents of \a sym.value is stolen. 475 void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); 476 477 /// Pop \a n symbols from the stack. 478 void yypop_ (int n = 1); 479 480 /// Constants. 481 enum 482 { 483 yylast_ = ]b4_last[, ///< Last index in yytable_. 484 yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols. 485 yyfinal_ = ]b4_final_state_number[ ///< Termination state number. 486 }; 487 488 ]b4_parse_param_vars[ 489 ]b4_percent_code_get([[yy_bison_internal_hook]])[ 490 }; 491 492 ]b4_token_ctor_if([b4_yytranslate_define([$1])[ 493 ]b4_public_types_define([$1])])[ 494 ]b4_namespace_close[ 495 496 ]b4_percent_code_get([[provides]])[ 497 ]]) 498 499 ## -------------- ## 500 ## Output files. ## 501 ## -------------- ## 502 503 b4_defines_if( 504 [b4_output_begin([b4_spec_header_file]) 505 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) 506 [ 507 /** 508 ** \file ]b4_spec_mapped_header_file[ 509 ** Define the ]b4_namespace_ref[::parser class. 510 */ 511 512 // C++ LALR(1) parser skeleton written by Akim Demaille. 513 514 ]b4_disclaimer[ 515 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[ 516 ]b4_shared_declarations(hh)[ 517 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[ 518 ]b4_output_end[ 519 ]]) 520 521 522 b4_output_begin([b4_parser_file_name])[ 523 ]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[ 524 ]b4_disclaimer[ 525 ]b4_percent_code_get([[top]])[]dnl 526 m4_if(b4_prefix, [yy], [], 527 [ 528 // Take the name prefix into account. 529 [#]define yylex b4_prefix[]lex])[ 530 531 ]b4_user_pre_prologue[ 532 533 ]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]], 534 [b4_shared_declarations([cc])])[ 535 536 ]b4_user_post_prologue[ 537 ]b4_percent_code_get[ 538 539 #ifndef YY_ 540 # if defined YYENABLE_NLS && YYENABLE_NLS 541 # if ENABLE_NLS 542 # include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE. 543 # define YY_(msgid) dgettext ("bison-runtime", msgid) 544 # endif 545 # endif 546 # ifndef YY_ 547 # define YY_(msgid) msgid 548 # endif 549 #endif 550 ]b4_has_translations_if([ 551 #ifndef N_ 552 # define N_(Msgid) Msgid 553 #endif 554 ])[ 555 556 // Whether we are compiled with exception support. 557 #ifndef YY_EXCEPTIONS 558 # if defined __GNUC__ && !defined __EXCEPTIONS 559 # define YY_EXCEPTIONS 0 560 # else 561 # define YY_EXCEPTIONS 1 562 # endif 563 #endif 564 565 ]b4_locations_if([dnl 566 [#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) 567 ]b4_yylloc_default_define])[ 568 569 // Enable debugging if requested. 570 #if ]b4_api_PREFIX[DEBUG 571 572 // A pseudo ostream that takes yydebug_ into account. 573 # define YYCDEBUG if (yydebug_) (*yycdebug_) 574 575 # define YY_SYMBOL_PRINT(Title, Symbol) \ 576 do { \ 577 if (yydebug_) \ 578 { \ 579 *yycdebug_ << Title << ' '; \ 580 yy_print_ (*yycdebug_, Symbol); \ 581 *yycdebug_ << '\n'; \ 582 } \ 583 } while (false) 584 585 # define YY_REDUCE_PRINT(Rule) \ 586 do { \ 587 if (yydebug_) \ 588 yy_reduce_print_ (Rule); \ 589 } while (false) 590 591 # define YY_STACK_PRINT() \ 592 do { \ 593 if (yydebug_) \ 594 yy_stack_print_ (); \ 595 } while (false) 596 597 #else // !]b4_api_PREFIX[DEBUG 598 599 # define YYCDEBUG if (false) std::cerr 600 # define YY_SYMBOL_PRINT(Title, Symbol) YY_USE (Symbol) 601 # define YY_REDUCE_PRINT(Rule) static_cast<void> (0) 602 # define YY_STACK_PRINT() static_cast<void> (0) 603 604 #endif // !]b4_api_PREFIX[DEBUG 605 606 #define yyerrok (yyerrstatus_ = 0) 607 #define yyclearin (yyla.clear ()) 608 609 #define YYACCEPT goto yyacceptlab 610 #define YYABORT goto yyabortlab 611 #define YYERROR goto yyerrorlab 612 #define YYRECOVERING() (!!yyerrstatus_) 613 614 ]b4_namespace_open[ 615 /// Build a parser object. 616 ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[) 617 #if ]b4_api_PREFIX[DEBUG 618 : yydebug_ (false), 619 yycdebug_ (&std::cerr)]b4_lac_if([,], [m4_ifset([b4_parse_param], [,])])[ 620 #else 621 ]b4_lac_if([ :], [m4_ifset([b4_parse_param], [ :])])[ 622 #endif]b4_lac_if([[ 623 yy_lac_established_ (false)]m4_ifset([b4_parse_param], [,])])[]b4_parse_param_cons[ 624 {} 625 626 ]b4_parser_class::~b4_parser_class[ () 627 {} 628 629 ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW 630 {} 631 632 /*---------------. 633 | symbol kinds. | 634 `---------------*/ 635 636 ]b4_token_ctor_if([], [b4_public_types_define([cc])])[ 637 638 // by_state. 639 ]b4_parser_class[::by_state::by_state () YY_NOEXCEPT 640 : state (empty_state) 641 {} 642 643 ]b4_parser_class[::by_state::by_state (const by_state& that) YY_NOEXCEPT 644 : state (that.state) 645 {} 646 647 void 648 ]b4_parser_class[::by_state::clear () YY_NOEXCEPT 649 { 650 state = empty_state; 651 } 652 653 void 654 ]b4_parser_class[::by_state::move (by_state& that) 655 { 656 state = that.state; 657 that.clear (); 658 } 659 660 ]b4_parser_class[::by_state::by_state (state_type s) YY_NOEXCEPT 661 : state (s) 662 {} 663 664 ]b4_parser_class[::symbol_kind_type 665 ]b4_parser_class[::by_state::kind () const YY_NOEXCEPT 666 { 667 if (state == empty_state) 668 return ]b4_symbol(-2, kind)[; 669 else 670 return YY_CAST (symbol_kind_type, yystos_[+state]); 671 } 672 673 ]b4_parser_class[::stack_symbol_type::stack_symbol_type () 674 {} 675 676 ]b4_parser_class[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that) 677 : super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[) 678 {]b4_variant_if([ 679 b4_symbol_variant([that.kind ()], 680 [value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[ 681 #if 201103L <= YY_CPLUSPLUS 682 // that is emptied. 683 that.state = empty_state; 684 #endif 685 } 686 687 ]b4_parser_class[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that) 688 : super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[) 689 {]b4_variant_if([ 690 b4_symbol_variant([that.kind ()], 691 [value], [move], [YY_MOVE (that.value)])])[ 692 // that is emptied. 693 that.kind_ = ]b4_symbol(-2, kind)[; 694 } 695 696 #if YY_CPLUSPLUS < 201103L 697 ]b4_parser_class[::stack_symbol_type& 698 ]b4_parser_class[::stack_symbol_type::operator= (const stack_symbol_type& that) 699 { 700 state = that.state; 701 ]b4_variant_if([b4_symbol_variant([that.kind ()], 702 [value], [copy], [that.value])], 703 [[value = that.value;]])[]b4_locations_if([ 704 location = that.location;])[ 705 return *this; 706 } 707 708 ]b4_parser_class[::stack_symbol_type& 709 ]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that) 710 { 711 state = that.state; 712 ]b4_variant_if([b4_symbol_variant([that.kind ()], 713 [value], [move], [that.value])], 714 [[value = that.value;]])[]b4_locations_if([ 715 location = that.location;])[ 716 // that is emptied. 717 that.state = empty_state; 718 return *this; 719 } 720 #endif 721 722 template <typename Base> 723 void 724 ]b4_parser_class[::yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const 725 { 726 if (yymsg) 727 YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [ 728 729 // User destructor. 730 b4_symbol_actions([destructor], [yysym.kind ()])])[ 731 } 732 733 #if ]b4_api_PREFIX[DEBUG 734 template <typename Base> 735 void 736 ]b4_parser_class[::yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const 737 { 738 std::ostream& yyoutput = yyo; 739 YY_USE (yyoutput); 740 if (yysym.empty ()) 741 yyo << "empty symbol"; 742 else 743 { 744 symbol_kind_type yykind = yysym.kind (); 745 yyo << (yykind < YYNTOKENS ? "token" : "nterm") 746 << ' ' << yysym.name () << " ("]b4_locations_if([ 747 << yysym.location << ": "])[; 748 ]b4_symbol_actions([printer])[ 749 yyo << ')'; 750 } 751 } 752 #endif 753 754 void 755 ]b4_parser_class[::yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym) 756 { 757 if (m) 758 YY_SYMBOL_PRINT (m, sym); 759 yystack_.push (YY_MOVE (sym)); 760 } 761 762 void 763 ]b4_parser_class[::yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym) 764 { 765 #if 201103L <= YY_CPLUSPLUS 766 yypush_ (m, stack_symbol_type (s, std::move (sym))); 767 #else 768 stack_symbol_type ss (s, sym); 769 yypush_ (m, ss); 770 #endif 771 } 772 773 void 774 ]b4_parser_class[::yypop_ (int n) 775 { 776 yystack_.pop (n); 777 } 778 779 #if ]b4_api_PREFIX[DEBUG 780 std::ostream& 781 ]b4_parser_class[::debug_stream () const 782 { 783 return *yycdebug_; 784 } 785 786 void 787 ]b4_parser_class[::set_debug_stream (std::ostream& o) 788 { 789 yycdebug_ = &o; 790 } 791 792 793 ]b4_parser_class[::debug_level_type 794 ]b4_parser_class[::debug_level () const 795 { 796 return yydebug_; 797 } 798 799 void 800 ]b4_parser_class[::set_debug_level (debug_level_type l) 801 { 802 yydebug_ = l; 803 } 804 #endif // ]b4_api_PREFIX[DEBUG 805 806 ]b4_parser_class[::state_type 807 ]b4_parser_class[::yy_lr_goto_state_ (state_type yystate, int yysym) 808 { 809 int yyr = yypgoto_[yysym - YYNTOKENS] + yystate; 810 if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) 811 return yytable_[yyr]; 812 else 813 return yydefgoto_[yysym - YYNTOKENS]; 814 } 815 816 bool 817 ]b4_parser_class[::yy_pact_value_is_default_ (int yyvalue) 818 { 819 return yyvalue == yypact_ninf_; 820 } 821 822 bool 823 ]b4_parser_class[::yy_table_value_is_error_ (int yyvalue) 824 { 825 return yyvalue == yytable_ninf_; 826 } 827 828 int 829 ]b4_parser_class[::operator() () 830 { 831 return parse (); 832 } 833 834 int 835 ]b4_parser_class[::parse () 836 { 837 int yyn; 838 /// Length of the RHS of the rule being reduced. 839 int yylen = 0; 840 841 // Error handling. 842 int yynerrs_ = 0; 843 int yyerrstatus_ = 0; 844 845 /// The lookahead symbol. 846 symbol_type yyla;]b4_locations_if([[ 847 848 /// The locations where the error started and ended. 849 stack_symbol_type yyerror_range[3];]])[ 850 851 /// The return value of parse (). 852 int yyresult;]b4_lac_if([[ 853 854 /// Discard the LAC context in case there still is one left from a 855 /// previous invocation. 856 yy_lac_discard_ ("init");]])[ 857 858 #if YY_EXCEPTIONS 859 try 860 #endif // YY_EXCEPTIONS 861 { 862 YYCDEBUG << "Starting parse\n"; 863 864 ]m4_ifdef([b4_initial_action], [ 865 b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl 866 b4_user_initial_action 867 b4_dollar_popdef])[]dnl 868 869 [ /* Initialize the stack. The initial state will be set in 870 yynewstate, since the latter expects the semantical and the 871 location values to have been already stored, initialize these 872 stacks with a primary value. */ 873 yystack_.clear (); 874 yypush_ (YY_NULLPTR, 0, YY_MOVE (yyla)); 875 876 /*-----------------------------------------------. 877 | yynewstate -- push a new symbol on the stack. | 878 `-----------------------------------------------*/ 879 yynewstate: 880 YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n'; 881 YY_STACK_PRINT (); 882 883 // Accept? 884 if (yystack_[0].state == yyfinal_) 885 YYACCEPT; 886 887 goto yybackup; 888 889 890 /*-----------. 891 | yybackup. | 892 `-----------*/ 893 yybackup: 894 // Try to take a decision without lookahead. 895 yyn = yypact_[+yystack_[0].state]; 896 if (yy_pact_value_is_default_ (yyn)) 897 goto yydefault; 898 899 // Read a lookahead token. 900 if (yyla.empty ()) 901 { 902 YYCDEBUG << "Reading a token\n"; 903 #if YY_EXCEPTIONS 904 try 905 #endif // YY_EXCEPTIONS 906 {]b4_token_ctor_if([[ 907 symbol_type yylookahead (]b4_lex[); 908 yyla.move (yylookahead);]], [[ 909 yyla.kind_ = yytranslate_ (]b4_lex[);]])[ 910 } 911 #if YY_EXCEPTIONS 912 catch (const syntax_error& yyexc) 913 { 914 YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; 915 error (yyexc); 916 goto yyerrlab1; 917 } 918 #endif // YY_EXCEPTIONS 919 } 920 YY_SYMBOL_PRINT ("Next token is", yyla); 921 922 if (yyla.kind () == ]b4_symbol(1, kind)[) 923 { 924 // The scanner already issued an error message, process directly 925 // to error recovery. But do not keep the error token as 926 // lookahead, it is too special and may lead us to an endless 927 // loop in error recovery. */ 928 yyla.kind_ = ]b4_symbol(2, kind)[; 929 goto yyerrlab1; 930 } 931 932 /* If the proper action on seeing token YYLA.TYPE is to reduce or 933 to detect an error, take that action. */ 934 yyn += yyla.kind (); 935 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ()) 936 {]b4_lac_if([[ 937 if (!yy_lac_establish_ (yyla.kind ())) 938 goto yyerrlab;]])[ 939 goto yydefault; 940 } 941 942 // Reduce or error. 943 yyn = yytable_[yyn]; 944 if (yyn <= 0) 945 { 946 if (yy_table_value_is_error_ (yyn)) 947 goto yyerrlab;]b4_lac_if([[ 948 if (!yy_lac_establish_ (yyla.kind ())) 949 goto yyerrlab; 950 ]])[ 951 yyn = -yyn; 952 goto yyreduce; 953 } 954 955 // Count tokens shifted since error; after three, turn off error status. 956 if (yyerrstatus_) 957 --yyerrstatus_; 958 959 // Shift the lookahead token. 960 yypush_ ("Shifting", state_type (yyn), YY_MOVE (yyla));]b4_lac_if([[ 961 yy_lac_discard_ ("shift");]])[ 962 goto yynewstate; 963 964 965 /*-----------------------------------------------------------. 966 | yydefault -- do the default action for the current state. | 967 `-----------------------------------------------------------*/ 968 yydefault: 969 yyn = yydefact_[+yystack_[0].state]; 970 if (yyn == 0) 971 goto yyerrlab; 972 goto yyreduce; 973 974 975 /*-----------------------------. 976 | yyreduce -- do a reduction. | 977 `-----------------------------*/ 978 yyreduce: 979 yylen = yyr2_[yyn]; 980 { 981 stack_symbol_type yylhs; 982 yylhs.state = yy_lr_goto_state_ (yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([ 983 /* Variants are always initialized to an empty instance of the 984 correct type. The default '$$ = $1' action is NOT applied 985 when using variants. */ 986 b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [ 987 /* If YYLEN is nonzero, implement the default value of the 988 action: '$$ = $1'. Otherwise, use the top of the stack. 989 990 Otherwise, the following line sets YYLHS.VALUE to garbage. 991 This behavior is undocumented and Bison users should not rely 992 upon it. */ 993 if (yylen) 994 yylhs.value = yystack_@{yylen - 1@}.value; 995 else 996 yylhs.value = yystack_@{0@}.value;])[ 997 ]b4_locations_if([dnl 998 [ 999 // Default location. 1000 { 1001 stack_type::slice range (yystack_, yylen); 1002 YYLLOC_DEFAULT (yylhs.location, range, yylen); 1003 yyerror_range[1].location = yylhs.location; 1004 }]])[ 1005 1006 // Perform the reduction. 1007 YY_REDUCE_PRINT (yyn); 1008 #if YY_EXCEPTIONS 1009 try 1010 #endif // YY_EXCEPTIONS 1011 { 1012 switch (yyn) 1013 { 1014 ]b4_user_actions[ 1015 default: 1016 break; 1017 } 1018 } 1019 #if YY_EXCEPTIONS 1020 catch (const syntax_error& yyexc) 1021 { 1022 YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; 1023 error (yyexc); 1024 YYERROR; 1025 } 1026 #endif // YY_EXCEPTIONS 1027 YY_SYMBOL_PRINT ("-> $$ =", yylhs); 1028 yypop_ (yylen); 1029 yylen = 0; 1030 1031 // Shift the result of the reduction. 1032 yypush_ (YY_NULLPTR, YY_MOVE (yylhs)); 1033 } 1034 goto yynewstate; 1035 1036 1037 /*--------------------------------------. 1038 | yyerrlab -- here on detecting error. | 1039 `--------------------------------------*/ 1040 yyerrlab: 1041 // If not already recovering from an error, report this error. 1042 if (!yyerrstatus_) 1043 { 1044 ++yynerrs_;]b4_parse_error_case( 1045 [simple], [[ 1046 std::string msg = YY_("syntax error"); 1047 error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]], 1048 [custom], [[ 1049 context yyctx (*this, yyla); 1050 report_syntax_error (yyctx);]], 1051 [[ 1052 context yyctx (*this, yyla); 1053 std::string msg = yysyntax_error_ (yyctx); 1054 error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[ 1055 } 1056 1057 ]b4_locations_if([[ 1058 yyerror_range[1].location = yyla.location;]])[ 1059 if (yyerrstatus_ == 3) 1060 { 1061 /* If just tried and failed to reuse lookahead token after an 1062 error, discard it. */ 1063 1064 // Return failure if at end of input. 1065 if (yyla.kind () == ]b4_symbol(0, kind)[) 1066 YYABORT; 1067 else if (!yyla.empty ()) 1068 { 1069 yy_destroy_ ("Error: discarding", yyla); 1070 yyla.clear (); 1071 } 1072 } 1073 1074 // Else will try to reuse lookahead token after shifting the error token. 1075 goto yyerrlab1; 1076 1077 1078 /*---------------------------------------------------. 1079 | yyerrorlab -- error raised explicitly by YYERROR. | 1080 `---------------------------------------------------*/ 1081 yyerrorlab: 1082 /* Pacify compilers when the user code never invokes YYERROR and 1083 the label yyerrorlab therefore never appears in user code. */ 1084 if (false) 1085 YYERROR; 1086 1087 /* Do not reclaim the symbols of the rule whose action triggered 1088 this YYERROR. */ 1089 yypop_ (yylen); 1090 yylen = 0; 1091 YY_STACK_PRINT (); 1092 goto yyerrlab1; 1093 1094 1095 /*-------------------------------------------------------------. 1096 | yyerrlab1 -- common code for both syntax error and YYERROR. | 1097 `-------------------------------------------------------------*/ 1098 yyerrlab1: 1099 yyerrstatus_ = 3; // Each real token shifted decrements this. 1100 // Pop stack until we find a state that shifts the error token. 1101 for (;;) 1102 { 1103 yyn = yypact_[+yystack_[0].state]; 1104 if (!yy_pact_value_is_default_ (yyn)) 1105 { 1106 yyn += ]b4_symbol(1, kind)[; 1107 if (0 <= yyn && yyn <= yylast_ 1108 && yycheck_[yyn] == ]b4_symbol(1, kind)[) 1109 { 1110 yyn = yytable_[yyn]; 1111 if (0 < yyn) 1112 break; 1113 } 1114 } 1115 1116 // Pop the current state because it cannot handle the error token. 1117 if (yystack_.size () == 1) 1118 YYABORT; 1119 ]b4_locations_if([[ 1120 yyerror_range[1].location = yystack_[0].location;]])[ 1121 yy_destroy_ ("Error: popping", yystack_[0]); 1122 yypop_ (); 1123 YY_STACK_PRINT (); 1124 } 1125 { 1126 stack_symbol_type error_token; 1127 ]b4_locations_if([[ 1128 yyerror_range[2].location = yyla.location; 1129 YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[ 1130 1131 // Shift the error token.]b4_lac_if([[ 1132 yy_lac_discard_ ("error recovery");]])[ 1133 error_token.state = state_type (yyn); 1134 yypush_ ("Shifting", YY_MOVE (error_token)); 1135 } 1136 goto yynewstate; 1137 1138 1139 /*-------------------------------------. 1140 | yyacceptlab -- YYACCEPT comes here. | 1141 `-------------------------------------*/ 1142 yyacceptlab: 1143 yyresult = 0; 1144 goto yyreturn; 1145 1146 1147 /*-----------------------------------. 1148 | yyabortlab -- YYABORT comes here. | 1149 `-----------------------------------*/ 1150 yyabortlab: 1151 yyresult = 1; 1152 goto yyreturn; 1153 1154 1155 /*-----------------------------------------------------. 1156 | yyreturn -- parsing is finished, return the result. | 1157 `-----------------------------------------------------*/ 1158 yyreturn: 1159 if (!yyla.empty ()) 1160 yy_destroy_ ("Cleanup: discarding lookahead", yyla); 1161 1162 /* Do not reclaim the symbols of the rule whose action triggered 1163 this YYABORT or YYACCEPT. */ 1164 yypop_ (yylen); 1165 YY_STACK_PRINT (); 1166 while (1 < yystack_.size ()) 1167 { 1168 yy_destroy_ ("Cleanup: popping", yystack_[0]); 1169 yypop_ (); 1170 } 1171 1172 return yyresult; 1173 } 1174 #if YY_EXCEPTIONS 1175 catch (...) 1176 { 1177 YYCDEBUG << "Exception caught: cleaning lookahead and stack\n"; 1178 // Do not try to display the values of the reclaimed symbols, 1179 // as their printers might throw an exception. 1180 if (!yyla.empty ()) 1181 yy_destroy_ (YY_NULLPTR, yyla); 1182 1183 while (1 < yystack_.size ()) 1184 { 1185 yy_destroy_ (YY_NULLPTR, yystack_[0]); 1186 yypop_ (); 1187 } 1188 throw; 1189 } 1190 #endif // YY_EXCEPTIONS 1191 } 1192 1193 void 1194 ]b4_parser_class[::error (const syntax_error& yyexc) 1195 { 1196 error (]b4_join(b4_locations_if([yyexc.location]), 1197 [[yyexc.what ()]])[); 1198 } 1199 1200 ]b4_parse_error_bmatch([custom\|detailed], 1201 [[ const char * 1202 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) 1203 { 1204 static const char *const yy_sname[] = 1205 { 1206 ]b4_symbol_names[ 1207 };]b4_has_translations_if([[ 1208 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is 1209 internationalizable. */ 1210 static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = 1211 { 1212 ]b4_translatable[ 1213 }; 1214 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] 1215 ? _(yy_sname[yysymbol]) 1216 : yy_sname[yysymbol]);]], [[ 1217 return yy_sname[yysymbol];]])[ 1218 } 1219 ]], 1220 [simple], 1221 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 1222 const char * 1223 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) 1224 { 1225 return yytname_[yysymbol]; 1226 } 1227 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 1228 ]], 1229 [verbose], 1230 [[ /* Return YYSTR after stripping away unnecessary quotes and 1231 backslashes, so that it's suitable for yyerror. The heuristic is 1232 that double-quoting is unnecessary unless the string contains an 1233 apostrophe, a comma, or backslash (other than backslash-backslash). 1234 YYSTR is taken from yytname. */ 1235 std::string 1236 ]b4_parser_class[::yytnamerr_ (const char *yystr) 1237 { 1238 if (*yystr == '"') 1239 { 1240 std::string yyr; 1241 char const *yyp = yystr; 1242 1243 for (;;) 1244 switch (*++yyp) 1245 { 1246 case '\'': 1247 case ',': 1248 goto do_not_strip_quotes; 1249 1250 case '\\': 1251 if (*++yyp != '\\') 1252 goto do_not_strip_quotes; 1253 else 1254 goto append; 1255 1256 append: 1257 default: 1258 yyr += *yyp; 1259 break; 1260 1261 case '"': 1262 return yyr; 1263 } 1264 do_not_strip_quotes: ; 1265 } 1266 1267 return yystr; 1268 } 1269 1270 std::string 1271 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) 1272 { 1273 return yytnamerr_ (yytname_[yysymbol]); 1274 } 1275 ]])[ 1276 1277 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ 1278 // ]b4_parser_class[::context. 1279 ]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla) 1280 : yyparser_ (yyparser) 1281 , yyla_ (yyla) 1282 {} 1283 1284 int 1285 ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const 1286 { 1287 // Actual number of expected tokens 1288 int yycount = 0; 1289 ]b4_lac_if([[ 1290 #if ]b4_api_PREFIX[DEBUG 1291 // Execute LAC once. We don't care if it is successful, we 1292 // only do it for the sake of debugging output. 1293 if (!yyparser_.yy_lac_established_) 1294 yyparser_.yy_lac_check_ (yyla_.kind ()); 1295 #endif 1296 1297 for (int yyx = 0; yyx < YYNTOKENS; ++yyx) 1298 { 1299 symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx); 1300 if (yysym != ]b4_symbol(1, kind)[ 1301 && yysym != ]b4_symbol(2, kind)[ 1302 && yyparser_.yy_lac_check_ (yysym)) 1303 { 1304 if (!yyarg) 1305 ++yycount; 1306 else if (yycount == yyargn) 1307 return 0; 1308 else 1309 yyarg[yycount++] = yysym; 1310 } 1311 }]], [[ 1312 int yyn = yypact_[+yyparser_.yystack_[0].state]; 1313 if (!yy_pact_value_is_default_ (yyn)) 1314 { 1315 /* Start YYX at -YYN if negative to avoid negative indexes in 1316 YYCHECK. In other words, skip the first -YYN actions for 1317 this state because they are default actions. */ 1318 int yyxbegin = yyn < 0 ? -yyn : 0; 1319 // Stay within bounds of both yycheck and yytname. 1320 int yychecklim = yylast_ - yyn + 1; 1321 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 1322 for (int yyx = yyxbegin; yyx < yyxend; ++yyx) 1323 if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[ 1324 && !yy_table_value_is_error_ (yytable_[yyx + yyn])) 1325 { 1326 if (!yyarg) 1327 ++yycount; 1328 else if (yycount == yyargn) 1329 return 0; 1330 else 1331 yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx); 1332 } 1333 } 1334 ]])[ 1335 if (yyarg && yycount == 0 && 0 < yyargn) 1336 yyarg[0] = ]b4_symbol(-2, kind)[; 1337 return yycount; 1338 } 1339 1340 ]])b4_lac_if([[ 1341 bool 1342 ]b4_parser_class[::yy_lac_check_ (symbol_kind_type yytoken) const 1343 { 1344 // Logically, the yylac_stack's lifetime is confined to this function. 1345 // Clear it, to get rid of potential left-overs from previous call. 1346 yylac_stack_.clear (); 1347 // Reduce until we encounter a shift and thereby accept the token. 1348 #if ]b4_api_PREFIX[DEBUG 1349 YYCDEBUG << "LAC: checking lookahead " << symbol_name (yytoken) << ':'; 1350 #endif 1351 std::ptrdiff_t lac_top = 0; 1352 while (true) 1353 { 1354 state_type top_state = (yylac_stack_.empty () 1355 ? yystack_[lac_top].state 1356 : yylac_stack_.back ()); 1357 int yyrule = yypact_[+top_state]; 1358 if (yy_pact_value_is_default_ (yyrule) 1359 || (yyrule += yytoken) < 0 || yylast_ < yyrule 1360 || yycheck_[yyrule] != yytoken) 1361 { 1362 // Use the default action. 1363 yyrule = yydefact_[+top_state]; 1364 if (yyrule == 0) 1365 { 1366 YYCDEBUG << " Err\n"; 1367 return false; 1368 } 1369 } 1370 else 1371 { 1372 // Use the action from yytable. 1373 yyrule = yytable_[yyrule]; 1374 if (yy_table_value_is_error_ (yyrule)) 1375 { 1376 YYCDEBUG << " Err\n"; 1377 return false; 1378 } 1379 if (0 < yyrule) 1380 { 1381 YYCDEBUG << " S" << yyrule << '\n'; 1382 return true; 1383 } 1384 yyrule = -yyrule; 1385 } 1386 // By now we know we have to simulate a reduce. 1387 YYCDEBUG << " R" << yyrule - 1; 1388 // Pop the corresponding number of values from the stack. 1389 { 1390 std::ptrdiff_t yylen = yyr2_[yyrule]; 1391 // First pop from the LAC stack as many tokens as possible. 1392 std::ptrdiff_t lac_size = std::ptrdiff_t (yylac_stack_.size ()); 1393 if (yylen < lac_size) 1394 { 1395 yylac_stack_.resize (std::size_t (lac_size - yylen)); 1396 yylen = 0; 1397 } 1398 else if (lac_size) 1399 { 1400 yylac_stack_.clear (); 1401 yylen -= lac_size; 1402 } 1403 // Only afterwards look at the main stack. 1404 // We simulate popping elements by incrementing lac_top. 1405 lac_top += yylen; 1406 } 1407 // Keep top_state in sync with the updated stack. 1408 top_state = (yylac_stack_.empty () 1409 ? yystack_[lac_top].state 1410 : yylac_stack_.back ()); 1411 // Push the resulting state of the reduction. 1412 state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]); 1413 YYCDEBUG << " G" << int (state); 1414 yylac_stack_.push_back (state); 1415 } 1416 } 1417 1418 // Establish the initial context if no initial context currently exists. 1419 bool 1420 ]b4_parser_class[::yy_lac_establish_ (symbol_kind_type yytoken) 1421 { 1422 /* Establish the initial context for the current lookahead if no initial 1423 context is currently established. 1424 1425 We define a context as a snapshot of the parser stacks. We define 1426 the initial context for a lookahead as the context in which the 1427 parser initially examines that lookahead in order to select a 1428 syntactic action. Thus, if the lookahead eventually proves 1429 syntactically unacceptable (possibly in a later context reached via a 1430 series of reductions), the initial context can be used to determine 1431 the exact set of tokens that would be syntactically acceptable in the 1432 lookahead's place. Moreover, it is the context after which any 1433 further semantic actions would be erroneous because they would be 1434 determined by a syntactically unacceptable token. 1435 1436 yy_lac_establish_ should be invoked when a reduction is about to be 1437 performed in an inconsistent state (which, for the purposes of LAC, 1438 includes consistent states that don't know they're consistent because 1439 their default reductions have been disabled). 1440 1441 For parse.lac=full, the implementation of yy_lac_establish_ is as 1442 follows. If no initial context is currently established for the 1443 current lookahead, then check if that lookahead can eventually be 1444 shifted if syntactic actions continue from the current context. */ 1445 if (!yy_lac_established_) 1446 { 1447 #if ]b4_api_PREFIX[DEBUG 1448 YYCDEBUG << "LAC: initial context established for " 1449 << symbol_name (yytoken) << '\n'; 1450 #endif 1451 yy_lac_established_ = true; 1452 return yy_lac_check_ (yytoken); 1453 } 1454 return true; 1455 } 1456 1457 // Discard any previous initial lookahead context. 1458 void 1459 ]b4_parser_class[::yy_lac_discard_ (const char* evt) 1460 { 1461 /* Discard any previous initial lookahead context because of Event, 1462 which may be a lookahead change or an invalidation of the currently 1463 established initial context for the current lookahead. 1464 1465 The most common example of a lookahead change is a shift. An example 1466 of both cases is syntax error recovery. That is, a syntax error 1467 occurs when the lookahead is syntactically erroneous for the 1468 currently established initial context, so error recovery manipulates 1469 the parser stacks to try to find a new initial context in which the 1470 current lookahead is syntactically acceptable. If it fails to find 1471 such a context, it discards the lookahead. */ 1472 if (yy_lac_established_) 1473 { 1474 YYCDEBUG << "LAC: initial context discarded due to " 1475 << evt << '\n'; 1476 yy_lac_established_ = false; 1477 } 1478 }]])b4_parse_error_bmatch([detailed\|verbose], [[ 1479 1480 int 1481 ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx, 1482 symbol_kind_type yyarg[], int yyargn) const 1483 { 1484 /* There are many possibilities here to consider: 1485 - If this state is a consistent state with a default action, then 1486 the only way this function was invoked is if the default action 1487 is an error action. In that case, don't check for expected 1488 tokens because there are none. 1489 - The only way there can be no lookahead present (in yyla) is 1490 if this state is a consistent state with a default action. 1491 Thus, detecting the absence of a lookahead is sufficient to 1492 determine that there is no unexpected or expected token to 1493 report. In that case, just report a simple "syntax error". 1494 - Don't assume there isn't a lookahead just because this state is 1495 a consistent state with a default action. There might have 1496 been a previous inconsistent state, consistent state with a 1497 non-default action, or user semantic action that manipulated 1498 yyla. (However, yyla is currently not documented for users.)]b4_lac_if([[ 1499 In the first two cases, it might appear that the current syntax 1500 error should have been detected in the previous state when 1501 yy_lac_check was invoked. However, at that time, there might 1502 have been a different syntax error that discarded a different 1503 initial context during error recovery, leaving behind the 1504 current lookahead.]], [[ 1505 - Of course, the expected token list depends on states to have 1506 correct lookahead information, and it depends on the parser not 1507 to perform extra reductions after fetching a lookahead from the 1508 scanner and before detecting a syntax error. Thus, state merging 1509 (from LALR or IELR) and default reductions corrupt the expected 1510 token list. However, the list is correct for canonical LR with 1511 one exception: it will still contain any token that will not be 1512 accepted due to an error action in a later state.]])[ 1513 */ 1514 1515 if (!yyctx.lookahead ().empty ()) 1516 { 1517 if (yyarg) 1518 yyarg[0] = yyctx.token (); 1519 int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1); 1520 return yyn + 1; 1521 } 1522 return 0; 1523 } 1524 1525 // Generate an error message. 1526 std::string 1527 ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const 1528 { 1529 // Its maximum. 1530 enum { YYARGS_MAX = 5 }; 1531 // Arguments of yyformat. 1532 symbol_kind_type yyarg[YYARGS_MAX]; 1533 int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX); 1534 1535 char const* yyformat = YY_NULLPTR; 1536 switch (yycount) 1537 { 1538 #define YYCASE_(N, S) \ 1539 case N: \ 1540 yyformat = S; \ 1541 break 1542 default: // Avoid compiler warnings. 1543 YYCASE_ (0, YY_("syntax error")); 1544 YYCASE_ (1, YY_("syntax error, unexpected %s")); 1545 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s")); 1546 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s")); 1547 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); 1548 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); 1549 #undef YYCASE_ 1550 } 1551 1552 std::string yyres; 1553 // Argument number. 1554 std::ptrdiff_t yyi = 0; 1555 for (char const* yyp = yyformat; *yyp; ++yyp) 1556 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) 1557 { 1558 yyres += symbol_name (yyarg[yyi++]); 1559 ++yyp; 1560 } 1561 else 1562 yyres += *yyp; 1563 return yyres; 1564 }]])[ 1565 1566 1567 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class::yypact_ninf_ = b4_pact_ninf[; 1568 1569 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class::yytable_ninf_ = b4_table_ninf[; 1570 1571 ]b4_parser_tables_define[ 1572 1573 ]b4_parse_error_bmatch([simple\|verbose], 1574 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[ 1575 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 1576 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. 1577 const char* 1578 const ]b4_parser_class[::yytname_[] = 1579 { 1580 ]b4_tname[ 1581 }; 1582 #endif 1583 ]])[ 1584 1585 #if ]b4_api_PREFIX[DEBUG][ 1586 ]b4_integral_parser_table_define([rline], [b4_rline])[ 1587 1588 void 1589 ]b4_parser_class[::yy_stack_print_ () const 1590 { 1591 *yycdebug_ << "Stack now"; 1592 for (stack_type::const_iterator 1593 i = yystack_.begin (), 1594 i_end = yystack_.end (); 1595 i != i_end; ++i) 1596 *yycdebug_ << ' ' << int (i->state); 1597 *yycdebug_ << '\n'; 1598 } 1599 1600 void 1601 ]b4_parser_class[::yy_reduce_print_ (int yyrule) const 1602 { 1603 int yylno = yyrline_[yyrule]; 1604 int yynrhs = yyr2_[yyrule]; 1605 // Print the symbols being reduced, and their result. 1606 *yycdebug_ << "Reducing stack by rule " << yyrule - 1 1607 << " (line " << yylno << "):\n"; 1608 // The symbols being reduced. 1609 for (int yyi = 0; yyi < yynrhs; yyi++) 1610 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", 1611 ]b4_rhs_data(yynrhs, yyi + 1)[); 1612 } 1613 #endif // ]b4_api_PREFIX[DEBUG 1614 1615 ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ 1616 ]b4_namespace_close[ 1617 ]b4_epilogue[]dnl 1618 b4_output_end 1619 1620 1621 m4_popdef([b4_copyright_years])dnl 1622