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