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