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