]> git.saurik.com Git - bison.git/blob - data/glr.c
5069f6131a64df93716ff384ae4888957fd331e6
[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 YY_ATTRIBUTE_UNUSED;
449 static void yypdumpstack (struct yyGLRStack* yystackp)
450 YY_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 _Noreturn void
673 yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
674 {
675 if (yymsg != YY_NULLPTR)
676 yyerror (]b4_yyerror_args[yymsg);
677 YYLONGJMP (yystackp->yyexception_buffer, 1);
678 }
679
680 static _Noreturn void
681 yyMemoryExhausted (yyGLRStack* yystackp)
682 {
683 YYLONGJMP (yystackp->yyexception_buffer, 2);
684 }
685
686 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
687 /** A printable representation of TOKEN. */
688 static inline const char*
689 yytokenName (yySymbol yytoken)
690 {
691 if (yytoken == YYEMPTY)
692 return "";
693
694 return yytname[yytoken];
695 }
696 #endif
697
698 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
699 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
700 * containing the pointer to the next state in the chain. */
701 static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED;
702 static void
703 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
704 {
705 int i;
706 yyGLRState *s = yyvsp[yylow0].yystate.yypred;
707 for (i = yylow0-1; i >= yylow1; i -= 1)
708 {
709 #if ]b4_api_PREFIX[DEBUG
710 yyvsp[i].yystate.yylrState = s->yylrState;
711 #endif
712 yyvsp[i].yystate.yyresolved = s->yyresolved;
713 if (s->yyresolved)
714 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
715 else
716 /* The effect of using yysval or yyloc (in an immediate rule) is
717 * undefined. */
718 yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;]b4_locations_if([[
719 yyvsp[i].yystate.yyloc = s->yyloc;]])[
720 s = yyvsp[i].yystate.yypred = s->yypred;
721 }
722 }
723
724 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
725 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
726 * For convenience, always return YYLOW1. */
727 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
728 YY_ATTRIBUTE_UNUSED;
729 static inline int
730 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
731 {
732 if (!yynormal && yylow1 < *yylow)
733 {
734 yyfillin (yyvsp, *yylow, yylow1);
735 *yylow = yylow1;
736 }
737 return yylow1;
738 }
739
740 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
741 * and top stack item YYVSP. YYLVALP points to place to put semantic
742 * value ($$), and yylocp points to place for location information
743 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
744 * yyerr for YYERROR, yyabort for YYABORT. */
745 static YYRESULTTAG
746 yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
747 yyGLRStack* yystackp,
748 YYSTYPE* yyvalp]b4_locuser_formals[)
749 {
750 yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULLPTR);
751 int yylow;
752 ]b4_parse_param_use([yyvalp], [yylocp])dnl
753 [ YYUSE (yyrhslen);
754 # undef yyerrok
755 # define yyerrok (yystackp->yyerrState = 0)
756 # undef YYACCEPT
757 # define YYACCEPT return yyaccept
758 # undef YYABORT
759 # define YYABORT return yyabort
760 # undef YYERROR
761 # define YYERROR return yyerrok, yyerr
762 # undef YYRECOVERING
763 # define YYRECOVERING() (yystackp->yyerrState != 0)
764 # undef yyclearin
765 # define yyclearin (yychar = YYEMPTY)
766 # undef YYFILL
767 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
768 # undef YYBACKUP
769 # define YYBACKUP(Token, Value) \
770 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
771 yyerrok, yyerr
772
773 yylow = 1;
774 if (yyrhslen == 0)
775 *yyvalp = yyval_default;
776 else
777 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
778 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
779 yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
780 ]])[
781 switch (yyn)
782 {
783 ]b4_user_actions[
784 default: break;
785 }
786
787 return yyok;
788 # undef yyerrok
789 # undef YYABORT
790 # undef YYACCEPT
791 # undef YYERROR
792 # undef YYBACKUP
793 # undef yyclearin
794 # undef YYRECOVERING
795 }
796
797
798 static void
799 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
800 {
801 YYUSE (yy0);
802 YYUSE (yy1);
803
804 switch (yyn)
805 {
806 ]b4_mergers[
807 default: break;
808 }
809 }
810
811 /* Bison grammar-table manipulation. */
812
813 ]b4_yydestruct_define[
814
815 /** Number of symbols composing the right hand side of rule #RULE. */
816 static inline int
817 yyrhsLength (yyRuleNum yyrule)
818 {
819 return yyr2[yyrule];
820 }
821
822 static void
823 yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
824 {
825 if (yys->yyresolved)
826 yydestruct (yymsg, yystos[yys->yylrState],
827 &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
828 else
829 {
830 #if ]b4_api_PREFIX[DEBUG
831 if (yydebug)
832 {
833 if (yys->yysemantics.yyfirstVal)
834 YYFPRINTF (stderr, "%s unresolved", yymsg);
835 else
836 YYFPRINTF (stderr, "%s incomplete", yymsg);
837 YY_SYMBOL_PRINT ("", yystos[yys->yylrState], YY_NULLPTR, &yys->yyloc);
838 }
839 #endif
840
841 if (yys->yysemantics.yyfirstVal)
842 {
843 yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
844 yyGLRState *yyrh;
845 int yyn;
846 for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
847 yyn > 0;
848 yyrh = yyrh->yypred, yyn -= 1)
849 yydestroyGLRState (yymsg, yyrh]b4_user_args[);
850 }
851 }
852 }
853
854 /** Left-hand-side symbol for rule #YYRULE. */
855 static inline yySymbol
856 yylhsNonterm (yyRuleNum yyrule)
857 {
858 return yyr1[yyrule];
859 }
860
861 #define yypact_value_is_default(Yystate) \
862 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
863
864 /** True iff LR state YYSTATE has only a default reduction (regardless
865 * of token). */
866 static inline yybool
867 yyisDefaultedState (yyStateNum yystate)
868 {
869 return yypact_value_is_default (yypact[yystate]);
870 }
871
872 /** The default reduction for YYSTATE, assuming it has one. */
873 static inline yyRuleNum
874 yydefaultAction (yyStateNum yystate)
875 {
876 return yydefact[yystate];
877 }
878
879 #define yytable_value_is_error(Yytable_value) \
880 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
881
882 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
883 * Result R means
884 * R < 0: Reduce on rule -R.
885 * R = 0: Error.
886 * R > 0: Shift to state R.
887 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
888 * of conflicting reductions.
889 */
890 static inline void
891 yygetLRActions (yyStateNum yystate, int yytoken,
892 int* yyaction, const short int** yyconflicts)
893 {
894 int yyindex = yypact[yystate] + yytoken;
895 if (yypact_value_is_default (yypact[yystate])
896 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
897 {
898 *yyaction = -yydefact[yystate];
899 *yyconflicts = yyconfl;
900 }
901 else if (! yytable_value_is_error (yytable[yyindex]))
902 {
903 *yyaction = yytable[yyindex];
904 *yyconflicts = yyconfl + yyconflp[yyindex];
905 }
906 else
907 {
908 *yyaction = 0;
909 *yyconflicts = yyconfl + yyconflp[yyindex];
910 }
911 }
912
913 static inline yyStateNum
914 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
915 {
916 int yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
917 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
918 return yytable[yyr];
919 else
920 return yydefgoto[yylhs - YYNTOKENS];
921 }
922
923 static inline yybool
924 yyisShiftAction (int yyaction)
925 {
926 return 0 < yyaction;
927 }
928
929 static inline yybool
930 yyisErrorAction (int yyaction)
931 {
932 return yyaction == 0;
933 }
934
935 /* GLRStates */
936
937 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
938 * if YYISSTATE, and otherwise a semantic option. Callers should call
939 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
940 * headroom. */
941
942 static inline yyGLRStackItem*
943 yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
944 {
945 yyGLRStackItem* yynewItem = yystackp->yynextFree;
946 yystackp->yyspaceLeft -= 1;
947 yystackp->yynextFree += 1;
948 yynewItem->yystate.yyisState = yyisState;
949 return yynewItem;
950 }
951
952 /** Add a new semantic action that will execute the action for rule
953 * YYRULE on the semantic values in YYRHS to the list of
954 * alternative actions for YYSTATE. Assumes that YYRHS comes from
955 * stack #YYK of *YYSTACKP. */
956 static void
957 yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
958 yyGLRState* yyrhs, yyRuleNum yyrule)
959 {
960 yySemanticOption* yynewOption =
961 &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
962 YYASSERT (!yynewOption->yyisState);
963 yynewOption->yystate = yyrhs;
964 yynewOption->yyrule = yyrule;
965 if (yystackp->yytops.yylookaheadNeeds[yyk])
966 {
967 yynewOption->yyrawchar = yychar;
968 yynewOption->yyval = yylval;]b4_locations_if([
969 yynewOption->yyloc = yylloc;])[
970 }
971 else
972 yynewOption->yyrawchar = YYEMPTY;
973 yynewOption->yynext = yystate->yysemantics.yyfirstVal;
974 yystate->yysemantics.yyfirstVal = yynewOption;
975
976 YY_RESERVE_GLRSTACK (yystackp);
977 }
978
979 /* GLRStacks */
980
981 /** Initialize YYSET to a singleton set containing an empty stack. */
982 static yybool
983 yyinitStateSet (yyGLRStateSet* yyset)
984 {
985 yyset->yysize = 1;
986 yyset->yycapacity = 16;
987 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
988 if (! yyset->yystates)
989 return yyfalse;
990 yyset->yystates[0] = YY_NULLPTR;
991 yyset->yylookaheadNeeds =
992 (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
993 if (! yyset->yylookaheadNeeds)
994 {
995 YYFREE (yyset->yystates);
996 return yyfalse;
997 }
998 return yytrue;
999 }
1000
1001 static void yyfreeStateSet (yyGLRStateSet* yyset)
1002 {
1003 YYFREE (yyset->yystates);
1004 YYFREE (yyset->yylookaheadNeeds);
1005 }
1006
1007 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1008 * capacity for all stacks of YYSIZE. */
1009 static yybool
1010 yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
1011 {
1012 yystackp->yyerrState = 0;
1013 yynerrs = 0;
1014 yystackp->yyspaceLeft = yysize;
1015 yystackp->yyitems =
1016 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
1017 if (!yystackp->yyitems)
1018 return yyfalse;
1019 yystackp->yynextFree = yystackp->yyitems;
1020 yystackp->yysplitPoint = YY_NULLPTR;
1021 yystackp->yylastDeleted = YY_NULLPTR;
1022 return yyinitStateSet (&yystackp->yytops);
1023 }
1024
1025
1026 #if YYSTACKEXPANDABLE
1027 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1028 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1029
1030 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1031 stack from outside should be considered invalid after this call.
1032 We always expand when there are 1 or fewer items left AFTER an
1033 allocation, so that we can avoid having external pointers exist
1034 across an allocation. */
1035 static void
1036 yyexpandGLRStack (yyGLRStack* yystackp)
1037 {
1038 yyGLRStackItem* yynewItems;
1039 yyGLRStackItem* yyp0, *yyp1;
1040 size_t yynewSize;
1041 size_t yyn;
1042 size_t yysize = yystackp->yynextFree - yystackp->yyitems;
1043 if (YYMAXDEPTH - YYHEADROOM < yysize)
1044 yyMemoryExhausted (yystackp);
1045 yynewSize = 2*yysize;
1046 if (YYMAXDEPTH < yynewSize)
1047 yynewSize = YYMAXDEPTH;
1048 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1049 if (! yynewItems)
1050 yyMemoryExhausted (yystackp);
1051 for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
1052 0 < yyn;
1053 yyn -= 1, yyp0 += 1, yyp1 += 1)
1054 {
1055 *yyp1 = *yyp0;
1056 if (*(yybool *) yyp0)
1057 {
1058 yyGLRState* yys0 = &yyp0->yystate;
1059 yyGLRState* yys1 = &yyp1->yystate;
1060 if (yys0->yypred != YY_NULLPTR)
1061 yys1->yypred =
1062 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
1063 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULLPTR)
1064 yys1->yysemantics.yyfirstVal =
1065 YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
1066 }
1067 else
1068 {
1069 yySemanticOption* yyv0 = &yyp0->yyoption;
1070 yySemanticOption* yyv1 = &yyp1->yyoption;
1071 if (yyv0->yystate != YY_NULLPTR)
1072 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
1073 if (yyv0->yynext != YY_NULLPTR)
1074 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1075 }
1076 }
1077 if (yystackp->yysplitPoint != YY_NULLPTR)
1078 yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
1079 yystackp->yysplitPoint, yystate);
1080
1081 for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
1082 if (yystackp->yytops.yystates[yyn] != YY_NULLPTR)
1083 yystackp->yytops.yystates[yyn] =
1084 YYRELOC (yystackp->yyitems, yynewItems,
1085 yystackp->yytops.yystates[yyn], yystate);
1086 YYFREE (yystackp->yyitems);
1087 yystackp->yyitems = yynewItems;
1088 yystackp->yynextFree = yynewItems + yysize;
1089 yystackp->yyspaceLeft = yynewSize - yysize;
1090 }
1091 #endif
1092
1093 static void
1094 yyfreeGLRStack (yyGLRStack* yystackp)
1095 {
1096 YYFREE (yystackp->yyitems);
1097 yyfreeStateSet (&yystackp->yytops);
1098 }
1099
1100 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1101 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1102 * YYS. */
1103 static inline void
1104 yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
1105 {
1106 if (yystackp->yysplitPoint != YY_NULLPTR && yystackp->yysplitPoint > yys)
1107 yystackp->yysplitPoint = yys;
1108 }
1109
1110 /** Invalidate stack #YYK in *YYSTACKP. */
1111 static inline void
1112 yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
1113 {
1114 if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
1115 yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
1116 yystackp->yytops.yystates[yyk] = YY_NULLPTR;
1117 }
1118
1119 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1120 only be done once after a deletion, and only when all other stacks have
1121 been deleted. */
1122 static void
1123 yyundeleteLastStack (yyGLRStack* yystackp)
1124 {
1125 if (yystackp->yylastDeleted == YY_NULLPTR || yystackp->yytops.yysize != 0)
1126 return;
1127 yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
1128 yystackp->yytops.yysize = 1;
1129 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
1130 yystackp->yylastDeleted = YY_NULLPTR;
1131 }
1132
1133 static inline void
1134 yyremoveDeletes (yyGLRStack* yystackp)
1135 {
1136 size_t yyi, yyj;
1137 yyi = yyj = 0;
1138 while (yyj < yystackp->yytops.yysize)
1139 {
1140 if (yystackp->yytops.yystates[yyi] == YY_NULLPTR)
1141 {
1142 if (yyi == yyj)
1143 {
1144 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1145 }
1146 yystackp->yytops.yysize -= 1;
1147 }
1148 else
1149 {
1150 yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
1151 /* In the current implementation, it's unnecessary to copy
1152 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1153 yyremoveDeletes returns, the parser immediately either enters
1154 deterministic operation or shifts a token. However, it doesn't
1155 hurt, and the code might evolve to need it. */
1156 yystackp->yytops.yylookaheadNeeds[yyj] =
1157 yystackp->yytops.yylookaheadNeeds[yyi];
1158 if (yyj != yyi)
1159 {
1160 YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
1161 (unsigned long int) yyi, (unsigned long int) yyj));
1162 }
1163 yyj += 1;
1164 }
1165 yyi += 1;
1166 }
1167 }
1168
1169 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1170 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1171 * value *YYVALP and source location *YYLOCP. */
1172 static inline void
1173 yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1174 size_t yyposn,
1175 YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
1176 {
1177 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1178
1179 yynewState->yylrState = yylrState;
1180 yynewState->yyposn = yyposn;
1181 yynewState->yyresolved = yytrue;
1182 yynewState->yypred = yystackp->yytops.yystates[yyk];
1183 yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
1184 yynewState->yyloc = *yylocp;])[
1185 yystackp->yytops.yystates[yyk] = yynewState;
1186
1187 YY_RESERVE_GLRSTACK (yystackp);
1188 }
1189
1190 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1191 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1192 * semantic value of YYRHS under the action for YYRULE. */
1193 static inline void
1194 yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1195 size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
1196 {
1197 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1198 YYASSERT (yynewState->yyisState);
1199
1200 yynewState->yylrState = yylrState;
1201 yynewState->yyposn = yyposn;
1202 yynewState->yyresolved = yyfalse;
1203 yynewState->yypred = yystackp->yytops.yystates[yyk];
1204 yynewState->yysemantics.yyfirstVal = YY_NULLPTR;
1205 yystackp->yytops.yystates[yyk] = yynewState;
1206
1207 /* Invokes YY_RESERVE_GLRSTACK. */
1208 yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
1209 }
1210
1211 #if !]b4_api_PREFIX[DEBUG
1212 # define YY_REDUCE_PRINT(Args)
1213 #else
1214 # define YY_REDUCE_PRINT(Args) \
1215 do { \
1216 if (yydebug) \
1217 yy_reduce_print Args; \
1218 } while (0)
1219
1220 /*----------------------------------------------------------------------.
1221 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1222 `----------------------------------------------------------------------*/
1223
1224 static inline void
1225 yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
1226 yyRuleNum yyrule]b4_user_formals[)
1227 {
1228 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1229 int yylow = 1;])[
1230 int yyi;
1231 YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
1232 (unsigned long int) yyk, yyrule - 1,
1233 (unsigned long int) yyrline[yyrule]);
1234 if (! yynormal)
1235 yyfillin (yyvsp, 1, -yynrhs);
1236 /* The symbols being reduced. */
1237 for (yyi = 0; yyi < yynrhs; yyi++)
1238 {
1239 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1240 yy_symbol_print (stderr,
1241 yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
1242 &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval
1243 ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
1244 b4_user_args[);
1245 if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
1246 YYFPRINTF (stderr, " (unresolved)");
1247 YYFPRINTF (stderr, "\n");
1248 }
1249 }
1250 #endif
1251
1252 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1253 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1254 * semantic values. Assumes that all ambiguities in semantic values
1255 * have been previously resolved. Set *YYVALP to the resulting value,
1256 * and *YYLOCP to the computed location (if any). Return value is as
1257 * for userAction. */
1258 static inline YYRESULTTAG
1259 yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1260 YYSTYPE* yyvalp]b4_locuser_formals[)
1261 {
1262 int yynrhs = yyrhsLength (yyrule);
1263
1264 if (yystackp->yysplitPoint == YY_NULLPTR)
1265 {
1266 /* Standard special case: single stack. */
1267 yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1268 YYASSERT (yyk == 0);
1269 yystackp->yynextFree -= yynrhs;
1270 yystackp->yyspaceLeft += yynrhs;
1271 yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
1272 YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[));
1273 return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
1274 yyvalp]b4_locuser_args[);
1275 }
1276 else
1277 {
1278 int yyi;
1279 yyGLRState* yys;
1280 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1281 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
1282 = yystackp->yytops.yystates[yyk];]b4_locations_if([[
1283 if (yynrhs == 0)
1284 /* Set default location. */
1285 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
1286 for (yyi = 0; yyi < yynrhs; yyi += 1)
1287 {
1288 yys = yys->yypred;
1289 YYASSERT (yys);
1290 }
1291 yyupdateSplit (yystackp, yys);
1292 yystackp->yytops.yystates[yyk] = yys;
1293 YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
1294 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1295 yystackp, yyvalp]b4_locuser_args[);
1296 }
1297 }
1298
1299 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1300 * and push back on the resulting nonterminal symbol. Perform the
1301 * semantic action associated with YYRULE and store its value with the
1302 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1303 * unambiguous. Otherwise, store the deferred semantic action with
1304 * the new state. If the new state would have an identical input
1305 * position, LR state, and predecessor to an existing state on the stack,
1306 * it is identified with that existing state, eliminating stack #YYK from
1307 * *YYSTACKP. In this case, the semantic value is
1308 * added to the options for the existing state's semantic value.
1309 */
1310 static inline YYRESULTTAG
1311 yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1312 yybool yyforceEval]b4_user_formals[)
1313 {
1314 size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
1315
1316 if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR)
1317 {
1318 YYSTYPE yysval;]b4_locations_if([[
1319 YYLTYPE yyloc;]])[
1320
1321 YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[);
1322 if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR)
1323 {
1324 YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
1325 (unsigned long int) yyk, yyrule - 1));
1326 }
1327 if (yyflag != yyok)
1328 return yyflag;
1329 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
1330 yyglrShift (yystackp, yyk,
1331 yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
1332 yylhsNonterm (yyrule)),
1333 yyposn, &yysval]b4_locations_if([, &yyloc])[);
1334 }
1335 else
1336 {
1337 size_t yyi;
1338 int yyn;
1339 yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
1340 yyStateNum yynewLRState;
1341
1342 for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1343 0 < yyn; yyn -= 1)
1344 {
1345 yys = yys->yypred;
1346 YYASSERT (yys);
1347 }
1348 yyupdateSplit (yystackp, yys);
1349 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1350 YYDPRINTF ((stderr,
1351 "Reduced stack %lu by rule #%d; action deferred. "
1352 "Now in state %d.\n",
1353 (unsigned long int) yyk, yyrule - 1, yynewLRState));
1354 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
1355 if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
1356 {
1357 yyGLRState *yysplit = yystackp->yysplitPoint;
1358 yyGLRState *yyp = yystackp->yytops.yystates[yyi];
1359 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1360 {
1361 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1362 {
1363 yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
1364 yymarkStackDeleted (yystackp, yyk);
1365 YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
1366 (unsigned long int) yyk,
1367 (unsigned long int) yyi));
1368 return yyok;
1369 }
1370 yyp = yyp->yypred;
1371 }
1372 }
1373 yystackp->yytops.yystates[yyk] = yys;
1374 yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
1375 }
1376 return yyok;
1377 }
1378
1379 static size_t
1380 yysplitStack (yyGLRStack* yystackp, size_t yyk)
1381 {
1382 if (yystackp->yysplitPoint == YY_NULLPTR)
1383 {
1384 YYASSERT (yyk == 0);
1385 yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
1386 }
1387 if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
1388 {
1389 yyGLRState** yynewStates;
1390 yybool* yynewLookaheadNeeds;
1391
1392 yynewStates = YY_NULLPTR;
1393
1394 if (yystackp->yytops.yycapacity
1395 > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1396 yyMemoryExhausted (yystackp);
1397 yystackp->yytops.yycapacity *= 2;
1398
1399 yynewStates =
1400 (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
1401 (yystackp->yytops.yycapacity
1402 * sizeof yynewStates[0]));
1403 if (yynewStates == YY_NULLPTR)
1404 yyMemoryExhausted (yystackp);
1405 yystackp->yytops.yystates = yynewStates;
1406
1407 yynewLookaheadNeeds =
1408 (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
1409 (yystackp->yytops.yycapacity
1410 * sizeof yynewLookaheadNeeds[0]));
1411 if (yynewLookaheadNeeds == YY_NULLPTR)
1412 yyMemoryExhausted (yystackp);
1413 yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
1414 }
1415 yystackp->yytops.yystates[yystackp->yytops.yysize]
1416 = yystackp->yytops.yystates[yyk];
1417 yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
1418 = yystackp->yytops.yylookaheadNeeds[yyk];
1419 yystackp->yytops.yysize += 1;
1420 return yystackp->yytops.yysize-1;
1421 }
1422
1423 /** True iff YYY0 and YYY1 represent identical options at the top level.
1424 * That is, they represent the same rule applied to RHS symbols
1425 * that produce the same terminal symbols. */
1426 static yybool
1427 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1428 {
1429 if (yyy0->yyrule == yyy1->yyrule)
1430 {
1431 yyGLRState *yys0, *yys1;
1432 int yyn;
1433 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1434 yyn = yyrhsLength (yyy0->yyrule);
1435 yyn > 0;
1436 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1437 if (yys0->yyposn != yys1->yyposn)
1438 return yyfalse;
1439 return yytrue;
1440 }
1441 else
1442 return yyfalse;
1443 }
1444
1445 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1446 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1447 static void
1448 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1449 {
1450 yyGLRState *yys0, *yys1;
1451 int yyn;
1452 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1453 yyn = yyrhsLength (yyy0->yyrule);
1454 yyn > 0;
1455 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1456 {
1457 if (yys0 == yys1)
1458 break;
1459 else if (yys0->yyresolved)
1460 {
1461 yys1->yyresolved = yytrue;
1462 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1463 }
1464 else if (yys1->yyresolved)
1465 {
1466 yys0->yyresolved = yytrue;
1467 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1468 }
1469 else
1470 {
1471 yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
1472 yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
1473 while (yytrue)
1474 {
1475 if (yyz1 == *yyz0p || yyz1 == YY_NULLPTR)
1476 break;
1477 else if (*yyz0p == YY_NULLPTR)
1478 {
1479 *yyz0p = yyz1;
1480 break;
1481 }
1482 else if (*yyz0p < yyz1)
1483 {
1484 yySemanticOption* yyz = *yyz0p;
1485 *yyz0p = yyz1;
1486 yyz1 = yyz1->yynext;
1487 (*yyz0p)->yynext = yyz;
1488 }
1489 yyz0p = &(*yyz0p)->yynext;
1490 }
1491 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
1492 }
1493 }
1494 }
1495
1496 /** Y0 and Y1 represent two possible actions to take in a given
1497 * parsing state; return 0 if no combination is possible,
1498 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1499 static int
1500 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1501 {
1502 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1503 int p0 = yydprec[r0], p1 = yydprec[r1];
1504
1505 if (p0 == p1)
1506 {
1507 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1508 return 0;
1509 else
1510 return 1;
1511 }
1512 if (p0 == 0 || p1 == 0)
1513 return 0;
1514 if (p0 < p1)
1515 return 3;
1516 if (p1 < p0)
1517 return 2;
1518 return 0;
1519 }
1520
1521 static YYRESULTTAG yyresolveValue (yyGLRState* yys,
1522 yyGLRStack* yystackp]b4_user_formals[);
1523
1524
1525 /** Resolve the previous YYN states starting at and including state YYS
1526 * on *YYSTACKP. If result != yyok, some states may have been left
1527 * unresolved possibly with empty semantic option chains. Regardless
1528 * of whether result = yyok, each state has been left with consistent
1529 * data so that yydestroyGLRState can be invoked if necessary. */
1530 static YYRESULTTAG
1531 yyresolveStates (yyGLRState* yys, int yyn,
1532 yyGLRStack* yystackp]b4_user_formals[)
1533 {
1534 if (0 < yyn)
1535 {
1536 YYASSERT (yys->yypred);
1537 YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
1538 if (! yys->yyresolved)
1539 YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
1540 }
1541 return yyok;
1542 }
1543
1544 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1545 * user action, and return the semantic value and location in *YYVALP
1546 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1547 * have been destroyed (assuming the user action destroys all RHS
1548 * semantic values if invoked). */
1549 static YYRESULTTAG
1550 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
1551 YYSTYPE* yyvalp]b4_locuser_formals[)
1552 {
1553 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1554 int yynrhs = yyrhsLength (yyopt->yyrule);
1555 YYRESULTTAG yyflag =
1556 yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
1557 if (yyflag != yyok)
1558 {
1559 yyGLRState *yys;
1560 for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
1561 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
1562 return yyflag;
1563 }
1564
1565 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[
1566 if (yynrhs == 0)
1567 /* Set default location. */
1568 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
1569 {
1570 int yychar_current = yychar;
1571 YYSTYPE yylval_current = yylval;]b4_locations_if([
1572 YYLTYPE yylloc_current = yylloc;])[
1573 yychar = yyopt->yyrawchar;
1574 yylval = yyopt->yyval;]b4_locations_if([
1575 yylloc = yyopt->yyloc;])[
1576 yyflag = yyuserAction (yyopt->yyrule, yynrhs,
1577 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1578 yystackp, yyvalp]b4_locuser_args[);
1579 yychar = yychar_current;
1580 yylval = yylval_current;]b4_locations_if([
1581 yylloc = yylloc_current;])[
1582 }
1583 return yyflag;
1584 }
1585
1586 #if ]b4_api_PREFIX[DEBUG
1587 static void
1588 yyreportTree (yySemanticOption* yyx, int yyindent)
1589 {
1590 int yynrhs = yyrhsLength (yyx->yyrule);
1591 int yyi;
1592 yyGLRState* yys;
1593 yyGLRState* yystates[1 + YYMAXRHS];
1594 yyGLRState yyleftmost_state;
1595
1596 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1597 yystates[yyi] = yys;
1598 if (yys == YY_NULLPTR)
1599 {
1600 yyleftmost_state.yyposn = 0;
1601 yystates[0] = &yyleftmost_state;
1602 }
1603 else
1604 yystates[0] = yys;
1605
1606 if (yyx->yystate->yyposn < yys->yyposn + 1)
1607 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1608 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1609 yyx->yyrule - 1);
1610 else
1611 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1612 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1613 yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
1614 (unsigned long int) yyx->yystate->yyposn);
1615 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1616 {
1617 if (yystates[yyi]->yyresolved)
1618 {
1619 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1620 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1621 yytokenName (yystos[yystates[yyi]->yylrState]));
1622 else
1623 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
1624 yytokenName (yystos[yystates[yyi]->yylrState]),
1625 (unsigned long int) (yystates[yyi-1]->yyposn + 1),
1626 (unsigned long int) yystates[yyi]->yyposn);
1627 }
1628 else
1629 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1630 }
1631 }
1632 #endif
1633
1634 static YYRESULTTAG
1635 yyreportAmbiguity (yySemanticOption* yyx0,
1636 yySemanticOption* yyx1]b4_pure_formals[)
1637 {
1638 YYUSE (yyx0);
1639 YYUSE (yyx1);
1640
1641 #if ]b4_api_PREFIX[DEBUG
1642 YYFPRINTF (stderr, "Ambiguity detected.\n");
1643 YYFPRINTF (stderr, "Option 1,\n");
1644 yyreportTree (yyx0, 2);
1645 YYFPRINTF (stderr, "\nOption 2,\n");
1646 yyreportTree (yyx1, 2);
1647 YYFPRINTF (stderr, "\n");
1648 #endif
1649
1650 yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
1651 return yyabort;
1652 }]b4_locations_if([[
1653
1654 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1655 * ending at YYS1. Has no effect on previously resolved states.
1656 * The first semantic option of a state is always chosen. */
1657 static void
1658 yyresolveLocations (yyGLRState* yys1, int yyn1,
1659 yyGLRStack *yystackp]b4_user_formals[)
1660 {
1661 if (0 < yyn1)
1662 {
1663 yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
1664 if (!yys1->yyresolved)
1665 {
1666 yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
1667 int yynrhs;
1668 yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
1669 YYASSERT (yyoption != YY_NULLPTR);
1670 yynrhs = yyrhsLength (yyoption->yyrule);
1671 if (yynrhs > 0)
1672 {
1673 yyGLRState *yys;
1674 int yyn;
1675 yyresolveLocations (yyoption->yystate, yynrhs,
1676 yystackp]b4_user_args[);
1677 for (yys = yyoption->yystate, yyn = yynrhs;
1678 yyn > 0;
1679 yys = yys->yypred, yyn -= 1)
1680 yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
1681 }
1682 else
1683 {
1684 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1685 in reverse rightmost order. It is only necessary to invoke
1686 yyresolveLocations on a subforest for which yyresolveAction
1687 would have been invoked next had an ambiguity not been
1688 detected. Thus the location of the previous state (but not
1689 necessarily the previous state itself) is guaranteed to be
1690 resolved already. */
1691 yyGLRState *yyprevious = yyoption->yystate;
1692 yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
1693 }
1694 {
1695 int yychar_current = yychar;
1696 YYSTYPE yylval_current = yylval;
1697 YYLTYPE yylloc_current = yylloc;
1698 yychar = yyoption->yyrawchar;
1699 yylval = yyoption->yyval;
1700 yylloc = yyoption->yyloc;
1701 YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
1702 yychar = yychar_current;
1703 yylval = yylval_current;
1704 yylloc = yylloc_current;
1705 }
1706 }
1707 }
1708 }]])[
1709
1710 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1711 * perform the indicated actions, and set the semantic value of YYS.
1712 * If result != yyok, the chain of semantic options in YYS has been
1713 * cleared instead or it has been left unmodified except that
1714 * redundant options may have been removed. Regardless of whether
1715 * result = yyok, YYS has been left with consistent data so that
1716 * yydestroyGLRState can be invoked if necessary. */
1717 static YYRESULTTAG
1718 yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
1719 {
1720 yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
1721 yySemanticOption* yybest = yyoptionList;
1722 yySemanticOption** yypp;
1723 yybool yymerge = yyfalse;
1724 YYSTYPE yysval;
1725 YYRESULTTAG yyflag;]b4_locations_if([
1726 YYLTYPE *yylocp = &yys->yyloc;])[
1727
1728 for (yypp = &yyoptionList->yynext; *yypp != YY_NULLPTR; )
1729 {
1730 yySemanticOption* yyp = *yypp;
1731
1732 if (yyidenticalOptions (yybest, yyp))
1733 {
1734 yymergeOptionSets (yybest, yyp);
1735 *yypp = yyp->yynext;
1736 }
1737 else
1738 {
1739 switch (yypreference (yybest, yyp))
1740 {
1741 case 0:]b4_locations_if([[
1742 yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[
1743 return yyreportAmbiguity (yybest, yyp]b4_pure_args[);
1744 break;
1745 case 1:
1746 yymerge = yytrue;
1747 break;
1748 case 2:
1749 break;
1750 case 3:
1751 yybest = yyp;
1752 yymerge = yyfalse;
1753 break;
1754 default:
1755 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1756 but some compilers complain if the default case is
1757 omitted. */
1758 break;
1759 }
1760 yypp = &yyp->yynext;
1761 }
1762 }
1763
1764 if (yymerge)
1765 {
1766 yySemanticOption* yyp;
1767 int yyprec = yydprec[yybest->yyrule];
1768 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
1769 if (yyflag == yyok)
1770 for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext)
1771 {
1772 if (yyprec == yydprec[yyp->yyrule])
1773 {
1774 YYSTYPE yysval_other;]b4_locations_if([
1775 YYLTYPE yydummy;])[
1776 yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
1777 if (yyflag != yyok)
1778 {
1779 yydestruct ("Cleanup: discarding incompletely merged value for",
1780 yystos[yys->yylrState],
1781 &yysval]b4_locuser_args[);
1782 break;
1783 }
1784 yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
1785 }
1786 }
1787 }
1788 else
1789 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
1790
1791 if (yyflag == yyok)
1792 {
1793 yys->yyresolved = yytrue;
1794 yys->yysemantics.yysval = yysval;
1795 }
1796 else
1797 yys->yysemantics.yyfirstVal = YY_NULLPTR;
1798 return yyflag;
1799 }
1800
1801 static YYRESULTTAG
1802 yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
1803 {
1804 if (yystackp->yysplitPoint != YY_NULLPTR)
1805 {
1806 yyGLRState* yys;
1807 int yyn;
1808
1809 for (yyn = 0, yys = yystackp->yytops.yystates[0];
1810 yys != yystackp->yysplitPoint;
1811 yys = yys->yypred, yyn += 1)
1812 continue;
1813 YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
1814 ]b4_user_args[));
1815 }
1816 return yyok;
1817 }
1818
1819 static void
1820 yycompressStack (yyGLRStack* yystackp)
1821 {
1822 yyGLRState* yyp, *yyq, *yyr;
1823
1824 if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR)
1825 return;
1826
1827 for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR;
1828 yyp != yystackp->yysplitPoint;
1829 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1830 yyp->yypred = yyr;
1831
1832 yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
1833 yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
1834 yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
1835 yystackp->yysplitPoint = YY_NULLPTR;
1836 yystackp->yylastDeleted = YY_NULLPTR;
1837
1838 while (yyr != YY_NULLPTR)
1839 {
1840 yystackp->yynextFree->yystate = *yyr;
1841 yyr = yyr->yypred;
1842 yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
1843 yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
1844 yystackp->yynextFree += 1;
1845 yystackp->yyspaceLeft -= 1;
1846 }
1847 }
1848
1849 static YYRESULTTAG
1850 yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
1851 size_t yyposn]b4_pure_formals[)
1852 {
1853 while (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
1854 {
1855 yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
1856 YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
1857 (unsigned long int) yyk, yystate));
1858
1859 YYASSERT (yystate != YYFINAL);
1860
1861 if (yyisDefaultedState (yystate))
1862 {
1863 YYRESULTTAG yyflag;
1864 yyRuleNum yyrule = yydefaultAction (yystate);
1865 if (yyrule == 0)
1866 {
1867 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1868 (unsigned long int) yyk));
1869 yymarkStackDeleted (yystackp, yyk);
1870 return yyok;
1871 }
1872 yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[);
1873 if (yyflag == yyerr)
1874 {
1875 YYDPRINTF ((stderr,
1876 "Stack %lu dies "
1877 "(predicate failure or explicit user error).\n",
1878 (unsigned long int) yyk));
1879 yymarkStackDeleted (yystackp, yyk);
1880 return yyok;
1881 }
1882 if (yyflag != yyok)
1883 return yyflag;
1884 }
1885 else
1886 {
1887 yySymbol yytoken;
1888 int yyaction;
1889 const short int* yyconflicts;
1890
1891 yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
1892 if (yychar == YYEMPTY)
1893 {
1894 YYDPRINTF ((stderr, "Reading a token: "));
1895 yychar = ]b4_lex[;
1896 }
1897
1898 if (yychar <= YYEOF)
1899 {
1900 yychar = yytoken = YYEOF;
1901 YYDPRINTF ((stderr, "Now at end of input.\n"));
1902 }
1903 else
1904 {
1905 yytoken = YYTRANSLATE (yychar);
1906 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1907 }
1908
1909 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
1910
1911 while (*yyconflicts != 0)
1912 {
1913 YYRESULTTAG yyflag;
1914 size_t yynewStack = yysplitStack (yystackp, yyk);
1915 YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
1916 (unsigned long int) yynewStack,
1917 (unsigned long int) yyk));
1918 yyflag = yyglrReduce (yystackp, yynewStack,
1919 *yyconflicts,
1920 yyimmediate[*yyconflicts]]b4_user_args[);
1921 if (yyflag == yyok)
1922 YYCHK (yyprocessOneStack (yystackp, yynewStack,
1923 yyposn]b4_pure_args[));
1924 else if (yyflag == yyerr)
1925 {
1926 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1927 (unsigned long int) yynewStack));
1928 yymarkStackDeleted (yystackp, yynewStack);
1929 }
1930 else
1931 return yyflag;
1932 yyconflicts += 1;
1933 }
1934
1935 if (yyisShiftAction (yyaction))
1936 break;
1937 else if (yyisErrorAction (yyaction))
1938 {
1939 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1940 (unsigned long int) yyk));
1941 yymarkStackDeleted (yystackp, yyk);
1942 break;
1943 }
1944 else
1945 {
1946 YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction,
1947 yyimmediate[-yyaction]]b4_user_args[);
1948 if (yyflag == yyerr)
1949 {
1950 YYDPRINTF ((stderr,
1951 "Stack %lu dies "
1952 "(predicate failure or explicit user error).\n",
1953 (unsigned long int) yyk));
1954 yymarkStackDeleted (yystackp, yyk);
1955 break;
1956 }
1957 else if (yyflag != yyok)
1958 return yyflag;
1959 }
1960 }
1961 }
1962 return yyok;
1963 }
1964
1965 static void
1966 yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
1967 {
1968 if (yystackp->yyerrState != 0)
1969 return;
1970 #if ! YYERROR_VERBOSE
1971 yyerror (]b4_lyyerror_args[YY_("syntax error"));
1972 #else
1973 {
1974 yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1975 size_t yysize0 = yytnamerr (YY_NULLPTR, yytokenName (yytoken));
1976 size_t yysize = yysize0;
1977 yybool yysize_overflow = yyfalse;
1978 char* yymsg = YY_NULLPTR;
1979 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1980 /* Internationalized format string. */
1981 const char *yyformat = YY_NULLPTR;
1982 /* Arguments of yyformat. */
1983 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1984 /* Number of reported tokens (one for the "unexpected", one per
1985 "expected"). */
1986 int yycount = 0;
1987
1988 /* There are many possibilities here to consider:
1989 - If this state is a consistent state with a default action, then
1990 the only way this function was invoked is if the default action
1991 is an error action. In that case, don't check for expected
1992 tokens because there are none.
1993 - The only way there can be no lookahead present (in yychar) is if
1994 this state is a consistent state with a default action. Thus,
1995 detecting the absence of a lookahead is sufficient to determine
1996 that there is no unexpected or expected token to report. In that
1997 case, just report a simple "syntax error".
1998 - Don't assume there isn't a lookahead just because this state is a
1999 consistent state with a default action. There might have been a
2000 previous inconsistent state, consistent state with a non-default
2001 action, or user semantic action that manipulated yychar.
2002 - Of course, the expected token list depends on states to have
2003 correct lookahead information, and it depends on the parser not
2004 to perform extra reductions after fetching a lookahead from the
2005 scanner and before detecting a syntax error. Thus, state merging
2006 (from LALR or IELR) and default reductions corrupt the expected
2007 token list. However, the list is correct for canonical LR with
2008 one exception: it will still contain any token that will not be
2009 accepted due to an error action in a later state.
2010 */
2011 if (yytoken != YYEMPTY)
2012 {
2013 int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
2014 yyarg[yycount++] = yytokenName (yytoken);
2015 if (!yypact_value_is_default (yyn))
2016 {
2017 /* Start YYX at -YYN if negative to avoid negative indexes in
2018 YYCHECK. In other words, skip the first -YYN actions for this
2019 state because they are default actions. */
2020 int yyxbegin = yyn < 0 ? -yyn : 0;
2021 /* Stay within bounds of both yycheck and yytname. */
2022 int yychecklim = YYLAST - yyn + 1;
2023 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2024 int yyx;
2025 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
2026 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
2027 && !yytable_value_is_error (yytable[yyx + yyn]))
2028 {
2029 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
2030 {
2031 yycount = 1;
2032 yysize = yysize0;
2033 break;
2034 }
2035 yyarg[yycount++] = yytokenName (yyx);
2036 {
2037 size_t yysz = yysize + yytnamerr (YY_NULLPTR, yytokenName (yyx));
2038 yysize_overflow |= yysz < yysize;
2039 yysize = yysz;
2040 }
2041 }
2042 }
2043 }
2044
2045 switch (yycount)
2046 {
2047 #define YYCASE_(N, S) \
2048 case N: \
2049 yyformat = S; \
2050 break
2051 YYCASE_(0, YY_("syntax error"));
2052 YYCASE_(1, YY_("syntax error, unexpected %s"));
2053 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2054 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2055 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2056 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2057 #undef YYCASE_
2058 }
2059
2060 {
2061 size_t yysz = yysize + strlen (yyformat);
2062 yysize_overflow |= yysz < yysize;
2063 yysize = yysz;
2064 }
2065
2066 if (!yysize_overflow)
2067 yymsg = (char *) YYMALLOC (yysize);
2068
2069 if (yymsg)
2070 {
2071 char *yyp = yymsg;
2072 int yyi = 0;
2073 while ((*yyp = *yyformat))
2074 {
2075 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
2076 {
2077 yyp += yytnamerr (yyp, yyarg[yyi++]);
2078 yyformat += 2;
2079 }
2080 else
2081 {
2082 yyp++;
2083 yyformat++;
2084 }
2085 }
2086 yyerror (]b4_lyyerror_args[yymsg);
2087 YYFREE (yymsg);
2088 }
2089 else
2090 {
2091 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2092 yyMemoryExhausted (yystackp);
2093 }
2094 }
2095 #endif /* YYERROR_VERBOSE */
2096 yynerrs += 1;
2097 }
2098
2099 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2100 yylval, and yylloc are the syntactic category, semantic value, and location
2101 of the lookahead. */
2102 static void
2103 yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
2104 {
2105 size_t yyk;
2106 int yyj;
2107
2108 if (yystackp->yyerrState == 3)
2109 /* We just shifted the error token and (perhaps) took some
2110 reductions. Skip tokens until we can proceed. */
2111 while (yytrue)
2112 {
2113 yySymbol yytoken;
2114 if (yychar == YYEOF)
2115 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
2116 if (yychar != YYEMPTY)
2117 {]b4_locations_if([[
2118 /* We throw away the lookahead, but the error range
2119 of the shifted error token must take it into account. */
2120 yyGLRState *yys = yystackp->yytops.yystates[0];
2121 yyGLRStackItem yyerror_range[3];
2122 yyerror_range[1].yystate.yyloc = yys->yyloc;
2123 yyerror_range[2].yystate.yyloc = yylloc;
2124 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2125 yytoken = YYTRANSLATE (yychar);
2126 yydestruct ("Error: discarding",
2127 yytoken, &yylval]b4_locuser_args([&yylloc])[);
2128 }
2129 YYDPRINTF ((stderr, "Reading a token: "));
2130 yychar = ]b4_lex[;
2131 if (yychar <= YYEOF)
2132 {
2133 yychar = yytoken = YYEOF;
2134 YYDPRINTF ((stderr, "Now at end of input.\n"));
2135 }
2136 else
2137 {
2138 yytoken = YYTRANSLATE (yychar);
2139 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2140 }
2141 yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
2142 if (yypact_value_is_default (yyj))
2143 return;
2144 yyj += yytoken;
2145 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
2146 {
2147 if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
2148 return;
2149 }
2150 else if (! yytable_value_is_error (yytable[yyj]))
2151 return;
2152 }
2153
2154 /* Reduce to one stack. */
2155 for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
2156 if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
2157 break;
2158 if (yyk >= yystackp->yytops.yysize)
2159 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
2160 for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
2161 yymarkStackDeleted (yystackp, yyk);
2162 yyremoveDeletes (yystackp);
2163 yycompressStack (yystackp);
2164
2165 /* Now pop stack until we find a state that shifts the error token. */
2166 yystackp->yyerrState = 3;
2167 while (yystackp->yytops.yystates[0] != YY_NULLPTR)
2168 {
2169 yyGLRState *yys = yystackp->yytops.yystates[0];
2170 yyj = yypact[yys->yylrState];
2171 if (! yypact_value_is_default (yyj))
2172 {
2173 yyj += YYTERROR;
2174 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2175 && yyisShiftAction (yytable[yyj]))
2176 {
2177 /* Shift the error token. */]b4_locations_if([[
2178 /* First adjust its location.*/
2179 YYLTYPE yyerrloc;
2180 yystackp->yyerror_range[2].yystate.yyloc = yylloc;
2181 YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
2182 YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
2183 &yylval, &yyerrloc);
2184 yyglrShift (yystackp, 0, yytable[yyj],
2185 yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
2186 yys = yystackp->yytops.yystates[0];
2187 break;
2188 }
2189 }]b4_locations_if([[
2190 yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
2191 if (yys->yypred != YY_NULLPTR)
2192 yydestroyGLRState ("Error: popping", yys]b4_user_args[);
2193 yystackp->yytops.yystates[0] = yys->yypred;
2194 yystackp->yynextFree -= 1;
2195 yystackp->yyspaceLeft += 1;
2196 }
2197 if (yystackp->yytops.yystates[0] == YY_NULLPTR)
2198 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
2199 }
2200
2201 #define YYCHK1(YYE) \
2202 do { \
2203 switch (YYE) { \
2204 case yyok: \
2205 break; \
2206 case yyabort: \
2207 goto yyabortlab; \
2208 case yyaccept: \
2209 goto yyacceptlab; \
2210 case yyerr: \
2211 goto yyuser_error; \
2212 default: \
2213 goto yybuglab; \
2214 } \
2215 } while (0)
2216
2217 /*----------.
2218 | yyparse. |
2219 `----------*/
2220
2221 ]b4_function_define([yyparse], [int], b4_parse_param)[
2222 {
2223 int yyresult;
2224 yyGLRStack yystack;
2225 yyGLRStack* const yystackp = &yystack;
2226 size_t yyposn;
2227
2228 YYDPRINTF ((stderr, "Starting parse\n"));
2229
2230 yychar = YYEMPTY;
2231 yylval = yyval_default;]b4_locations_if([
2232 yylloc = yyloc_default;])[
2233 ]m4_ifdef([b4_initial_action], [
2234 b4_dollar_pushdef([yylval], [], [yylloc])dnl
2235 /* User initialization code. */
2236 b4_user_initial_action
2237 b4_dollar_popdef])[]dnl
2238 [
2239 if (! yyinitGLRStack (yystackp, YYINITDEPTH))
2240 goto yyexhaustedlab;
2241 switch (YYSETJMP (yystack.yyexception_buffer))
2242 {
2243 case 0: break;
2244 case 1: goto yyabortlab;
2245 case 2: goto yyexhaustedlab;
2246 default: goto yybuglab;
2247 }
2248 yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[);
2249 yyposn = 0;
2250
2251 while (yytrue)
2252 {
2253 /* For efficiency, we have two loops, the first of which is
2254 specialized to deterministic operation (single stack, no
2255 potential ambiguity). */
2256 /* Standard mode */
2257 while (yytrue)
2258 {
2259 yyRuleNum yyrule;
2260 int yyaction;
2261 const short int* yyconflicts;
2262
2263 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
2264 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2265 if (yystate == YYFINAL)
2266 goto yyacceptlab;
2267 if (yyisDefaultedState (yystate))
2268 {
2269 yyrule = yydefaultAction (yystate);
2270 if (yyrule == 0)
2271 {
2272 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2273 yyreportSyntaxError (&yystack]b4_user_args[);
2274 goto yyuser_error;
2275 }
2276 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
2277 }
2278 else
2279 {
2280 yySymbol yytoken;
2281 if (yychar == YYEMPTY)
2282 {
2283 YYDPRINTF ((stderr, "Reading a token: "));
2284 yychar = ]b4_lex[;
2285 }
2286
2287 if (yychar <= YYEOF)
2288 {
2289 yychar = yytoken = YYEOF;
2290 YYDPRINTF ((stderr, "Now at end of input.\n"));
2291 }
2292 else
2293 {
2294 yytoken = YYTRANSLATE (yychar);
2295 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2296 }
2297
2298 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
2299 if (*yyconflicts != 0)
2300 break;
2301 if (yyisShiftAction (yyaction))
2302 {
2303 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2304 yychar = YYEMPTY;
2305 yyposn += 1;
2306 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
2307 if (0 < yystack.yyerrState)
2308 yystack.yyerrState -= 1;
2309 }
2310 else if (yyisErrorAction (yyaction))
2311 {
2312 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2313 yyreportSyntaxError (&yystack]b4_user_args[);
2314 goto yyuser_error;
2315 }
2316 else
2317 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
2318 }
2319 }
2320
2321 while (yytrue)
2322 {
2323 yySymbol yytoken_to_shift;
2324 size_t yys;
2325
2326 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2327 yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
2328
2329 /* yyprocessOneStack returns one of three things:
2330
2331 - An error flag. If the caller is yyprocessOneStack, it
2332 immediately returns as well. When the caller is finally
2333 yyparse, it jumps to an error label via YYCHK1.
2334
2335 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2336 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2337 yyparse's following invocation of yyremoveDeletes will remove
2338 the stack.
2339
2340 - yyok, when ready to shift a token.
2341
2342 Except in the first case, yyparse will invoke yyremoveDeletes and
2343 then shift the next token onto all remaining stacks. This
2344 synchronization of the shift (that is, after all preceding
2345 reductions on all stacks) helps prevent double destructor calls
2346 on yylval in the event of memory exhaustion. */
2347
2348 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2349 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
2350 yyremoveDeletes (&yystack);
2351 if (yystack.yytops.yysize == 0)
2352 {
2353 yyundeleteLastStack (&yystack);
2354 if (yystack.yytops.yysize == 0)
2355 yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
2356 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2357 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2358 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2359 yyreportSyntaxError (&yystack]b4_user_args[);
2360 goto yyuser_error;
2361 }
2362
2363 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2364 a copy of yylval will already be on stack 0 in the event of a
2365 failure in the following loop. Thus, yychar is set to YYEMPTY
2366 before the loop to make sure the user destructor for yylval isn't
2367 called twice. */
2368 yytoken_to_shift = YYTRANSLATE (yychar);
2369 yychar = YYEMPTY;
2370 yyposn += 1;
2371 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2372 {
2373 int yyaction;
2374 const short int* yyconflicts;
2375 yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
2376 yygetLRActions (yystate, yytoken_to_shift, &yyaction,
2377 &yyconflicts);
2378 /* Note that yyconflicts were handled by yyprocessOneStack. */
2379 YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
2380 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
2381 yyglrShift (&yystack, yys, yyaction, yyposn,
2382 &yylval]b4_locations_if([, &yylloc])[);
2383 YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
2384 (unsigned long int) yys,
2385 yystack.yytops.yystates[yys]->yylrState));
2386 }
2387
2388 if (yystack.yytops.yysize == 1)
2389 {
2390 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2391 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2392 yycompressStack (&yystack);
2393 break;
2394 }
2395 }
2396 continue;
2397 yyuser_error:
2398 yyrecoverSyntaxError (&yystack]b4_user_args[);
2399 yyposn = yystack.yytops.yystates[0]->yyposn;
2400 }
2401
2402 yyacceptlab:
2403 yyresult = 0;
2404 goto yyreturn;
2405
2406 yybuglab:
2407 YYASSERT (yyfalse);
2408 goto yyabortlab;
2409
2410 yyabortlab:
2411 yyresult = 1;
2412 goto yyreturn;
2413
2414 yyexhaustedlab:
2415 yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
2416 yyresult = 2;
2417 goto yyreturn;
2418
2419 yyreturn:
2420 if (yychar != YYEMPTY)
2421 yydestruct ("Cleanup: discarding lookahead",
2422 YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
2423
2424 /* If the stack is well-formed, pop the stack until it is empty,
2425 destroying its entries as we go. But free the stack regardless
2426 of whether it is well-formed. */
2427 if (yystack.yyitems)
2428 {
2429 yyGLRState** yystates = yystack.yytops.yystates;
2430 if (yystates)
2431 {
2432 size_t yysize = yystack.yytops.yysize;
2433 size_t yyk;
2434 for (yyk = 0; yyk < yysize; yyk += 1)
2435 if (yystates[yyk])
2436 {
2437 while (yystates[yyk])
2438 {
2439 yyGLRState *yys = yystates[yyk];
2440 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
2441 )[ if (yys->yypred != YY_NULLPTR)
2442 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
2443 yystates[yyk] = yys->yypred;
2444 yystack.yynextFree -= 1;
2445 yystack.yyspaceLeft += 1;
2446 }
2447 break;
2448 }
2449 }
2450 yyfreeGLRStack (&yystack);
2451 }
2452
2453 return yyresult;
2454 }
2455
2456 /* DEBUGGING ONLY */
2457 #if ]b4_api_PREFIX[DEBUG
2458 static void
2459 yy_yypstack (yyGLRState* yys)
2460 {
2461 if (yys->yypred)
2462 {
2463 yy_yypstack (yys->yypred);
2464 YYFPRINTF (stderr, " -> ");
2465 }
2466 YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
2467 (unsigned long int) yys->yyposn);
2468 }
2469
2470 static void
2471 yypstates (yyGLRState* yyst)
2472 {
2473 if (yyst == YY_NULLPTR)
2474 YYFPRINTF (stderr, "<null>");
2475 else
2476 yy_yypstack (yyst);
2477 YYFPRINTF (stderr, "\n");
2478 }
2479
2480 static void
2481 yypstack (yyGLRStack* yystackp, size_t yyk)
2482 {
2483 yypstates (yystackp->yytops.yystates[yyk]);
2484 }
2485
2486 #define YYINDEX(YYX) \
2487 ((YYX) == YY_NULLPTR ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2488
2489
2490 static void
2491 yypdumpstack (yyGLRStack* yystackp)
2492 {
2493 yyGLRStackItem* yyp;
2494 size_t yyi;
2495 for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
2496 {
2497 YYFPRINTF (stderr, "%3lu. ",
2498 (unsigned long int) (yyp - yystackp->yyitems));
2499 if (*(yybool *) yyp)
2500 {
2501 YYASSERT (yyp->yystate.yyisState);
2502 YYASSERT (yyp->yyoption.yyisState);
2503 YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2504 yyp->yystate.yyresolved, yyp->yystate.yylrState,
2505 (unsigned long int) yyp->yystate.yyposn,
2506 (long int) YYINDEX (yyp->yystate.yypred));
2507 if (! yyp->yystate.yyresolved)
2508 YYFPRINTF (stderr, ", firstVal: %ld",
2509 (long int) YYINDEX (yyp->yystate
2510 .yysemantics.yyfirstVal));
2511 }
2512 else
2513 {
2514 YYASSERT (!yyp->yystate.yyisState);
2515 YYASSERT (!yyp->yyoption.yyisState);
2516 YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
2517 yyp->yyoption.yyrule - 1,
2518 (long int) YYINDEX (yyp->yyoption.yystate),
2519 (long int) YYINDEX (yyp->yyoption.yynext));
2520 }
2521 YYFPRINTF (stderr, "\n");
2522 }
2523 YYFPRINTF (stderr, "Tops:");
2524 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
2525 YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
2526 (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
2527 YYFPRINTF (stderr, "\n");
2528 }
2529 #endif
2530
2531 #undef yylval
2532 #undef yychar
2533 #undef yynerrs]b4_locations_if([
2534 #undef yylloc])
2535
2536 m4_if(b4_prefix, [yy], [],
2537 [[/* Substitute the variable and function names. */
2538 #define yyparse ]b4_prefix[parse
2539 #define yylex ]b4_prefix[lex
2540 #define yyerror ]b4_prefix[error
2541 #define yylval ]b4_prefix[lval
2542 #define yychar ]b4_prefix[char
2543 #define yydebug ]b4_prefix[debug
2544 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
2545 #define yylloc ]b4_prefix[lloc]])])[
2546
2547 ]b4_epilogue[]dnl
2548 b4_output_end()
2549
2550 # glr.cc produces its own header.
2551 m4_if(b4_skeleton, ["glr.c"],
2552 [b4_defines_if(
2553 [b4_output_begin([b4_spec_defines_file])
2554 b4_copyright([Skeleton interface for Bison GLR parsers in C],
2555 [2002-2013])[
2556
2557 ]b4_cpp_guard_open([b4_spec_defines_file])[
2558 ]b4_shared_declarations[
2559 ]b4_cpp_guard_close([b4_spec_defines_file])[
2560 ]b4_output_end()
2561 ])])