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