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