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