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