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