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