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