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