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