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