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