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