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