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