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