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