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