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