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