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