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