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