]> git.saurik.com Git - bison.git/blame - data/glr.c
Let nondeterministic skeletons be usable with deterministic
[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
17acead5 139b4_token_defines(b4_tokens)
01241d47 140
17acead5
PE
141/* Copy the first part of user declarations. */
142b4_pre_prologue[
01241d47
PH
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([
f50adbbd
AD
172 int first_line;
173 int first_column;
174 int last_line;
175 int last_column;])[
01241d47
PH
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 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. */
a762e609 244static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
01241d47
PH
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. */
a762e609 252static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
01241d47
PH
253{
254 ]b4_prhs[
255};
256
257/* YYRHS -- A `-1'-separated list of the rules' RHS. */
a762e609 258static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
01241d47
PH
259{
260 ]b4_rhs[
261};
262
263/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
a762e609 264static const ]b4_int_type_for([b4_rline])[ yyrline[] =
01241d47
PH
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. */
a762e609 282static const ]b4_int_type_for([b4_r1])[ yyr1[] =
01241d47
PH
283{
284 ]b4_r1[
285};
286
287/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
a762e609 288static const ]b4_int_type_for([b4_r2])[ yyr2[] =
01241d47
PH
289{
290 ]b4_r2[
291};
292
293/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
a762e609 294static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
01241d47
PH
295{
296 ]b4_dprec[
297};
298
299/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
a762e609 300static const ]b4_int_type_for([b4_merger])[ yymerger[] =
01241d47
PH
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. */
a762e609 308static const ]b4_int_type_for([b4_defact])[ yydefact[] =
01241d47
PH
309{
310 ]b4_defact[
311};
312
12b0043a 313/* YYPDEFGOTO[NTERM-NUM]. */
a762e609 314static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
01241d47
PH
315{
316 ]b4_defgoto[
317};
318
319/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
320 STATE-NUM. */
12b0043a 321#define YYPACT_NINF ]b4_pact_ninf[
a762e609 322static const ]b4_int_type_for([b4_pact])[ yypact[] =
01241d47
PH
323{
324 ]b4_pact[
325};
326
327/* YYPGOTO[NTERM-NUM]. */
a762e609 328static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
01241d47
PH
329{
330 ]b4_pgoto[
331};
332
333/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
334 positive, shift that token. If negative, reduce the rule which
f50adbbd
AD
335 number is the opposite. If zero, do what YYDEFACT says.
336 If YYTABLE_NINF, parse error. */
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
ea99527d
AD
343/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
344 list of conflicting reductions corresponding to action entry for
345 state STATE-NUM in yytable. 0 means no conflicts. The list in
346 yyconfl 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
ea99527d
AD
352/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
353 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 398# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
f50adbbd
AD
399 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
400 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
401 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
402 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
01241d47
PH
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
2a1fe6ed 695/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
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;
f50adbbd 708 if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
01241d47
PH
709 {
710 *yyaction = -yydefact[yystate];
711 *yyconflicts = yyconfl;
712 }
f50adbbd 713 else if (yytable[yyindex] != YYTABLE_NINF)
01241d47
PH
714 {
715 *yyaction = yytable[yyindex];
716 *yyconflicts = yyconfl + yyconflp[yyindex];
717 }
f50adbbd
AD
718 else
719 {
720 *yyaction = 0;
721 *yyconflicts = yyconfl + yyconflp[yyindex];
722 }
01241d47
PH
723}
724
725static inline yyStateNum
726yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
727{
728 int yyr;
729 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
f50adbbd 730 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
01241d47
PH
731 return yytable[yyr];
732 else
733 return yydefgoto[yylhs - YYNTOKENS];
734}
735
736static inline bool
fb8135fa 737yyisShiftAction (int yyaction)
01241d47
PH
738{
739 return yyaction > 0;
740}
741
742static inline bool
fb8135fa 743yyisErrorAction (int yyaction)
01241d47 744{
f50adbbd 745 return yyaction == 0;
01241d47
PH
746}
747
748 /* GLRStates */
749
750/** True iff the semantic value of the edge leading to STATE is
751 * resolved. */
752static inline bool
fb8135fa 753yyhasResolvedValue (yyGLRState* yystate)
01241d47
PH
754{
755 return yystate->yyresolved;
756}
757
1154cced
AD
758static void
759yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
760 yyGLRState* yyrhs, yyRuleNum yyrule)
01241d47
PH
761{
762 yySemanticOption* yynewItem;
763 yynewItem = &yystack->yynextFree->yyoption;
764 yystack->yyspaceLeft -= 1;
765 yystack->yynextFree += 1;
766 yynewItem->yyisState = yyfalse;
767 yynewItem->yystate = yyrhs;
fb8135fa 768 yynewItem->yyrule = yyrule;
01241d47
PH
769 yynewItem->yynext = yystate->yysemantics.yyfirstVal;
770 yystate->yysemantics.yyfirstVal = yynewItem;
771 if (yystack->yyspaceLeft < YYHEADROOM)
772 yyexpandGLRStack (yystack);
773}
774
775 /* GLRStacks */
776
777/** Initialize SET to a singleton set containing an empty stack. */
778static void
779yyinitStateSet (yyGLRStateSet* yyset)
780{
781 yyset->yysize = 1;
782 yyset->yycapacity = 16;
783 yyset->yystates = (yyGLRState**) malloc (16 * sizeof (yyset->yystates[0]));
784 yyset->yystates[0] = NULL;
785}
786
fb8135fa 787static void yyfreeStateSet (yyGLRStateSet* yyset)
01241d47
PH
788{
789 free (yyset->yystates);
790}
791
792/** Initialize STACK to a single empty stack, with total maximum
793 * capacity for all stacks of SIZE. */
794static void
795yyinitGLRStack (yyGLRStack* yystack, size_t yysize)
796{
797 yystack->yyerrflag = 0;
798 yystack->yyerrState = 0;
799 yynerrs = 0;
800 yystack->yyspaceLeft = yysize;
fb8135fa 801 yystack->yynextFree = yystack->yyitems =
01241d47
PH
802 (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0]));
803 yystack->yysplitPoint = NULL;
804 yystack->yylastDeleted = NULL;
805 yyinitStateSet (&yystack->yytops);
806}
807
808#define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
809 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
810
811/** If STACK is expandable, extend it. WARNING: Pointers into the
812 stack from outside should be considered invalid after this call.
813 We always expand when there are 1 or fewer items left AFTER an
814 allocation, so that we can avoid having external pointers exist
815 across an allocation. */
816static void
fb8135fa 817yyexpandGLRStack (yyGLRStack* yystack)
01241d47
PH
818{
819#if YYSTACKEXPANDABLE
820 yyGLRStack yynewStack;
821 yyGLRStackItem* yyp0, *yyp1;
822 size_t yysize, yynewSize;
823 size_t yyn;
824 yysize = yystack->yynextFree - yystack->yyitems;
825 if (yysize >= YYMAXDEPTH)
826 yyFail (yystack, "parsing stack overflow (%d items)", yysize);
827 yynewSize = 2*yysize;
828 if (yynewSize > YYMAXDEPTH)
829 yynewSize = YYMAXDEPTH;
830 yyinitGLRStack (&yynewStack, yynewSize);
fb8135fa 831 for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;
01241d47 832 yyn > 0;
fb8135fa 833 yyn -= 1, yyp0 += 1, yyp1 += 1)
01241d47
PH
834 {
835 *yyp1 = *yyp0;
fb8135fa
AD
836 if (*(bool*) yyp0)
837 {
01241d47
PH
838 yyGLRState* yys0 = &yyp0->yystate;
839 yyGLRState* yys1 = &yyp1->yystate;
fb8135fa
AD
840 if (yys0->yypred != NULL)
841 yys1->yypred =
01241d47
PH
842 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
843 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
fb8135fa 844 yys1->yysemantics.yyfirstVal =
01241d47
PH
845 YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
846 }
fb8135fa 847 else
01241d47
PH
848 {
849 yySemanticOption* yyv0 = &yyp0->yyoption;
850 yySemanticOption* yyv1 = &yyp1->yyoption;
851 if (yyv0->yystate != NULL)
852 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
853 if (yyv0->yynext != NULL)
854 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
855 }
856 }
857 if (yystack->yysplitPoint != NULL)
fb8135fa 858 yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems,
01241d47 859 yystack->yysplitPoint, yystate);
fb8135fa
AD
860
861 for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1)
01241d47 862 if (yystack->yytops.yystates[yyn] != NULL)
fb8135fa
AD
863 yystack->yytops.yystates[yyn] =
864 YYRELOC (yystack->yyitems, yynewStack.yyitems,
01241d47
PH
865 yystack->yytops.yystates[yyn], yystate);
866 free (yystack->yyitems);
867 yystack->yyitems = yynewStack.yyitems;
868 yystack->yynextFree = yynewStack.yynextFree + yysize;
869 yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize;
870
871#else
fb8135fa 872
01241d47
PH
873 yyFail (yystack, "parsing stack overflow (%d items)", yysize);
874
fb8135fa 875#endif
01241d47
PH
876}
877
878static void
fb8135fa 879yyfreeGLRStack (yyGLRStack* yystack)
01241d47
PH
880{
881 free (yystack->yyitems);
882 yyfreeStateSet (&yystack->yytops);
883}
884
885/** Assuming that S is a GLRState somewhere on STACK, update the
fb8135fa 886 * splitpoint of STACK, if needed, so that it is at least as deep as
01241d47
PH
887 * S. */
888static inline void
fb8135fa 889yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys)
01241d47 890{
fb8135fa 891 if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys)
01241d47
PH
892 yystack->yysplitPoint = yys;
893}
894
895/** Invalidate stack #K in STACK. */
896static inline void
fb8135fa 897yymarkStackDeleted (yyGLRStack* yystack, int yyk)
01241d47
PH
898{
899 if (yystack->yytops.yystates[yyk] != NULL)
900 yystack->yylastDeleted = yystack->yytops.yystates[yyk];
901 yystack->yytops.yystates[yyk] = NULL;
902}
903
fb8135fa 904/** Undelete the last stack that was marked as deleted. Can only be
01241d47
PH
905 done once after a deletion, and only when all other stacks have
906 been deleted. */
907static void
908yyundeleteLastStack (yyGLRStack* yystack)
909{
910 if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0)
911 return;
fb8135fa 912 yystack->yytops.yystates[0] = yystack->yylastDeleted;
01241d47
PH
913 yystack->yytops.yysize = 1;
914 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
915 yystack->yylastDeleted = NULL;
916}
917
918static inline void
919yyremoveDeletes (yyGLRStack* yystack)
920{
1154cced 921 size_t yyi, yyj;
01241d47 922 yyi = yyj = 0;
fb8135fa 923 while (yyj < yystack->yytops.yysize)
01241d47
PH
924 {
925 if (yystack->yytops.yystates[yyi] == NULL)
926 {
1154cced 927 if (yyi == yyj)
01241d47
PH
928 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
929 yystack->yytops.yysize -= 1;
930 }
fb8135fa 931 else
01241d47
PH
932 {
933 yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi];
934 if (yyj != yyi)
935 YYDPRINTF ((stderr, "Rename stack %d -> %d.\n", yyi, yyj));
936 yyj += 1;
937 }
938 yyi += 1;
939 }
940}
941
fb8135fa 942/** Shift to a new state on stack #K of STACK, corresponding to LR state
01241d47
PH
943 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
944static inline void
fb8135fa
AD
945yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn,
946 YYSTYPE yysval, YYLTYPE* yylocp)
01241d47
PH
947{
948 yyGLRStackItem* yynewItem;
949
950 yynewItem = yystack->yynextFree;
951 yystack->yynextFree += 1;
952 yystack->yyspaceLeft -= 1;
953 yynewItem->yystate.yyisState = yytrue;
954 yynewItem->yystate.yylrState = yylrState;
955 yynewItem->yystate.yyposn = yyposn;
956 yynewItem->yystate.yyresolved = yytrue;
957 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
958 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
959 yynewItem->yystate.yysemantics.yysval = yysval;
960 yynewItem->yystate.yyloc = *yylocp;
961 if (yystack->yyspaceLeft < YYHEADROOM)
962 yyexpandGLRStack (yystack);
963}
964
965/** Shift to a new state on stack #K of STACK, to a new state
966 * corresponding to LR state LRSTATE, at input position POSN, with
967 * the (unresolved) semantic value of RHS under the action for RULE. */
968static inline void
fb8135fa 969yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState,
01241d47
PH
970 size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
971{
972 yyGLRStackItem* yynewItem;
973
974 yynewItem = yystack->yynextFree;
975 yynewItem->yystate.yyisState = yytrue;
976 yynewItem->yystate.yylrState = yylrState;
977 yynewItem->yystate.yyposn = yyposn;
978 yynewItem->yystate.yyresolved = yyfalse;
979 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
980 yynewItem->yystate.yysemantics.yyfirstVal = NULL;
981 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
982 yystack->yynextFree += 1;
983 yystack->yyspaceLeft -= 1;
984 yyaddDeferredAction (yystack, &yynewItem->yystate, yyrhs, yyrule);
985}
986
987/** Pop the symbols consumed by reduction #RULE from the top of stack
fb8135fa
AD
988 * #K of STACK, and perform the appropriate semantic action on their
989 * semantic values. Assumes that all ambiguities in semantic values
01241d47
PH
990 * have been previously resolved. Set *VALP to the resulting value,
991 * and *LOCP to the computed location (if any). Return value is as
992 * for userAction. */
993static inline int
994yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule,
995 YYSTYPE* yyvalp, YYLTYPE* yylocp)
996{
997 int yynrhs = yyrhsLength (yyrule);
998
fb8135fa 999 if (yystack->yysplitPoint == NULL)
01241d47
PH
1000 {
1001 /* Standard special case: single stack. */
1002 yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
1003 assert (yyk == 0);
1004 yystack->yynextFree -= yynrhs;
1005 yystack->yyspaceLeft += yynrhs;
1006 yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate;
fb8135fa 1007 if (yynrhs == 0)
01241d47
PH
1008 {
1009 *yyvalp = yyval_default;
1010 *yylocp = yyloc_default;
1011 }
fb8135fa 1012 else
01241d47
PH
1013 {
1014 *yyvalp = yyrhs[1-yynrhs].yystate.yysemantics.yysval;
1015 *yylocp = yyrhs[1-yynrhs].yystate.yyloc;
1016 }
1017 return yyuserAction (yyrule, yynrhs, yyrhs, yyvalp, yylocp, yystack);
1018 }
fb8135fa 1019 else
01241d47
PH
1020 {
1021 int yyi;
1022 yyGLRState* yys;
1023 yyGLRStackItem yyrhsVals[YYMAXRHS];
fb8135fa
AD
1024 for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; yyi >= 0;
1025 yyi -= 1, yys = yys->yypred)
01241d47
PH
1026 {
1027 assert (yys->yypred != NULL);
1028 yyrhsVals[yyi].yystate.yyresolved = yytrue;
1029 yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval;
1030 yyrhsVals[yyi].yystate.yyloc = yys->yyloc;
1031 }
1032 yyupdateSplit (yystack, yys);
1033 yystack->yytops.yystates[yyk] = yys;
fb8135fa 1034 if (yynrhs == 0)
01241d47
PH
1035 {
1036 *yyvalp = yyval_default;
1037 *yylocp = yyloc_default;
1038 }
fb8135fa 1039 else
01241d47
PH
1040 {
1041 *yyvalp = yyrhsVals[0].yystate.yysemantics.yysval;
1042 *yylocp = yyrhsVals[0].yystate.yyloc;
1043 }
fb8135fa 1044 return yyuserAction (yyrule, yynrhs, yyrhsVals + (yynrhs-1),
01241d47
PH
1045 yyvalp, yylocp, yystack);
1046 }
1047}
1048
1049/** Pop items off stack #K of STACK according to grammar rule RULE,
1050 * and push back on the resulting nonterminal symbol. Perform the
fb8135fa 1051 * semantic action associated with RULE and store its value with the
01241d47
PH
1052 * newly pushed state, if FORCEEVAL or if STACK is currently
1053 * unambiguous. Otherwise, store the deferred semantic action with
1054 * the new state. If the new state would have an identical input
1055 * position, LR state, and predecessor to an existing state on the stack,
fb8135fa
AD
1056 * it is identified with that existing state, eliminating stack #K from
1057 * the STACK. In this case, the (necessarily deferred) semantic value is
1058 * added to the options for the existing state's semantic value.
01241d47
PH
1059 */
1060static inline YYRESULTTAG
1154cced
AD
1061yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
1062 bool yyforceEval)
01241d47 1063{
1154cced 1064 size_t yyposn = yystack->yytops.yystates[yyk]->yyposn;
01241d47 1065
fb8135fa 1066 if (yyforceEval || yystack->yysplitPoint == NULL)
01241d47
PH
1067 {
1068 YYSTYPE yysval;
1069 YYLTYPE yyloc;
fb8135fa 1070
2a1fe6ed
AD
1071#if YYDEBUG
1072 if (yydebug)
1073 {
1074 int yyi;
1075 YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),",
1076 yyk, yyrule - 1, yyrline[yyrule]));
1077 /* Print the symbols being reduced, and their result. */
1078 for (yyi = yyprhs[yyrule]; yyrhs[yyi] >= 0; yyi++)
1079 YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
1080 YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule]));
1081 }
1082#endif
01241d47 1083 YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc));
fb8135fa
AD
1084 yyglrShift (yystack, yyk,
1085 yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,
01241d47
PH
1086 yylhsNonterm (yyrule)),
1087 yyposn, yysval, &yyloc);
2a1fe6ed
AD
1088 YYDPRINTF ((stderr, "Stack %d entering state %d\n",
1089 yyk, yystack->yytops.yystates[yyk]->yylrState));
01241d47 1090 }
fb8135fa 1091 else
01241d47 1092 {
1154cced
AD
1093 size_t yyi;
1094 int yyn;
01241d47
PH
1095 yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
1096 yyStateNum yynewLRState;
1097
fb8135fa
AD
1098 for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1099 yyn > 0; yyn -= 1)
01241d47
PH
1100 {
1101 yys = yys->yypred;
1102 assert (yys != NULL);
1103 }
1104 yyupdateSplit (yystack, yys);
1105 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
fb8135fa 1106 YYDPRINTF ((stderr,
01241d47
PH
1107 "Reduced stack %d by rule #%d; action deferred. "
1108 "Now in state %d.\n",
1109 yyk, yyrule-1, yynewLRState));
1110 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
fb8135fa 1111 if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL)
01241d47
PH
1112 {
1113 yyGLRState* yyp, *yysplit = yystack->yysplitPoint;
1114 yyp = yystack->yytops.yystates[yyi];
fb8135fa 1115 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
01241d47 1116 {
fb8135fa 1117 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
01241d47
PH
1118 {
1119 yyaddDeferredAction (yystack, yyp, yys0, yyrule);
1120 yymarkStackDeleted (yystack, yyk);
1121 YYDPRINTF ((stderr, "Merging stack %d into stack %d.\n",
1122 yyk, yyi));
1123 return 0;
1124 }
1125 yyp = yyp->yypred;
1126 }
1127 }
1128 yystack->yytops.yystates[yyk] = yys;
1129 yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule);
fb8135fa 1130 }
01241d47
PH
1131 return 0;
1132}
1133
1134static int
1135yysplitStack (yyGLRStack* yystack, int yyk)
1136{
fb8135fa 1137 if (yystack->yysplitPoint == NULL)
01241d47
PH
1138 {
1139 assert (yyk == 0);
1140 yystack->yysplitPoint = yystack->yytops.yystates[yyk];
1141 }
fb8135fa 1142 if (yystack->yytops.yysize >= yystack->yytops.yycapacity)
01241d47
PH
1143 {
1144 yystack->yytops.yycapacity *= 2;
fb8135fa
AD
1145 yystack->yytops.yystates =
1146 (yyGLRState**) realloc (yystack->yytops.yystates,
1147 yystack->yytops.yycapacity
01241d47
PH
1148 * sizeof (yyGLRState*));
1149 }
fb8135fa 1150 yystack->yytops.yystates[yystack->yytops.yysize]
01241d47
PH
1151 = yystack->yytops.yystates[yyk];
1152 yystack->yytops.yysize += 1;
1153 return yystack->yytops.yysize-1;
1154}
1155
1156/** True iff Y0 and Y1 represent identical options at the top level.
1157 * That is, they represent the same rule applied to RHS symbols
1158 * that produce the same terminal symbols. */
1159static bool
1160yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1161{
fb8135fa 1162 if (yyy0->yyrule == yyy1->yyrule)
01241d47
PH
1163 {
1164 yyGLRState *yys0, *yys1;
1165 int yyn;
fb8135fa 1166 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
01241d47
PH
1167 yyn = yyrhsLength (yyy0->yyrule);
1168 yyn > 0;
1169 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1170 if (yys0->yyposn != yys1->yyposn)
1171 return yyfalse;
1172 return yytrue;
1173 }
1174 else
1175 return yyfalse;
1176}
1177
1178/** Assuming identicalOptions (Y0,Y1), (destructively) merge the
fb8135fa 1179 * alternative semantic values for the RHS-symbols of Y1 into the
01241d47
PH
1180 * corresponding semantic value sets of the symbols of Y0. */
1181static void
1182yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1183{
1184 yyGLRState *yys0, *yys1;
1185 int yyn;
fb8135fa 1186 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
01241d47
PH
1187 yyn = yyrhsLength (yyy0->yyrule);
1188 yyn > 0;
1189 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1190 if (yys0 == yys1)
1191 break;
fb8135fa 1192 else if (! yys0->yyresolved && ! yys1->yyresolved)
01241d47
PH
1193 {
1194 yySemanticOption* yyz;
fb8135fa 1195 for (yyz = yys0->yysemantics.yyfirstVal; yyz->yynext != NULL;
01241d47
PH
1196 yyz = yyz->yynext)
1197 ;
1198 yyz->yynext = yys1->yysemantics.yyfirstVal;
1199 }
1200}
1201
1202/** Y0 and Y1 represent two possible actions to take in a given
1203 * parsing state; return 0 if no combination is possible,
1204 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1205static int
1154cced 1206yypreference (yySemanticOption* y0, yySemanticOption* y1)
01241d47 1207{
1154cced
AD
1208 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1209 int p0 = yydprec[r0], p1 = yydprec[r1];
01241d47 1210
1154cced 1211 if (p0 == p1)
01241d47 1212 {
1154cced 1213 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
01241d47
PH
1214 return 0;
1215 else
1216 return 1;
1217 }
1154cced 1218 if (p0 == 0 || p1 == 0)
01241d47 1219 return 0;
1154cced 1220 if (p0 < p1)
01241d47 1221 return 3;
1154cced 1222 if (p0 > p1)
01241d47
PH
1223 return 2;
1224 return 0;
1225}
1226
fb8135fa
AD
1227static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,
1228 yyGLRStack* yystack, YYSTYPE* yyvalp,
01241d47
PH
1229 YYLTYPE* yylocp);
1230
1231static YYRESULTTAG
1232yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack)
1233{
1234 YYRESULTTAG yyflag;
fb8135fa 1235 if (yyn > 0)
01241d47
PH
1236 {
1237 assert (yys->yypred != NULL);
1238 yyflag = yyresolveStates (yys->yypred, yyn-1, yystack);
1239 if (yyflag != yyok)
1240 return yyflag;
fb8135fa 1241 if (! yys->yyresolved)
01241d47
PH
1242 {
1243 yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,
1244 &yys->yysemantics.yysval, &yys->yyloc);
1245 if (yyflag != yyok)
1246 return yyflag;
1247 yys->yyresolved = yytrue;
1248 }
1249 }
1250 return yyok;
1251}
1252
1253static YYRESULTTAG
fb8135fa 1254yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
01241d47
PH
1255 YYSTYPE* yyvalp, YYLTYPE* yylocp)
1256{
1257 yyGLRStackItem yyrhsVals[YYMAXRHS];
1258 int yynrhs, yyi;
1259 yyGLRState* yys;
1260
1261 yynrhs = yyrhsLength (yyopt->yyrule);
1262 YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack));
fb8135fa 1263 for (yyi = yynrhs-1, yys = yyopt->yystate; yyi >= 0;
01241d47
PH
1264 yyi -= 1, yys = yys->yypred)
1265 {
1266 assert (yys->yypred != NULL);
1267 yyrhsVals[yyi].yystate.yyresolved = yytrue;
1268 yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval;
1269 yyrhsVals[yyi].yystate.yyloc = yys->yyloc;
fb8135fa
AD
1270 }
1271 return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + (yynrhs-1),
01241d47
PH
1272 yyvalp, yylocp, yystack);
1273}
1274
1275#if YYDEBUG
f50adbbd 1276static yyGLRState YYLEFTMOST_STATE = { 0, 0, -1, NULL, 0, { NULL } };
01241d47 1277
fb8135fa 1278static void yyreportTree (yySemanticOption* yyx, int yyindent)
01241d47
PH
1279{
1280 int yynrhs = yyrhsLength (yyx->yyrule);
1281 int yyi;
1282 yyGLRState* yys;
1283 yyGLRState* yystates[YYMAXRHS];
1284
1285 for (yyi = yynrhs, yys = yyx->yystate; yyi > 0; yyi -= 1, yys = yys->yypred)
1286 yystates[yyi] = yys;
1287 if (yys == NULL)
1288 yystates[0] = &YYLEFTMOST_STATE;
1289 else
1290 yystates[0] = yys;
1291
1292 if (yys->yyposn+1 > yyx->yystate->yyposn)
1293 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
fb8135fa 1294 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
01241d47
PH
1295 yyx->yyrule);
1296 else
fb8135fa 1297 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
01241d47
PH
1298 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1299 yyx->yyrule, yys->yyposn+1, yyx->yystate->yyposn);
fb8135fa 1300 for (yyi = 1; yyi <= yynrhs; yyi += 1)
01241d47 1301 {
fb8135fa 1302 if (yystates[yyi]->yyresolved)
01241d47
PH
1303 {
1304 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1305 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1306 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1307 else
1308 YYFPRINTF (stderr, "%*s%s <tokens %d .. %d>\n", yyindent+2, "",
1309 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1310 yystates[yyi-1]->yyposn+1, yystates[yyi]->yyposn);
1311 }
fb8135fa 1312 else
01241d47
PH
1313 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1314 }
1315}
fb8135fa 1316#endif
01241d47
PH
1317
1318static void
1319yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
1320 yyGLRStack* yystack)
1321{
1154cced
AD
1322 /* `Unused' warnings. */
1323 (void) yyx0;
1324 (void) yyx1;
1325
01241d47
PH
1326#if YYDEBUG
1327 YYFPRINTF (stderr, "Ambiguity detected.\n");
1328 YYFPRINTF (stderr, "Option 1,\n");
1329 yyreportTree (yyx0, 2);
1330 YYFPRINTF (stderr, "\nOption 2,\n");
1331 yyreportTree (yyx1, 2);
1332 YYFPRINTF (stderr, "\n");
1333#endif
1334 yyFail (yystack, "ambiguity detected");
1335}
1336
1337
1338/** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1339 * actions, and return the result. */
1340static YYRESULTTAG
fb8135fa
AD
1341yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,
1342 YYSTYPE* yyvalp, YYLTYPE* yylocp)
01241d47
PH
1343{
1344 yySemanticOption* yybest;
1345 yySemanticOption* yyp;
1346 int yymerge;
1347
fb8135fa 1348 yybest = yyoptionList;
01241d47 1349 yymerge = 0;
fb8135fa 1350 for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)
01241d47
PH
1351 {
1352 if (yyidenticalOptions (yybest, yyp))
1353 yymergeOptionSets (yybest, yyp);
1354 else
fb8135fa 1355 switch (yypreference (yybest, yyp))
01241d47
PH
1356 {
1357 case 0:
1358 yyreportAmbiguity (yybest, yyp, yystack);
1359 break;
1360 case 1:
1361 yymerge = 1;
1362 break;
1363 case 2:
1364 break;
1365 case 3:
1366 yybest = yyp;
1367 yymerge = 0;
1368 break;
1369 }
1370 }
1371
fb8135fa 1372 if (yymerge)
01241d47
PH
1373 {
1374 int yyprec = yydprec[yybest->yyrule];
1375 YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp));
fb8135fa 1376 for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
01241d47 1377 {
fb8135fa 1378 if (yyprec == yydprec[yyp->yyrule])
01241d47
PH
1379 {
1380 YYSTYPE yyval1;
1381 YYLTYPE yydummy;
1382 YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy));
1383 *yyvalp = yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1);
1384 }
1385 }
1386 return yyok;
1387 }
1388 else
1389 return yyresolveAction (yybest, yystack, yyvalp, yylocp);
1390}
1391
1392static YYRESULTTAG
fb8135fa 1393yyresolveStack (yyGLRStack* yystack)
01241d47 1394{
fb8135fa 1395 if (yystack->yysplitPoint != NULL)
01241d47
PH
1396 {
1397 yyGLRState* yys;
1398 int yyn;
1399
fb8135fa
AD
1400 for (yyn = 0, yys = yystack->yytops.yystates[0];
1401 yys != yystack->yysplitPoint;
01241d47
PH
1402 yys = yys->yypred, yyn += 1)
1403 ;
1404 YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack));
1405 }
1406 return yyok;
1407}
1408
1409static void
fb8135fa 1410yycompressStack (yyGLRStack* yystack)
01241d47
PH
1411{
1412 yyGLRState* yyp, *yyq, *yyr;
1413
1414 if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)
1415 return;
1416
fb8135fa
AD
1417 for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;
1418 yyp != yystack->yysplitPoint;
01241d47
PH
1419 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1420 yyp->yypred = yyr;
fb8135fa 1421
01241d47
PH
1422 yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;
1423 yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;
1424 yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;
1425 yystack->yysplitPoint = NULL;
1426 yystack->yylastDeleted = NULL;
fb8135fa
AD
1427
1428 while (yyr != NULL)
1429 {
01241d47
PH
1430 yystack->yynextFree->yystate = *yyr;
1431 yyr = yyr->yypred;
1432 yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;
1433 yystack->yytops.yystates[0] = &yystack->yynextFree->yystate;
1434 yystack->yynextFree += 1;
1435 yystack->yyspaceLeft -= 1;
1436 }
1437}
1438
1439static YYRESULTTAG
fb8135fa 1440yyprocessOneStack (yyGLRStack* yystack, int yyk,
01241d47
PH
1441 size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
1442{
1443 int yyaction;
1444 const short* yyconflicts;
1445 yyRuleNum yyrule;
1446 yySymbol* const yytokenp = yystack->yytokenp;
1447
fb8135fa 1448 while (yystack->yytops.yystates[yyk] != NULL)
01241d47
PH
1449 {
1450 yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;
1451
1452 assert (yystate != YYFINAL);
fb8135fa 1453 if (yyisDefaultedState (yystate))
01241d47
PH
1454 {
1455 yyrule = yydefaultAction (yystate);
fb8135fa 1456 if (yyrule == 0)
01241d47
PH
1457 {
1458 YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1459 yymarkStackDeleted (yystack, yyk);
1460 return yyok;
1461 }
1462 YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse));
1463 }
fb8135fa 1464 else
01241d47 1465 {
fb8135fa 1466 if (*yytokenp == YYEMPTY)
01241d47 1467 {
2a1fe6ed 1468 YYDPRINTF ((stderr, "Reading a token: "));
01241d47
PH
1469 yychar = YYLEX;
1470 *yytokenp = YYTRANSLATE(yychar);
2a1fe6ed
AD
1471 YYDPRINTF ((stderr, "Next token is %s\n",
1472 yytokenName (*yytokenp)));
01241d47
PH
1473 }
1474 yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
1475
fb8135fa 1476 while (*yyconflicts != 0)
01241d47
PH
1477 {
1478 int yynewStack = yysplitStack (yystack, yyk);
1479 YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n",
1480 yynewStack, yyk));
1481 YYCHK (yyglrReduce (yystack, yynewStack, *yyconflicts, yyfalse));
fb8135fa 1482 YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,
01241d47
PH
1483 yylvalp, yyllocp));
1484 yyconflicts += 1;
1485 }
fb8135fa
AD
1486
1487 if (yyisShiftAction (yyaction))
01241d47 1488 {
2a1fe6ed 1489 YYDPRINTF ((stderr, "Shifting token %s on stack %d, ",
01241d47
PH
1490 yytokenName (*yytokenp), yyk));
1491 yyglrShift (yystack, yyk, yyaction, yyposn+1, *yylvalp, yyllocp);
fb8135fa 1492 YYDPRINTF ((stderr, "which is now in state #%d\n",
01241d47
PH
1493 yystack->yytops.yystates[yyk]->yylrState));
1494 break;
1495 }
fb8135fa 1496 else if (yyisErrorAction (yyaction))
01241d47
PH
1497 {
1498 YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1499 yymarkStackDeleted (yystack, yyk);
1500 break;
1501 }
1502 else
1503 YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse));
1504 }
1505 }
1506 return yyok;
1507}
1508
1509static void
1510yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
1511{
1154cced
AD
1512 /* `Unused' warnings. */
1513 (void) yylvalp;
1514 (void) yyllocp;
01241d47
PH
1515
1516 if (yystack->yyerrState == 0)
1517 {
fb8135fa 1518#if YYERROR_VERBOSE
1154cced 1519 yySymbol* const yytokenp = yystack->yytokenp;
cf126971
PE
1520 int yyn, yyx, yycount;
1521 size_t yysize;
1154cced 1522 const char* yyprefix;
01241d47
PH
1523 char* yyp;
1524 char* yymsg;
1525 yyn = yypact[yystack->yytops.yystates[0]->yylrState];
12b0043a 1526 if (YYPACT_NINF < yyn && yyn < YYLAST)
01241d47
PH
1527 {
1528 yycount = 0;
1529 /* Start YYX at -YYN if negative to avoid negative indexes in
1530 YYCHECK. */
fb8135fa 1531 yysize = sizeof ("parse error, unexpected ")
01241d47
PH
1532 + strlen (yytokenName (*yytokenp));
1533 yyprefix = ", expecting ";
fb8135fa 1534 for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;
01241d47 1535 yyx += 1)
217598da 1536 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
01241d47
PH
1537 yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
1538 yycount += 1, yyprefix = " or ";
1539 yymsg = yyp = (char*) malloc (yysize);
fb8135fa 1540 yyp += sprintf (yyp, "parse error, unexpected %s",
01241d47
PH
1541 yytokenName (*yytokenp));
1542 if (yycount < 5)
1543 {
1544 yyprefix = ", expecting ";
1545 for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size; yyx += 1)
f50adbbd 1546 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
01241d47
PH
1547 {
1548 yyp += sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
1549 yyprefix = " or ";
1550 }
1551 }
1552 yyerror (yymsg);
1553 free (yymsg);
1554 }
1555 else
1556#endif
1557 yyerror ("parse error");
1558 yynerrs += 1;
1559 }
1560}
1561
f50adbbd 1562/* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
01241d47 1563 YYLVALP, and YYLLOCP point to the syntactic category, semantic
f50adbbd 1564 value, and location of the lookahead. */
fb8135fa 1565static void
01241d47
PH
1566yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
1567{
1568 yySymbol* const yytokenp = yystack->yytokenp;
1154cced
AD
1569 size_t yyk;
1570 int yyj;
01241d47 1571
fb8135fa 1572 if (yystack->yyerrState == 0)
01241d47 1573 yystack->yyerrState = 3;
fb8135fa 1574 else if (yystack->yyerrState == 3)
2a1fe6ed
AD
1575 /* We just shifted the error token and (perhaps) took some
1576 reductions. Skip tokens until we can proceed. */
1577 while (yytrue)
1578 {
01241d47
PH
1579 if (*yytokenp == YYEOF)
1580 yyFail (yystack, NULL);
1581 if (*yytokenp != YYEMPTY)
fb8135fa 1582 YYDPRINTF ((stderr, "Discarding token %s\n",
01241d47 1583 yytokenName (*yytokenp)));
2a1fe6ed 1584 YYDPRINTF ((stderr, "Reading a token: "));
01241d47
PH
1585 yychar = YYLEX;
1586 *yytokenp = YYTRANSLATE (yychar);
2a1fe6ed 1587 YYDPRINTF ((stderr, "Next token is %s\n", yytokenName (*yytokenp)));
01241d47 1588 yyj = yypact[yystack->yytops.yystates[0]->yylrState];
12b0043a 1589 if (yyj == YYPACT_NINF)
2a1fe6ed 1590 /* Something's not right; we shouldn't be here. */
01241d47
PH
1591 yyFail (yystack, NULL);
1592 yyj += *yytokenp;
ea99527d 1593 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp)
01241d47
PH
1594 {
1595 if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
1596 return;
1597 }
12b0043a 1598 else if (yytable[yyj] != 0 && yytable[yyj] != YYTABLE_NINF)
01241d47 1599 return;
2a1fe6ed 1600 }
fb8135fa 1601
2a1fe6ed 1602 /* Reduce to one stack. */
01241d47
PH
1603 for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)
1604 if (yystack->yytops.yystates[yyk] != NULL)
1605 break;
1606 if (yyk >= yystack->yytops.yysize)
1607 yyFail (yystack, NULL);
1608 for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1)
1609 yymarkStackDeleted (yystack, yyk);
1610 yyremoveDeletes (yystack);
1611 yycompressStack (yystack);
1612
1613 /* Now pop stack until we find a state that shifts the error token. */
fb8135fa 1614 while (yystack->yytops.yystates[0] != NULL)
01241d47
PH
1615 {
1616 yyj = yypact[yystack->yytops.yystates[0]->yylrState] + YYTERROR;
12b0043a 1617 if (yyj != YYPACT_NINF + YYTERROR && yyj >= 0 && yyj <= YYLAST &&
01241d47
PH
1618 yycheck[yyj] == YYTERROR && yyisShiftAction (yytable[yyj]))
1619 {
fb8135fa 1620 yyglrShift (yystack, 0, yytable[yyj],
01241d47
PH
1621 yystack->yytops.yystates[0]->yyposn, *yylvalp, yyllocp);
1622 break;
1623 }
1624 yystack->yytops.yystates[0] = yystack->yytops.yystates[0]->yypred;
1625 yystack->yynextFree -= 1;
1626 yystack->yyspaceLeft += 1;
1627 }
1628 if (yystack->yytops.yystates[0] == NULL)
1629 yyFail (yystack, NULL);
fb8135fa
AD
1630}
1631
01241d47
PH
1632#define YYCHK1(YYE) \
1633 do { \
1634 switch (YYE) { \
1635 default: \
1636 break; \
1637 case yyabort: \
1638 yystack.yyerrflag = 1; \
1639 goto yyDone; \
1640 case yyaccept: \
1641 yystack.yyerrflag = 0; \
1642 goto yyDone; \
1643 case yyerr: \
1644 goto yyuser_error; \
1645 } \
fb8135fa 1646 } while (0)
01241d47
PH
1647
1648int
fb8135fa 1649yyparse (YYPARSE_PARAM_ARG)
01241d47
PH
1650{
1651 yySymbol yytoken;
1652 yyGLRStack yystack;
1653 size_t yyposn;
1654]b4_pure_if(
1655[
1656 YYSTYPE yylval;
1657 YYLTYPE yylloc;
1658 #undef yychar
1659 #define yychar (yystack.yyrawchar)
1660])[
1661
1662 YYSTYPE* const yylvalp = &yylval;
1663 YYLTYPE* const yyllocp = &yylloc;
fb8135fa 1664
01241d47
PH
1665 yyinitGLRStack (&yystack, YYINITDEPTH);
1666 yystack.yytokenp = &yytoken;
1667
2a1fe6ed
AD
1668 YYDPRINTF ((stderr, "Starting parse\n"));
1669
01241d47
PH
1670 if (setjmp (yystack.yyexception_buffer) != 0)
1671 goto yyDone;
1672
1673 yyglrShift (&yystack, 0, 0, 0, yyval_default, &yyloc_default);
1674 yytoken = YYEMPTY;
1675 yyposn = 0;
1676
fb8135fa 1677 while (yytrue)
01241d47
PH
1678 {
1679 /* For efficiency, we have two loops, of which the first of which
1680 * is specialized to deterministic operation (single stack, no
1681 * potential ambiguity). */
fb8135fa 1682
01241d47 1683 /* Standard mode */
fb8135fa 1684 while (yytrue)
01241d47
PH
1685 {
1686 yyRuleNum yyrule;
1687 int yyaction;
1688 const short* yyconflicts;
1689
1690 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
1691 if (yystate == YYFINAL)
1692 goto yyDone;
fb8135fa 1693 if (yyisDefaultedState (yystate))
01241d47
PH
1694 {
1695 yyrule = yydefaultAction (yystate);
fb8135fa 1696 if (yyrule == 0)
01241d47
PH
1697 {
1698 yyreportParseError (&yystack, yylvalp, yyllocp);
1699 goto yyuser_error;
1700 }
1701 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue));
1702 }
fb8135fa 1703 else
01241d47 1704 {
fb8135fa 1705 if (yytoken == YYEMPTY)
01241d47 1706 {
2a1fe6ed 1707 YYDPRINTF ((stderr, "Reading a token: "));
01241d47
PH
1708 yychar = YYLEX;
1709 yytoken = YYTRANSLATE (yychar);
2a1fe6ed 1710 YYDPRINTF ((stderr, "Next token is %s\n",
01241d47
PH
1711 yytokenName (yytoken)));
1712 }
1713 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
1714 if (*yyconflicts != 0)
1715 break;
fb8135fa 1716 if (yyisShiftAction (yyaction))
01241d47 1717 {
2a1fe6ed 1718 YYDPRINTF ((stderr, "Shifting token %s, ",
01241d47
PH
1719 yytokenName (yytoken)));
1720 if (yytoken != YYEOF)
1721 yytoken = YYEMPTY;
1722 yyposn += 1;
1723 yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
1724 if (yystack.yyerrState > 0)
1725 yystack.yyerrState -= 1;
2a1fe6ed 1726 YYDPRINTF ((stderr, "Entering state %d\n",
01241d47
PH
1727 yystack.yytops.yystates[0]->yylrState));
1728 }
1729 else if (yyisErrorAction (yyaction))
1730 {
1731 yyreportParseError (&yystack, yylvalp, yyllocp);
1732 goto yyuser_error;
1733 }
1734 else
1735 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue));
1736 }
1737 }
1738
fb8135fa 1739 while (yytrue)
01241d47
PH
1740 {
1741 int yys;
1742 int yyn = yystack.yytops.yysize;
1743 for (yys = 0; yys < yyn; yys += 1)
1744 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn,
1745 yylvalp, yyllocp));
1746 yytoken = YYEMPTY;
1747 yyposn += 1;
1748 yyremoveDeletes (&yystack);
1749 if (yystack.yytops.yysize == 0)
1750 {
1751 yyundeleteLastStack (&yystack);
1752 if (yystack.yytops.yysize == 0)
1753 yyFail (&yystack, "parse error");
1754 YYCHK1 (yyresolveStack (&yystack));
1755 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
1756 yyreportParseError (&yystack, yylvalp, yyllocp);
1757 goto yyuser_error;
1758 }
fb8135fa 1759 else if (yystack.yytops.yysize == 1)
01241d47
PH
1760 {
1761 YYCHK1 (yyresolveStack (&yystack));
1762 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
1763 yycompressStack (&yystack);
1764 break;
1765 }
1766 }
1767 continue;
1768 yyuser_error:
1769 yyrecoverParseError (&yystack, yylvalp, yyllocp);
1770 yyposn = yystack.yytops.yystates[0]->yyposn;
1771 }
1772 yyDone:
1773 ;
1774
1775 yyfreeGLRStack (&yystack);
1776 return yystack.yyerrflag;
1777}
1778
1779/* DEBUGGING ONLY */
1154cced
AD
1780static void yypstack (yyGLRStack* yystack, int yyk) ATTRIBUTE_UNUSED;
1781static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED;
01241d47 1782
1154cced 1783static void
cf126971 1784yy_yypstack (yyGLRState* yys)
01241d47 1785{
cf126971 1786 if (yys->yypred)
01241d47 1787 {
cf126971
PE
1788 yy_yypstack (yys->yypred);
1789 fprintf (stderr, " -> ");
01241d47 1790 }
cf126971
PE
1791 fprintf (stderr, "%d@%lu", yys->yylrState, (unsigned long) yys->yyposn);
1792}
01241d47 1793
cf126971
PE
1794static void
1795yypstates (yyGLRState* yyst)
1796{
fb8135fa 1797 if (yyst == NULL)
01241d47 1798 fprintf (stderr, "<null>");
fb8135fa 1799 else
01241d47
PH
1800 yy_yypstack (yyst);
1801 fprintf (stderr, "\n");
1802}
1803
1154cced 1804static void
fb8135fa 1805yypstack (yyGLRStack* yystack, int yyk)
01241d47
PH
1806{
1807 yypstates (yystack->yytops.yystates[yyk]);
1808}
1809
1810#define YYINDEX(YYX) \
1811 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1812
1813
1154cced 1814static void
fb8135fa 1815yypdumpstack (yyGLRStack* yystack)
01241d47
PH
1816{
1817 yyGLRStackItem* yyp;
1154cced 1818 size_t yyi;
fb8135fa 1819 for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
01241d47 1820 {
cf126971 1821 fprintf (stderr, "%3lu. ", (unsigned long) (yyp - yystack->yyitems));
fb8135fa 1822 if (*(bool*) yyp)
01241d47 1823 {
cf126971 1824 fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
fb8135fa 1825 yyp->yystate.yyresolved, yyp->yystate.yylrState,
cf126971
PE
1826 (unsigned long) yyp->yystate.yyposn,
1827 (long) YYINDEX (yyp->yystate.yypred));
fb8135fa 1828 if (! yyp->yystate.yyresolved)
cf126971
PE
1829 fprintf (stderr, ", firstVal: %ld",
1830 (long) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
01241d47 1831 }
fb8135fa 1832 else
01241d47 1833 {
cf126971
PE
1834 fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
1835 yyp->yyoption.yyrule,
1836 (long) YYINDEX (yyp->yyoption.yystate),
1837 (long) YYINDEX (yyp->yyoption.yynext));
01241d47
PH
1838 }
1839 fprintf (stderr, "\n");
1840 }
1841 fprintf (stderr, "Tops:");
1842 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
cf126971
PE
1843 fprintf (stderr, "%lu: %ld; ", (unsigned long) yyi,
1844 (long) YYINDEX (yystack->yytops.yystates[yyi]));
01241d47
PH
1845 fprintf (stderr, "\n");
1846}
1847
1848]
1849
1850b4_epilogue
1851m4_if(b4_defines_flag, 0, [],
1852[#output "b4_output_header_name"
fb8135fa 1853b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
01241d47
PH
1854#ifndef b4_header_guard
1855# define b4_header_guard
1856
1857b4_token_defines(b4_tokens)
1858
1859#ifndef YYSTYPE
1860m4_ifdef([b4_stype],
1861[#line b4_stype_line "b4_filename"
1862typedef union b4_stype yystype;
1863/* Line __line__ of __file__. */
1864#line __oline__ "__ofile__"],
1865[typedef int yystype;])
1866# define YYSTYPE yystype
1867#endif
1868
1869b4_pure_if([],
1870[extern YYSTYPE b4_prefix[]lval;])
1871
1872b4_location_if(
1873[#ifndef YYLTYPE
1874typedef struct yyltype
1875{
f50adbbd
AD
1876 int first_line;
1877 int first_column;
1878 int last_line;
1879 int last_column;
01241d47
PH
1880} yyltype;
1881# define YYLTYPE yyltype
1882#endif
1883
1884m4_if(b4_pure, [0],
1885[extern YYLTYPE b4_prefix[]lloc;])
1886])
1887#endif /* not b4_header_guard */
1888])