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