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