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