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