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