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