1 # -*- C -*- 2 3 # GLR skeleton for Bison 4 5 # Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc. 6 7 # This program is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program. If not, see <https://www.gnu.org/licenses/>. 19 20 21 # If we are loaded by glr.cc, do not override c++.m4 definitions by 22 # those of c.m4. 23 m4_if(b4_skeleton, ["glr.c"], 24 [m4_include(b4_skeletonsdir/[c.m4])]) 25 26 27 ## ---------------- ## 28 ## Default values. ## 29 ## ---------------- ## 30 31 # Stack parameters. 32 m4_define_default([b4_stack_depth_max], [10000]) 33 m4_define_default([b4_stack_depth_init], [200]) 34 35 # Included header. 36 b4_percent_define_default([[api.header.include]], 37 [["@basename(]b4_spec_header_file[@)"]]) 38 39 ## ------------------------ ## 40 ## Pure/impure interfaces. ## 41 ## ------------------------ ## 42 43 b4_define_flag_if([pure]) 44 # If glr.cc is including this file and thus has already set b4_pure_flag, 45 # do not change the value of b4_pure_flag, and do not record a use of api.pure. 46 m4_ifndef([b4_pure_flag], 47 [b4_percent_define_default([[api.pure]], [[false]]) 48 m4_define([b4_pure_flag], 49 [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])]) 50 51 # b4_yyerror_args 52 # --------------- 53 # Optional effective arguments passed to yyerror: user args plus yylloc, and 54 # a trailing comma. 55 m4_define([b4_yyerror_args], 56 [b4_pure_if([b4_locations_if([yylocp, ])])dnl 57 m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) 58 59 60 # b4_lyyerror_args 61 # ---------------- 62 # Same as above, but on the lookahead, hence &yylloc instead of yylocp. 63 m4_define([b4_lyyerror_args], 64 [b4_pure_if([b4_locations_if([&yylloc, ])])dnl 65 m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) 66 67 68 # b4_pure_args 69 # ------------ 70 # Same as b4_yyerror_args, but with a leading comma. 71 m4_define([b4_pure_args], 72 [b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args]) 73 74 75 # b4_lpure_args 76 # ------------- 77 # Same as above, but on the lookahead, hence &yylloc instead of yylocp. 78 m4_define([b4_lpure_args], 79 [b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args]) 80 81 82 83 # b4_pure_formals 84 # --------------- 85 # Arguments passed to yyerror: user formals plus yylocp with leading comma. 86 m4_define([b4_pure_formals], 87 [b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals]) 88 89 90 # b4_locuser_formals(LOC = yylocp) 91 # -------------------------------- 92 # User formal arguments, possibly preceded by location argument. 93 m4_define([b4_locuser_formals], 94 [b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals]) 95 96 97 # b4_locuser_args(LOC = yylocp) 98 # ----------------------------- 99 m4_define([b4_locuser_args], 100 [b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args]) 101 102 103 104 ## ----------------- ## 105 ## Semantic Values. ## 106 ## ----------------- ## 107 108 109 # b4_lhs_value(SYMBOL-NUM, [TYPE]) 110 # -------------------------------- 111 # See README. 112 m4_define([b4_lhs_value], 113 [b4_symbol_value([(*yyvalp)], [$1], [$2])]) 114 115 116 # b4_rhs_data(RULE-LENGTH, POS) 117 # ----------------------------- 118 # See README. 119 m4_define([b4_rhs_data], 120 [YY_CAST (yyGLRStackItem const *, yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate]) 121 122 123 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) 124 # -------------------------------------------------- 125 # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM. 126 m4_define([b4_rhs_value], 127 [b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yyval], [$3], [$4])]) 128 129 130 131 ## ----------- ## 132 ## Locations. ## 133 ## ----------- ## 134 135 # b4_lhs_location() 136 # ----------------- 137 # Expansion of @$. 138 m4_define([b4_lhs_location], 139 [(*yylocp)]) 140 141 142 # b4_rhs_location(RULE-LENGTH, NUM) 143 # --------------------------------- 144 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols 145 # on RHS. 146 m4_define([b4_rhs_location], 147 [(b4_rhs_data([$1], [$2]).yyloc)]) 148 149 150 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM) 151 # --------------------------------------------------- 152 m4_define([b4_call_merger], 153 [b4_case([$1], 154 [ b4_symbol_if([$3], [has_type], 155 [yy0->b4_symbol($3, slot) = $2 (*yy0, *yy1);], 156 [*yy0 = $2 (*yy0, *yy1);])])]) 157 158 159 ## -------------- ## 160 ## Declarations. ## 161 ## -------------- ## 162 163 # b4_shared_declarations 164 # ---------------------- 165 # Declaration that might either go into the header (if --header) 166 # or open coded in the parser body. glr.cc has its own definition. 167 m4_if(b4_skeleton, ["glr.c"], 168 [m4_define([b4_shared_declarations], 169 [b4_declare_yydebug[ 170 ]b4_percent_code_get([[requires]])[ 171 ]b4_token_enums[ 172 ]b4_declare_yylstype[ 173 int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[); 174 ]b4_percent_code_get([[provides]])[]dnl 175 ]) 176 ]) 177 178 ## -------------- ## 179 ## Output files. ## 180 ## -------------- ## 181 182 # Unfortunately the order of generation between the header and the 183 # implementation file matters (for glr.c) because of the current 184 # implementation of api.value.type=union. In that case we still use a 185 # union for YYSTYPE, but we generate the contents of this union when 186 # setting up YYSTYPE. This is needed for other aspects, such as 187 # defining yy_symbol_value_print, since we need to now the name of the 188 # members of this union. 189 # 190 # To avoid this issue, just generate the header before the 191 # implementation file. But we should also make them more independent. 192 193 # ----------------- # 194 # The header file. # 195 # ----------------- # 196 197 # glr.cc produces its own header. 198 b4_glr_cc_if([], 199 [b4_header_if( 200 [b4_output_begin([b4_spec_header_file]) 201 b4_copyright([Skeleton interface for Bison GLR parsers in C], 202 [2002-2015, 2018-2021])[ 203 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[ 204 ]b4_shared_declarations[ 205 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[ 206 ]b4_output_end[ 207 ]])]) 208 209 210 # ------------------------- # 211 # The implementation file. # 212 # ------------------------- # 213 214 b4_output_begin([b4_parser_file_name]) 215 b4_copyright([Skeleton implementation for Bison GLR parsers in C], 216 [2002-2015, 2018-2021])[ 217 /* C GLR parser skeleton written by Paul Hilfinger. */ 218 219 ]b4_disclaimer[ 220 ]b4_identification[ 221 222 ]b4_percent_code_get([[top]])[ 223 ]m4_if(b4_api_prefix, [yy], [], 224 [[/* Substitute the type names. */ 225 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ 226 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[ 227 ]m4_if(b4_prefix, [yy], [], 228 [[/* Substitute the variable and function names. */ 229 #define ]b4_glr_cc_if([yy_parse_impl], [yyparse])[ ]b4_prefix[]b4_glr_cc_if([_parse_impl], [parse])[ 230 #define yylex ]b4_prefix[lex 231 #define yyerror ]b4_prefix[error 232 #define yydebug ]b4_prefix[debug]]b4_pure_if([], [[ 233 #define yylval ]b4_prefix[lval 234 #define yychar ]b4_prefix[char 235 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ 236 #define yylloc ]b4_prefix[lloc]])]))[ 237 238 ]b4_user_pre_prologue[ 239 ]b4_cast_define[ 240 ]b4_null_define[ 241 242 ]b4_header_if([[#include ]b4_percent_define_get([[api.header.include]])], 243 [b4_shared_declarations])[ 244 245 ]b4_glr_cc_if([b4_glr_cc_setup], 246 [b4_declare_symbol_enum])[ 247 248 /* Default (constant) value used for initialization for null 249 right-hand sides. Unlike the standard yacc.c template, here we set 250 the default value of $$ to a zeroed-out value. Since the default 251 value is undefined, this behavior is technically correct. */ 252 static YYSTYPE yyval_default;]b4_locations_if([[ 253 static YYLTYPE yyloc_default][]b4_yyloc_default;])[ 254 255 ]b4_user_post_prologue[ 256 ]b4_percent_code_get[]dnl 257 258 [#include <stddef.h> 259 #include <stdint.h> 260 #include <stdio.h> 261 #include <stdlib.h> 262 #include <string.h> 263 264 ]b4_c99_int_type_define[ 265 ]b4_sizes_types_define[ 266 267 #ifndef YY_ 268 # if defined YYENABLE_NLS && YYENABLE_NLS 269 # if ENABLE_NLS 270 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ 271 # define YY_(Msgid) dgettext ("bison-runtime", Msgid) 272 # endif 273 # endif 274 # ifndef YY_ 275 # define YY_(Msgid) Msgid 276 # endif 277 #endif 278 ]b4_has_translations_if([ 279 #ifndef N_ 280 # define N_(Msgid) Msgid 281 #endif 282 ])[ 283 284 #ifndef YYFREE 285 # define YYFREE free 286 #endif 287 #ifndef YYMALLOC 288 # define YYMALLOC malloc 289 #endif 290 #ifndef YYREALLOC 291 # define YYREALLOC realloc 292 #endif 293 294 #ifdef __cplusplus 295 typedef bool yybool; 296 # define yytrue true 297 # define yyfalse false 298 #else 299 /* When we move to stdbool, get rid of the various casts to yybool. */ 300 typedef signed char yybool; 301 # define yytrue 1 302 # define yyfalse 0 303 #endif 304 305 #ifndef YYSETJMP 306 # include <setjmp.h> 307 # define YYJMP_BUF jmp_buf 308 # define YYSETJMP(Env) setjmp (Env) 309 /* Pacify Clang and ICC. */ 310 # define YYLONGJMP(Env, Val) \ 311 do { \ 312 longjmp (Env, Val); \ 313 YY_ASSERT (0); \ 314 } while (yyfalse) 315 #endif 316 317 ]b4_attribute_define([noreturn])[ 318 319 ]b4_parse_assert_if([[#ifdef NDEBUG 320 # define YY_ASSERT(E) ((void) (0 && (E))) 321 #else 322 # include <assert.h> /* INFRINGES ON USER NAME SPACE */ 323 # define YY_ASSERT(E) assert (E) 324 #endif 325 ]], 326 [[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ 327 328 /* YYFINAL -- State number of the termination state. */ 329 #define YYFINAL ]b4_final_state_number[ 330 /* YYLAST -- Last index in YYTABLE. */ 331 #define YYLAST ]b4_last[ 332 333 /* YYNTOKENS -- Number of terminals. */ 334 #define YYNTOKENS ]b4_tokens_number[ 335 /* YYNNTS -- Number of nonterminals. */ 336 #define YYNNTS ]b4_nterms_number[ 337 /* YYNRULES -- Number of rules. */ 338 #define YYNRULES ]b4_rules_number[ 339 /* YYNSTATES -- Number of states. */ 340 #define YYNSTATES ]b4_states_number[ 341 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ 342 #define YYMAXRHS ]b4_r2_max[ 343 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle 344 accessed by $0, $-1, etc., in any rule. */ 345 #define YYMAXLEFT ]b4_max_left_semantic_context[ 346 347 /* YYMAXUTOK -- Last valid token kind. */ 348 #define YYMAXUTOK ]b4_code_max[ 349 350 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM 351 as returned by yylex, with out-of-bounds checking. */ 352 ]b4_api_token_raw_if(dnl 353 [[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)]], 354 [[#define YYTRANSLATE(YYX) \ 355 (0 <= (YYX) && (YYX) <= YYMAXUTOK \ 356 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ 357 : ]b4_symbol_prefix[YYUNDEF) 358 359 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 360 as returned by yylex. */ 361 static const ]b4_int_type_for([b4_translate])[ yytranslate[] = 362 { 363 ]b4_translate[ 364 };]])[ 365 366 #if ]b4_api_PREFIX[DEBUG 367 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 368 static const ]b4_int_type_for([b4_rline])[ yyrline[] = 369 { 370 ]b4_rline[ 371 }; 372 #endif 373 374 #define YYPACT_NINF (]b4_pact_ninf[) 375 #define YYTABLE_NINF (]b4_table_ninf[) 376 377 ]b4_parser_tables_define[ 378 379 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ 380 static const ]b4_int_type_for([b4_dprec])[ yydprec[] = 381 { 382 ]b4_dprec[ 383 }; 384 385 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ 386 static const ]b4_int_type_for([b4_merger])[ yymerger[] = 387 { 388 ]b4_merger[ 389 }; 390 391 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as 392 in the case of predicates. */ 393 static const yybool yyimmediate[] = 394 { 395 ]b4_immediate[ 396 }; 397 398 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of 399 list of conflicting reductions corresponding to action entry for 400 state STATE-NUM in yytable. 0 means no conflicts. The list in 401 yyconfl is terminated by a rule number of 0. */ 402 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = 403 { 404 ]b4_conflict_list_heads[ 405 }; 406 407 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by 408 0, pointed into by YYCONFLP. */ 409 ]dnl Do not use b4_int_type_for here, since there are places where 410 dnl pointers onto yyconfl are taken, whose type is "short*". 411 dnl We probably ought to introduce a type for confl. 412 [static const short yyconfl[] = 413 { 414 ]b4_conflicting_rules[ 415 }; 416 417 ]b4_locations_if([[ 418 ]b4_yylloc_default_define[ 419 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) 420 ]])[ 421 422 ]b4_pure_if( 423 [ 424 #undef yynerrs 425 #define yynerrs (yystackp->yyerrcnt) 426 #undef yychar 427 #define yychar (yystackp->yyrawchar) 428 #undef yylval 429 #define yylval (yystackp->yyval) 430 #undef yylloc 431 #define yylloc (yystackp->yyloc) 432 m4_if(b4_prefix[], [yy], [], 433 [#define b4_prefix[]nerrs yynerrs 434 #define b4_prefix[]char yychar 435 #define b4_prefix[]lval yylval 436 #define b4_prefix[]lloc yylloc])], 437 [YYSTYPE yylval;]b4_locations_if([[ 438 YYLTYPE yylloc;]])[ 439 440 int yynerrs; 441 int yychar;])[ 442 443 enum { YYENOMEM = -2 }; 444 445 typedef enum { yyok, yyaccept, yyabort, yyerr, yynomem } YYRESULTTAG; 446 447 #define YYCHK(YYE) \ 448 do { \ 449 YYRESULTTAG yychk_flag = YYE; \ 450 if (yychk_flag != yyok) \ 451 return yychk_flag; \ 452 } while (0) 453 454 /* YYINITDEPTH -- initial size of the parser's stacks. */ 455 #ifndef YYINITDEPTH 456 # define YYINITDEPTH ]b4_stack_depth_init[ 457 #endif 458 459 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 460 if the built-in stack extension method is used). 461 462 Do not make this value too large; the results are undefined if 463 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) 464 evaluated with infinite-precision integer arithmetic. */ 465 466 #ifndef YYMAXDEPTH 467 # define YYMAXDEPTH ]b4_stack_depth_max[ 468 #endif 469 470 /* Minimum number of free items on the stack allowed after an 471 allocation. This is to allow allocation and initialization 472 to be completed by functions that call yyexpandGLRStack before the 473 stack is expanded, thus insuring that all necessary pointers get 474 properly redirected to new data. */ 475 #define YYHEADROOM 2 476 477 #ifndef YYSTACKEXPANDABLE 478 # define YYSTACKEXPANDABLE 1 479 #endif 480 481 #if YYSTACKEXPANDABLE 482 # define YY_RESERVE_GLRSTACK(Yystack) \ 483 do { \ 484 if (Yystack->yyspaceLeft < YYHEADROOM) \ 485 yyexpandGLRStack (Yystack); \ 486 } while (0) 487 #else 488 # define YY_RESERVE_GLRSTACK(Yystack) \ 489 do { \ 490 if (Yystack->yyspaceLeft < YYHEADROOM) \ 491 yyMemoryExhausted (Yystack); \ 492 } while (0) 493 #endif 494 495 /** State numbers. */ 496 typedef int yy_state_t; 497 498 /** Rule numbers. */ 499 typedef int yyRuleNum; 500 501 /** Item references. */ 502 typedef short yyItemNum; 503 504 typedef struct yyGLRState yyGLRState; 505 typedef struct yyGLRStateSet yyGLRStateSet; 506 typedef struct yySemanticOption yySemanticOption; 507 typedef union yyGLRStackItem yyGLRStackItem; 508 typedef struct yyGLRStack yyGLRStack; 509 510 struct yyGLRState 511 { 512 /** Type tag: always true. */ 513 yybool yyisState; 514 /** Type tag for yysemantics. If true, yyval applies, otherwise 515 * yyfirstVal applies. */ 516 yybool yyresolved; 517 /** Number of corresponding LALR(1) machine state. */ 518 yy_state_t yylrState; 519 /** Preceding state in this stack */ 520 yyGLRState* yypred; 521 /** Source position of the last token produced by my symbol */ 522 YYPTRDIFF_T yyposn; 523 union { 524 /** First in a chain of alternative reductions producing the 525 * nonterminal corresponding to this state, threaded through 526 * yynext. */ 527 yySemanticOption* yyfirstVal; 528 /** Semantic value for this state. */ 529 YYSTYPE yyval; 530 } yysemantics;]b4_locations_if([[ 531 /** Source location for this state. */ 532 YYLTYPE yyloc;]])[ 533 }; 534 535 struct yyGLRStateSet 536 { 537 yyGLRState** yystates; 538 /** During nondeterministic operation, yylookaheadNeeds tracks which 539 * stacks have actually needed the current lookahead. During deterministic 540 * operation, yylookaheadNeeds[0] is not maintained since it would merely 541 * duplicate yychar != ]b4_symbol(empty, id)[. */ 542 yybool* yylookaheadNeeds; 543 YYPTRDIFF_T yysize; 544 YYPTRDIFF_T yycapacity; 545 }; 546 547 struct yySemanticOption 548 { 549 /** Type tag: always false. */ 550 yybool yyisState; 551 /** Rule number for this reduction */ 552 yyRuleNum yyrule; 553 /** The last RHS state in the list of states to be reduced. */ 554 yyGLRState* yystate; 555 /** The lookahead for this reduction. */ 556 int yyrawchar; 557 YYSTYPE yyval;]b4_locations_if([[ 558 YYLTYPE yyloc;]])[ 559 /** Next sibling in chain of options. To facilitate merging, 560 * options are chained in decreasing order by address. */ 561 yySemanticOption* yynext; 562 }; 563 564 /** Type of the items in the GLR stack. The yyisState field 565 * indicates which item of the union is valid. */ 566 union yyGLRStackItem { 567 yyGLRState yystate; 568 yySemanticOption yyoption; 569 }; 570 571 struct yyGLRStack { 572 int yyerrState; 573 ]b4_locations_if([[ /* To compute the location of the error token. */ 574 yyGLRStackItem yyerror_range[3];]])[ 575 ]b4_pure_if( 576 [ 577 int yyerrcnt; 578 int yyrawchar; 579 YYSTYPE yyval;]b4_locations_if([[ 580 YYLTYPE yyloc;]])[ 581 ])[ 582 YYJMP_BUF yyexception_buffer; 583 yyGLRStackItem* yyitems; 584 yyGLRStackItem* yynextFree; 585 YYPTRDIFF_T yyspaceLeft; 586 yyGLRState* yysplitPoint; 587 yyGLRState* yylastDeleted; 588 yyGLRStateSet yytops; 589 }; 590 591 #if YYSTACKEXPANDABLE 592 static void yyexpandGLRStack (yyGLRStack* yystackp); 593 #endif 594 595 _Noreturn static void 596 yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg) 597 { 598 if (yymsg != YY_NULLPTR) 599 yyerror (]b4_yyerror_args[yymsg); 600 YYLONGJMP (yystackp->yyexception_buffer, 1); 601 } 602 603 _Noreturn static void 604 yyMemoryExhausted (yyGLRStack* yystackp) 605 { 606 YYLONGJMP (yystackp->yyexception_buffer, 2); 607 } 608 609 /** Accessing symbol of state YYSTATE. */ 610 static inline yysymbol_kind_t 611 yy_accessing_symbol (yy_state_t yystate) 612 { 613 return YY_CAST (yysymbol_kind_t, yystos[yystate]); 614 } 615 616 #if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ 617 /* The user-facing name of the symbol whose (internal) number is 618 YYSYMBOL. No bounds checking. */ 619 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; 620 621 ]b4_parse_error_bmatch([simple\|verbose], 622 [[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 623 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 624 static const char *const yytname[] = 625 { 626 ]b4_tname[ 627 }; 628 629 static const char * 630 yysymbol_name (yysymbol_kind_t yysymbol) 631 { 632 return yytname[yysymbol]; 633 }]], 634 [[static const char * 635 yysymbol_name (yysymbol_kind_t yysymbol) 636 { 637 static const char *const yy_sname[] = 638 { 639 ]b4_symbol_names[ 640 };]b4_has_translations_if([[ 641 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is 642 internationalizable. */ 643 static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = 644 { 645 ]b4_translatable[ 646 }; 647 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] 648 ? _(yy_sname[yysymbol]) 649 : yy_sname[yysymbol]);]], [[ 650 return yy_sname[yysymbol];]])[ 651 }]])[ 652 #endif 653 654 /** Left-hand-side symbol for rule #YYRULE. */ 655 static inline yysymbol_kind_t 656 yylhsNonterm (yyRuleNum yyrule) 657 { 658 return YY_CAST (yysymbol_kind_t, yyr1[yyrule]); 659 } 660 661 #if ]b4_api_PREFIX[DEBUG 662 663 # ifndef YYFPRINTF 664 # define YYFPRINTF fprintf 665 # endif 666 667 # define YY_FPRINTF \ 668 YY_IGNORE_USELESS_CAST_BEGIN YY_FPRINTF_ 669 670 # define YY_FPRINTF_(Args) \ 671 do { \ 672 YYFPRINTF Args; \ 673 YY_IGNORE_USELESS_CAST_END \ 674 } while (0) 675 676 # define YY_DPRINTF \ 677 YY_IGNORE_USELESS_CAST_BEGIN YY_DPRINTF_ 678 679 # define YY_DPRINTF_(Args) \ 680 do { \ 681 if (yydebug) \ 682 YYFPRINTF Args; \ 683 YY_IGNORE_USELESS_CAST_END \ 684 } while (0) 685 686 ]b4_yylocation_print_define[ 687 688 ]b4_yy_symbol_print_define[ 689 690 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ 691 do { \ 692 if (yydebug) \ 693 { \ 694 YY_FPRINTF ((stderr, "%s ", Title)); \ 695 yy_symbol_print (stderr, Kind, Value]b4_locuser_args([Location])[); \ 696 YY_FPRINTF ((stderr, "\n")); \ 697 } \ 698 } while (0) 699 700 static inline void 701 yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk, 702 yyRuleNum yyrule]b4_user_formals[); 703 704 # define YY_REDUCE_PRINT(Args) \ 705 do { \ 706 if (yydebug) \ 707 yy_reduce_print Args; \ 708 } while (0) 709 710 /* Nonzero means print parse trace. It is left uninitialized so that 711 multiple parsers can coexist. */ 712 int yydebug; 713 714 static void yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) 715 YY_ATTRIBUTE_UNUSED; 716 static void yypdumpstack (yyGLRStack* yystackp) 717 YY_ATTRIBUTE_UNUSED; 718 719 #else /* !]b4_api_PREFIX[DEBUG */ 720 721 # define YY_DPRINTF(Args) do {} while (yyfalse) 722 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) 723 # define YY_REDUCE_PRINT(Args) 724 725 #endif /* !]b4_api_PREFIX[DEBUG */ 726 727 ]b4_parse_error_case( 728 [simple], 729 [[]], 730 [[#ifndef yystrlen 731 # define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) 732 #endif 733 734 ]b4_parse_error_bmatch( 735 [detailed\|verbose], 736 [[#ifndef yystpcpy 737 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE 738 # define yystpcpy stpcpy 739 # else 740 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 741 YYDEST. */ 742 static char * 743 yystpcpy (char *yydest, const char *yysrc) 744 { 745 char *yyd = yydest; 746 const char *yys = yysrc; 747 748 while ((*yyd++ = *yys++) != '\0') 749 continue; 750 751 return yyd - 1; 752 } 753 # endif 754 #endif]])[ 755 756 ]b4_parse_error_case( 757 [verbose], 758 [[#ifndef yytnamerr 759 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary 760 quotes and backslashes, so that it's suitable for yyerror. The 761 heuristic is that double-quoting is unnecessary unless the string 762 contains an apostrophe, a comma, or backslash (other than 763 backslash-backslash). YYSTR is taken from yytname. If YYRES is 764 null, do not copy; instead, return the length of what the result 765 would have been. */ 766 static YYPTRDIFF_T 767 yytnamerr (char *yyres, const char *yystr) 768 { 769 if (*yystr == '"') 770 { 771 YYPTRDIFF_T yyn = 0; 772 char const *yyp = yystr; 773 774 for (;;) 775 switch (*++yyp) 776 { 777 case '\'': 778 case ',': 779 goto do_not_strip_quotes; 780 781 case '\\': 782 if (*++yyp != '\\') 783 goto do_not_strip_quotes; 784 else 785 goto append; 786 787 append: 788 default: 789 if (yyres) 790 yyres[yyn] = *yyp; 791 yyn++; 792 break; 793 794 case '"': 795 if (yyres) 796 yyres[yyn] = '\0'; 797 return yyn; 798 } 799 do_not_strip_quotes: ; 800 } 801 802 if (yyres) 803 return yystpcpy (yyres, yystr) - yyres; 804 else 805 return yystrlen (yystr); 806 } 807 #endif 808 ]])])[ 809 810 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting 811 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred 812 * containing the pointer to the next state in the chain. */ 813 static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED; 814 static void 815 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) 816 { 817 int i; 818 yyGLRState *s = yyvsp[yylow0].yystate.yypred; 819 for (i = yylow0-1; i >= yylow1; i -= 1) 820 { 821 #if ]b4_api_PREFIX[DEBUG 822 yyvsp[i].yystate.yylrState = s->yylrState; 823 #endif 824 yyvsp[i].yystate.yyresolved = s->yyresolved; 825 if (s->yyresolved) 826 yyvsp[i].yystate.yysemantics.yyval = s->yysemantics.yyval; 827 else 828 /* The effect of using yyval or yyloc (in an immediate rule) is 829 * undefined. */ 830 yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;]b4_locations_if([[ 831 yyvsp[i].yystate.yyloc = s->yyloc;]])[ 832 s = yyvsp[i].yystate.yypred = s->yypred; 833 } 834 } 835 836 ]m4_define([b4_yygetToken_call], 837 [[yygetToken (&yychar][]b4_pure_if([, yystackp])[]b4_user_args[)]])[ 838 /** If yychar is empty, fetch the next token. */ 839 static inline yysymbol_kind_t 840 yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals[) 841 { 842 yysymbol_kind_t yytoken; 843 ]b4_parse_param_use()dnl 844 [ if (*yycharp == ]b4_symbol(empty, id)[) 845 { 846 YY_DPRINTF ((stderr, "Reading a token\n"));]b4_glr_cc_if([[ 847 #if YY_EXCEPTIONS 848 try 849 { 850 #endif // YY_EXCEPTIONS 851 *yycharp = ]b4_yylex[; 852 #if YY_EXCEPTIONS 853 } 854 catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc) 855 { 856 YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ 857 yylloc = yyexc.location;])[ 858 yyerror (]b4_lyyerror_args[yyexc.what ()); 859 // Map errors caught in the scanner to the undefined token, 860 // so that error handling is started. However, record this 861 // with this special value of yychar. 862 *yycharp = ]b4_symbol(error, id)[; 863 } 864 #endif // YY_EXCEPTIONS]], [[ 865 *yycharp = ]b4_yylex[;]])[ 866 } 867 if (*yycharp <= ]b4_symbol(eof, [id])[) 868 { 869 *yycharp = ]b4_symbol(eof, [id])[; 870 yytoken = ]b4_symbol_prefix[YYEOF; 871 YY_DPRINTF ((stderr, "Now at end of input.\n")); 872 } 873 else 874 { 875 yytoken = YYTRANSLATE (*yycharp); 876 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 877 } 878 return yytoken; 879 } 880 881 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in 882 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. 883 * For convenience, always return YYLOW1. */ 884 static inline int yyfill (yyGLRStackItem *, int *, int, yybool) 885 YY_ATTRIBUTE_UNUSED; 886 static inline int 887 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) 888 { 889 if (!yynormal && yylow1 < *yylow) 890 { 891 yyfillin (yyvsp, *yylow, yylow1); 892 *yylow = yylow1; 893 } 894 return yylow1; 895 } 896 897 /** Perform user action for rule number YYN, with RHS length YYRHSLEN, 898 * and top stack item YYVSP. YYLVALP points to place to put semantic 899 * value ($$), and yylocp points to place for location information 900 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, 901 * yyerr for YYERROR, yyabort for YYABORT, yynomem for YYNOMEM. */ 902 static YYRESULTTAG 903 yyuserAction (yyRuleNum yyrule, int yyrhslen, yyGLRStackItem* yyvsp, 904 yyGLRStack* yystackp, YYPTRDIFF_T yyk, 905 YYSTYPE* yyvalp]b4_locuser_formals[) 906 { 907 const yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR; 908 int yylow = 1; 909 ]b4_parse_param_use([yyvalp], [yylocp])dnl 910 [ YY_USE (yyk); 911 YY_USE (yyrhslen); 912 # undef yyerrok 913 # define yyerrok (yystackp->yyerrState = 0) 914 # undef YYACCEPT 915 # define YYACCEPT return yyaccept 916 # undef YYABORT 917 # define YYABORT return yyabort 918 # undef YYNOMEM 919 # define YYNOMEM return yynomem 920 # undef YYERROR 921 # define YYERROR return yyerrok, yyerr 922 # undef YYRECOVERING 923 # define YYRECOVERING() (yystackp->yyerrState != 0) 924 # undef yyclearin 925 # define yyclearin (yychar = ]b4_symbol(empty, id)[) 926 # undef YYFILL 927 # define YYFILL(N) yyfill (yyvsp, &yylow, (N), yynormal) 928 # undef YYBACKUP 929 # define YYBACKUP(Token, Value) \ 930 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \ 931 yyerrok, yyerr 932 933 if (yyrhslen == 0) 934 *yyvalp = yyval_default; 935 else 936 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yyval;]b4_locations_if([[ 937 /* Default location. */ 938 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); 939 yystackp->yyerror_range[1].yystate.yyloc = *yylocp;]])[ 940 /* If yyk == -1, we are running a deferred action on a temporary 941 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL, 942 so pretend the stack is "normal". */ 943 YY_REDUCE_PRINT ((yynormal || yyk == -1, yyvsp, yyk, yyrule]b4_user_args[));]b4_glr_cc_if([[ 944 #if YY_EXCEPTIONS 945 typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error; 946 try 947 { 948 #endif // YY_EXCEPTIONS]])[ 949 switch (yyrule) 950 { 951 ]b4_user_actions[ 952 default: break; 953 }]b4_glr_cc_if([[ 954 #if YY_EXCEPTIONS 955 } 956 catch (const syntax_error& yyexc) 957 { 958 YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ 959 *yylocp = yyexc.location;])[ 960 yyerror (]b4_yyerror_args[yyexc.what ()); 961 YYERROR; 962 } 963 #endif // YY_EXCEPTIONS]])[ 964 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), yyvalp, yylocp); 965 966 return yyok; 967 # undef yyerrok 968 # undef YYABORT 969 # undef YYACCEPT 970 # undef YYNOMEM 971 # undef YYERROR 972 # undef YYBACKUP 973 # undef yyclearin 974 # undef YYRECOVERING 975 } 976 977 978 static void 979 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) 980 { 981 YY_USE (yy0); 982 YY_USE (yy1); 983 984 switch (yyn) 985 { 986 ]b4_mergers[ 987 default: break; 988 } 989 } 990 991 /* Bison grammar-table manipulation. */ 992 993 ]b4_yydestruct_define[ 994 995 /** Number of symbols composing the right hand side of rule #RULE. */ 996 static inline int 997 yyrhsLength (yyRuleNum yyrule) 998 { 999 return yyr2[yyrule]; 1000 } 1001 1002 static void 1003 yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) 1004 { 1005 if (yys->yyresolved) 1006 yydestruct (yymsg, yy_accessing_symbol (yys->yylrState), 1007 &yys->yysemantics.yyval]b4_locuser_args([&yys->yyloc])[); 1008 else 1009 { 1010 #if ]b4_api_PREFIX[DEBUG 1011 if (yydebug) 1012 { 1013 if (yys->yysemantics.yyfirstVal) 1014 YY_FPRINTF ((stderr, "%s unresolved", yymsg)); 1015 else 1016 YY_FPRINTF ((stderr, "%s incomplete", yymsg)); 1017 YY_SYMBOL_PRINT ("", yy_accessing_symbol (yys->yylrState), YY_NULLPTR, &yys->yyloc); 1018 } 1019 #endif 1020 1021 if (yys->yysemantics.yyfirstVal) 1022 { 1023 yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; 1024 yyGLRState *yyrh; 1025 int yyn; 1026 for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); 1027 yyn > 0; 1028 yyrh = yyrh->yypred, yyn -= 1) 1029 yydestroyGLRState (yymsg, yyrh]b4_user_args[); 1030 } 1031 } 1032 } 1033 1034 #define yypact_value_is_default(Yyn) \ 1035 ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[ 1036 1037 /** True iff LR state YYSTATE has only a default reduction (regardless 1038 * of token). */ 1039 static inline yybool 1040 yyisDefaultedState (yy_state_t yystate) 1041 { 1042 return yypact_value_is_default (yypact[yystate]); 1043 } 1044 1045 /** The default reduction for YYSTATE, assuming it has one. */ 1046 static inline yyRuleNum 1047 yydefaultAction (yy_state_t yystate) 1048 { 1049 return yydefact[yystate]; 1050 } 1051 1052 #define yytable_value_is_error(Yyn) \ 1053 ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[ 1054 1055 /** The action to take in YYSTATE on seeing YYTOKEN. 1056 * Result R means 1057 * R < 0: Reduce on rule -R. 1058 * R = 0: Error. 1059 * R > 0: Shift to state R. 1060 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list 1061 * of conflicting reductions. 1062 */ 1063 static inline int 1064 yygetLRActions (yy_state_t yystate, yysymbol_kind_t yytoken, const short** yyconflicts) 1065 { 1066 int yyindex = yypact[yystate] + yytoken; 1067 if (yytoken == ]b4_symbol(error, kind)[) 1068 { 1069 // This is the error token. 1070 *yyconflicts = yyconfl; 1071 return 0; 1072 } 1073 else if (yyisDefaultedState (yystate) 1074 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) 1075 { 1076 *yyconflicts = yyconfl; 1077 return -yydefact[yystate]; 1078 } 1079 else if (! yytable_value_is_error (yytable[yyindex])) 1080 { 1081 *yyconflicts = yyconfl + yyconflp[yyindex]; 1082 return yytable[yyindex]; 1083 } 1084 else 1085 { 1086 *yyconflicts = yyconfl + yyconflp[yyindex]; 1087 return 0; 1088 } 1089 } 1090 1091 /** Compute post-reduction state. 1092 * \param yystate the current state 1093 * \param yysym the nonterminal to push on the stack 1094 */ 1095 static inline yy_state_t 1096 yyLRgotoState (yy_state_t yystate, yysymbol_kind_t yysym) 1097 { 1098 int yyr = yypgoto[yysym - YYNTOKENS] + yystate; 1099 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) 1100 return yytable[yyr]; 1101 else 1102 return yydefgoto[yysym - YYNTOKENS]; 1103 } 1104 1105 static inline yybool 1106 yyisShiftAction (int yyaction) 1107 { 1108 return 0 < yyaction; 1109 } 1110 1111 static inline yybool 1112 yyisErrorAction (int yyaction) 1113 { 1114 return yyaction == 0; 1115 } 1116 1117 /* GLRStates */ 1118 1119 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state 1120 * if YYISSTATE, and otherwise a semantic option. Callers should call 1121 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient 1122 * headroom. */ 1123 1124 static inline yyGLRStackItem* 1125 yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState) 1126 { 1127 yyGLRStackItem* yynewItem = yystackp->yynextFree; 1128 yystackp->yyspaceLeft -= 1; 1129 yystackp->yynextFree += 1; 1130 yynewItem->yystate.yyisState = yyisState; 1131 return yynewItem; 1132 } 1133 1134 /** Add a new semantic action that will execute the action for rule 1135 * YYRULE on the semantic values in YYRHS to the list of 1136 * alternative actions for YYSTATE. Assumes that YYRHS comes from 1137 * stack #YYK of *YYSTACKP. */ 1138 static void 1139 yyaddDeferredAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyGLRState* yystate, 1140 yyGLRState* yyrhs, yyRuleNum yyrule) 1141 { 1142 yySemanticOption* yynewOption = 1143 &yynewGLRStackItem (yystackp, yyfalse)->yyoption; 1144 YY_ASSERT (!yynewOption->yyisState); 1145 yynewOption->yystate = yyrhs; 1146 yynewOption->yyrule = yyrule; 1147 if (yystackp->yytops.yylookaheadNeeds[yyk]) 1148 { 1149 yynewOption->yyrawchar = yychar; 1150 yynewOption->yyval = yylval;]b4_locations_if([ 1151 yynewOption->yyloc = yylloc;])[ 1152 } 1153 else 1154 yynewOption->yyrawchar = ]b4_symbol(empty, id)[; 1155 yynewOption->yynext = yystate->yysemantics.yyfirstVal; 1156 yystate->yysemantics.yyfirstVal = yynewOption; 1157 1158 YY_RESERVE_GLRSTACK (yystackp); 1159 } 1160 1161 /* GLRStacks */ 1162 1163 /** Initialize YYSET to a singleton set containing an empty stack. */ 1164 static yybool 1165 yyinitStateSet (yyGLRStateSet* yyset) 1166 { 1167 yyset->yysize = 1; 1168 yyset->yycapacity = 16; 1169 yyset->yystates 1170 = YY_CAST (yyGLRState**, 1171 YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity) 1172 * sizeof yyset->yystates[0])); 1173 if (! yyset->yystates) 1174 return yyfalse; 1175 yyset->yystates[0] = YY_NULLPTR; 1176 yyset->yylookaheadNeeds 1177 = YY_CAST (yybool*, 1178 YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity) 1179 * sizeof yyset->yylookaheadNeeds[0])); 1180 if (! yyset->yylookaheadNeeds) 1181 { 1182 YYFREE (yyset->yystates); 1183 return yyfalse; 1184 } 1185 memset (yyset->yylookaheadNeeds, 1186 0, 1187 YY_CAST (YYSIZE_T, yyset->yycapacity) * sizeof yyset->yylookaheadNeeds[0]); 1188 return yytrue; 1189 } 1190 1191 static void yyfreeStateSet (yyGLRStateSet* yyset) 1192 { 1193 YYFREE (yyset->yystates); 1194 YYFREE (yyset->yylookaheadNeeds); 1195 } 1196 1197 /** Initialize *YYSTACKP to a single empty stack, with total maximum 1198 * capacity for all stacks of YYSIZE. */ 1199 static yybool 1200 yyinitGLRStack (yyGLRStack* yystackp, YYPTRDIFF_T yysize) 1201 { 1202 yystackp->yyerrState = 0; 1203 yynerrs = 0; 1204 yystackp->yyspaceLeft = yysize; 1205 yystackp->yyitems 1206 = YY_CAST (yyGLRStackItem*, 1207 YYMALLOC (YY_CAST (YYSIZE_T, yysize) 1208 * sizeof yystackp->yynextFree[0])); 1209 if (!yystackp->yyitems) 1210 return yyfalse; 1211 yystackp->yynextFree = yystackp->yyitems; 1212 yystackp->yysplitPoint = YY_NULLPTR; 1213 yystackp->yylastDeleted = YY_NULLPTR; 1214 return yyinitStateSet (&yystackp->yytops); 1215 } 1216 1217 1218 #if YYSTACKEXPANDABLE 1219 # define YYRELOC(YYFROMITEMS, YYTOITEMS, YYX, YYTYPE) \ 1220 &((YYTOITEMS) \ 1221 - ((YYFROMITEMS) - YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX))))->YYTYPE 1222 1223 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the 1224 stack from outside should be considered invalid after this call. 1225 We always expand when there are 1 or fewer items left AFTER an 1226 allocation, so that we can avoid having external pointers exist 1227 across an allocation. */ 1228 static void 1229 yyexpandGLRStack (yyGLRStack* yystackp) 1230 { 1231 yyGLRStackItem* yynewItems; 1232 yyGLRStackItem* yyp0, *yyp1; 1233 YYPTRDIFF_T yynewSize; 1234 YYPTRDIFF_T yyn; 1235 YYPTRDIFF_T yysize = yystackp->yynextFree - yystackp->yyitems; 1236 if (YYMAXDEPTH - YYHEADROOM < yysize) 1237 yyMemoryExhausted (yystackp); 1238 yynewSize = 2*yysize; 1239 if (YYMAXDEPTH < yynewSize) 1240 yynewSize = YYMAXDEPTH; 1241 yynewItems 1242 = YY_CAST (yyGLRStackItem*, 1243 YYMALLOC (YY_CAST (YYSIZE_T, yynewSize) 1244 * sizeof yynewItems[0])); 1245 if (! yynewItems) 1246 yyMemoryExhausted (yystackp); 1247 for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize; 1248 0 < yyn; 1249 yyn -= 1, yyp0 += 1, yyp1 += 1) 1250 { 1251 *yyp1 = *yyp0; 1252 if (*YY_REINTERPRET_CAST (yybool *, yyp0)) 1253 { 1254 yyGLRState* yys0 = &yyp0->yystate; 1255 yyGLRState* yys1 = &yyp1->yystate; 1256 if (yys0->yypred != YY_NULLPTR) 1257 yys1->yypred = 1258 YYRELOC (yyp0, yyp1, yys0->yypred, yystate); 1259 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULLPTR) 1260 yys1->yysemantics.yyfirstVal = 1261 YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); 1262 } 1263 else 1264 { 1265 yySemanticOption* yyv0 = &yyp0->yyoption; 1266 yySemanticOption* yyv1 = &yyp1->yyoption; 1267 if (yyv0->yystate != YY_NULLPTR) 1268 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); 1269 if (yyv0->yynext != YY_NULLPTR) 1270 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); 1271 } 1272 } 1273 if (yystackp->yysplitPoint != YY_NULLPTR) 1274 yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems, 1275 yystackp->yysplitPoint, yystate); 1276 1277 for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1) 1278 if (yystackp->yytops.yystates[yyn] != YY_NULLPTR) 1279 yystackp->yytops.yystates[yyn] = 1280 YYRELOC (yystackp->yyitems, yynewItems, 1281 yystackp->yytops.yystates[yyn], yystate); 1282 YYFREE (yystackp->yyitems); 1283 yystackp->yyitems = yynewItems; 1284 yystackp->yynextFree = yynewItems + yysize; 1285 yystackp->yyspaceLeft = yynewSize - yysize; 1286 } 1287 #endif 1288 1289 static void 1290 yyfreeGLRStack (yyGLRStack* yystackp) 1291 { 1292 YYFREE (yystackp->yyitems); 1293 yyfreeStateSet (&yystackp->yytops); 1294 } 1295 1296 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the 1297 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as 1298 * YYS. */ 1299 static inline void 1300 yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys) 1301 { 1302 if (yystackp->yysplitPoint != YY_NULLPTR && yystackp->yysplitPoint > yys) 1303 yystackp->yysplitPoint = yys; 1304 } 1305 1306 /** Invalidate stack #YYK in *YYSTACKP. */ 1307 static inline void 1308 yymarkStackDeleted (yyGLRStack* yystackp, YYPTRDIFF_T yyk) 1309 { 1310 if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) 1311 yystackp->yylastDeleted = yystackp->yytops.yystates[yyk]; 1312 yystackp->yytops.yystates[yyk] = YY_NULLPTR; 1313 } 1314 1315 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can 1316 only be done once after a deletion, and only when all other stacks have 1317 been deleted. */ 1318 static void 1319 yyundeleteLastStack (yyGLRStack* yystackp) 1320 { 1321 if (yystackp->yylastDeleted == YY_NULLPTR || yystackp->yytops.yysize != 0) 1322 return; 1323 yystackp->yytops.yystates[0] = yystackp->yylastDeleted; 1324 yystackp->yytops.yysize = 1; 1325 YY_DPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); 1326 yystackp->yylastDeleted = YY_NULLPTR; 1327 } 1328 1329 static inline void 1330 yyremoveDeletes (yyGLRStack* yystackp) 1331 { 1332 YYPTRDIFF_T yyi, yyj; 1333 yyi = yyj = 0; 1334 while (yyj < yystackp->yytops.yysize) 1335 { 1336 if (yystackp->yytops.yystates[yyi] == YY_NULLPTR) 1337 { 1338 if (yyi == yyj) 1339 YY_DPRINTF ((stderr, "Removing dead stacks.\n")); 1340 yystackp->yytops.yysize -= 1; 1341 } 1342 else 1343 { 1344 yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi]; 1345 /* In the current implementation, it's unnecessary to copy 1346 yystackp->yytops.yylookaheadNeeds[yyi] since, after 1347 yyremoveDeletes returns, the parser immediately either enters 1348 deterministic operation or shifts a token. However, it doesn't 1349 hurt, and the code might evolve to need it. */ 1350 yystackp->yytops.yylookaheadNeeds[yyj] = 1351 yystackp->yytops.yylookaheadNeeds[yyi]; 1352 if (yyj != yyi) 1353 YY_DPRINTF ((stderr, "Rename stack %ld -> %ld.\n", 1354 YY_CAST (long, yyi), YY_CAST (long, yyj))); 1355 yyj += 1; 1356 } 1357 yyi += 1; 1358 } 1359 } 1360 1361 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR 1362 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic 1363 * value *YYVALP and source location *YYLOCP. */ 1364 static inline void 1365 yyglrShift (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState, 1366 YYPTRDIFF_T yyposn, 1367 YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[) 1368 { 1369 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; 1370 1371 yynewState->yylrState = yylrState; 1372 yynewState->yyposn = yyposn; 1373 yynewState->yyresolved = yytrue; 1374 yynewState->yypred = yystackp->yytops.yystates[yyk]; 1375 yynewState->yysemantics.yyval = *yyvalp;]b4_locations_if([ 1376 yynewState->yyloc = *yylocp;])[ 1377 yystackp->yytops.yystates[yyk] = yynewState; 1378 1379 YY_RESERVE_GLRSTACK (yystackp); 1380 } 1381 1382 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR 1383 * state YYLRSTATE, at input position YYPOSN, with the (unresolved) 1384 * semantic value of YYRHS under the action for YYRULE. */ 1385 static inline void 1386 yyglrShiftDefer (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState, 1387 YYPTRDIFF_T yyposn, yyGLRState* yyrhs, yyRuleNum yyrule) 1388 { 1389 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; 1390 YY_ASSERT (yynewState->yyisState); 1391 1392 yynewState->yylrState = yylrState; 1393 yynewState->yyposn = yyposn; 1394 yynewState->yyresolved = yyfalse; 1395 yynewState->yypred = yystackp->yytops.yystates[yyk]; 1396 yynewState->yysemantics.yyfirstVal = YY_NULLPTR; 1397 yystackp->yytops.yystates[yyk] = yynewState; 1398 1399 /* Invokes YY_RESERVE_GLRSTACK. */ 1400 yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule); 1401 } 1402 1403 #if ]b4_api_PREFIX[DEBUG 1404 1405 /*----------------------------------------------------------------------. 1406 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | 1407 `----------------------------------------------------------------------*/ 1408 1409 static inline void 1410 yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk, 1411 yyRuleNum yyrule]b4_user_formals[) 1412 { 1413 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([ 1414 int yylow = 1;])[ 1415 int yyi; 1416 YY_FPRINTF ((stderr, "Reducing stack %ld by rule %d (line %d):\n", 1417 YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule])); 1418 if (! yynormal) 1419 yyfillin (yyvsp, 1, -yynrhs); 1420 /* The symbols being reduced. */ 1421 for (yyi = 0; yyi < yynrhs; yyi++) 1422 { 1423 YY_FPRINTF ((stderr, " $%d = ", yyi + 1)); 1424 yy_symbol_print (stderr, 1425 yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].yystate.yylrState), 1426 &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yyval]b4_locations_if([, 1427 &]b4_rhs_location(yynrhs, yyi + 1))[]dnl 1428 b4_user_args[); 1429 if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved) 1430 YY_FPRINTF ((stderr, " (unresolved)")); 1431 YY_FPRINTF ((stderr, "\n")); 1432 } 1433 } 1434 #endif 1435 1436 /** Pop the symbols consumed by reduction #YYRULE from the top of stack 1437 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their 1438 * semantic values. Assumes that all ambiguities in semantic values 1439 * have been previously resolved. Set *YYVALP to the resulting value, 1440 * and *YYLOCP to the computed location (if any). Return value is as 1441 * for userAction. */ 1442 static inline YYRESULTTAG 1443 yydoAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule, 1444 YYSTYPE* yyvalp]b4_locuser_formals[) 1445 { 1446 int yynrhs = yyrhsLength (yyrule); 1447 1448 if (yystackp->yysplitPoint == YY_NULLPTR) 1449 { 1450 /* Standard special case: single stack. */ 1451 yyGLRStackItem* yyrhs 1452 = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yytops.yystates[yyk]); 1453 YY_ASSERT (yyk == 0); 1454 yystackp->yynextFree -= yynrhs; 1455 yystackp->yyspaceLeft += yynrhs; 1456 yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate; 1457 return yyuserAction (yyrule, yynrhs, yyrhs, yystackp, yyk, 1458 yyvalp]b4_locuser_args[); 1459 } 1460 else 1461 { 1462 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; 1463 yyGLRState* yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred 1464 = yystackp->yytops.yystates[yyk]; 1465 int yyi;]b4_locations_if([[ 1466 if (yynrhs == 0) 1467 /* Set default location. */ 1468 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[ 1469 for (yyi = 0; yyi < yynrhs; yyi += 1) 1470 { 1471 yys = yys->yypred; 1472 YY_ASSERT (yys); 1473 } 1474 yyupdateSplit (yystackp, yys); 1475 yystackp->yytops.yystates[yyk] = yys; 1476 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, 1477 yystackp, yyk, yyvalp]b4_locuser_args[); 1478 } 1479 } 1480 1481 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE, 1482 * and push back on the resulting nonterminal symbol. Perform the 1483 * semantic action associated with YYRULE and store its value with the 1484 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently 1485 * unambiguous. Otherwise, store the deferred semantic action with 1486 * the new state. If the new state would have an identical input 1487 * position, LR state, and predecessor to an existing state on the stack, 1488 * it is identified with that existing state, eliminating stack #YYK from 1489 * *YYSTACKP. In this case, the semantic value is 1490 * added to the options for the existing state's semantic value. 1491 */ 1492 static inline YYRESULTTAG 1493 yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule, 1494 yybool yyforceEval]b4_user_formals[) 1495 { 1496 YYPTRDIFF_T yyposn = yystackp->yytops.yystates[yyk]->yyposn; 1497 1498 if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR) 1499 { 1500 YYSTYPE yyval;]b4_locations_if([[ 1501 YYLTYPE yyloc;]])[ 1502 1503 YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yyval]b4_locuser_args([&yyloc])[); 1504 if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR) 1505 YY_DPRINTF ((stderr, 1506 "Parse on stack %ld rejected by rule %d (line %d).\n", 1507 YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule])); 1508 if (yyflag != yyok) 1509 return yyflag; 1510 yyglrShift (yystackp, yyk, 1511 yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState, 1512 yylhsNonterm (yyrule)), 1513 yyposn, &yyval]b4_locations_if([, &yyloc])[); 1514 } 1515 else 1516 { 1517 YYPTRDIFF_T yyi; 1518 int yyn; 1519 yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk]; 1520 yy_state_t yynewLRState; 1521 1522 for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); 1523 0 < yyn; yyn -= 1) 1524 { 1525 yys = yys->yypred; 1526 YY_ASSERT (yys); 1527 } 1528 yyupdateSplit (yystackp, yys); 1529 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); 1530 YY_DPRINTF ((stderr, 1531 "Reduced stack %ld by rule %d (line %d); action deferred. " 1532 "Now in state %d.\n", 1533 YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule], 1534 yynewLRState)); 1535 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) 1536 if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR) 1537 { 1538 yyGLRState *yysplit = yystackp->yysplitPoint; 1539 yyGLRState *yyp = yystackp->yytops.yystates[yyi]; 1540 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) 1541 { 1542 if (yyp->yylrState == yynewLRState && yyp->yypred == yys) 1543 { 1544 yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule); 1545 yymarkStackDeleted (yystackp, yyk); 1546 YY_DPRINTF ((stderr, "Merging stack %ld into stack %ld.\n", 1547 YY_CAST (long, yyk), YY_CAST (long, yyi))); 1548 return yyok; 1549 } 1550 yyp = yyp->yypred; 1551 } 1552 } 1553 yystackp->yytops.yystates[yyk] = yys; 1554 yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule); 1555 } 1556 return yyok; 1557 } 1558 1559 static YYPTRDIFF_T 1560 yysplitStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) 1561 { 1562 if (yystackp->yysplitPoint == YY_NULLPTR) 1563 { 1564 YY_ASSERT (yyk == 0); 1565 yystackp->yysplitPoint = yystackp->yytops.yystates[yyk]; 1566 } 1567 if (yystackp->yytops.yycapacity <= yystackp->yytops.yysize) 1568 { 1569 YYPTRDIFF_T state_size = YYSIZEOF (yystackp->yytops.yystates[0]); 1570 YYPTRDIFF_T half_max_capacity = YYSIZE_MAXIMUM / 2 / state_size; 1571 if (half_max_capacity < yystackp->yytops.yycapacity) 1572 yyMemoryExhausted (yystackp); 1573 yystackp->yytops.yycapacity *= 2; 1574 1575 { 1576 yyGLRState** yynewStates 1577 = YY_CAST (yyGLRState**, 1578 YYREALLOC (yystackp->yytops.yystates, 1579 (YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity) 1580 * sizeof yynewStates[0]))); 1581 if (yynewStates == YY_NULLPTR) 1582 yyMemoryExhausted (yystackp); 1583 yystackp->yytops.yystates = yynewStates; 1584 } 1585 1586 { 1587 yybool* yynewLookaheadNeeds 1588 = YY_CAST (yybool*, 1589 YYREALLOC (yystackp->yytops.yylookaheadNeeds, 1590 (YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity) 1591 * sizeof yynewLookaheadNeeds[0]))); 1592 if (yynewLookaheadNeeds == YY_NULLPTR) 1593 yyMemoryExhausted (yystackp); 1594 yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds; 1595 } 1596 } 1597 yystackp->yytops.yystates[yystackp->yytops.yysize] 1598 = yystackp->yytops.yystates[yyk]; 1599 yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize] 1600 = yystackp->yytops.yylookaheadNeeds[yyk]; 1601 yystackp->yytops.yysize += 1; 1602 return yystackp->yytops.yysize - 1; 1603 } 1604 1605 /** True iff YYY0 and YYY1 represent identical options at the top level. 1606 * That is, they represent the same rule applied to RHS symbols 1607 * that produce the same terminal symbols. */ 1608 static yybool 1609 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) 1610 { 1611 if (yyy0->yyrule == yyy1->yyrule) 1612 { 1613 yyGLRState *yys0, *yys1; 1614 int yyn; 1615 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, 1616 yyn = yyrhsLength (yyy0->yyrule); 1617 yyn > 0; 1618 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) 1619 if (yys0->yyposn != yys1->yyposn) 1620 return yyfalse; 1621 return yytrue; 1622 } 1623 else 1624 return yyfalse; 1625 } 1626 1627 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the 1628 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */ 1629 static void 1630 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) 1631 { 1632 yyGLRState *yys0, *yys1; 1633 int yyn; 1634 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, 1635 yyn = yyrhsLength (yyy0->yyrule); 1636 0 < yyn; 1637 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) 1638 { 1639 if (yys0 == yys1) 1640 break; 1641 else if (yys0->yyresolved) 1642 { 1643 yys1->yyresolved = yytrue; 1644 yys1->yysemantics.yyval = yys0->yysemantics.yyval; 1645 } 1646 else if (yys1->yyresolved) 1647 { 1648 yys0->yyresolved = yytrue; 1649 yys0->yysemantics.yyval = yys1->yysemantics.yyval; 1650 } 1651 else 1652 { 1653 yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal; 1654 yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal; 1655 while (yytrue) 1656 { 1657 if (yyz1 == *yyz0p || yyz1 == YY_NULLPTR) 1658 break; 1659 else if (*yyz0p == YY_NULLPTR) 1660 { 1661 *yyz0p = yyz1; 1662 break; 1663 } 1664 else if (*yyz0p < yyz1) 1665 { 1666 yySemanticOption* yyz = *yyz0p; 1667 *yyz0p = yyz1; 1668 yyz1 = yyz1->yynext; 1669 (*yyz0p)->yynext = yyz; 1670 } 1671 yyz0p = &(*yyz0p)->yynext; 1672 } 1673 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal; 1674 } 1675 } 1676 } 1677 1678 /** Y0 and Y1 represent two possible actions to take in a given 1679 * parsing state; return 0 if no combination is possible, 1680 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ 1681 static int 1682 yypreference (yySemanticOption* y0, yySemanticOption* y1) 1683 { 1684 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; 1685 int p0 = yydprec[r0], p1 = yydprec[r1]; 1686 1687 if (p0 == p1) 1688 { 1689 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) 1690 return 0; 1691 else 1692 return 1; 1693 } 1694 if (p0 == 0 || p1 == 0) 1695 return 0; 1696 if (p0 < p1) 1697 return 3; 1698 if (p1 < p0) 1699 return 2; 1700 return 0; 1701 } 1702 1703 static YYRESULTTAG 1704 yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[); 1705 1706 1707 /** Resolve the previous YYN states starting at and including state YYS 1708 * on *YYSTACKP. If result != yyok, some states may have been left 1709 * unresolved possibly with empty semantic option chains. Regardless 1710 * of whether result = yyok, each state has been left with consistent 1711 * data so that yydestroyGLRState can be invoked if necessary. */ 1712 static YYRESULTTAG 1713 yyresolveStates (yyGLRState* yys, int yyn, 1714 yyGLRStack* yystackp]b4_user_formals[) 1715 { 1716 if (0 < yyn) 1717 { 1718 YY_ASSERT (yys->yypred); 1719 YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[)); 1720 if (! yys->yyresolved) 1721 YYCHK (yyresolveValue (yys, yystackp]b4_user_args[)); 1722 } 1723 return yyok; 1724 } 1725 1726 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its 1727 * user action, and return the semantic value and location in *YYVALP 1728 * and *YYLOCP. Regardless of whether result = yyok, all RHS states 1729 * have been destroyed (assuming the user action destroys all RHS 1730 * semantic values if invoked). */ 1731 static YYRESULTTAG 1732 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp, 1733 YYSTYPE* yyvalp]b4_locuser_formals[) 1734 { 1735 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; 1736 int yynrhs = yyrhsLength (yyopt->yyrule); 1737 YYRESULTTAG yyflag = 1738 yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[); 1739 if (yyflag != yyok) 1740 { 1741 yyGLRState *yys; 1742 for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1) 1743 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); 1744 return yyflag; 1745 } 1746 1747 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[ 1748 if (yynrhs == 0) 1749 /* Set default location. */ 1750 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[ 1751 { 1752 int yychar_current = yychar; 1753 YYSTYPE yylval_current = yylval;]b4_locations_if([ 1754 YYLTYPE yylloc_current = yylloc;])[ 1755 yychar = yyopt->yyrawchar; 1756 yylval = yyopt->yyval;]b4_locations_if([ 1757 yylloc = yyopt->yyloc;])[ 1758 yyflag = yyuserAction (yyopt->yyrule, yynrhs, 1759 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, 1760 yystackp, -1, yyvalp]b4_locuser_args[); 1761 yychar = yychar_current; 1762 yylval = yylval_current;]b4_locations_if([ 1763 yylloc = yylloc_current;])[ 1764 } 1765 return yyflag; 1766 } 1767 1768 #if ]b4_api_PREFIX[DEBUG 1769 static void 1770 yyreportTree (yySemanticOption* yyx, int yyindent) 1771 { 1772 int yynrhs = yyrhsLength (yyx->yyrule); 1773 int yyi; 1774 yyGLRState* yys; 1775 yyGLRState* yystates[1 + YYMAXRHS]; 1776 yyGLRState yyleftmost_state; 1777 1778 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) 1779 yystates[yyi] = yys; 1780 if (yys == YY_NULLPTR) 1781 { 1782 yyleftmost_state.yyposn = 0; 1783 yystates[0] = &yyleftmost_state; 1784 } 1785 else 1786 yystates[0] = yys; 1787 1788 if (yyx->yystate->yyposn < yys->yyposn + 1) 1789 YY_FPRINTF ((stderr, "%*s%s -> <Rule %d, empty>\n", 1790 yyindent, "", yysymbol_name (yylhsNonterm (yyx->yyrule)), 1791 yyx->yyrule - 1)); 1792 else 1793 YY_FPRINTF ((stderr, "%*s%s -> <Rule %d, tokens %ld .. %ld>\n", 1794 yyindent, "", yysymbol_name (yylhsNonterm (yyx->yyrule)), 1795 yyx->yyrule - 1, YY_CAST (long, yys->yyposn + 1), 1796 YY_CAST (long, yyx->yystate->yyposn))); 1797 for (yyi = 1; yyi <= yynrhs; yyi += 1) 1798 { 1799 if (yystates[yyi]->yyresolved) 1800 { 1801 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) 1802 YY_FPRINTF ((stderr, "%*s%s <empty>\n", yyindent+2, "", 1803 yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)))); 1804 else 1805 YY_FPRINTF ((stderr, "%*s%s <tokens %ld .. %ld>\n", yyindent+2, "", 1806 yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)), 1807 YY_CAST (long, yystates[yyi-1]->yyposn + 1), 1808 YY_CAST (long, yystates[yyi]->yyposn))); 1809 } 1810 else 1811 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); 1812 } 1813 } 1814 #endif 1815 1816 static YYRESULTTAG 1817 yyreportAmbiguity (yySemanticOption* yyx0, 1818 yySemanticOption* yyx1]b4_pure_formals[) 1819 { 1820 YY_USE (yyx0); 1821 YY_USE (yyx1); 1822 1823 #if ]b4_api_PREFIX[DEBUG 1824 YY_FPRINTF ((stderr, "Ambiguity detected.\n")); 1825 YY_FPRINTF ((stderr, "Option 1,\n")); 1826 yyreportTree (yyx0, 2); 1827 YY_FPRINTF ((stderr, "\nOption 2,\n")); 1828 yyreportTree (yyx1, 2); 1829 YY_FPRINTF ((stderr, "\n")); 1830 #endif 1831 1832 yyerror (]b4_yyerror_args[YY_("syntax is ambiguous")); 1833 return yyabort; 1834 }]b4_locations_if([[ 1835 1836 /** Resolve the locations for each of the YYN1 states in *YYSTACKP, 1837 * ending at YYS1. Has no effect on previously resolved states. 1838 * The first semantic option of a state is always chosen. */ 1839 static void 1840 yyresolveLocations (yyGLRState *yys1, int yyn1, 1841 yyGLRStack *yystackp]b4_user_formals[) 1842 { 1843 if (0 < yyn1) 1844 { 1845 yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[); 1846 if (!yys1->yyresolved) 1847 { 1848 yyGLRStackItem yyrhsloc[1 + YYMAXRHS]; 1849 int yynrhs; 1850 yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal; 1851 YY_ASSERT (yyoption); 1852 yynrhs = yyrhsLength (yyoption->yyrule); 1853 if (0 < yynrhs) 1854 { 1855 yyGLRState *yys; 1856 int yyn; 1857 yyresolveLocations (yyoption->yystate, yynrhs, 1858 yystackp]b4_user_args[); 1859 for (yys = yyoption->yystate, yyn = yynrhs; 1860 yyn > 0; 1861 yys = yys->yypred, yyn -= 1) 1862 yyrhsloc[yyn].yystate.yyloc = yys->yyloc; 1863 } 1864 else 1865 { 1866 /* Both yyresolveAction and yyresolveLocations traverse the GSS 1867 in reverse rightmost order. It is only necessary to invoke 1868 yyresolveLocations on a subforest for which yyresolveAction 1869 would have been invoked next had an ambiguity not been 1870 detected. Thus the location of the previous state (but not 1871 necessarily the previous state itself) is guaranteed to be 1872 resolved already. */ 1873 yyGLRState *yyprevious = yyoption->yystate; 1874 yyrhsloc[0].yystate.yyloc = yyprevious->yyloc; 1875 } 1876 YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs); 1877 } 1878 } 1879 }]])[ 1880 1881 /** Resolve the ambiguity represented in state YYS in *YYSTACKP, 1882 * perform the indicated actions, and set the semantic value of YYS. 1883 * If result != yyok, the chain of semantic options in YYS has been 1884 * cleared instead or it has been left unmodified except that 1885 * redundant options may have been removed. Regardless of whether 1886 * result = yyok, YYS has been left with consistent data so that 1887 * yydestroyGLRState can be invoked if necessary. */ 1888 static YYRESULTTAG 1889 yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[) 1890 { 1891 yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal; 1892 yySemanticOption* yybest = yyoptionList; 1893 yySemanticOption** yypp; 1894 yybool yymerge = yyfalse; 1895 YYSTYPE yyval; 1896 YYRESULTTAG yyflag;]b4_locations_if([ 1897 YYLTYPE *yylocp = &yys->yyloc;])[ 1898 1899 for (yypp = &yyoptionList->yynext; *yypp != YY_NULLPTR; ) 1900 { 1901 yySemanticOption* yyp = *yypp; 1902 1903 if (yyidenticalOptions (yybest, yyp)) 1904 { 1905 yymergeOptionSets (yybest, yyp); 1906 *yypp = yyp->yynext; 1907 } 1908 else 1909 { 1910 switch (yypreference (yybest, yyp)) 1911 { 1912 case 0:]b4_locations_if([[ 1913 yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[ 1914 return yyreportAmbiguity (yybest, yyp]b4_pure_args[); 1915 break; 1916 case 1: 1917 yymerge = yytrue; 1918 break; 1919 case 2: 1920 break; 1921 case 3: 1922 yybest = yyp; 1923 yymerge = yyfalse; 1924 break; 1925 default: 1926 /* This cannot happen so it is not worth a YY_ASSERT (yyfalse), 1927 but some compilers complain if the default case is 1928 omitted. */ 1929 break; 1930 } 1931 yypp = &yyp->yynext; 1932 } 1933 } 1934 1935 if (yymerge) 1936 { 1937 yySemanticOption* yyp; 1938 int yyprec = yydprec[yybest->yyrule]; 1939 yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args[); 1940 if (yyflag == yyok) 1941 for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext) 1942 { 1943 if (yyprec == yydprec[yyp->yyrule]) 1944 { 1945 YYSTYPE yyval_other;]b4_locations_if([ 1946 YYLTYPE yydummy;])[ 1947 yyflag = yyresolveAction (yyp, yystackp, &yyval_other]b4_locuser_args([&yydummy])[); 1948 if (yyflag != yyok) 1949 { 1950 yydestruct ("Cleanup: discarding incompletely merged value for", 1951 yy_accessing_symbol (yys->yylrState), 1952 &yyval]b4_locuser_args[); 1953 break; 1954 } 1955 yyuserMerge (yymerger[yyp->yyrule], &yyval, &yyval_other); 1956 } 1957 } 1958 } 1959 else 1960 yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args([yylocp])[); 1961 1962 if (yyflag == yyok) 1963 { 1964 yys->yyresolved = yytrue; 1965 yys->yysemantics.yyval = yyval; 1966 } 1967 else 1968 yys->yysemantics.yyfirstVal = YY_NULLPTR; 1969 return yyflag; 1970 } 1971 1972 static YYRESULTTAG 1973 yyresolveStack (yyGLRStack* yystackp]b4_user_formals[) 1974 { 1975 if (yystackp->yysplitPoint != YY_NULLPTR) 1976 { 1977 yyGLRState* yys; 1978 int yyn; 1979 1980 for (yyn = 0, yys = yystackp->yytops.yystates[0]; 1981 yys != yystackp->yysplitPoint; 1982 yys = yys->yypred, yyn += 1) 1983 continue; 1984 YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp 1985 ]b4_user_args[)); 1986 } 1987 return yyok; 1988 } 1989 1990 /** Called when returning to deterministic operation to clean up the extra 1991 * stacks. */ 1992 static void 1993 yycompressStack (yyGLRStack* yystackp) 1994 { 1995 /* yyr is the state after the split point. */ 1996 yyGLRState *yyr; 1997 1998 if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR) 1999 return; 2000 2001 { 2002 yyGLRState *yyp, *yyq; 2003 for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR; 2004 yyp != yystackp->yysplitPoint; 2005 yyr = yyp, yyp = yyq, yyq = yyp->yypred) 2006 yyp->yypred = yyr; 2007 } 2008 2009 yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems; 2010 yystackp->yynextFree = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yysplitPoint) + 1; 2011 yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems; 2012 yystackp->yysplitPoint = YY_NULLPTR; 2013 yystackp->yylastDeleted = YY_NULLPTR; 2014 2015 while (yyr != YY_NULLPTR) 2016 { 2017 yystackp->yynextFree->yystate = *yyr; 2018 yyr = yyr->yypred; 2019 yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate; 2020 yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate; 2021 yystackp->yynextFree += 1; 2022 yystackp->yyspaceLeft -= 1; 2023 } 2024 } 2025 2026 static YYRESULTTAG 2027 yyprocessOneStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk, 2028 YYPTRDIFF_T yyposn]b4_pure_formals[) 2029 { 2030 while (yystackp->yytops.yystates[yyk] != YY_NULLPTR) 2031 { 2032 yy_state_t yystate = yystackp->yytops.yystates[yyk]->yylrState; 2033 YY_DPRINTF ((stderr, "Stack %ld Entering state %d\n", 2034 YY_CAST (long, yyk), yystate)); 2035 2036 YY_ASSERT (yystate != YYFINAL); 2037 2038 if (yyisDefaultedState (yystate)) 2039 { 2040 YYRESULTTAG yyflag; 2041 yyRuleNum yyrule = yydefaultAction (yystate); 2042 if (yyrule == 0) 2043 { 2044 YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk))); 2045 yymarkStackDeleted (yystackp, yyk); 2046 return yyok; 2047 } 2048 yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[); 2049 if (yyflag == yyerr) 2050 { 2051 YY_DPRINTF ((stderr, 2052 "Stack %ld dies " 2053 "(predicate failure or explicit user error).\n", 2054 YY_CAST (long, yyk))); 2055 yymarkStackDeleted (yystackp, yyk); 2056 return yyok; 2057 } 2058 if (yyflag != yyok) 2059 return yyflag; 2060 } 2061 else 2062 { 2063 yysymbol_kind_t yytoken = ]b4_yygetToken_call[; 2064 const short* yyconflicts; 2065 const int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); 2066 yystackp->yytops.yylookaheadNeeds[yyk] = yytrue; 2067 2068 for (/* nothing */; *yyconflicts; yyconflicts += 1) 2069 { 2070 YYRESULTTAG yyflag; 2071 YYPTRDIFF_T yynewStack = yysplitStack (yystackp, yyk); 2072 YY_DPRINTF ((stderr, "Splitting off stack %ld from %ld.\n", 2073 YY_CAST (long, yynewStack), YY_CAST (long, yyk))); 2074 yyflag = yyglrReduce (yystackp, yynewStack, 2075 *yyconflicts, 2076 yyimmediate[*yyconflicts]]b4_user_args[); 2077 if (yyflag == yyok) 2078 YYCHK (yyprocessOneStack (yystackp, yynewStack, 2079 yyposn]b4_pure_args[)); 2080 else if (yyflag == yyerr) 2081 { 2082 YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yynewStack))); 2083 yymarkStackDeleted (yystackp, yynewStack); 2084 } 2085 else 2086 return yyflag; 2087 } 2088 2089 if (yyisShiftAction (yyaction)) 2090 break; 2091 else if (yyisErrorAction (yyaction)) 2092 { 2093 YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk))); 2094 yymarkStackDeleted (yystackp, yyk); 2095 break; 2096 } 2097 else 2098 { 2099 YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction, 2100 yyimmediate[-yyaction]]b4_user_args[); 2101 if (yyflag == yyerr) 2102 { 2103 YY_DPRINTF ((stderr, 2104 "Stack %ld dies " 2105 "(predicate failure or explicit user error).\n", 2106 YY_CAST (long, yyk))); 2107 yymarkStackDeleted (yystackp, yyk); 2108 break; 2109 } 2110 else if (yyflag != yyok) 2111 return yyflag; 2112 } 2113 } 2114 } 2115 return yyok; 2116 } 2117 2118 ]b4_parse_error_case([simple], [], 2119 [[/* Put in YYARG at most YYARGN of the expected tokens given the 2120 current YYSTACKP, and return the number of tokens stored in YYARG. If 2121 YYARG is null, return the number of expected tokens (guaranteed to 2122 be less than YYNTOKENS). */ 2123 static int 2124 yypcontext_expected_tokens (const yyGLRStack* yystackp, 2125 yysymbol_kind_t yyarg[], int yyargn) 2126 { 2127 /* Actual size of YYARG. */ 2128 int yycount = 0; 2129 int yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; 2130 if (!yypact_value_is_default (yyn)) 2131 { 2132 /* Start YYX at -YYN if negative to avoid negative indexes in 2133 YYCHECK. In other words, skip the first -YYN actions for 2134 this state because they are default actions. */ 2135 int yyxbegin = yyn < 0 ? -yyn : 0; 2136 /* Stay within bounds of both yycheck and yytname. */ 2137 int yychecklim = YYLAST - yyn + 1; 2138 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 2139 int yyx; 2140 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 2141 if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ 2142 && !yytable_value_is_error (yytable[yyx + yyn])) 2143 { 2144 if (!yyarg) 2145 ++yycount; 2146 else if (yycount == yyargn) 2147 return 0; 2148 else 2149 yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); 2150 } 2151 } 2152 if (yyarg && yycount == 0 && 0 < yyargn) 2153 yyarg[0] = ]b4_symbol(empty, kind)[; 2154 return yycount; 2155 }]])[ 2156 2157 ]b4_parse_error_bmatch( 2158 [custom], 2159 [[/* User defined function to report a syntax error. */ 2160 typedef yyGLRStack yypcontext_t; 2161 static int 2162 yyreport_syntax_error (const yyGLRStack* yystackp]b4_user_formals[); 2163 2164 /* The kind of the lookahead of this context. */ 2165 static yysymbol_kind_t 2166 yypcontext_token (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; 2167 2168 static yysymbol_kind_t 2169 yypcontext_token (const yyGLRStack *yystackp) 2170 { 2171 YY_USE (yystackp); 2172 yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); 2173 return yytoken; 2174 } 2175 2176 ]b4_locations_if([[/* The location of the lookahead of this context. */ 2177 static const YYLTYPE * 2178 yypcontext_location (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; 2179 2180 static const YYLTYPE * 2181 yypcontext_location (const yyGLRStack *yystackp) 2182 { 2183 YY_USE (yystackp); 2184 return &yylloc; 2185 }]])], 2186 [detailed\|verbose], 2187 [[static int 2188 yy_syntax_error_arguments (const yyGLRStack* yystackp, 2189 yysymbol_kind_t yyarg[], int yyargn) 2190 { 2191 yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); 2192 /* Actual size of YYARG. */ 2193 int yycount = 0; 2194 /* There are many possibilities here to consider: 2195 - If this state is a consistent state with a default action, then 2196 the only way this function was invoked is if the default action 2197 is an error action. In that case, don't check for expected 2198 tokens because there are none. 2199 - The only way there can be no lookahead present (in yychar) is if 2200 this state is a consistent state with a default action. Thus, 2201 detecting the absence of a lookahead is sufficient to determine 2202 that there is no unexpected or expected token to report. In that 2203 case, just report a simple "syntax error". 2204 - Don't assume there isn't a lookahead just because this state is a 2205 consistent state with a default action. There might have been a 2206 previous inconsistent state, consistent state with a non-default 2207 action, or user semantic action that manipulated yychar. 2208 - Of course, the expected token list depends on states to have 2209 correct lookahead information, and it depends on the parser not 2210 to perform extra reductions after fetching a lookahead from the 2211 scanner and before detecting a syntax error. Thus, state merging 2212 (from LALR or IELR) and default reductions corrupt the expected 2213 token list. However, the list is correct for canonical LR with 2214 one exception: it will still contain any token that will not be 2215 accepted due to an error action in a later state. 2216 */ 2217 if (yytoken != ]b4_symbol(empty, kind)[) 2218 { 2219 int yyn; 2220 if (yyarg) 2221 yyarg[yycount] = yytoken; 2222 ++yycount; 2223 yyn = yypcontext_expected_tokens (yystackp, 2224 yyarg ? yyarg + 1 : yyarg, yyargn - 1); 2225 if (yyn == YYENOMEM) 2226 return YYENOMEM; 2227 else 2228 yycount += yyn; 2229 } 2230 return yycount; 2231 } 2232 ]])[ 2233 2234 2235 static void 2236 yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) 2237 { 2238 if (yystackp->yyerrState != 0) 2239 return; 2240 ]b4_parse_error_case( 2241 [custom], 2242 [[ if (yyreport_syntax_error (yystackp]b4_user_args[)) 2243 yyMemoryExhausted (yystackp);]], 2244 [simple], 2245 [[ yyerror (]b4_lyyerror_args[YY_("syntax error"));]], 2246 [[ { 2247 yybool yysize_overflow = yyfalse; 2248 char* yymsg = YY_NULLPTR; 2249 enum { YYARGS_MAX = 5 }; 2250 /* Internationalized format string. */ 2251 const char *yyformat = YY_NULLPTR; 2252 /* Arguments of yyformat: reported tokens (one for the "unexpected", 2253 one per "expected"). */ 2254 yysymbol_kind_t yyarg[YYARGS_MAX]; 2255 /* Cumulated lengths of YYARG. */ 2256 YYPTRDIFF_T yysize = 0; 2257 2258 /* Actual size of YYARG. */ 2259 int yycount 2260 = yy_syntax_error_arguments (yystackp, yyarg, YYARGS_MAX); 2261 if (yycount == YYENOMEM) 2262 yyMemoryExhausted (yystackp); 2263 2264 switch (yycount) 2265 { 2266 #define YYCASE_(N, S) \ 2267 case N: \ 2268 yyformat = S; \ 2269 break 2270 default: /* Avoid compiler warnings. */ 2271 YYCASE_(0, YY_("syntax error")); 2272 YYCASE_(1, YY_("syntax error, unexpected %s")); 2273 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); 2274 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); 2275 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); 2276 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); 2277 #undef YYCASE_ 2278 } 2279 2280 /* Compute error message size. Don't count the "%s"s, but reserve 2281 room for the terminator. */ 2282 yysize = yystrlen (yyformat) - 2 * yycount + 1; 2283 { 2284 int yyi; 2285 for (yyi = 0; yyi < yycount; ++yyi) 2286 { 2287 YYPTRDIFF_T yysz 2288 = ]b4_parse_error_case( 2289 [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], 2290 [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ 2291 if (YYSIZE_MAXIMUM - yysize < yysz) 2292 yysize_overflow = yytrue; 2293 else 2294 yysize += yysz; 2295 } 2296 } 2297 2298 if (!yysize_overflow) 2299 yymsg = YY_CAST (char *, YYMALLOC (YY_CAST (YYSIZE_T, yysize))); 2300 2301 if (yymsg) 2302 { 2303 char *yyp = yymsg; 2304 int yyi = 0; 2305 while ((*yyp = *yyformat)) 2306 { 2307 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) 2308 {]b4_parse_error_case([verbose], [[ 2309 yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ 2310 yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ 2311 yyformat += 2; 2312 } 2313 else 2314 { 2315 ++yyp; 2316 ++yyformat; 2317 } 2318 } 2319 yyerror (]b4_lyyerror_args[yymsg); 2320 YYFREE (yymsg); 2321 } 2322 else 2323 { 2324 yyerror (]b4_lyyerror_args[YY_("syntax error")); 2325 yyMemoryExhausted (yystackp); 2326 } 2327 }]])[ 2328 yynerrs += 1; 2329 } 2330 2331 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, 2332 yylval, and yylloc are the syntactic category, semantic value, and location 2333 of the lookahead. */ 2334 static void 2335 yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) 2336 { 2337 if (yystackp->yyerrState == 3) 2338 /* We just shifted the error token and (perhaps) took some 2339 reductions. Skip tokens until we can proceed. */ 2340 while (yytrue) 2341 { 2342 yysymbol_kind_t yytoken; 2343 int yyj; 2344 if (yychar == ]b4_symbol(eof, [id])[) 2345 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); 2346 if (yychar != ]b4_symbol(empty, id)[) 2347 {]b4_locations_if([[ 2348 /* We throw away the lookahead, but the error range 2349 of the shifted error token must take it into account. */ 2350 yyGLRState *yys = yystackp->yytops.yystates[0]; 2351 yyGLRStackItem yyerror_range[3]; 2352 yyerror_range[1].yystate.yyloc = yys->yyloc; 2353 yyerror_range[2].yystate.yyloc = yylloc; 2354 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[ 2355 yytoken = YYTRANSLATE (yychar); 2356 yydestruct ("Error: discarding", 2357 yytoken, &yylval]b4_locuser_args([&yylloc])[); 2358 yychar = ]b4_symbol(empty, id)[; 2359 } 2360 yytoken = ]b4_yygetToken_call[; 2361 yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; 2362 if (yypact_value_is_default (yyj)) 2363 return; 2364 yyj += yytoken; 2365 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken) 2366 { 2367 if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0) 2368 return; 2369 } 2370 else if (! yytable_value_is_error (yytable[yyj])) 2371 return; 2372 } 2373 2374 /* Reduce to one stack. */ 2375 { 2376 YYPTRDIFF_T yyk; 2377 for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1) 2378 if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) 2379 break; 2380 if (yyk >= yystackp->yytops.yysize) 2381 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); 2382 for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1) 2383 yymarkStackDeleted (yystackp, yyk); 2384 yyremoveDeletes (yystackp); 2385 yycompressStack (yystackp); 2386 } 2387 2388 /* Pop stack until we find a state that shifts the error token. */ 2389 yystackp->yyerrState = 3; 2390 while (yystackp->yytops.yystates[0] != YY_NULLPTR) 2391 { 2392 yyGLRState *yys = yystackp->yytops.yystates[0]; 2393 int yyj = yypact[yys->yylrState]; 2394 if (! yypact_value_is_default (yyj)) 2395 { 2396 yyj += ]b4_symbol(error, kind)[; 2397 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(error, kind)[ 2398 && yyisShiftAction (yytable[yyj])) 2399 { 2400 /* Shift the error token. */ 2401 int yyaction = yytable[yyj];]b4_locations_if([[ 2402 /* First adjust its location.*/ 2403 YYLTYPE yyerrloc; 2404 yystackp->yyerror_range[2].yystate.yyloc = yylloc; 2405 YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[ 2406 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yyaction), 2407 &yylval, &yyerrloc); 2408 yyglrShift (yystackp, 0, yyaction, 2409 yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[); 2410 yys = yystackp->yytops.yystates[0]; 2411 break; 2412 } 2413 }]b4_locations_if([[ 2414 yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ 2415 if (yys->yypred != YY_NULLPTR) 2416 yydestroyGLRState ("Error: popping", yys]b4_user_args[); 2417 yystackp->yytops.yystates[0] = yys->yypred; 2418 yystackp->yynextFree -= 1; 2419 yystackp->yyspaceLeft += 1; 2420 } 2421 if (yystackp->yytops.yystates[0] == YY_NULLPTR) 2422 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); 2423 } 2424 2425 #define YYCHK1(YYE) \ 2426 do { \ 2427 switch (YYE) { \ 2428 case yyok: break; \ 2429 case yyabort: goto yyabortlab; \ 2430 case yyaccept: goto yyacceptlab; \ 2431 case yyerr: goto yyuser_error; \ 2432 case yynomem: goto yyexhaustedlab; \ 2433 default: goto yybuglab; \ 2434 } \ 2435 } while (0) 2436 2437 /*----------. 2438 | yyparse. | 2439 `----------*/ 2440 2441 int 2442 ]b4_glr_cc_if([yy_parse_impl], [yyparse])[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) 2443 { 2444 int yyresult; 2445 yyGLRStack yystack; 2446 yyGLRStack* const yystackp = &yystack; 2447 YYPTRDIFF_T yyposn; 2448 2449 YY_DPRINTF ((stderr, "Starting parse\n")); 2450 2451 yychar = ]b4_symbol(empty, id)[; 2452 yylval = yyval_default;]b4_locations_if([ 2453 yylloc = yyloc_default;])[ 2454 ]m4_ifdef([b4_initial_action], [ 2455 b4_dollar_pushdef([yylval], [], [], [yylloc])dnl 2456 b4_user_initial_action 2457 b4_dollar_popdef])[]dnl 2458 [ 2459 if (! yyinitGLRStack (yystackp, YYINITDEPTH)) 2460 goto yyexhaustedlab; 2461 switch (YYSETJMP (yystack.yyexception_buffer)) 2462 { 2463 case 0: break; 2464 case 1: goto yyabortlab; 2465 case 2: goto yyexhaustedlab; 2466 default: goto yybuglab; 2467 } 2468 yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[); 2469 yyposn = 0; 2470 2471 while (yytrue) 2472 { 2473 /* For efficiency, we have two loops, the first of which is 2474 specialized to deterministic operation (single stack, no 2475 potential ambiguity). */ 2476 /* Standard mode. */ 2477 while (yytrue) 2478 { 2479 yy_state_t yystate = yystack.yytops.yystates[0]->yylrState; 2480 YY_DPRINTF ((stderr, "Entering state %d\n", yystate)); 2481 if (yystate == YYFINAL) 2482 goto yyacceptlab; 2483 if (yyisDefaultedState (yystate)) 2484 { 2485 yyRuleNum yyrule = yydefaultAction (yystate); 2486 if (yyrule == 0) 2487 {]b4_locations_if([[ 2488 yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ 2489 yyreportSyntaxError (&yystack]b4_user_args[); 2490 goto yyuser_error; 2491 } 2492 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[)); 2493 } 2494 else 2495 { 2496 yysymbol_kind_t yytoken = ]b4_yygetToken_call;[ 2497 const short* yyconflicts; 2498 int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); 2499 if (*yyconflicts) 2500 /* Enter nondeterministic mode. */ 2501 break; 2502 if (yyisShiftAction (yyaction)) 2503 { 2504 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 2505 yychar = ]b4_symbol(empty, id)[; 2506 yyposn += 1; 2507 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[); 2508 if (0 < yystack.yyerrState) 2509 yystack.yyerrState -= 1; 2510 } 2511 else if (yyisErrorAction (yyaction)) 2512 {]b4_locations_if([[ 2513 yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ 2514 /* Issue an error message unless the scanner already 2515 did. */ 2516 if (yychar != ]b4_symbol(error, id)[) 2517 yyreportSyntaxError (&yystack]b4_user_args[); 2518 goto yyuser_error; 2519 } 2520 else 2521 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[)); 2522 } 2523 } 2524 2525 /* Nondeterministic mode. */ 2526 while (yytrue) 2527 { 2528 yysymbol_kind_t yytoken_to_shift; 2529 YYPTRDIFF_T yys; 2530 2531 for (yys = 0; yys < yystack.yytops.yysize; yys += 1) 2532 yystackp->yytops.yylookaheadNeeds[yys] = yychar != ]b4_symbol(empty, id)[; 2533 2534 /* yyprocessOneStack returns one of three things: 2535 2536 - An error flag. If the caller is yyprocessOneStack, it 2537 immediately returns as well. When the caller is finally 2538 yyparse, it jumps to an error label via YYCHK1. 2539 2540 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted 2541 (&yystack, yys), which sets the top state of yys to NULL. Thus, 2542 yyparse's following invocation of yyremoveDeletes will remove 2543 the stack. 2544 2545 - yyok, when ready to shift a token. 2546 2547 Except in the first case, yyparse will invoke yyremoveDeletes and 2548 then shift the next token onto all remaining stacks. This 2549 synchronization of the shift (that is, after all preceding 2550 reductions on all stacks) helps prevent double destructor calls 2551 on yylval in the event of memory exhaustion. */ 2552 2553 for (yys = 0; yys < yystack.yytops.yysize; yys += 1) 2554 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[)); 2555 yyremoveDeletes (&yystack); 2556 if (yystack.yytops.yysize == 0) 2557 { 2558 yyundeleteLastStack (&yystack); 2559 if (yystack.yytops.yysize == 0) 2560 yyFail (&yystack][]b4_lpure_args[, YY_("syntax error")); 2561 YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); 2562 YY_DPRINTF ((stderr, "Returning to deterministic operation.\n"));]b4_locations_if([[ 2563 yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ 2564 yyreportSyntaxError (&yystack]b4_user_args[); 2565 goto yyuser_error; 2566 } 2567 2568 /* If any yyglrShift call fails, it will fail after shifting. Thus, 2569 a copy of yylval will already be on stack 0 in the event of a 2570 failure in the following loop. Thus, yychar is set to ]b4_symbol(empty, id)[ 2571 before the loop to make sure the user destructor for yylval isn't 2572 called twice. */ 2573 yytoken_to_shift = YYTRANSLATE (yychar); 2574 yychar = ]b4_symbol(empty, id)[; 2575 yyposn += 1; 2576 for (yys = 0; yys < yystack.yytops.yysize; yys += 1) 2577 { 2578 yy_state_t yystate = yystack.yytops.yystates[yys]->yylrState; 2579 const short* yyconflicts; 2580 int yyaction = yygetLRActions (yystate, yytoken_to_shift, 2581 &yyconflicts); 2582 /* Note that yyconflicts were handled by yyprocessOneStack. */ 2583 YY_DPRINTF ((stderr, "On stack %ld, ", YY_CAST (long, yys))); 2584 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc); 2585 yyglrShift (&yystack, yys, yyaction, yyposn, 2586 &yylval]b4_locations_if([, &yylloc])[); 2587 YY_DPRINTF ((stderr, "Stack %ld now in state %d\n", 2588 YY_CAST (long, yys), 2589 yystack.yytops.yystates[yys]->yylrState)); 2590 } 2591 2592 if (yystack.yytops.yysize == 1) 2593 { 2594 YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); 2595 YY_DPRINTF ((stderr, "Returning to deterministic operation.\n")); 2596 yycompressStack (&yystack); 2597 break; 2598 } 2599 } 2600 continue; 2601 yyuser_error: 2602 yyrecoverSyntaxError (&yystack]b4_user_args[); 2603 yyposn = yystack.yytops.yystates[0]->yyposn; 2604 } 2605 2606 yyacceptlab: 2607 yyresult = 0; 2608 goto yyreturnlab; 2609 2610 yybuglab: 2611 YY_ASSERT (yyfalse); 2612 goto yyabortlab; 2613 2614 yyabortlab: 2615 yyresult = 1; 2616 goto yyreturnlab; 2617 2618 yyexhaustedlab: 2619 yyerror (]b4_lyyerror_args[YY_("memory exhausted")); 2620 yyresult = 2; 2621 goto yyreturnlab; 2622 2623 yyreturnlab: 2624 if (yychar != ]b4_symbol(empty, id)[) 2625 yydestruct ("Cleanup: discarding lookahead", 2626 YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[); 2627 2628 /* If the stack is well-formed, pop the stack until it is empty, 2629 destroying its entries as we go. But free the stack regardless 2630 of whether it is well-formed. */ 2631 if (yystack.yyitems) 2632 { 2633 yyGLRState** yystates = yystack.yytops.yystates; 2634 if (yystates) 2635 { 2636 YYPTRDIFF_T yysize = yystack.yytops.yysize; 2637 YYPTRDIFF_T yyk; 2638 for (yyk = 0; yyk < yysize; yyk += 1) 2639 if (yystates[yyk]) 2640 { 2641 while (yystates[yyk]) 2642 { 2643 yyGLRState *yys = yystates[yyk];]b4_locations_if([[ 2644 yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ 2645 if (yys->yypred != YY_NULLPTR) 2646 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); 2647 yystates[yyk] = yys->yypred; 2648 yystack.yynextFree -= 1; 2649 yystack.yyspaceLeft += 1; 2650 } 2651 break; 2652 } 2653 } 2654 yyfreeGLRStack (&yystack); 2655 } 2656 2657 return yyresult; 2658 } 2659 2660 /* DEBUGGING ONLY */ 2661 #if ]b4_api_PREFIX[DEBUG 2662 /* Print *YYS and its predecessors. */ 2663 static void 2664 yy_yypstack (yyGLRState* yys) 2665 { 2666 if (yys->yypred) 2667 { 2668 yy_yypstack (yys->yypred); 2669 YY_FPRINTF ((stderr, " -> ")); 2670 } 2671 YY_FPRINTF ((stderr, "%d@@%ld", yys->yylrState, YY_CAST (long, yys->yyposn))); 2672 } 2673 2674 /* Print YYS (possibly NULL) and its predecessors. */ 2675 static void 2676 yypstates (yyGLRState* yys) 2677 { 2678 if (yys == YY_NULLPTR) 2679 YY_FPRINTF ((stderr, "<null>")); 2680 else 2681 yy_yypstack (yys); 2682 YY_FPRINTF ((stderr, "\n")); 2683 } 2684 2685 /* Print the stack #YYK. */ 2686 static void 2687 yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) 2688 { 2689 yypstates (yystackp->yytops.yystates[yyk]); 2690 } 2691 2692 /* Print all the stacks. */ 2693 static void 2694 yypdumpstack (yyGLRStack* yystackp) 2695 { 2696 #define YYINDEX(YYX) \ 2697 YY_CAST (long, \ 2698 ((YYX) \ 2699 ? YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX)) - yystackp->yyitems \ 2700 : -1)) 2701 2702 yyGLRStackItem* yyp; 2703 for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1) 2704 { 2705 YY_FPRINTF ((stderr, "%3ld. ", 2706 YY_CAST (long, yyp - yystackp->yyitems))); 2707 if (*YY_REINTERPRET_CAST (yybool *, yyp)) 2708 { 2709 YY_ASSERT (yyp->yystate.yyisState); 2710 YY_ASSERT (yyp->yyoption.yyisState); 2711 YY_FPRINTF ((stderr, "Res: %d, LR State: %d, posn: %ld, pred: %ld", 2712 yyp->yystate.yyresolved, yyp->yystate.yylrState, 2713 YY_CAST (long, yyp->yystate.yyposn), 2714 YYINDEX (yyp->yystate.yypred))); 2715 if (! yyp->yystate.yyresolved) 2716 YY_FPRINTF ((stderr, ", firstVal: %ld", 2717 YYINDEX (yyp->yystate.yysemantics.yyfirstVal))); 2718 } 2719 else 2720 { 2721 YY_ASSERT (!yyp->yystate.yyisState); 2722 YY_ASSERT (!yyp->yyoption.yyisState); 2723 YY_FPRINTF ((stderr, "Option. rule: %d, state: %ld, next: %ld", 2724 yyp->yyoption.yyrule - 1, 2725 YYINDEX (yyp->yyoption.yystate), 2726 YYINDEX (yyp->yyoption.yynext))); 2727 } 2728 YY_FPRINTF ((stderr, "\n")); 2729 } 2730 2731 YY_FPRINTF ((stderr, "Tops:")); 2732 { 2733 YYPTRDIFF_T yyi; 2734 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) 2735 YY_FPRINTF ((stderr, "%ld: %ld; ", YY_CAST (long, yyi), 2736 YYINDEX (yystackp->yytops.yystates[yyi]))); 2737 YY_FPRINTF ((stderr, "\n")); 2738 } 2739 #undef YYINDEX 2740 } 2741 #endif 2742 2743 #undef yylval 2744 #undef yychar 2745 #undef yynerrs]b4_locations_if([ 2746 #undef yylloc]) 2747 2748 m4_if(b4_prefix, [yy], [], 2749 [[/* Substitute the variable and function names. */ 2750 #define yyparse ]b4_prefix[parse 2751 #define yylex ]b4_prefix[lex 2752 #define yyerror ]b4_prefix[error 2753 #define yylval ]b4_prefix[lval 2754 #define yychar ]b4_prefix[char 2755 #define yydebug ]b4_prefix[debug 2756 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ 2757 #define yylloc ]b4_prefix[lloc]])])[ 2758 2759 ]b4_glr_cc_if([b4_glr_cc_pre_epilogue 2760 b4_glr_cc_cleanup])[ 2761 ]b4_percent_code_get([[epilogue]])[]dnl 2762 b4_epilogue[]dnl 2763 b4_output_end 2764