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