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