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