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