]> git.saurik.com Git - bison.git/blame - data/glr.c
remove support for lint
[bison.git] / data / glr.c
CommitLineData
08af01c2 1 -*- C -*-
01241d47 2
fb8135fa 3# GLR skeleton for Bison
7d424de1 4
34136e65 5# Copyright (C) 2002-2012 Free Software Foundation, Inc.
fb8135fa 6
f16b0819 7# This program is free software: you can redistribute it and/or modify
fb8135fa 8# it under the terms of the GNU General Public License as published by
f16b0819 9# the Free Software Foundation, either version 3 of the License, or
fb8135fa 10# (at your option) any later version.
f16b0819 11#
fb8135fa
AD
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.
f16b0819 16#
fb8135fa 17# You should have received a copy of the GNU General Public License
f16b0819 18# along with this program. If not, see <http://www.gnu.org/licenses/>.
fb8135fa 19
66d30cd4 20
53ab797d
AD
21# If we are loaded by glr.cc, do not override c++.m4 definitions by
22# those of c.m4.
23m4_if(b4_skeleton, ["glr.c"],
24 [m4_include(b4_pkgdatadir/[c.m4])])
7eb8a0bc 25
66d30cd4
AD
26## ---------------- ##
27## Default values. ##
28## ---------------- ##
29
30# Stack parameters.
31m4_define_default([b4_stack_depth_max], [10000])
32m4_define_default([b4_stack_depth_init], [200])
33
2a8d363a
AD
34
35
36## ------------------------ ##
37## Pure/impure interfaces. ##
38## ------------------------ ##
39
d9df47b6 40b4_define_flag_if([pure])
3c9b20ff
PE
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.
d9df47b6
JD
43m4_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]])])])
2a8d363a 47
4b367315
AD
48# b4_user_formals
49# ---------------
1989d947
AD
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.
4b367315 54m4_define([b4_user_formals],
15f66669 55[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
4b367315
AD
56
57
2a8d363a
AD
58# b4_lex_param
59# ------------
21964f43
AD
60# Accumule in b4_lex_param all the yylex arguments.
61# Yes, this is quite ugly...
62m4_define([b4_lex_param],
d6cff4dc 63m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl
327afc7c 64b4_locations_if([, [[YYLTYPE *], [&yylloc]]])])dnl
21964f43
AD
65m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
66
2a8d363a 67
93724f13
AD
68# b4_yyerror_args
69# ---------------
1989d947
AD
70# Optional effective arguments passed to yyerror: user args plus yylloc, and
71# a trailing comma.
93724f13 72m4_define([b4_yyerror_args],
327afc7c 73[b4_pure_if([b4_locations_if([yylocp, ])])dnl
15f66669 74m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
93724f13
AD
75
76
77# b4_lyyerror_args
78# ----------------
742e4900 79# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
93724f13 80m4_define([b4_lyyerror_args],
327afc7c 81[b4_pure_if([b4_locations_if([&yylloc, ])])dnl
15f66669 82m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
93724f13
AD
83
84
2a8d363a
AD
85# b4_pure_args
86# ------------
1989d947 87# Same as b4_yyerror_args, but with a leading comma.
2a8d363a 88m4_define([b4_pure_args],
327afc7c 89[b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args])
2a8d363a
AD
90
91
2a8d363a
AD
92# b4_lpure_args
93# -------------
742e4900 94# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
2a8d363a 95m4_define([b4_lpure_args],
327afc7c 96[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args])
0245f82d 97
66d30cd4 98
769a8ef9 99
1989d947
AD
100# b4_pure_formals
101# ---------------
769a8ef9 102# Arguments passed to yyerror: user formals plus yylocp with leading comma.
1989d947 103m4_define([b4_pure_formals],
327afc7c 104[b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals])
1989d947
AD
105
106
769a8ef9
AD
107# b4_locuser_formals(LOC = yylocp)
108# --------------------------------
109m4_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# -----------------------------
115m4_define([b4_locuser_args],
116[b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args])
117
118
119
66d30cd4
AD
120## ----------------- ##
121## Semantic Values. ##
122## ----------------- ##
123
124
01241d47
PH
125# b4_lhs_value([TYPE])
126# --------------------
127# Expansion of $<TYPE>$.
128m4_define([b4_lhs_value],
1fa5d8bb
AD
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.
136m4_define([b4_rhs_data],
bd187d7b 137[((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate])
01241d47
PH
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.
144m4_define([b4_rhs_value],
1fa5d8bb 145[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])])
01241d47
PH
146
147
148
149## ----------- ##
150## Locations. ##
151## ----------- ##
152
01241d47
PH
153# b4_lhs_location()
154# -----------------
155# Expansion of @$.
156m4_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.
164m4_define([b4_rhs_location],
1fa5d8bb 165[(b4_rhs_data([$1], [$2]).yyloc)])
01241d47 166
5059b5c8 167
5059b5c8 168## -------------- ##
e9807a79 169## Declarations. ##
5059b5c8
AD
170## -------------- ##
171
e9807a79
AD
172# b4_shared_declarations
173# ----------------------
174# Declaration that might either go into the header (if --defines)
175# or open coded in the parser body.
5059b5c8 176m4_define([b4_shared_declarations],
56ca3d8f
AD
177[b4_declare_yydebug[
178]b4_percent_code_get([[requires]])[
6687da34 179]b4_token_enums[
c0828abf 180]b4_declare_yylstype[
15f66669 181]b4_function_declare(b4_prefix[parse], [int], b4_parse_param)[
a4e25e1d 182]b4_percent_code_get([[provides]])[]dnl
9bc0dd67 183])
5059b5c8 184
5059b5c8
AD
185
186## -------------- ##
187## Output files. ##
188## -------------- ##
189
b526ee61
AD
190# We do want M4 expansion after # for CPP macros.
191m4_changecom()
08af01c2 192m4_divert_push(0)dnl
a0d4650a 193@output(b4_parser_file_name@)@
193d7c70 194b4_copyright([Skeleton implementation for Bison GLR parsers in C],
34136e65 195 [2002-2012])
fb8135fa 196[
193d7c70 197/* C GLR parser skeleton written by Paul Hilfinger. */
01241d47 198
2a8d363a 199]b4_identification
5059b5c8 200
6e2d7b09 201b4_percent_code_get([[top]])[
4b3847c3
AD
202]m4_if(b4_api_prefix, [yy], [],
203[[/* Substitute the type names. */
9104636b
AD
204#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
205#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
6e2d7b09
AD
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]])])[
9bc0dd67 216
28427f57 217/* First part of user declarations. */
e9807a79 218]b4_user_pre_prologue[
01241d47 219
e9807a79 220]b4_null_define[
5059b5c8 221
e9807a79 222]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
28427f57 223 [b4_shared_declarations])[
5059b5c8 224
5059b5c8
AD
225/* Enabling verbose error messages. */
226#ifdef YYERROR_VERBOSE
227# undef YYERROR_VERBOSE
228# define YYERROR_VERBOSE 1
229#else
b3a2272a 230# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
5059b5c8
AD
231#endif
232
288006a2 233/* Default (constant) value used for initialization for null
f6abc26e 234 right-hand sides. Unlike the standard yacc.c template,
288006a2 235 here we set the default value of $$ to a zeroed-out value.
b9b51bf0 236 Since the default value is undefined, this behavior is
9d9b8b70 237 technically correct. */
01241d47 238static YYSTYPE yyval_default;
01241d47
PH
239
240/* Copy the second part of user declarations. */
8e0a5e9e 241]b4_user_post_prologue
a4e25e1d 242b4_percent_code_get[]dnl
01241d47 243
8e0a5e9e 244[#include <stdio.h>
63cb01d6
PE
245#include <stdlib.h>
246#include <string.h>
63cb01d6 247
30757c8c 248#ifndef YY_
ae93128c 249# if defined YYENABLE_NLS && YYENABLE_NLS
30757c8c
PE
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
2a4647a3 260/* Suppress unused-variable warnings by "using" E. */
56f8d560 261#ifdef __GNUC__
12ce2df6 262# define YYUSE(e) ((void) (e))
613d8952 263#else
12ce2df6
PE
264# define YYUSE(e) /* empty */
265#endif
266
a525b568
PE
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
63cb01d6
PE
277#define YYSIZEMAX ((size_t) -1)
278
f7c398aa
PE
279#ifdef __cplusplus
280 typedef bool yybool;
281#else
282 typedef unsigned char yybool;
01241d47 283#endif
f7c398aa
PE
284#define yytrue 1
285#define yyfalse 0
01241d47 286
c89b4c03
PE
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
1154cced
AD
294/*-----------------.
295| GCC extensions. |
296`-----------------*/
297
298#ifndef __attribute__
299/* This feature is available in gcc versions 2.5 and later. */
02650b7f 300# if (! defined __GNUC__ || __GNUC__ < 2 \
ef51bfa7 301 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
1154cced
AD
302# define __attribute__(Spec) /* empty */
303# endif
304#endif
305
327afc7c 306]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
3bc00d6c
PE
307#ifdef __cplusplus
308# define YYOPTIONAL_LOC(Name) /* empty */
309#else
310# define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
311#endif])[
312
64c4fd52
PE
313#ifndef YYASSERT
314# define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
315#endif
316
9d9b8b70 317/* YYFINAL -- State number of the termination state. */
7db2ed2d 318#define YYFINAL ]b4_final_state_number[
39912f52 319/* YYLAST -- Last index in YYTABLE. */
01241d47
PH
320#define YYLAST ]b4_last[
321
9d9b8b70 322/* YYNTOKENS -- Number of terminals. */
7db2ed2d 323#define YYNTOKENS ]b4_tokens_number[
9d9b8b70 324/* YYNNTS -- Number of nonterminals. */
7db2ed2d 325#define YYNNTS ]b4_nterms_number[
9d9b8b70 326/* YYNRULES -- Number of rules. */
7db2ed2d 327#define YYNRULES ]b4_rules_number[
9d9b8b70 328/* YYNRULES -- Number of states. */
7db2ed2d 329#define YYNSTATES ]b4_states_number[
9d9b8b70 330/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
01241d47 331#define YYMAXRHS ]b4_r2_max[
25005f6a 332/* YYMAXLEFT -- Maximum number of symbols to the left of a handle
9d9b8b70 333 accessed by $0, $-1, etc., in any rule. */
25005f6a 334#define YYMAXLEFT ]b4_max_left_semantic_context[
01241d47
PH
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
e9690142 340#define YYTRANSLATE(YYX) \
cf806753 341 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
01241d47
PH
342
343/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
a762e609 344static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
01241d47
PH
345{
346 ]b4_translate[
347};
348
5f108727 349#if ]b4_api_PREFIX[DEBUG
01241d47 350/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
a762e609 351static const ]b4_int_type_for([b4_rline])[ yyrline[] =
01241d47
PH
352{
353 ]b4_rline[
354};
355#endif
356
5f108727 357#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
9e0876fb 358/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
9d9b8b70 359 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
01241d47
PH
360static const char *const yytname[] =
361{
362 ]b4_tname[
363};
01241d47
PH
364#endif
365
728e89a0
AD
366#define YYPACT_NINF ]b4_pact_ninf[
367#define YYTABLE_NINF ]b4_table_ninf[
01241d47 368
728e89a0 369]b4_parser_tables_define[
01241d47 370
9d9b8b70 371/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
a762e609 372static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
01241d47
PH
373{
374 ]b4_dprec[
375};
376
9d9b8b70 377/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
a762e609 378static const ]b4_int_type_for([b4_merger])[ yymerger[] =
01241d47
PH
379{
380 ]b4_merger[
381};
382
ca2a6d15
PH
383/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
384 in the case of predicates. */
385static const yybool yyimmediate[] =
386{
387 ]b4_immediate[
388};
389
ea99527d
AD
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. */
a762e609 394static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
01241d47
PH
395{
396 ]b4_conflict_list_heads[
397};
398
ea99527d
AD
399/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
400 0, pointed into by YYCONFLP. */
a762e609 401]dnl Do not use b4_int_type_for here, since there are places where
779e7ceb 402dnl pointers onto yyconfl are taken, which type is "short int *".
a762e609 403dnl We probably ought to introduce a type for confl.
779e7ceb 404[static const short int yyconfl[] =
01241d47
PH
405{
406 ]b4_conflicting_rules[
407};
01241d47 408\f
2a8d363a 409/* Error token number */
01241d47
PH
410#define YYTERROR 1
411
327afc7c 412]b4_locations_if([[
01241d47 413#ifndef YYLLOC_DEFAULT
426903aa
AD
414]b4_yylloc_default_define[
415# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
3fc16193
AD
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
e9690142
JD
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)
25005f6a
PH
425#endif
426]],[
427#ifndef YYLLOC_DEFAULT
9fafc4dd 428# define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
01241d47 429#endif
25005f6a
PH
430])[
431
3fc16193
AD
432#ifndef YY_LOCATION_PRINT
433# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
434#endif
435
01241d47 436/* YYLEX -- calling `yylex' with the right arguments. */
15f66669 437#define YYLEX ]b4_function_call([yylex], [int], b4_lex_param)[
01241d47
PH
438
439]b4_pure_if(
440[
01241d47 441#undef yynerrs
3e7a2cd9 442#define yynerrs (yystackp->yyerrcnt)
01241d47 443#undef yychar
d6cff4dc
AD
444#define yychar (yystackp->yyrawchar)
445#undef yylval
446#define yylval (yystackp->yyval)
447#undef yylloc
448#define yylloc (yystackp->yyloc)
449m4_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])],
d834eca0
AD
454[YYSTYPE yylval;]b4_locations_if([[
455YYLTYPE yylloc;]])[
01241d47
PH
456
457int yynerrs;
458int yychar;])[
459
460static const int YYEOF = 0;
461static const int YYEMPTY = -2;
462
463typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
464
5860cc8c
AD
465#define YYCHK(YYE) \
466 do { \
c49784f5
AD
467 YYRESULTTAG yychk_flag = YYE; \
468 if (yychk_flag != yyok) \
469 return yychk_flag; \
56f8d560 470 } while (0)
01241d47 471
5f108727 472#if ]b4_api_PREFIX[DEBUG
01241d47 473
02650b7f 474# ifndef YYFPRINTF
01241d47 475# define YYFPRINTF fprintf
02650b7f 476# endif
01241d47 477
e9690142
JD
478# define YYDPRINTF(Args) \
479 do { \
5860cc8c 480 if (yydebug) \
e9690142 481 YYFPRINTF Args; \
56f8d560 482 } while (0)
7bd6c77e 483
e3f12e08 484]b4_yy_symbol_print_define[
7bd6c77e 485
5860cc8c
AD
486# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
487 do { \
488 if (yydebug) \
489 { \
490 YYFPRINTF (stderr, "%s ", Title); \
77567371 491 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
5860cc8c
AD
492 YYFPRINTF (stderr, "\n"); \
493 } \
56f8d560 494 } while (0)
9c1e26bd 495
01241d47
PH
496/* Nonzero means print parse trace. It is left uninitialized so that
497 multiple parsers can coexist. */
498int yydebug;
7bd6c77e 499
5f108727 500#else /* !]b4_api_PREFIX[DEBUG */
7bd6c77e 501
ee16363f 502# define YYDPRINTF(Args)
284acc8b 503# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
7bd6c77e 504
5f108727 505#endif /* !]b4_api_PREFIX[DEBUG */
01241d47
PH
506
507/* YYINITDEPTH -- initial size of the parser's stacks. */
e9690142 508#ifndef YYINITDEPTH
66d30cd4 509# define YYINITDEPTH ]b4_stack_depth_init[
01241d47
PH
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
fb8135fa 516 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
01241d47
PH
517 evaluated with infinite-precision integer arithmetic. */
518
01241d47 519#ifndef YYMAXDEPTH
66d30cd4 520# define YYMAXDEPTH ]b4_stack_depth_max[
01241d47
PH
521#endif
522
523/* Minimum number of free items on the stack allowed after an
fb8135fa 524 allocation. This is to allow allocation and initialization
63cb01d6 525 to be completed by functions that call yyexpandGLRStack before the
fb8135fa 526 stack is expanded, thus insuring that all necessary pointers get
9d9b8b70 527 properly redirected to new data. */
01241d47
PH
528#define YYHEADROOM 2
529
e2688cd9 530#ifndef YYSTACKEXPANDABLE
e2688cd9 531# define YYSTACKEXPANDABLE 1
01241d47
PH
532#endif
533
02998094 534#if YYSTACKEXPANDABLE
e9690142
JD
535# define YY_RESERVE_GLRSTACK(Yystack) \
536 do { \
537 if (Yystack->yyspaceLeft < YYHEADROOM) \
538 yyexpandGLRStack (Yystack); \
56f8d560 539 } while (0)
02998094 540#else
e9690142
JD
541# define YY_RESERVE_GLRSTACK(Yystack) \
542 do { \
543 if (Yystack->yyspaceLeft < YYHEADROOM) \
544 yyMemoryExhausted (Yystack); \
56f8d560 545 } while (0)
02998094
AD
546#endif
547
548
63cb01d6
PE
549#if YYERROR_VERBOSE
550
551# ifndef yystpcpy
02650b7f 552# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
63cb01d6
PE
553# define yystpcpy stpcpy
554# else
555/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
556 YYDEST. */
557static char *
558yystpcpy (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
9e0876fb
PE
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. */
579static size_t
580yytnamerr (char *yyres, const char *yystr)
581{
582 if (*yystr == '"')
583 {
584 size_t yyn = 0;
585 char const *yyp = yystr;
586
587 for (;;)
e9690142
JD
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 }
9e0876fb
PE
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
63cb01d6
PE
619#endif /* !YYERROR_VERBOSE */
620
01241d47
PH
621/** State numbers, as in LALR(1) machine */
622typedef int yyStateNum;
623
624/** Rule numbers, as in LALR(1) machine */
625typedef int yyRuleNum;
626
627/** Grammar symbol */
39f5757a 628typedef int yySymbol;
01241d47
PH
629
630/** Item references, as in LALR(1) machine */
779e7ceb 631typedef short int yyItemNum;
01241d47
PH
632
633typedef struct yyGLRState yyGLRState;
3e7a2cd9 634typedef struct yyGLRStateSet yyGLRStateSet;
01241d47
PH
635typedef struct yySemanticOption yySemanticOption;
636typedef union yyGLRStackItem yyGLRStackItem;
637typedef struct yyGLRStack yyGLRStack;
01241d47
PH
638
639struct yyGLRState {
9d9b8b70 640 /** Type tag: always true. */
f7c398aa 641 yybool yyisState;
9d9b8b70
PE
642 /** Type tag for yysemantics. If true, yysval applies, otherwise
643 * yyfirstVal applies. */
f7c398aa 644 yybool yyresolved;
9d9b8b70 645 /** Number of corresponding LALR(1) machine state. */
01241d47 646 yyStateNum yylrState;
5e6f62f2 647 /** Preceding state in this stack */
01241d47 648 yyGLRState* yypred;
ca2a6d15 649 /** Source position of the last token produced by my symbol */
01241d47
PH
650 size_t yyposn;
651 union {
5e6f62f2 652 /** First in a chain of alternative reductions producing the
010f91c3 653 * non-terminal corresponding to this state, threaded through
9d9b8b70 654 * yynext. */
01241d47 655 yySemanticOption* yyfirstVal;
9d9b8b70 656 /** Semantic value for this state. */
01241d47 657 YYSTYPE yysval;
d834eca0 658 } yysemantics;]b4_locations_if([[
9d9b8b70 659 /** Source location for this state. */
d834eca0 660 YYLTYPE yyloc;]])[
01241d47
PH
661};
662
663struct yyGLRStateSet {
664 yyGLRState** yystates;
b7691f15 665 /** During nondeterministic operation, yylookaheadNeeds tracks which
bf70fa87 666 * stacks have actually needed the current lookahead. During deterministic
b7691f15 667 * operation, yylookaheadNeeds[0] is not maintained since it would merely
bf70fa87 668 * duplicate yychar != YYEMPTY. */
b7691f15 669 yybool* yylookaheadNeeds;
01241d47
PH
670 size_t yysize, yycapacity;
671};
672
673struct yySemanticOption {
9d9b8b70 674 /** Type tag: always false. */
f7c398aa 675 yybool yyisState;
5e6f62f2 676 /** Rule number for this reduction */
01241d47 677 yyRuleNum yyrule;
9d9b8b70 678 /** The last RHS state in the list of states to be reduced. */
01241d47 679 yyGLRState* yystate;
bf70fa87
JD
680 /** The lookahead for this reduction. */
681 int yyrawchar;
d834eca0
AD
682 YYSTYPE yyval;]b4_locations_if([[
683 YYLTYPE yyloc;]])[
9d9b8b70
PE
684 /** Next sibling in chain of options. To facilitate merging,
685 * options are chained in decreasing order by address. */
01241d47
PH
686 yySemanticOption* yynext;
687};
688
9d9b8b70
PE
689/** Type of the items in the GLR stack. The yyisState field
690 * indicates which item of the union is valid. */
01241d47
PH
691union yyGLRStackItem {
692 yyGLRState yystate;
693 yySemanticOption yyoption;
694};
695
696struct yyGLRStack {
01241d47 697 int yyerrState;
327afc7c 698]b4_locations_if([[ /* To compute the location of the error token. */
63d72da7 699 yyGLRStackItem yyerror_range[3];]])[
01241d47
PH
700]b4_pure_if(
701[
702 int yyerrcnt;
703 int yyrawchar;
d834eca0
AD
704 YYSTYPE yyval;]b4_locations_if([[
705 YYLTYPE yyloc;]])[
01241d47 706])[
c89b4c03 707 YYJMP_BUF yyexception_buffer;
01241d47
PH
708 yyGLRStackItem* yyitems;
709 yyGLRStackItem* yynextFree;
63cb01d6 710 size_t yyspaceLeft;
01241d47
PH
711 yyGLRState* yysplitPoint;
712 yyGLRState* yylastDeleted;
713 yyGLRStateSet yytops;
714};
715
b2741627 716#if YYSTACKEXPANDABLE
3e7a2cd9 717static void yyexpandGLRStack (yyGLRStack* yystackp);
b2741627 718#endif
01241d47 719
3e7a2cd9 720static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
135bc829 721 __attribute__ ((__noreturn__));
01241d47 722static void
3e7a2cd9 723yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
01241d47 724{
ef51bfa7 725 if (yymsg != YY_NULL)
fd2df2ed 726 yyerror (]b4_yyerror_args[yymsg);
3e7a2cd9 727 YYLONGJMP (yystackp->yyexception_buffer, 1);
01241d47
PH
728}
729
3e7a2cd9 730static void yyMemoryExhausted (yyGLRStack* yystackp)
135bc829 731 __attribute__ ((__noreturn__));
63cb01d6 732static void
3e7a2cd9 733yyMemoryExhausted (yyGLRStack* yystackp)
63cb01d6 734{
3e7a2cd9 735 YYLONGJMP (yystackp->yyexception_buffer, 2);
63cb01d6
PE
736}
737
5f108727 738#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
63cb01d6 739/** A printable representation of TOKEN. */
fb8135fa
AD
740static inline const char*
741yytokenName (yySymbol yytoken)
01241d47 742{
d0d5aa64
PE
743 if (yytoken == YYEMPTY)
744 return "";
745
01241d47
PH
746 return yytname[yytoken];
747}
748#endif
749
f868dc04
PH
750/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
751 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
9d9b8b70 752 * containing the pointer to the next state in the chain. */
135bc829 753static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
6a84279c
PE
754static void
755yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
f868dc04 756{
f868dc04 757 int i;
aebb55eb 758 yyGLRState *s = yyvsp[yylow0].yystate.yypred;
f868dc04
PH
759 for (i = yylow0-1; i >= yylow1; i -= 1)
760 {
ccdc1577 761#if ]b4_api_PREFIX[DEBUG
ca2a6d15
PH
762 yyvsp[i].yystate.yylrState = s->yylrState;
763#endif
764 yyvsp[i].yystate.yyresolved = s->yyresolved;
765 if (s->yyresolved)
e9690142 766 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
ca2a6d15 767 else
e9690142 768 /* The effect of using yysval or yyloc (in an immediate rule) is
ca2a6d15 769 * undefined. */
72cd9a91 770 yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULL;]b4_locations_if([[
d834eca0 771 yyvsp[i].yystate.yyloc = s->yyloc;]])[
f868dc04
PH
772 s = yyvsp[i].yystate.yypred = s->yypred;
773 }
6a84279c
PE
774}
775
776/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
44e7ead1
PH
777 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
778 * For convenience, always return YYLOW1. */
6a84279c 779static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
135bc829 780 __attribute__ ((__unused__));
6a84279c
PE
781static inline int
782yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
783{
784 if (!yynormal && yylow1 < *yylow)
785 {
786 yyfillin (yyvsp, *yylow, yylow1);
787 *yylow = yylow1;
788 }
f868dc04
PH
789 return yylow1;
790}
791
01241d47
PH
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
9d9b8b70
PE
795 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
796 * yyerr for YYERROR, yyabort for YYABORT. */
56f8d560 797static YYRESULTTAG
fb8135fa 798yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
3e75a2c9
AD
799 yyGLRStack* yystackp,
800 YYSTYPE* yyvalp]b4_locuser_formals[)
01241d47 801{
135bc829 802 yybool yynormal __attribute__ ((__unused__)) =
ef51bfa7 803 (yystackp->yysplitPoint == YY_NULL);
f868dc04 804 int yylow;
1e5d6540
AD
805]b4_parse_param_use([yyvalp], [yylocp])dnl
806[# undef yyerrok
3e7a2cd9 807# define yyerrok (yystackp->yyerrState = 0)
01241d47
PH
808# undef YYACCEPT
809# define YYACCEPT return yyaccept
810# undef YYABORT
811# define YYABORT return yyabort
812# undef YYERROR
5cc16ecc 813# define YYERROR return yyerrok, yyerr
01241d47 814# undef YYRECOVERING
02103984 815# define YYRECOVERING() (yystackp->yyerrState != 0)
01241d47 816# undef yyclearin
3f001415 817# define yyclearin (yychar = YYEMPTY)
f868dc04 818# undef YYFILL
6a84279c 819# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
01241d47 820# undef YYBACKUP
e9690142 821# define YYBACKUP(Token, Value) \
30757c8c 822 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
e9690142 823 yyerrok, yyerr
01241d47 824
25005f6a
PH
825 yylow = 1;
826 if (yyrhslen == 0)
b4a20338 827 *yyvalp = yyval_default;
25005f6a 828 else
769a8ef9 829 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
401aace6 830 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
769a8ef9 831 yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
a85284cf 832]])[
25005f6a
PH
833 switch (yyn)
834 {
8ec0a172 835 ]b4_user_actions[
95f22ad2 836 default: break;
25005f6a 837 }
01241d47 838
25005f6a 839 return yyok;
01241d47
PH
840# undef yyerrok
841# undef YYABORT
842# undef YYACCEPT
843# undef YYERROR
844# undef YYBACKUP
845# undef yyclearin
846# undef YYRECOVERING
01241d47 847}
01241d47 848
56f8d560
AD
849
850static void
01241d47
PH
851yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
852{
2a4647a3
PE
853 YYUSE (yy0);
854 YYUSE (yy1);
1154cced 855
fb8135fa 856 switch (yyn)
01241d47 857 {
a85284cf 858 ]b4_mergers[
e2688cd9 859 default: break;
01241d47 860 }
01241d47 861}
a85284cf 862
e9690142 863 /* Bison grammar-table manipulation. */
01241d47 864
e3f12e08 865]b4_yydestruct_define[
7bd6c77e 866
42a6501d
PE
867/** Number of symbols composing the right hand side of rule #RULE. */
868static inline int
869yyrhsLength (yyRuleNum yyrule)
870{
871 return yyr2[yyrule];
872}
873
a4cf101a 874static void
4b367315 875yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
a4cf101a
PE
876{
877 if (yys->yyresolved)
878 yydestruct (yymsg, yystos[yys->yylrState],
3e75a2c9 879 &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
a4cf101a
PE
880 else
881 {
5f108727 882#if ]b4_api_PREFIX[DEBUG
a4cf101a 883 if (yydebug)
e9690142
JD
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],
3e75a2c9 890 YY_NULL]b4_locuser_args([&yys->yyloc])[);
e9690142
JD
891 YYFPRINTF (stderr, "\n");
892 }
a4cf101a 893#endif
a4cf101a 894
42a6501d 895 if (yys->yysemantics.yyfirstVal)
e9690142
JD
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 }
42a6501d 905 }
01241d47
PH
906}
907
ca2a6d15 908/** Left-hand-side symbol for rule #YYRULE. */
01241d47 909static inline yySymbol
fb8135fa 910yylhsNonterm (yyRuleNum yyrule)
01241d47
PH
911{
912 return yyr1[yyrule];
913}
914
f2b30bdf 915#define yypact_value_is_default(yystate) \
87412882 916 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
944ed9f4 917
ca2a6d15 918/** True iff LR state YYSTATE has only a default reduction (regardless
9d9b8b70 919 * of token). */
f7c398aa 920static inline yybool
01241d47
PH
921yyisDefaultedState (yyStateNum yystate)
922{
f2b30bdf 923 return yypact_value_is_default (yypact[yystate]);
01241d47 924}
fb8135fa 925
ca2a6d15 926/** The default reduction for YYSTATE, assuming it has one. */
01241d47
PH
927static inline yyRuleNum
928yydefaultAction (yyStateNum yystate)
929{
930 return yydefact[yystate];
931}
932
f2b30bdf 933#define yytable_value_is_error(yytable_value) \
aa0cb40d 934 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
944ed9f4 935
2a1fe6ed 936/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
01241d47
PH
937 * Result R means
938 * R < 0: Reduce on rule -R.
939 * R = 0: Error.
fb8135fa 940 * R > 0: Shift to state R.
ca2a6d15
PH
941 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
942 * of conflicting reductions.
01241d47
PH
943 */
944static inline void
fb8135fa 945yygetLRActions (yyStateNum yystate, int yytoken,
e9690142 946 int* yyaction, const short int** yyconflicts)
01241d47
PH
947{
948 int yyindex = yypact[yystate] + yytoken;
f2b30bdf
JD
949 if (yypact_value_is_default (yypact[yystate])
950 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
01241d47
PH
951 {
952 *yyaction = -yydefact[yystate];
953 *yyconflicts = yyconfl;
954 }
f2b30bdf 955 else if (! yytable_value_is_error (yytable[yyindex]))
01241d47
PH
956 {
957 *yyaction = yytable[yyindex];
958 *yyconflicts = yyconfl + yyconflp[yyindex];
959 }
f50adbbd
AD
960 else
961 {
962 *yyaction = 0;
963 *yyconflicts = yyconfl + yyconflp[yyindex];
964 }
01241d47
PH
965}
966
967static inline yyStateNum
968yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
969{
7580c379 970 int yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
34ec3579 971 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
01241d47
PH
972 return yytable[yyr];
973 else
974 return yydefgoto[yylhs - YYNTOKENS];
975}
976
f7c398aa 977static inline yybool
fb8135fa 978yyisShiftAction (int yyaction)
01241d47 979{
39912f52 980 return 0 < yyaction;
01241d47
PH
981}
982
f7c398aa 983static inline yybool
fb8135fa 984yyisErrorAction (int yyaction)
01241d47 985{
f50adbbd 986 return yyaction == 0;
01241d47
PH
987}
988
e9690142 989 /* GLRStates */
01241d47 990
ca2a6d15
PH
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. */
02998094
AD
995
996static inline yyGLRStackItem*
3e7a2cd9 997yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
02998094 998{
3e7a2cd9
PE
999 yyGLRStackItem* yynewItem = yystackp->yynextFree;
1000 yystackp->yyspaceLeft -= 1;
1001 yystackp->yynextFree += 1;
02998094
AD
1002 yynewItem->yystate.yyisState = yyisState;
1003 return yynewItem;
1004}
1005
12f4614d 1006/** Add a new semantic action that will execute the action for rule
ca2a6d15
PH
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. */
1154cced 1010static void
bf70fa87 1011yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
e9690142 1012 yyGLRState* yyrhs, yyRuleNum yyrule)
01241d47 1013{
02998094 1014 yySemanticOption* yynewOption =
3e7a2cd9 1015 &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
8452c667 1016 yynewOption->yystate = yyrhs;
02998094 1017 yynewOption->yyrule = yyrule;
b7691f15 1018 if (yystackp->yytops.yylookaheadNeeds[yyk])
bf70fa87
JD
1019 {
1020 yynewOption->yyrawchar = yychar;
769a8ef9
AD
1021 yynewOption->yyval = yylval;]b4_locations_if([
1022 yynewOption->yyloc = yylloc;])[
bf70fa87
JD
1023 }
1024 else
1025 yynewOption->yyrawchar = YYEMPTY;
02998094
AD
1026 yynewOption->yynext = yystate->yysemantics.yyfirstVal;
1027 yystate->yysemantics.yyfirstVal = yynewOption;
1028
3e7a2cd9 1029 YY_RESERVE_GLRSTACK (yystackp);
01241d47
PH
1030}
1031
e9690142 1032 /* GLRStacks */
01241d47 1033
ca2a6d15 1034/** Initialize YYSET to a singleton set containing an empty stack. */
63cb01d6 1035static yybool
01241d47
PH
1036yyinitStateSet (yyGLRStateSet* yyset)
1037{
1038 yyset->yysize = 1;
1039 yyset->yycapacity = 16;
be16239b 1040 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
63cb01d6
PE
1041 if (! yyset->yystates)
1042 return yyfalse;
ef51bfa7 1043 yyset->yystates[0] = YY_NULL;
b7691f15
JD
1044 yyset->yylookaheadNeeds =
1045 (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
1046 if (! yyset->yylookaheadNeeds)
bf70fa87
JD
1047 {
1048 YYFREE (yyset->yystates);
1049 return yyfalse;
1050 }
63cb01d6 1051 return yytrue;
01241d47
PH
1052}
1053
fb8135fa 1054static void yyfreeStateSet (yyGLRStateSet* yyset)
01241d47 1055{
a525b568 1056 YYFREE (yyset->yystates);
b7691f15 1057 YYFREE (yyset->yylookaheadNeeds);
01241d47
PH
1058}
1059
ca2a6d15
PH
1060/** Initialize *YYSTACKP to a single empty stack, with total maximum
1061 * capacity for all stacks of YYSIZE. */
63cb01d6 1062static yybool
3e7a2cd9 1063yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
01241d47 1064{
3e7a2cd9 1065 yystackp->yyerrState = 0;
01241d47 1066 yynerrs = 0;
3e7a2cd9
PE
1067 yystackp->yyspaceLeft = yysize;
1068 yystackp->yyitems =
1069 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
1070 if (!yystackp->yyitems)
3922956a 1071 return yyfalse;
3e7a2cd9 1072 yystackp->yynextFree = yystackp->yyitems;
ef51bfa7
AD
1073 yystackp->yysplitPoint = YY_NULL;
1074 yystackp->yylastDeleted = YY_NULL;
3e7a2cd9 1075 return yyinitStateSet (&yystackp->yytops);
01241d47
PH
1076}
1077
02998094
AD
1078
1079#if YYSTACKEXPANDABLE
1080# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
01241d47
PH
1081 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1082
ca2a6d15 1083/** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
01241d47
PH
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
9d9b8b70 1087 across an allocation. */
01241d47 1088static void
3e7a2cd9 1089yyexpandGLRStack (yyGLRStack* yystackp)
01241d47 1090{
63cb01d6 1091 yyGLRStackItem* yynewItems;
01241d47 1092 yyGLRStackItem* yyp0, *yyp1;
aebb55eb 1093 size_t yynewSize;
01241d47 1094 size_t yyn;
aebb55eb 1095 size_t yysize = yystackp->yynextFree - yystackp->yyitems;
18d9185c 1096 if (YYMAXDEPTH - YYHEADROOM < yysize)
3e7a2cd9 1097 yyMemoryExhausted (yystackp);
01241d47 1098 yynewSize = 2*yysize;
39912f52 1099 if (YYMAXDEPTH < yynewSize)
01241d47 1100 yynewSize = YYMAXDEPTH;
63cb01d6
PE
1101 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1102 if (! yynewItems)
3e7a2cd9
PE
1103 yyMemoryExhausted (yystackp);
1104 for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
39912f52 1105 0 < yyn;
fb8135fa 1106 yyn -= 1, yyp0 += 1, yyp1 += 1)
01241d47
PH
1107 {
1108 *yyp1 = *yyp0;
f7c398aa 1109 if (*(yybool *) yyp0)
e9690142
JD
1110 {
1111 yyGLRState* yys0 = &yyp0->yystate;
1112 yyGLRState* yys1 = &yyp1->yystate;
3e75a2c9 1113 if (yys0->yypred != YY_NULL)
e9690142
JD
1114 yys1->yypred =
1115 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
3e75a2c9 1116 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL)
e9690142 1117 yys1->yysemantics.yyfirstVal =
aebb55eb 1118 YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
e9690142 1119 }
fb8135fa 1120 else
e9690142
JD
1121 {
1122 yySemanticOption* yyv0 = &yyp0->yyoption;
1123 yySemanticOption* yyv1 = &yyp1->yyoption;
3e75a2c9 1124 if (yyv0->yystate != YY_NULL)
e9690142 1125 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
3e75a2c9 1126 if (yyv0->yynext != YY_NULL)
e9690142
JD
1127 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1128 }
01241d47 1129 }
ef51bfa7 1130 if (yystackp->yysplitPoint != YY_NULL)
3e7a2cd9 1131 yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
e9690142 1132 yystackp->yysplitPoint, yystate);
3e7a2cd9
PE
1133
1134 for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
ef51bfa7 1135 if (yystackp->yytops.yystates[yyn] != YY_NULL)
3e7a2cd9 1136 yystackp->yytops.yystates[yyn] =
e9690142
JD
1137 YYRELOC (yystackp->yyitems, yynewItems,
1138 yystackp->yytops.yystates[yyn], yystate);
3e7a2cd9
PE
1139 YYFREE (yystackp->yyitems);
1140 yystackp->yyitems = yynewItems;
1141 yystackp->yynextFree = yynewItems + yysize;
1142 yystackp->yyspaceLeft = yynewSize - yysize;
01241d47 1143}
02998094 1144#endif
01241d47
PH
1145
1146static void
3e7a2cd9 1147yyfreeGLRStack (yyGLRStack* yystackp)
01241d47 1148{
3e7a2cd9
PE
1149 YYFREE (yystackp->yyitems);
1150 yyfreeStateSet (&yystackp->yytops);
01241d47
PH
1151}
1152
ca2a6d15
PH
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. */
01241d47 1156static inline void
3e7a2cd9 1157yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
01241d47 1158{
ef51bfa7 1159 if (yystackp->yysplitPoint != YY_NULL && yystackp->yysplitPoint > yys)
3e7a2cd9 1160 yystackp->yysplitPoint = yys;
01241d47
PH
1161}
1162
ca2a6d15 1163/** Invalidate stack #YYK in *YYSTACKP. */
01241d47 1164static inline void
3e7a2cd9 1165yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
01241d47 1166{
ef51bfa7 1167 if (yystackp->yytops.yystates[yyk] != YY_NULL)
3e7a2cd9 1168 yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
ef51bfa7 1169 yystackp->yytops.yystates[yyk] = YY_NULL;
01241d47
PH
1170}
1171
ca2a6d15
PH
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
9d9b8b70 1174 been deleted. */
01241d47 1175static void
3e7a2cd9 1176yyundeleteLastStack (yyGLRStack* yystackp)
01241d47 1177{
ef51bfa7 1178 if (yystackp->yylastDeleted == YY_NULL || yystackp->yytops.yysize != 0)
01241d47 1179 return;
3e7a2cd9
PE
1180 yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
1181 yystackp->yytops.yysize = 1;
2f4f028d 1182 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
ef51bfa7 1183 yystackp->yylastDeleted = YY_NULL;
01241d47
PH
1184}
1185
1186static inline void
3e7a2cd9 1187yyremoveDeletes (yyGLRStack* yystackp)
01241d47 1188{
1154cced 1189 size_t yyi, yyj;
01241d47 1190 yyi = yyj = 0;
3e7a2cd9 1191 while (yyj < yystackp->yytops.yysize)
01241d47 1192 {
ef51bfa7 1193 if (yystackp->yytops.yystates[yyi] == YY_NULL)
e9690142
JD
1194 {
1195 if (yyi == yyj)
1196 {
1197 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1198 }
1199 yystackp->yytops.yysize -= 1;
1200 }
fb8135fa 1201 else
e9690142
JD
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 }
01241d47
PH
1218 yyi += 1;
1219 }
1220}
1221
ca2a6d15
PH
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. */
01241d47 1225static inline void
3e7a2cd9 1226yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
e9690142 1227 size_t yyposn,
3e75a2c9 1228 YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
01241d47 1229{
3e7a2cd9 1230 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
01241d47 1231
02998094
AD
1232 yynewState->yylrState = yylrState;
1233 yynewState->yyposn = yyposn;
1234 yynewState->yyresolved = yytrue;
3e7a2cd9 1235 yynewState->yypred = yystackp->yytops.yystates[yyk];
769a8ef9
AD
1236 yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
1237 yynewState->yyloc = *yylocp;])[
3e7a2cd9 1238 yystackp->yytops.yystates[yyk] = yynewState;
02998094 1239
3e7a2cd9 1240 YY_RESERVE_GLRSTACK (yystackp);
01241d47
PH
1241}
1242
ca2a6d15 1243/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
c4749565 1244 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
9d9b8b70 1245 * semantic value of YYRHS under the action for YYRULE. */
01241d47 1246static inline void
3e7a2cd9 1247yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
e9690142 1248 size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
01241d47 1249{
3e7a2cd9 1250 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
02998094
AD
1251
1252 yynewState->yylrState = yylrState;
1253 yynewState->yyposn = yyposn;
1254 yynewState->yyresolved = yyfalse;
3e7a2cd9 1255 yynewState->yypred = yystackp->yytops.yystates[yyk];
ef51bfa7 1256 yynewState->yysemantics.yyfirstVal = YY_NULL;
3e7a2cd9 1257 yystackp->yytops.yystates[yyk] = yynewState;
02998094 1258
9d9b8b70 1259 /* Invokes YY_RESERVE_GLRSTACK. */
8452c667 1260 yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
01241d47
PH
1261}
1262
ccdc1577 1263#if !]b4_api_PREFIX[DEBUG
ca2a6d15
PH
1264# define YY_REDUCE_PRINT(Args)
1265#else
e9690142
JD
1266# define YY_REDUCE_PRINT(Args) \
1267do { \
1268 if (yydebug) \
1269 yy_reduce_print Args; \
56f8d560 1270} while (0)
ca2a6d15
PH
1271
1272/*----------------------------------------------------------------------.
1273| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1274`----------------------------------------------------------------------*/
1275
56f8d560 1276static inline void
f86a7807
AD
1277yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
1278 yyRuleNum yyrule]b4_user_formals[)
ca2a6d15 1279{
d467f443
PH
1280 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1281 int yylow = 1;])[
ca2a6d15 1282 int yyi;
beadb220 1283 YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
e9690142
JD
1284 (unsigned long int) yyk, yyrule - 1,
1285 (unsigned long int) yyrline[yyrule]);
ca2a6d15 1286 if (! yynormal)
d467f443 1287 yyfillin (yyvsp, 1, -yynrhs);
ca2a6d15
PH
1288 /* The symbols being reduced. */
1289 for (yyi = 0; yyi < yynrhs; yyi++)
1290 {
1291 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1292 yy_symbol_print (stderr,
e9690142
JD
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[);
d467f443 1297 if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
ca2a6d15
PH
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
fb8135fa 1306 * semantic values. Assumes that all ambiguities in semantic values
ca2a6d15
PH
1307 * have been previously resolved. Set *YYVALP to the resulting value,
1308 * and *YYLOCP to the computed location (if any). Return value is as
9d9b8b70 1309 * for userAction. */
ff032592 1310static inline YYRESULTTAG
3e7a2cd9 1311yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
3e75a2c9 1312 YYSTYPE* yyvalp]b4_locuser_formals[)
01241d47
PH
1313{
1314 int yynrhs = yyrhsLength (yyrule);
1315
ef51bfa7 1316 if (yystackp->yysplitPoint == YY_NULL)
01241d47 1317 {
9d9b8b70 1318 /* Standard special case: single stack. */
8452c667 1319 yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
64c4fd52 1320 YYASSERT (yyk == 0);
3e7a2cd9
PE
1321 yystackp->yynextFree -= yynrhs;
1322 yystackp->yyspaceLeft += yynrhs;
1323 yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
ca2a6d15 1324 YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[));
3e75a2c9
AD
1325 return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
1326 yyvalp]b4_locuser_args[);
01241d47 1327 }
fb8135fa 1328 else
01241d47
PH
1329 {
1330 int yyi;
1331 yyGLRState* yys;
25005f6a 1332 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
5cc16ecc 1333 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
e9690142 1334 = yystackp->yytops.yystates[yyk];]b4_locations_if([[
44e7ead1 1335 if (yynrhs == 0)
e9690142
JD
1336 /* Set default location. */
1337 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
f868dc04 1338 for (yyi = 0; yyi < yynrhs; yyi += 1)
e9690142
JD
1339 {
1340 yys = yys->yypred;
1341 YYASSERT (yys);
1342 }
3e7a2cd9
PE
1343 yyupdateSplit (yystackp, yys);
1344 yystackp->yytops.yystates[yyk] = yys;
ca2a6d15 1345 YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
25005f6a 1346 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
3e75a2c9 1347 yystackp, yyvalp]b4_locuser_args[);
01241d47
PH
1348 }
1349}
1350
ca2a6d15 1351/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
01241d47 1352 * and push back on the resulting nonterminal symbol. Perform the
ca2a6d15
PH
1353 * semantic action associated with YYRULE and store its value with the
1354 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
01241d47
PH
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,
ca2a6d15
PH
1358 * it is identified with that existing state, eliminating stack #YYK from
1359 * *YYSTACKP. In this case, the semantic value is
fb8135fa 1360 * added to the options for the existing state's semantic value.
01241d47
PH
1361 */
1362static inline YYRESULTTAG
3e7a2cd9 1363yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
e9690142 1364 yybool yyforceEval]b4_user_formals[)
01241d47 1365{
3e7a2cd9 1366 size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
01241d47 1367
ef51bfa7 1368 if (yyforceEval || yystackp->yysplitPoint == YY_NULL)
01241d47 1369 {
ca2a6d15 1370 YYRESULTTAG yyflag;
769a8ef9
AD
1371 YYSTYPE yysval;]b4_locations_if([
1372 YYLTYPE yyloc;])[
fb8135fa 1373
3e75a2c9 1374 yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[);
eeaf1dc6 1375 if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULL)
ca2a6d15 1376 {
e9690142
JD
1377 YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
1378 (unsigned long int) yyk, yyrule - 1));
ca2a6d15
PH
1379 }
1380 if (yyflag != yyok)
c49784f5 1381 return yyflag;
62b08cfc 1382 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
3e7a2cd9 1383 yyglrShift (yystackp, yyk,
e9690142
JD
1384 yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
1385 yylhsNonterm (yyrule)),
3e75a2c9 1386 yyposn, &yysval]b4_locations_if([, &yyloc])[);
01241d47 1387 }
fb8135fa 1388 else
01241d47 1389 {
1154cced
AD
1390 size_t yyi;
1391 int yyn;
3e7a2cd9 1392 yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
01241d47
PH
1393 yyStateNum yynewLRState;
1394
3e7a2cd9 1395 for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
e9690142
JD
1396 0 < yyn; yyn -= 1)
1397 {
1398 yys = yys->yypred;
1399 YYASSERT (yys);
1400 }
3e7a2cd9 1401 yyupdateSplit (yystackp, yys);
01241d47 1402 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
fb8135fa 1403 YYDPRINTF ((stderr,
f86a7807
AD
1404 "Reduced stack %lu by rule #%d; action deferred. "
1405 "Now in state %d.\n",
e9690142 1406 (unsigned long int) yyk, yyrule - 1, yynewLRState));
3e7a2cd9 1407 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
3e75a2c9 1408 if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL)
e9690142 1409 {
aebb55eb
AD
1410 yyGLRState *yysplit = yystackp->yysplitPoint;
1411 yyGLRState *yyp = yystackp->yytops.yystates[yyi];
e9690142
JD
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 }
3e7a2cd9
PE
1426 yystackp->yytops.yystates[yyk] = yys;
1427 yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
fb8135fa 1428 }
ff032592 1429 return yyok;
01241d47
PH
1430}
1431
63cb01d6 1432static size_t
3e7a2cd9 1433yysplitStack (yyGLRStack* yystackp, size_t yyk)
01241d47 1434{
ef51bfa7 1435 if (yystackp->yysplitPoint == YY_NULL)
01241d47 1436 {
64c4fd52 1437 YYASSERT (yyk == 0);
3e7a2cd9 1438 yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
01241d47 1439 }
3e7a2cd9 1440 if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
01241d47 1441 {
63cb01d6 1442 yyGLRState** yynewStates;
b7691f15 1443 yybool* yynewLookaheadNeeds;
ddee1b06 1444
ef51bfa7 1445 yynewStates = YY_NULL;
c66dfadd 1446
ddee1b06 1447 if (yystackp->yytops.yycapacity
e9690142
JD
1448 > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1449 yyMemoryExhausted (yystackp);
ddee1b06
PH
1450 yystackp->yytops.yycapacity *= 2;
1451
1452 yynewStates =
e9690142
JD
1453 (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
1454 (yystackp->yytops.yycapacity
1455 * sizeof yynewStates[0]));
ef51bfa7 1456 if (yynewStates == YY_NULL)
e9690142 1457 yyMemoryExhausted (yystackp);
3e7a2cd9 1458 yystackp->yytops.yystates = yynewStates;
ddee1b06 1459
b7691f15 1460 yynewLookaheadNeeds =
e9690142
JD
1461 (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
1462 (yystackp->yytops.yycapacity
1463 * sizeof yynewLookaheadNeeds[0]));
ef51bfa7 1464 if (yynewLookaheadNeeds == YY_NULL)
e9690142 1465 yyMemoryExhausted (yystackp);
b7691f15 1466 yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
01241d47 1467 }
3e7a2cd9
PE
1468 yystackp->yytops.yystates[yystackp->yytops.yysize]
1469 = yystackp->yytops.yystates[yyk];
b7691f15
JD
1470 yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
1471 = yystackp->yytops.yylookaheadNeeds[yyk];
3e7a2cd9
PE
1472 yystackp->yytops.yysize += 1;
1473 return yystackp->yytops.yysize-1;
01241d47
PH
1474}
1475
ca2a6d15 1476/** True iff YYY0 and YYY1 represent identical options at the top level.
01241d47 1477 * That is, they represent the same rule applied to RHS symbols
9d9b8b70 1478 * that produce the same terminal symbols. */
f7c398aa 1479static yybool
01241d47
PH
1480yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1481{
fb8135fa 1482 if (yyy0->yyrule == yyy1->yyrule)
01241d47
PH
1483 {
1484 yyGLRState *yys0, *yys1;
1485 int yyn;
fb8135fa 1486 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
e9690142
JD
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;
01241d47
PH
1492 return yytrue;
1493 }
1494 else
1495 return yyfalse;
1496}
1497
ca2a6d15
PH
1498/** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1499 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
01241d47
PH
1500static void
1501yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1502{
1503 yyGLRState *yys0, *yys1;
1504 int yyn;
fb8135fa 1505 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
01241d47
PH
1506 yyn = yyrhsLength (yyy0->yyrule);
1507 yyn > 0;
1508 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
5e6f62f2
PH
1509 {
1510 if (yys0 == yys1)
e9690142 1511 break;
010f91c3 1512 else if (yys0->yyresolved)
e9690142
JD
1513 {
1514 yys1->yyresolved = yytrue;
1515 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1516 }
5e6f62f2 1517 else if (yys1->yyresolved)
e9690142
JD
1518 {
1519 yys0->yyresolved = yytrue;
1520 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1521 }
010f91c3 1522 else
e9690142 1523 {
aebb55eb
AD
1524 yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
1525 yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
56f8d560 1526 while (yytrue)
e9690142 1527 {
3e75a2c9 1528 if (yyz1 == *yyz0p || yyz1 == YY_NULL)
e9690142 1529 break;
3e75a2c9 1530 else if (*yyz0p == YY_NULL)
e9690142
JD
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 }
5e6f62f2 1546 }
01241d47
PH
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,
9d9b8b70 1551 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
01241d47 1552static int
1154cced 1553yypreference (yySemanticOption* y0, yySemanticOption* y1)
01241d47 1554{
1154cced
AD
1555 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1556 int p0 = yydprec[r0], p1 = yydprec[r1];
01241d47 1557
1154cced 1558 if (p0 == p1)
01241d47 1559 {
1154cced 1560 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
e9690142 1561 return 0;
01241d47 1562 else
e9690142 1563 return 1;
01241d47 1564 }
1154cced 1565 if (p0 == 0 || p1 == 0)
01241d47 1566 return 0;
1154cced 1567 if (p0 < p1)
01241d47 1568 return 3;
39912f52 1569 if (p1 < p0)
01241d47
PH
1570 return 2;
1571 return 0;
1572}
1573
d659304d 1574static YYRESULTTAG yyresolveValue (yyGLRState* yys,
e9690142 1575 yyGLRStack* yystackp]b4_user_formals[);
520181ab 1576
01241d47 1577
ca2a6d15
PH
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. */
01241d47 1583static YYRESULTTAG
3e7a2cd9 1584yyresolveStates (yyGLRState* yys, int yyn,
e9690142 1585 yyGLRStack* yystackp]b4_user_formals[)
01241d47 1586{
39912f52 1587 if (0 < yyn)
01241d47 1588 {
64c4fd52 1589 YYASSERT (yys->yypred);
d659304d 1590 YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
fb8135fa 1591 if (! yys->yyresolved)
e9690142 1592 YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
01241d47
PH
1593 }
1594 return yyok;
1595}
1596
ca2a6d15
PH
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
520181ab 1601 * semantic values if invoked). */
01241d47 1602static YYRESULTTAG
3e7a2cd9 1603yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
3e75a2c9 1604 YYSTYPE* yyvalp]b4_locuser_formals[)
01241d47 1605{
25005f6a 1606 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
aebb55eb
AD
1607 int yynrhs = yyrhsLength (yyopt->yyrule);
1608 YYRESULTTAG yyflag =
1609 yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
520181ab
JD
1610 if (yyflag != yyok)
1611 {
1612 yyGLRState *yys;
1613 for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
e9690142 1614 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
520181ab
JD
1615 return yyflag;
1616 }
1617
327afc7c 1618 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[
44e7ead1 1619 if (yynrhs == 0)
9d9b8b70 1620 /* Set default location. */
44e7ead1 1621 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
aebb55eb
AD
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,
e9690142 1630 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
aebb55eb
AD
1631 yystackp, yyvalp]b4_locuser_args[);
1632 yychar = yychar_current;
1633 yylval = yylval_current;]b4_locations_if([
1634 yylloc = yylloc_current;])[
1635 }
520181ab 1636 return yyflag;
01241d47
PH
1637}
1638
5f108727 1639#if ]b4_api_PREFIX[DEBUG
e7cb57c0
AD
1640static void
1641yyreportTree (yySemanticOption* yyx, int yyindent)
01241d47
PH
1642{
1643 int yynrhs = yyrhsLength (yyx->yyrule);
1644 int yyi;
1645 yyGLRState* yys;
9138c575 1646 yyGLRState* yystates[1 + YYMAXRHS];
782a05f9 1647 yyGLRState yyleftmost_state;
01241d47 1648
39912f52 1649 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
01241d47 1650 yystates[yyi] = yys;
ef51bfa7 1651 if (yys == YY_NULL)
782a05f9
PE
1652 {
1653 yyleftmost_state.yyposn = 0;
1654 yystates[0] = &yyleftmost_state;
1655 }
01241d47
PH
1656 else
1657 yystates[0] = yys;
1658
39912f52 1659 if (yyx->yystate->yyposn < yys->yyposn + 1)
01241d47 1660 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
e9690142
JD
1661 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1662 yyx->yyrule - 1);
01241d47 1663 else
08fc98e5 1664 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
e9690142
JD
1665 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1666 yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
1667 (unsigned long int) yyx->yystate->yyposn);
fb8135fa 1668 for (yyi = 1; yyi <= yynrhs; yyi += 1)
01241d47 1669 {
fb8135fa 1670 if (yystates[yyi]->yyresolved)
e9690142
JD
1671 {
1672 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1673 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
a6b2f4fc 1674 yytokenName (yystos[yystates[yyi]->yylrState]));
e9690142
JD
1675 else
1676 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
a6b2f4fc 1677 yytokenName (yystos[yystates[yyi]->yylrState]),
e9690142
JD
1678 (unsigned long int) (yystates[yyi-1]->yyposn + 1),
1679 (unsigned long int) yystates[yyi]->yyposn);
1680 }
fb8135fa 1681 else
e9690142 1682 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
01241d47
PH
1683 }
1684}
fb8135fa 1685#endif
01241d47 1686
56f8d560 1687static YYRESULTTAG
35ee866a 1688yyreportAmbiguity (yySemanticOption* yyx0,
e9690142 1689 yySemanticOption* yyx1]b4_pure_formals[)
01241d47 1690{
2a4647a3
PE
1691 YYUSE (yyx0);
1692 YYUSE (yyx1);
1154cced 1693
5f108727 1694#if ]b4_api_PREFIX[DEBUG
2f4f028d
PE
1695 YYFPRINTF (stderr, "Ambiguity detected.\n");
1696 YYFPRINTF (stderr, "Option 1,\n");
01241d47 1697 yyreportTree (yyx0, 2);
2f4f028d 1698 YYFPRINTF (stderr, "\nOption 2,\n");
01241d47 1699 yyreportTree (yyx1, 2);
2f4f028d 1700 YYFPRINTF (stderr, "\n");
01241d47 1701#endif
35ee866a
JD
1702
1703 yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
1704 return yyabort;
67b8cfbd 1705}]b4_locations_if([[
01241d47 1706
ca2a6d15
PH
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. */
8710fc41 1710static void
6d05403d 1711yyresolveLocations (yyGLRState* yys1, int yyn1,
e9690142 1712 yyGLRStack *yystackp]b4_user_formals[)
8710fc41 1713{
6d05403d 1714 if (0 < yyn1)
8710fc41 1715 {
6d05403d
PE
1716 yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
1717 if (!yys1->yyresolved)
e9690142 1718 {
e9690142
JD
1719 yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
1720 int yynrhs;
aebb55eb 1721 yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
3e75a2c9 1722 YYASSERT (yyoption != YY_NULL);
e9690142
JD
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 }
aebb55eb
AD
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 }
e9690142 1759 }
8710fc41 1760 }
67b8cfbd 1761}]])[
01241d47 1762
ca2a6d15
PH
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
520181ab 1769 * yydestroyGLRState can be invoked if necessary. */
01241d47 1770static YYRESULTTAG
520181ab 1771yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
01241d47 1772{
d659304d 1773 yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
769a8ef9 1774 yySemanticOption* yybest = yyoptionList;
f9315de5 1775 yySemanticOption** yypp;
769a8ef9 1776 yybool yymerge = yyfalse;
520181ab 1777 YYSTYPE yysval;
769a8ef9
AD
1778 YYRESULTTAG yyflag;]b4_locations_if([
1779 YYLTYPE *yylocp = &yys->yyloc;])[
01241d47 1780
ef51bfa7 1781 for (yypp = &yyoptionList->yynext; *yypp != YY_NULL; )
01241d47 1782 {
f9315de5
PE
1783 yySemanticOption* yyp = *yypp;
1784
01241d47 1785 if (yyidenticalOptions (yybest, yyp))
e9690142
JD
1786 {
1787 yymergeOptionSets (yybest, yyp);
1788 *yypp = yyp->yynext;
1789 }
01241d47 1790 else
e9690142
JD
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 }
01241d47
PH
1815 }
1816
fb8135fa 1817 if (yymerge)
01241d47 1818 {
f9315de5 1819 yySemanticOption* yyp;
01241d47 1820 int yyprec = yydprec[yybest->yyrule];
769a8ef9 1821 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
520181ab 1822 if (yyflag == yyok)
3e75a2c9 1823 for (yyp = yybest->yynext; yyp != YY_NULL; yyp = yyp->yynext)
e9690142
JD
1824 {
1825 if (yyprec == yydprec[yyp->yyrule])
1826 {
3e75a2c9 1827 YYSTYPE yysval_other;]b4_locations_if([
769a8ef9
AD
1828 YYLTYPE yydummy;])[
1829 yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
e9690142
JD
1830 if (yyflag != yyok)
1831 {
1832 yydestruct ("Cleanup: discarding incompletely merged value for",
1833 yystos[yys->yylrState],
3e75a2c9 1834 &yysval]b4_locuser_args[);
e9690142
JD
1835 break;
1836 }
1837 yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
1838 }
1839 }
520181ab
JD
1840 }
1841 else
769a8ef9 1842 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
520181ab
JD
1843
1844 if (yyflag == yyok)
1845 {
1846 yys->yyresolved = yytrue;
1847 yys->yysemantics.yysval = yysval;
01241d47
PH
1848 }
1849 else
ef51bfa7 1850 yys->yysemantics.yyfirstVal = YY_NULL;
520181ab 1851 return yyflag;
01241d47
PH
1852}
1853
1854static YYRESULTTAG
3e7a2cd9 1855yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
01241d47 1856{
ef51bfa7 1857 if (yystackp->yysplitPoint != YY_NULL)
01241d47
PH
1858 {
1859 yyGLRState* yys;
1860 int yyn;
1861
3e7a2cd9 1862 for (yyn = 0, yys = yystackp->yytops.yystates[0];
e9690142
JD
1863 yys != yystackp->yysplitPoint;
1864 yys = yys->yypred, yyn += 1)
1865 continue;
3e7a2cd9 1866 YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
e9690142 1867 ]b4_user_args[));
01241d47
PH
1868 }
1869 return yyok;
1870}
1871
1872static void
3e7a2cd9 1873yycompressStack (yyGLRStack* yystackp)
01241d47
PH
1874{
1875 yyGLRState* yyp, *yyq, *yyr;
1876
ef51bfa7 1877 if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULL)
01241d47
PH
1878 return;
1879
ef51bfa7 1880 for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULL;
3e7a2cd9 1881 yyp != yystackp->yysplitPoint;
01241d47
PH
1882 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1883 yyp->yypred = yyr;
fb8135fa 1884
3e7a2cd9
PE
1885 yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
1886 yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
1887 yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
ef51bfa7
AD
1888 yystackp->yysplitPoint = YY_NULL;
1889 yystackp->yylastDeleted = YY_NULL;
fb8135fa 1890
ef51bfa7 1891 while (yyr != YY_NULL)
fb8135fa 1892 {
3e7a2cd9 1893 yystackp->yynextFree->yystate = *yyr;
01241d47 1894 yyr = yyr->yypred;
3e7a2cd9
PE
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;
01241d47
PH
1899 }
1900}
1901
1902static YYRESULTTAG
3e7a2cd9 1903yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
e9690142 1904 size_t yyposn]b4_pure_formals[)
01241d47 1905{
ef51bfa7 1906 while (yystackp->yytops.yystates[yyk] != YY_NULL)
01241d47 1907 {
3e7a2cd9 1908 yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
63cb01d6 1909 YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
e9690142 1910 (unsigned long int) yyk, yystate));
01241d47 1911
64c4fd52
PE
1912 YYASSERT (yystate != YYFINAL);
1913
fb8135fa 1914 if (yyisDefaultedState (yystate))
e9690142 1915 {
c49784f5
AD
1916 YYRESULTTAG yyflag;
1917 yyRuleNum yyrule = yydefaultAction (yystate);
e9690142
JD
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[);
ca2a6d15
PH
1926 if (yyflag == yyerr)
1927 {
f86a7807
AD
1928 YYDPRINTF ((stderr,
1929 "Stack %lu dies "
1930 "(predicate failure or explicit user error).\n",
e9690142
JD
1931 (unsigned long int) yyk));
1932 yymarkStackDeleted (yystackp, yyk);
1933 return yyok;
1934 }
1935 if (yyflag != yyok)
ca2a6d15 1936 return yyflag;
e9690142 1937 }
fb8135fa 1938 else
e9690142
JD
1939 {
1940 yySymbol yytoken;
c49784f5
AD
1941 int yyaction;
1942 const short int* yyconflicts;
ca2a6d15 1943
e9690142
JD
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[);
ca2a6d15 1974 if (yyflag == yyok)
e9690142
JD
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))
ca2a6d15 1991 {
e9690142
JD
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,
c49784f5 2000 yyimmediate[-yyaction]]b4_user_args[);
e9690142 2001 if (yyflag == yyerr)
ca2a6d15 2002 {
f86a7807
AD
2003 YYDPRINTF ((stderr,
2004 "Stack %lu dies "
2005 "(predicate failure or explicit user error).\n",
e9690142
JD
2006 (unsigned long int) yyk));
2007 yymarkStackDeleted (yystackp, yyk);
ca2a6d15 2008 break;
e9690142
JD
2009 }
2010 else if (yyflag != yyok)
ca2a6d15
PH
2011 return yyflag;
2012 }
e9690142 2013 }
01241d47
PH
2014 }
2015 return yyok;
2016}
2017
56f8d560 2018static void
d6cff4dc 2019yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
01241d47 2020{
25a648d8
JD
2021 if (yystackp->yyerrState != 0)
2022 return;
2023#if ! YYERROR_VERBOSE
2024 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2025#else
d2060f06 2026 yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
ef51bfa7 2027 size_t yysize0 = yytnamerr (YY_NULL, yytokenName (yytoken));
b4bbc4a0
JD
2028 size_t yysize = yysize0;
2029 size_t yysize1;
2030 yybool yysize_overflow = yyfalse;
ef51bfa7 2031 char* yymsg = YY_NULL;
b4bbc4a0
JD
2032 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
2033 /* Internationalized format string. */
ef51bfa7 2034 const char *yyformat = YY_NULL;
b4bbc4a0
JD
2035 /* Arguments of yyformat. */
2036 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
d2060f06
JD
2037 /* Number of reported tokens (one for the "unexpected", one per
2038 "expected"). */
2039 int yycount = 0;
b4bbc4a0 2040
d2060f06
JD
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 {
b4bbc4a0
JD
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;
b4bbc4a0
JD
2074 /* Stay within bounds of both yycheck and yytname. */
2075 int yychecklim = YYLAST - yyn + 1;
2076 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2b008529 2077 int yyx;
b4bbc4a0
JD
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);
ef51bfa7 2089 yysize1 = yysize + yytnamerr (YY_NULL, yytokenName (yyx));
b4bbc4a0
JD
2090 yysize_overflow |= yysize1 < yysize;
2091 yysize = yysize1;
2092 }
d2060f06
JD
2093 }
2094 }
b4bbc4a0
JD
2095
2096 switch (yycount)
2097 {
2098#define YYCASE_(N, S) \
2099 case N: \
2100 yyformat = S; \
2101 break
d2060f06 2102 YYCASE_(0, YY_("syntax error"));
b4bbc4a0
JD
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"));
2b008529 2108#undef YYCASE_
b4bbc4a0 2109 }
2b008529 2110
b4bbc4a0
JD
2111 yysize1 = yysize + strlen (yyformat);
2112 yysize_overflow |= yysize1 < yysize;
2113 yysize = yysize1;
63cb01d6 2114
b4bbc4a0
JD
2115 if (!yysize_overflow)
2116 yymsg = (char *) YYMALLOC (yysize);
63cb01d6 2117
b4bbc4a0
JD
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);
01241d47 2142 }
25a648d8 2143#endif /* YYERROR_VERBOSE */
b4bbc4a0
JD
2144 yynerrs += 1;
2145}
01241d47 2146
d6cff4dc
AD
2147/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2148 yylval, and yylloc are the syntactic category, semantic value, and location
742e4900 2149 of the lookahead. */
56f8d560 2150static void
d6cff4dc 2151yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
01241d47 2152{
1154cced
AD
2153 size_t yyk;
2154 int yyj;
01241d47 2155
3e7a2cd9 2156 if (yystackp->yyerrState == 3)
2a1fe6ed
AD
2157 /* We just shifted the error token and (perhaps) took some
2158 reductions. Skip tokens until we can proceed. */
56f8d560 2159 while (yytrue)
2a1fe6ed 2160 {
e9690142
JD
2161 yySymbol yytoken;
2162 if (yychar == YYEOF)
3e75a2c9 2163 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
e9690142
JD
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",
3e75a2c9 2175 yytoken, &yylval]b4_locuser_args([&yylloc])[);
e9690142
JD
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;
2a1fe6ed 2200 }
fb8135fa 2201
2a1fe6ed 2202 /* Reduce to one stack. */
3e7a2cd9 2203 for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
ef51bfa7 2204 if (yystackp->yytops.yystates[yyk] != YY_NULL)
01241d47 2205 break;
3e7a2cd9 2206 if (yyk >= yystackp->yytops.yysize)
ef51bfa7 2207 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
3e7a2cd9
PE
2208 for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
2209 yymarkStackDeleted (yystackp, yyk);
2210 yyremoveDeletes (yystackp);
2211 yycompressStack (yystackp);
01241d47 2212
9d9b8b70 2213 /* Now pop stack until we find a state that shifts the error token. */
3e7a2cd9 2214 yystackp->yyerrState = 3;
ef51bfa7 2215 while (yystackp->yytops.yystates[0] != YY_NULL)
01241d47 2216 {
3e7a2cd9 2217 yyGLRState *yys = yystackp->yytops.yystates[0];
7bd6c77e 2218 yyj = yypact[yys->yylrState];
f2b30bdf 2219 if (! yypact_value_is_default (yyj))
e9690142
JD
2220 {
2221 yyj += YYTERROR;
2222 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2223 && yyisShiftAction (yytable[yyj]))
2224 {
3e75a2c9
AD
2225 /* Shift the error token. */]b4_locations_if([[
2226 /* First adjust its location.*/
769a8ef9 2227 YYLTYPE yyerrloc;
e9690142
JD
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],
3e75a2c9 2233 yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
e9690142
JD
2234 yys = yystackp->yytops.yystates[0];
2235 break;
2236 }
3e75a2c9 2237 }]b4_locations_if([[
769a8ef9 2238 yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
ef51bfa7 2239 if (yys->yypred != YY_NULL)
e9690142 2240 yydestroyGLRState ("Error: popping", yys]b4_user_args[);
3e7a2cd9
PE
2241 yystackp->yytops.yystates[0] = yys->yypred;
2242 yystackp->yynextFree -= 1;
2243 yystackp->yyspaceLeft += 1;
01241d47 2244 }
ef51bfa7
AD
2245 if (yystackp->yytops.yystates[0] == YY_NULL)
2246 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
fb8135fa
AD
2247}
2248
e9690142
JD
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 } \
56f8d560 2263 } while (0)
01241d47 2264
0245f82d
AD
2265/*----------.
2266| yyparse. |
2267`----------*/
2268
15f66669 2269]b4_function_define([yyparse], [int], b4_parse_param)[
01241d47 2270{
6100a9aa 2271 int yyresult;
01241d47 2272 yyGLRStack yystack;
d6cff4dc 2273 yyGLRStack* const yystackp = &yystack;
01241d47 2274 size_t yyposn;
fb8135fa 2275
2f4f028d 2276 YYDPRINTF ((stderr, "Starting parse\n"));
2a1fe6ed 2277
bf70fa87 2278 yychar = YYEMPTY;
b8458aa5 2279 yylval = yyval_default;
327afc7c 2280]b4_locations_if([
9104636b 2281#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
cd48d21d
AD
2282 yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
2283 yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
b8458aa5
AD
2284#endif
2285])
2286m4_ifdef([b4_initial_action], [
cd735a8c 2287b4_dollar_pushdef([yylval], [], [yylloc])dnl
9d9b8b70 2288 /* User initialization code. */
8ec0a172 2289 b4_user_initial_action
cd735a8c 2290b4_dollar_popdef])[]dnl
b8458aa5 2291[
d6cff4dc 2292 if (! yyinitGLRStack (yystackp, YYINITDEPTH))
1a059451 2293 goto yyexhaustedlab;
c89b4c03 2294 switch (YYSETJMP (yystack.yyexception_buffer))
6100a9aa 2295 {
c89b4c03 2296 case 0: break;
6100a9aa 2297 case 1: goto yyabortlab;
1a059451 2298 case 2: goto yyexhaustedlab;
c89b4c03 2299 default: goto yybuglab;
6100a9aa 2300 }
769a8ef9 2301 yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[);
01241d47
PH
2302 yyposn = 0;
2303
56f8d560 2304 while (yytrue)
01241d47 2305 {
21964f43 2306 /* For efficiency, we have two loops, the first of which is
e9690142
JD
2307 specialized to deterministic operation (single stack, no
2308 potential ambiguity). */
01241d47 2309 /* Standard mode */
56f8d560 2310 while (yytrue)
e9690142
JD
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;
3e75a2c9 2359 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
e9690142
JD
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 }
01241d47 2373
56f8d560 2374 while (yytrue)
e9690142
JD
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,
3e75a2c9 2435 &yylval]b4_locations_if([, &yylloc])[);
e9690142
JD
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 }
01241d47
PH
2449 continue;
2450 yyuser_error:
d6cff4dc 2451 yyrecoverSyntaxError (&yystack]b4_user_args[);
01241d47
PH
2452 yyposn = yystack.yytops.yystates[0]->yyposn;
2453 }
6100a9aa
PE
2454
2455 yyacceptlab:
2456 yyresult = 0;
2457 goto yyreturn;
2458
127287e9
PE
2459 yybuglab:
2460 YYASSERT (yyfalse);
a85284cf 2461 goto yyabortlab;
127287e9 2462
6100a9aa
PE
2463 yyabortlab:
2464 yyresult = 1;
2465 goto yyreturn;
2466
1a059451
PE
2467 yyexhaustedlab:
2468 yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
6100a9aa 2469 yyresult = 2;
a85284cf 2470 goto yyreturn;
6100a9aa
PE
2471
2472 yyreturn:
868d2d96 2473 if (yychar != YYEMPTY)
dd5f2af2 2474 yydestruct ("Cleanup: discarding lookahead",
3e75a2c9 2475 YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
01241d47 2476
3922956a
PE
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)
e9690142
JD
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;]]
3e75a2c9 2494)[ if (yys->yypred != YY_NULL)
e9690142
JD
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 }
3922956a
PE
2503 yyfreeGLRStack (&yystack);
2504 }
258b75ca 2505
56f8d560 2506 return yyresult;
01241d47
PH
2507}
2508
2509/* DEBUGGING ONLY */
5f108727 2510#if ]b4_api_PREFIX[DEBUG
3e7a2cd9 2511static void yypstack (yyGLRStack* yystackp, size_t yyk)
135bc829 2512 __attribute__ ((__unused__));
3e7a2cd9 2513static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
01241d47 2514
1154cced 2515static void
cf126971 2516yy_yypstack (yyGLRState* yys)
01241d47 2517{
cf126971 2518 if (yys->yypred)
01241d47 2519 {
cf126971 2520 yy_yypstack (yys->yypred);
8a86eef0 2521 YYFPRINTF (stderr, " -> ");
01241d47 2522 }
8a86eef0
JD
2523 YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
2524 (unsigned long int) yys->yyposn);
cf126971 2525}
01241d47 2526
cf126971
PE
2527static void
2528yypstates (yyGLRState* yyst)
2529{
ef51bfa7 2530 if (yyst == YY_NULL)
8a86eef0 2531 YYFPRINTF (stderr, "<null>");
fb8135fa 2532 else
01241d47 2533 yy_yypstack (yyst);
8a86eef0 2534 YYFPRINTF (stderr, "\n");
01241d47
PH
2535}
2536
1154cced 2537static void
3e7a2cd9 2538yypstack (yyGLRStack* yystackp, size_t yyk)
01241d47 2539{
3e7a2cd9 2540 yypstates (yystackp->yytops.yystates[yyk]);
01241d47
PH
2541}
2542
e9690142 2543#define YYINDEX(YYX) \
ef51bfa7 2544 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
01241d47
PH
2545
2546
1154cced 2547static void
3e7a2cd9 2548yypdumpstack (yyGLRStack* yystackp)
01241d47
PH
2549{
2550 yyGLRStackItem* yyp;
1154cced 2551 size_t yyi;
3e7a2cd9 2552 for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
01241d47 2553 {
8a86eef0
JD
2554 YYFPRINTF (stderr, "%3lu. ",
2555 (unsigned long int) (yyp - yystackp->yyitems));
f7c398aa 2556 if (*(yybool *) yyp)
e9690142
JD
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
8a86eef0 2565 .yysemantics.yyfirstVal));
e9690142 2566 }
fb8135fa 2567 else
e9690142
JD
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 }
8a86eef0 2574 YYFPRINTF (stderr, "\n");
01241d47 2575 }
8a86eef0 2576 YYFPRINTF (stderr, "Tops:");
3e7a2cd9 2577 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
8a86eef0 2578 YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
e9690142 2579 (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
8a86eef0 2580 YYFPRINTF (stderr, "\n");
01241d47 2581}
417141dd 2582#endif
4524c55b 2583]b4_epilogue[]dnl
3f7ca628
JD
2584dnl
2585dnl glr.cc produces its own header.
2586dnl
2587m4_if(b4_skeleton, ["glr.c"],
2588[b4_defines_if(
a0d4650a 2589[@output(b4_spec_defines_file@)@
193d7c70 2590b4_copyright([Skeleton interface for Bison GLR parsers in C],
c3e9f08f
AD
2591 [2002-2012])[
2592
2593]b4_cpp_guard_open([b4_spec_defines_file])[
2594]b4_shared_declarations[
c3e9f08f
AD
2595]b4_cpp_guard_close([b4_spec_defines_file])[
2596]])])
08af01c2 2597m4_divert_pop(0)