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