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