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