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