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