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