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