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