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