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