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