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