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