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