]> git.saurik.com Git - bison.git/blame_incremental - data/glr.c
gnulib: update
[bison.git] / data / glr.c
... / ...
CommitLineData
1 -*- C -*-
2
3# GLR skeleton for Bison
4
5# Copyright (C) 2002-2015 Free Software Foundation, Inc.
6
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21# If we are loaded by glr.cc, do not override c++.m4 definitions by
22# those of c.m4.
23m4_if(b4_skeleton, ["glr.c"],
24 [m4_include(b4_pkgdatadir/[c.m4])])
25
26## ---------------- ##
27## Default values. ##
28## ---------------- ##
29
30# Stack parameters.
31m4_define_default([b4_stack_depth_max], [10000])
32m4_define_default([b4_stack_depth_init], [200])
33
34
35
36## ------------------------ ##
37## Pure/impure interfaces. ##
38## ------------------------ ##
39
40b4_define_flag_if([pure])
41# If glr.cc is including this file and thus has already set b4_pure_flag,
42# do not change the value of b4_pure_flag, and do not record a use of api.pure.
43m4_ifndef([b4_pure_flag],
44[b4_percent_define_default([[api.pure]], [[false]])
45 m4_define([b4_pure_flag],
46 [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])])
47
48# b4_user_formals
49# ---------------
50# The possible parse-params formal arguments preceded by a comma.
51#
52# This is not shared with yacc.c in c.m4 because GLR relies on ISO C
53# formal argument declarations.
54m4_define([b4_user_formals],
55[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
56
57
58# b4_yyerror_args
59# ---------------
60# Optional effective arguments passed to yyerror: user args plus yylloc, and
61# a trailing comma.
62m4_define([b4_yyerror_args],
63[b4_pure_if([b4_locations_if([yylocp, ])])dnl
64m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
65
66
67# b4_lyyerror_args
68# ----------------
69# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
70m4_define([b4_lyyerror_args],
71[b4_pure_if([b4_locations_if([&yylloc, ])])dnl
72m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
73
74
75# b4_pure_args
76# ------------
77# Same as b4_yyerror_args, but with a leading comma.
78m4_define([b4_pure_args],
79[b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args])
80
81
82# b4_lpure_args
83# -------------
84# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
85m4_define([b4_lpure_args],
86[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args])
87
88
89
90# b4_pure_formals
91# ---------------
92# Arguments passed to yyerror: user formals plus yylocp with leading comma.
93m4_define([b4_pure_formals],
94[b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals])
95
96
97# b4_locuser_formals(LOC = yylocp)
98# --------------------------------
99m4_define([b4_locuser_formals],
100[b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals])
101
102
103# b4_locuser_args(LOC = yylocp)
104# -----------------------------
105m4_define([b4_locuser_args],
106[b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args])
107
108
109
110## ----------------- ##
111## Semantic Values. ##
112## ----------------- ##
113
114
115# b4_lhs_value([TYPE])
116# --------------------
117# Expansion of $<TYPE>$.
118m4_define([b4_lhs_value],
119[b4_symbol_value([(*yyvalp)], [$1])])
120
121
122# b4_rhs_data(RULE-LENGTH, NUM)
123# -----------------------------
124# Expand to the semantic stack place that contains value and location
125# of symbol number NUM in a rule of length RULE-LENGTH.
126m4_define([b4_rhs_data],
127[((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate])
128
129
130# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
131# --------------------------------------
132# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
133# symbols on RHS.
134m4_define([b4_rhs_value],
135[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])])
136
137
138
139## ----------- ##
140## Locations. ##
141## ----------- ##
142
143# b4_lhs_location()
144# -----------------
145# Expansion of @$.
146m4_define([b4_lhs_location],
147[(*yylocp)])
148
149
150# b4_rhs_location(RULE-LENGTH, NUM)
151# ---------------------------------
152# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
153# on RHS.
154m4_define([b4_rhs_location],
155[(b4_rhs_data([$1], [$2]).yyloc)])
156
157
158## -------------- ##
159## Declarations. ##
160## -------------- ##
161
162# b4_shared_declarations
163# ----------------------
164# Declaration that might either go into the header (if --defines)
165# or open coded in the parser body. glr.cc has its own definition.
166m4_if(b4_skeleton, ["glr.c"],
167[m4_define([b4_shared_declarations],
168[b4_declare_yydebug[
169]b4_percent_code_get([[requires]])[
170]b4_token_enums[
171]b4_declare_yylstype[
172]b4_function_declare(b4_prefix[parse], [int], b4_parse_param)[
173]b4_percent_code_get([[provides]])[]dnl
174])
175])
176
177## -------------- ##
178## Output files. ##
179## -------------- ##
180
181# Unfortunately the order of generation between the header and the
182# implementation file matters (for glr.c) because of the current
183# implementation of api.value.type=union. In that case we still use a
184# union for YYSTYPE, but we generate the contents of this union when
185# setting up YYSTYPE. This is needed for other aspects, such as
186# defining yy_symbol_value_print, since we need to now the name of the
187# members of this union.
188#
189# To avoid this issue, just generate the header before the
190# implementation file. But we should also make them more independant.
191
192# ----------------- #
193# The header file. #
194# ----------------- #
195
196# glr.cc produces its own header.
197m4_if(b4_skeleton, ["glr.c"],
198[b4_defines_if(
199[b4_output_begin([b4_spec_defines_file])
200b4_copyright([Skeleton interface for Bison GLR parsers in C],
201 [2002-2015])[
202
203]b4_cpp_guard_open([b4_spec_defines_file])[
204]b4_shared_declarations[
205]b4_cpp_guard_close([b4_spec_defines_file])[
206]b4_output_end()
207])])
208
209
210# ------------------------- #
211# The implementation file. #
212# ------------------------- #
213
214b4_output_begin([b4_parser_file_name])
215b4_copyright([Skeleton implementation for Bison GLR parsers in C],
216 [2002-2015])[
217
218/* C GLR parser skeleton written by Paul Hilfinger. */
219
220]b4_identification
221
222b4_percent_code_get([[top]])[
223]m4_if(b4_api_prefix, [yy], [],
224[[/* Substitute the type names. */
225#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
226#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
227]m4_if(b4_prefix, [yy], [],
228[[/* Substitute the variable and function names. */
229#define yyparse ]b4_prefix[parse
230#define yylex ]b4_prefix[lex
231#define yyerror ]b4_prefix[error
232#define yydebug ]b4_prefix[debug
233]]b4_pure_if([], [[
234#define yylval ]b4_prefix[lval
235#define yychar ]b4_prefix[char
236#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
237#define yylloc ]b4_prefix[lloc]])]))[
238
239/* First part of user declarations. */
240]b4_user_pre_prologue[
241
242]b4_null_define[
243
244]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
245 [b4_shared_declarations])[
246
247/* Enabling verbose error messages. */
248#ifdef YYERROR_VERBOSE
249# undef YYERROR_VERBOSE
250# define YYERROR_VERBOSE 1
251#else
252# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
253#endif
254
255/* Default (constant) value used for initialization for null
256 right-hand sides. Unlike the standard yacc.c template, here we set
257 the default value of $$ to a zeroed-out value. Since the default
258 value is undefined, this behavior is technically correct. */
259static YYSTYPE yyval_default;]b4_locations_if([[
260static YYLTYPE yyloc_default][]b4_yyloc_default;])[
261
262/* Copy the second part of user declarations. */
263]b4_user_post_prologue
264b4_percent_code_get[]dnl
265
266[#include <stdio.h>
267#include <stdlib.h>
268#include <string.h>
269
270#ifndef YY_
271# if defined YYENABLE_NLS && YYENABLE_NLS
272# if ENABLE_NLS
273# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
274# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
275# endif
276# endif
277# ifndef YY_
278# define YY_(Msgid) Msgid
279# endif
280#endif
281
282#ifndef YYFREE
283# define YYFREE free
284#endif
285#ifndef YYMALLOC
286# define YYMALLOC malloc
287#endif
288#ifndef YYREALLOC
289# define YYREALLOC realloc
290#endif
291
292#define YYSIZEMAX ((size_t) -1)
293
294#ifdef __cplusplus
295 typedef bool yybool;
296#else
297 typedef unsigned char yybool;
298#endif
299#define yytrue 1
300#define yyfalse 0
301
302#ifndef YYSETJMP
303# include <setjmp.h>
304# define YYJMP_BUF jmp_buf
305# define YYSETJMP(Env) setjmp (Env)
306/* Pacify clang. */
307# define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
308#endif
309
310]b4_attribute_define[
311
312#ifndef YYASSERT
313# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
314#endif
315
316/* YYFINAL -- State number of the termination state. */
317#define YYFINAL ]b4_final_state_number[
318/* YYLAST -- Last index in YYTABLE. */
319#define YYLAST ]b4_last[
320
321/* YYNTOKENS -- Number of terminals. */
322#define YYNTOKENS ]b4_tokens_number[
323/* YYNNTS -- Number of nonterminals. */
324#define YYNNTS ]b4_nterms_number[
325/* YYNRULES -- Number of rules. */
326#define YYNRULES ]b4_rules_number[
327/* YYNRULES -- Number of states. */
328#define YYNSTATES ]b4_states_number[
329/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
330#define YYMAXRHS ]b4_r2_max[
331/* YYMAXLEFT -- Maximum number of symbols to the left of a handle
332 accessed by $0, $-1, etc., in any rule. */
333#define YYMAXLEFT ]b4_max_left_semantic_context[
334
335/* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
336#define YYUNDEFTOK ]b4_undef_token_number[
337#define YYMAXUTOK ]b4_user_token_number_max[
338
339#define YYTRANSLATE(YYX) \
340 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
341
342/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
343static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
344{
345 ]b4_translate[
346};
347
348#if ]b4_api_PREFIX[DEBUG
349/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
350static const ]b4_int_type_for([b4_rline])[ yyrline[] =
351{
352 ]b4_rline[
353};
354#endif
355
356#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
357/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
358 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
359static const char *const yytname[] =
360{
361 ]b4_tname[
362};
363#endif
364
365#define YYPACT_NINF ]b4_pact_ninf[
366#define YYTABLE_NINF ]b4_table_ninf[
367
368]b4_parser_tables_define[
369
370/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
371static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
372{
373 ]b4_dprec[
374};
375
376/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
377static const ]b4_int_type_for([b4_merger])[ yymerger[] =
378{
379 ]b4_merger[
380};
381
382/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
383 in the case of predicates. */
384static const yybool yyimmediate[] =
385{
386 ]b4_immediate[
387};
388
389/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
390 list of conflicting reductions corresponding to action entry for
391 state STATE-NUM in yytable. 0 means no conflicts. The list in
392 yyconfl is terminated by a rule number of 0. */
393static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
394{
395 ]b4_conflict_list_heads[
396};
397
398/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
399 0, pointed into by YYCONFLP. */
400]dnl Do not use b4_int_type_for here, since there are places where
401dnl pointers onto yyconfl are taken, whose type is "short int *".
402dnl We probably ought to introduce a type for confl.
403[static const short int yyconfl[] =
404{
405 ]b4_conflicting_rules[
406};
407
408/* Error token number */
409#define YYTERROR 1
410
411]b4_locations_if([[
412]b4_yylloc_default_define[
413# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
414]])[
415
416]b4_pure_if(
417[
418#undef yynerrs
419#define yynerrs (yystackp->yyerrcnt)
420#undef yychar
421#define yychar (yystackp->yyrawchar)
422#undef yylval
423#define yylval (yystackp->yyval)
424#undef yylloc
425#define yylloc (yystackp->yyloc)
426m4_if(b4_prefix[], [yy], [],
427[#define b4_prefix[]nerrs yynerrs
428#define b4_prefix[]char yychar
429#define b4_prefix[]lval yylval
430#define b4_prefix[]lloc yylloc])],
431[YYSTYPE yylval;]b4_locations_if([[
432YYLTYPE yylloc;]])[
433
434int yynerrs;
435int yychar;])[
436
437static const int YYEOF = 0;
438static const int YYEMPTY = -2;
439
440typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
441
442#define YYCHK(YYE) \
443 do { \
444 YYRESULTTAG yychk_flag = YYE; \
445 if (yychk_flag != yyok) \
446 return yychk_flag; \
447 } while (0)
448
449#if ]b4_api_PREFIX[DEBUG
450
451# ifndef YYFPRINTF
452# define YYFPRINTF fprintf
453# endif
454
455]b4_yy_location_print_define[
456
457# define YYDPRINTF(Args) \
458 do { \
459 if (yydebug) \
460 YYFPRINTF Args; \
461 } while (0)
462
463]b4_yy_symbol_print_define[
464
465# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
466 do { \
467 if (yydebug) \
468 { \
469 YYFPRINTF (stderr, "%s ", Title); \
470 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
471 YYFPRINTF (stderr, "\n"); \
472 } \
473 } while (0)
474
475/* Nonzero means print parse trace. It is left uninitialized so that
476 multiple parsers can coexist. */
477int yydebug;
478
479struct yyGLRStack;
480static void yypstack (struct yyGLRStack* yystackp, size_t yyk)
481 YY_ATTRIBUTE_UNUSED;
482static void yypdumpstack (struct yyGLRStack* yystackp)
483 YY_ATTRIBUTE_UNUSED;
484
485#else /* !]b4_api_PREFIX[DEBUG */
486
487# define YYDPRINTF(Args)
488# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
489
490#endif /* !]b4_api_PREFIX[DEBUG */
491
492/* YYINITDEPTH -- initial size of the parser's stacks. */
493#ifndef YYINITDEPTH
494# define YYINITDEPTH ]b4_stack_depth_init[
495#endif
496
497/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
498 if the built-in stack extension method is used).
499
500 Do not make this value too large; the results are undefined if
501 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
502 evaluated with infinite-precision integer arithmetic. */
503
504#ifndef YYMAXDEPTH
505# define YYMAXDEPTH ]b4_stack_depth_max[
506#endif
507
508/* Minimum number of free items on the stack allowed after an
509 allocation. This is to allow allocation and initialization
510 to be completed by functions that call yyexpandGLRStack before the
511 stack is expanded, thus insuring that all necessary pointers get
512 properly redirected to new data. */
513#define YYHEADROOM 2
514
515#ifndef YYSTACKEXPANDABLE
516# define YYSTACKEXPANDABLE 1
517#endif
518
519#if YYSTACKEXPANDABLE
520# define YY_RESERVE_GLRSTACK(Yystack) \
521 do { \
522 if (Yystack->yyspaceLeft < YYHEADROOM) \
523 yyexpandGLRStack (Yystack); \
524 } while (0)
525#else
526# define YY_RESERVE_GLRSTACK(Yystack) \
527 do { \
528 if (Yystack->yyspaceLeft < YYHEADROOM) \
529 yyMemoryExhausted (Yystack); \
530 } while (0)
531#endif
532
533
534#if YYERROR_VERBOSE
535
536# ifndef yystpcpy
537# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
538# define yystpcpy stpcpy
539# else
540/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
541 YYDEST. */
542static char *
543yystpcpy (char *yydest, const char *yysrc)
544{
545 char *yyd = yydest;
546 const char *yys = yysrc;
547
548 while ((*yyd++ = *yys++) != '\0')
549 continue;
550
551 return yyd - 1;
552}
553# endif
554# endif
555
556# ifndef yytnamerr
557/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
558 quotes and backslashes, so that it's suitable for yyerror. The
559 heuristic is that double-quoting is unnecessary unless the string
560 contains an apostrophe, a comma, or backslash (other than
561 backslash-backslash). YYSTR is taken from yytname. If YYRES is
562 null, do not copy; instead, return the length of what the result
563 would have been. */
564static size_t
565yytnamerr (char *yyres, const char *yystr)
566{
567 if (*yystr == '"')
568 {
569 size_t yyn = 0;
570 char const *yyp = yystr;
571
572 for (;;)
573 switch (*++yyp)
574 {
575 case '\'':
576 case ',':
577 goto do_not_strip_quotes;
578
579 case '\\':
580 if (*++yyp != '\\')
581 goto do_not_strip_quotes;
582 /* Fall through. */
583 default:
584 if (yyres)
585 yyres[yyn] = *yyp;
586 yyn++;
587 break;
588
589 case '"':
590 if (yyres)
591 yyres[yyn] = '\0';
592 return yyn;
593 }
594 do_not_strip_quotes: ;
595 }
596
597 if (! yyres)
598 return strlen (yystr);
599
600 return yystpcpy (yyres, yystr) - yyres;
601}
602# endif
603
604#endif /* !YYERROR_VERBOSE */
605
606/** State numbers, as in LALR(1) machine */
607typedef int yyStateNum;
608
609/** Rule numbers, as in LALR(1) machine */
610typedef int yyRuleNum;
611
612/** Grammar symbol */
613typedef int yySymbol;
614
615/** Item references, as in LALR(1) machine */
616typedef short int yyItemNum;
617
618typedef struct yyGLRState yyGLRState;
619typedef struct yyGLRStateSet yyGLRStateSet;
620typedef struct yySemanticOption yySemanticOption;
621typedef union yyGLRStackItem yyGLRStackItem;
622typedef struct yyGLRStack yyGLRStack;
623
624struct yyGLRState {
625 /** Type tag: always true. */
626 yybool yyisState;
627 /** Type tag for yysemantics. If true, yysval applies, otherwise
628 * yyfirstVal applies. */
629 yybool yyresolved;
630 /** Number of corresponding LALR(1) machine state. */
631 yyStateNum yylrState;
632 /** Preceding state in this stack */
633 yyGLRState* yypred;
634 /** Source position of the last token produced by my symbol */
635 size_t yyposn;
636 union {
637 /** First in a chain of alternative reductions producing the
638 * non-terminal corresponding to this state, threaded through
639 * yynext. */
640 yySemanticOption* yyfirstVal;
641 /** Semantic value for this state. */
642 YYSTYPE yysval;
643 } yysemantics;]b4_locations_if([[
644 /** Source location for this state. */
645 YYLTYPE yyloc;]])[
646};
647
648struct yyGLRStateSet {
649 yyGLRState** yystates;
650 /** During nondeterministic operation, yylookaheadNeeds tracks which
651 * stacks have actually needed the current lookahead. During deterministic
652 * operation, yylookaheadNeeds[0] is not maintained since it would merely
653 * duplicate yychar != YYEMPTY. */
654 yybool* yylookaheadNeeds;
655 size_t yysize, yycapacity;
656};
657
658struct yySemanticOption {
659 /** Type tag: always false. */
660 yybool yyisState;
661 /** Rule number for this reduction */
662 yyRuleNum yyrule;
663 /** The last RHS state in the list of states to be reduced. */
664 yyGLRState* yystate;
665 /** The lookahead for this reduction. */
666 int yyrawchar;
667 YYSTYPE yyval;]b4_locations_if([[
668 YYLTYPE yyloc;]])[
669 /** Next sibling in chain of options. To facilitate merging,
670 * options are chained in decreasing order by address. */
671 yySemanticOption* yynext;
672};
673
674/** Type of the items in the GLR stack. The yyisState field
675 * indicates which item of the union is valid. */
676union yyGLRStackItem {
677 yyGLRState yystate;
678 yySemanticOption yyoption;
679};
680
681struct yyGLRStack {
682 int yyerrState;
683]b4_locations_if([[ /* To compute the location of the error token. */
684 yyGLRStackItem yyerror_range[3];]])[
685]b4_pure_if(
686[
687 int yyerrcnt;
688 int yyrawchar;
689 YYSTYPE yyval;]b4_locations_if([[
690 YYLTYPE yyloc;]])[
691])[
692 YYJMP_BUF yyexception_buffer;
693 yyGLRStackItem* yyitems;
694 yyGLRStackItem* yynextFree;
695 size_t yyspaceLeft;
696 yyGLRState* yysplitPoint;
697 yyGLRState* yylastDeleted;
698 yyGLRStateSet yytops;
699};
700
701#if YYSTACKEXPANDABLE
702static void yyexpandGLRStack (yyGLRStack* yystackp);
703#endif
704
705static _Noreturn void
706yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
707{
708 if (yymsg != YY_NULLPTR)
709 yyerror (]b4_yyerror_args[yymsg);
710 YYLONGJMP (yystackp->yyexception_buffer, 1);
711}
712
713static _Noreturn void
714yyMemoryExhausted (yyGLRStack* yystackp)
715{
716 YYLONGJMP (yystackp->yyexception_buffer, 2);
717}
718
719#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
720/** A printable representation of TOKEN. */
721static inline const char*
722yytokenName (yySymbol yytoken)
723{
724 if (yytoken == YYEMPTY)
725 return "";
726
727 return yytname[yytoken];
728}
729#endif
730
731/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
732 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
733 * containing the pointer to the next state in the chain. */
734static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED;
735static void
736yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
737{
738 int i;
739 yyGLRState *s = yyvsp[yylow0].yystate.yypred;
740 for (i = yylow0-1; i >= yylow1; i -= 1)
741 {
742#if ]b4_api_PREFIX[DEBUG
743 yyvsp[i].yystate.yylrState = s->yylrState;
744#endif
745 yyvsp[i].yystate.yyresolved = s->yyresolved;
746 if (s->yyresolved)
747 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
748 else
749 /* The effect of using yysval or yyloc (in an immediate rule) is
750 * undefined. */
751 yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;]b4_locations_if([[
752 yyvsp[i].yystate.yyloc = s->yyloc;]])[
753 s = yyvsp[i].yystate.yypred = s->yypred;
754 }
755}
756
757/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
758 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
759 * For convenience, always return YYLOW1. */
760static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
761 YY_ATTRIBUTE_UNUSED;
762static inline int
763yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
764{
765 if (!yynormal && yylow1 < *yylow)
766 {
767 yyfillin (yyvsp, *yylow, yylow1);
768 *yylow = yylow1;
769 }
770 return yylow1;
771}
772
773/** Perform user action for rule number YYN, with RHS length YYRHSLEN,
774 * and top stack item YYVSP. YYLVALP points to place to put semantic
775 * value ($$), and yylocp points to place for location information
776 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
777 * yyerr for YYERROR, yyabort for YYABORT. */
778static YYRESULTTAG
779yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
780 yyGLRStack* yystackp,
781 YYSTYPE* yyvalp]b4_locuser_formals[)
782{
783 yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULLPTR);
784 int yylow;
785]b4_parse_param_use([yyvalp], [yylocp])dnl
786[ YYUSE (yyrhslen);
787# undef yyerrok
788# define yyerrok (yystackp->yyerrState = 0)
789# undef YYACCEPT
790# define YYACCEPT return yyaccept
791# undef YYABORT
792# define YYABORT return yyabort
793# undef YYERROR
794# define YYERROR return yyerrok, yyerr
795# undef YYRECOVERING
796# define YYRECOVERING() (yystackp->yyerrState != 0)
797# undef yyclearin
798# define yyclearin (yychar = YYEMPTY)
799# undef YYFILL
800# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
801# undef YYBACKUP
802# define YYBACKUP(Token, Value) \
803 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
804 yyerrok, yyerr
805
806 yylow = 1;
807 if (yyrhslen == 0)
808 *yyvalp = yyval_default;
809 else
810 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
811 /* Default location. */
812 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
813 yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
814]])[
815 switch (yyn)
816 {
817 ]b4_user_actions[
818 default: break;
819 }
820
821 return yyok;
822# undef yyerrok
823# undef YYABORT
824# undef YYACCEPT
825# undef YYERROR
826# undef YYBACKUP
827# undef yyclearin
828# undef YYRECOVERING
829}
830
831
832static void
833yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
834{
835 YYUSE (yy0);
836 YYUSE (yy1);
837
838 switch (yyn)
839 {
840]b4_mergers[
841 default: break;
842 }
843}
844
845 /* Bison grammar-table manipulation. */
846
847]b4_yydestruct_define[
848
849/** Number of symbols composing the right hand side of rule #RULE. */
850static inline int
851yyrhsLength (yyRuleNum yyrule)
852{
853 return yyr2[yyrule];
854}
855
856static void
857yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
858{
859 if (yys->yyresolved)
860 yydestruct (yymsg, yystos[yys->yylrState],
861 &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
862 else
863 {
864#if ]b4_api_PREFIX[DEBUG
865 if (yydebug)
866 {
867 if (yys->yysemantics.yyfirstVal)
868 YYFPRINTF (stderr, "%s unresolved", yymsg);
869 else
870 YYFPRINTF (stderr, "%s incomplete", yymsg);
871 YY_SYMBOL_PRINT ("", yystos[yys->yylrState], YY_NULLPTR, &yys->yyloc);
872 }
873#endif
874
875 if (yys->yysemantics.yyfirstVal)
876 {
877 yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
878 yyGLRState *yyrh;
879 int yyn;
880 for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
881 yyn > 0;
882 yyrh = yyrh->yypred, yyn -= 1)
883 yydestroyGLRState (yymsg, yyrh]b4_user_args[);
884 }
885 }
886}
887
888/** Left-hand-side symbol for rule #YYRULE. */
889static inline yySymbol
890yylhsNonterm (yyRuleNum yyrule)
891{
892 return yyr1[yyrule];
893}
894
895#define yypact_value_is_default(Yystate) \
896 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
897
898/** True iff LR state YYSTATE has only a default reduction (regardless
899 * of token). */
900static inline yybool
901yyisDefaultedState (yyStateNum yystate)
902{
903 return yypact_value_is_default (yypact[yystate]);
904}
905
906/** The default reduction for YYSTATE, assuming it has one. */
907static inline yyRuleNum
908yydefaultAction (yyStateNum yystate)
909{
910 return yydefact[yystate];
911}
912
913#define yytable_value_is_error(Yytable_value) \
914 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
915
916/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
917 * Result R means
918 * R < 0: Reduce on rule -R.
919 * R = 0: Error.
920 * R > 0: Shift to state R.
921 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
922 * of conflicting reductions.
923 */
924static inline void
925yygetLRActions (yyStateNum yystate, int yytoken,
926 int* yyaction, const short int** yyconflicts)
927{
928 int yyindex = yypact[yystate] + yytoken;
929 if (yypact_value_is_default (yypact[yystate])
930 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
931 {
932 *yyaction = -yydefact[yystate];
933 *yyconflicts = yyconfl;
934 }
935 else if (! yytable_value_is_error (yytable[yyindex]))
936 {
937 *yyaction = yytable[yyindex];
938 *yyconflicts = yyconfl + yyconflp[yyindex];
939 }
940 else
941 {
942 *yyaction = 0;
943 *yyconflicts = yyconfl + yyconflp[yyindex];
944 }
945}
946
947/** Compute post-reduction state.
948 * \param yystate the current state
949 * \param yysym the nonterminal to push on the stack
950 */
951static inline yyStateNum
952yyLRgotoState (yyStateNum yystate, yySymbol yysym)
953{
954 int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
955 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
956 return yytable[yyr];
957 else
958 return yydefgoto[yysym - YYNTOKENS];
959}
960
961static inline yybool
962yyisShiftAction (int yyaction)
963{
964 return 0 < yyaction;
965}
966
967static inline yybool
968yyisErrorAction (int yyaction)
969{
970 return yyaction == 0;
971}
972
973 /* GLRStates */
974
975/** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
976 * if YYISSTATE, and otherwise a semantic option. Callers should call
977 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
978 * headroom. */
979
980static inline yyGLRStackItem*
981yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
982{
983 yyGLRStackItem* yynewItem = yystackp->yynextFree;
984 yystackp->yyspaceLeft -= 1;
985 yystackp->yynextFree += 1;
986 yynewItem->yystate.yyisState = yyisState;
987 return yynewItem;
988}
989
990/** Add a new semantic action that will execute the action for rule
991 * YYRULE on the semantic values in YYRHS to the list of
992 * alternative actions for YYSTATE. Assumes that YYRHS comes from
993 * stack #YYK of *YYSTACKP. */
994static void
995yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
996 yyGLRState* yyrhs, yyRuleNum yyrule)
997{
998 yySemanticOption* yynewOption =
999 &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
1000 YYASSERT (!yynewOption->yyisState);
1001 yynewOption->yystate = yyrhs;
1002 yynewOption->yyrule = yyrule;
1003 if (yystackp->yytops.yylookaheadNeeds[yyk])
1004 {
1005 yynewOption->yyrawchar = yychar;
1006 yynewOption->yyval = yylval;]b4_locations_if([
1007 yynewOption->yyloc = yylloc;])[
1008 }
1009 else
1010 yynewOption->yyrawchar = YYEMPTY;
1011 yynewOption->yynext = yystate->yysemantics.yyfirstVal;
1012 yystate->yysemantics.yyfirstVal = yynewOption;
1013
1014 YY_RESERVE_GLRSTACK (yystackp);
1015}
1016
1017 /* GLRStacks */
1018
1019/** Initialize YYSET to a singleton set containing an empty stack. */
1020static yybool
1021yyinitStateSet (yyGLRStateSet* yyset)
1022{
1023 yyset->yysize = 1;
1024 yyset->yycapacity = 16;
1025 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
1026 if (! yyset->yystates)
1027 return yyfalse;
1028 yyset->yystates[0] = YY_NULLPTR;
1029 yyset->yylookaheadNeeds =
1030 (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
1031 if (! yyset->yylookaheadNeeds)
1032 {
1033 YYFREE (yyset->yystates);
1034 return yyfalse;
1035 }
1036 return yytrue;
1037}
1038
1039static void yyfreeStateSet (yyGLRStateSet* yyset)
1040{
1041 YYFREE (yyset->yystates);
1042 YYFREE (yyset->yylookaheadNeeds);
1043}
1044
1045/** Initialize *YYSTACKP to a single empty stack, with total maximum
1046 * capacity for all stacks of YYSIZE. */
1047static yybool
1048yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
1049{
1050 yystackp->yyerrState = 0;
1051 yynerrs = 0;
1052 yystackp->yyspaceLeft = yysize;
1053 yystackp->yyitems =
1054 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
1055 if (!yystackp->yyitems)
1056 return yyfalse;
1057 yystackp->yynextFree = yystackp->yyitems;
1058 yystackp->yysplitPoint = YY_NULLPTR;
1059 yystackp->yylastDeleted = YY_NULLPTR;
1060 return yyinitStateSet (&yystackp->yytops);
1061}
1062
1063
1064#if YYSTACKEXPANDABLE
1065# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1066 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1067
1068/** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1069 stack from outside should be considered invalid after this call.
1070 We always expand when there are 1 or fewer items left AFTER an
1071 allocation, so that we can avoid having external pointers exist
1072 across an allocation. */
1073static void
1074yyexpandGLRStack (yyGLRStack* yystackp)
1075{
1076 yyGLRStackItem* yynewItems;
1077 yyGLRStackItem* yyp0, *yyp1;
1078 size_t yynewSize;
1079 size_t yyn;
1080 size_t yysize = yystackp->yynextFree - yystackp->yyitems;
1081 if (YYMAXDEPTH - YYHEADROOM < yysize)
1082 yyMemoryExhausted (yystackp);
1083 yynewSize = 2*yysize;
1084 if (YYMAXDEPTH < yynewSize)
1085 yynewSize = YYMAXDEPTH;
1086 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1087 if (! yynewItems)
1088 yyMemoryExhausted (yystackp);
1089 for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
1090 0 < yyn;
1091 yyn -= 1, yyp0 += 1, yyp1 += 1)
1092 {
1093 *yyp1 = *yyp0;
1094 if (*(yybool *) yyp0)
1095 {
1096 yyGLRState* yys0 = &yyp0->yystate;
1097 yyGLRState* yys1 = &yyp1->yystate;
1098 if (yys0->yypred != YY_NULLPTR)
1099 yys1->yypred =
1100 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
1101 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULLPTR)
1102 yys1->yysemantics.yyfirstVal =
1103 YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
1104 }
1105 else
1106 {
1107 yySemanticOption* yyv0 = &yyp0->yyoption;
1108 yySemanticOption* yyv1 = &yyp1->yyoption;
1109 if (yyv0->yystate != YY_NULLPTR)
1110 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
1111 if (yyv0->yynext != YY_NULLPTR)
1112 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1113 }
1114 }
1115 if (yystackp->yysplitPoint != YY_NULLPTR)
1116 yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
1117 yystackp->yysplitPoint, yystate);
1118
1119 for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
1120 if (yystackp->yytops.yystates[yyn] != YY_NULLPTR)
1121 yystackp->yytops.yystates[yyn] =
1122 YYRELOC (yystackp->yyitems, yynewItems,
1123 yystackp->yytops.yystates[yyn], yystate);
1124 YYFREE (yystackp->yyitems);
1125 yystackp->yyitems = yynewItems;
1126 yystackp->yynextFree = yynewItems + yysize;
1127 yystackp->yyspaceLeft = yynewSize - yysize;
1128}
1129#endif
1130
1131static void
1132yyfreeGLRStack (yyGLRStack* yystackp)
1133{
1134 YYFREE (yystackp->yyitems);
1135 yyfreeStateSet (&yystackp->yytops);
1136}
1137
1138/** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1139 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1140 * YYS. */
1141static inline void
1142yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
1143{
1144 if (yystackp->yysplitPoint != YY_NULLPTR && yystackp->yysplitPoint > yys)
1145 yystackp->yysplitPoint = yys;
1146}
1147
1148/** Invalidate stack #YYK in *YYSTACKP. */
1149static inline void
1150yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
1151{
1152 if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
1153 yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
1154 yystackp->yytops.yystates[yyk] = YY_NULLPTR;
1155}
1156
1157/** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1158 only be done once after a deletion, and only when all other stacks have
1159 been deleted. */
1160static void
1161yyundeleteLastStack (yyGLRStack* yystackp)
1162{
1163 if (yystackp->yylastDeleted == YY_NULLPTR || yystackp->yytops.yysize != 0)
1164 return;
1165 yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
1166 yystackp->yytops.yysize = 1;
1167 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
1168 yystackp->yylastDeleted = YY_NULLPTR;
1169}
1170
1171static inline void
1172yyremoveDeletes (yyGLRStack* yystackp)
1173{
1174 size_t yyi, yyj;
1175 yyi = yyj = 0;
1176 while (yyj < yystackp->yytops.yysize)
1177 {
1178 if (yystackp->yytops.yystates[yyi] == YY_NULLPTR)
1179 {
1180 if (yyi == yyj)
1181 {
1182 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1183 }
1184 yystackp->yytops.yysize -= 1;
1185 }
1186 else
1187 {
1188 yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
1189 /* In the current implementation, it's unnecessary to copy
1190 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1191 yyremoveDeletes returns, the parser immediately either enters
1192 deterministic operation or shifts a token. However, it doesn't
1193 hurt, and the code might evolve to need it. */
1194 yystackp->yytops.yylookaheadNeeds[yyj] =
1195 yystackp->yytops.yylookaheadNeeds[yyi];
1196 if (yyj != yyi)
1197 {
1198 YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
1199 (unsigned long int) yyi, (unsigned long int) yyj));
1200 }
1201 yyj += 1;
1202 }
1203 yyi += 1;
1204 }
1205}
1206
1207/** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1208 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1209 * value *YYVALP and source location *YYLOCP. */
1210static inline void
1211yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1212 size_t yyposn,
1213 YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
1214{
1215 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1216
1217 yynewState->yylrState = yylrState;
1218 yynewState->yyposn = yyposn;
1219 yynewState->yyresolved = yytrue;
1220 yynewState->yypred = yystackp->yytops.yystates[yyk];
1221 yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
1222 yynewState->yyloc = *yylocp;])[
1223 yystackp->yytops.yystates[yyk] = yynewState;
1224
1225 YY_RESERVE_GLRSTACK (yystackp);
1226}
1227
1228/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1229 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1230 * semantic value of YYRHS under the action for YYRULE. */
1231static inline void
1232yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1233 size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
1234{
1235 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1236 YYASSERT (yynewState->yyisState);
1237
1238 yynewState->yylrState = yylrState;
1239 yynewState->yyposn = yyposn;
1240 yynewState->yyresolved = yyfalse;
1241 yynewState->yypred = yystackp->yytops.yystates[yyk];
1242 yynewState->yysemantics.yyfirstVal = YY_NULLPTR;
1243 yystackp->yytops.yystates[yyk] = yynewState;
1244
1245 /* Invokes YY_RESERVE_GLRSTACK. */
1246 yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
1247}
1248
1249#if !]b4_api_PREFIX[DEBUG
1250# define YY_REDUCE_PRINT(Args)
1251#else
1252# define YY_REDUCE_PRINT(Args) \
1253do { \
1254 if (yydebug) \
1255 yy_reduce_print Args; \
1256} while (0)
1257
1258/*----------------------------------------------------------------------.
1259| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1260`----------------------------------------------------------------------*/
1261
1262static inline void
1263yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
1264 yyRuleNum yyrule]b4_user_formals[)
1265{
1266 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1267 int yylow = 1;])[
1268 int yyi;
1269 YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
1270 (unsigned long int) yyk, yyrule - 1,
1271 (unsigned long int) yyrline[yyrule]);
1272 if (! yynormal)
1273 yyfillin (yyvsp, 1, -yynrhs);
1274 /* The symbols being reduced. */
1275 for (yyi = 0; yyi < yynrhs; yyi++)
1276 {
1277 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1278 yy_symbol_print (stderr,
1279 yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
1280 &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval
1281 ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
1282 b4_user_args[);
1283 if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
1284 YYFPRINTF (stderr, " (unresolved)");
1285 YYFPRINTF (stderr, "\n");
1286 }
1287}
1288#endif
1289
1290/** Pop the symbols consumed by reduction #YYRULE from the top of stack
1291 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1292 * semantic values. Assumes that all ambiguities in semantic values
1293 * have been previously resolved. Set *YYVALP to the resulting value,
1294 * and *YYLOCP to the computed location (if any). Return value is as
1295 * for userAction. */
1296static inline YYRESULTTAG
1297yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1298 YYSTYPE* yyvalp]b4_locuser_formals[)
1299{
1300 int yynrhs = yyrhsLength (yyrule);
1301
1302 if (yystackp->yysplitPoint == YY_NULLPTR)
1303 {
1304 /* Standard special case: single stack. */
1305 yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1306 YYASSERT (yyk == 0);
1307 yystackp->yynextFree -= yynrhs;
1308 yystackp->yyspaceLeft += yynrhs;
1309 yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
1310 YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[));
1311 return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
1312 yyvalp]b4_locuser_args[);
1313 }
1314 else
1315 {
1316 int yyi;
1317 yyGLRState* yys;
1318 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1319 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
1320 = yystackp->yytops.yystates[yyk];]b4_locations_if([[
1321 if (yynrhs == 0)
1322 /* Set default location. */
1323 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
1324 for (yyi = 0; yyi < yynrhs; yyi += 1)
1325 {
1326 yys = yys->yypred;
1327 YYASSERT (yys);
1328 }
1329 yyupdateSplit (yystackp, yys);
1330 yystackp->yytops.yystates[yyk] = yys;
1331 YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
1332 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1333 yystackp, yyvalp]b4_locuser_args[);
1334 }
1335}
1336
1337/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1338 * and push back on the resulting nonterminal symbol. Perform the
1339 * semantic action associated with YYRULE and store its value with the
1340 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1341 * unambiguous. Otherwise, store the deferred semantic action with
1342 * the new state. If the new state would have an identical input
1343 * position, LR state, and predecessor to an existing state on the stack,
1344 * it is identified with that existing state, eliminating stack #YYK from
1345 * *YYSTACKP. In this case, the semantic value is
1346 * added to the options for the existing state's semantic value.
1347 */
1348static inline YYRESULTTAG
1349yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1350 yybool yyforceEval]b4_user_formals[)
1351{
1352 size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
1353
1354 if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR)
1355 {
1356 YYSTYPE yysval;]b4_locations_if([[
1357 YYLTYPE yyloc;]])[
1358
1359 YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[);
1360 if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR)
1361 {
1362 YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
1363 (unsigned long int) yyk, yyrule - 1));
1364 }
1365 if (yyflag != yyok)
1366 return yyflag;
1367 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
1368 yyglrShift (yystackp, yyk,
1369 yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
1370 yylhsNonterm (yyrule)),
1371 yyposn, &yysval]b4_locations_if([, &yyloc])[);
1372 }
1373 else
1374 {
1375 size_t yyi;
1376 int yyn;
1377 yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
1378 yyStateNum yynewLRState;
1379
1380 for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1381 0 < yyn; yyn -= 1)
1382 {
1383 yys = yys->yypred;
1384 YYASSERT (yys);
1385 }
1386 yyupdateSplit (yystackp, yys);
1387 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1388 YYDPRINTF ((stderr,
1389 "Reduced stack %lu by rule #%d; action deferred. "
1390 "Now in state %d.\n",
1391 (unsigned long int) yyk, yyrule - 1, yynewLRState));
1392 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
1393 if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
1394 {
1395 yyGLRState *yysplit = yystackp->yysplitPoint;
1396 yyGLRState *yyp = yystackp->yytops.yystates[yyi];
1397 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1398 {
1399 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1400 {
1401 yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
1402 yymarkStackDeleted (yystackp, yyk);
1403 YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
1404 (unsigned long int) yyk,
1405 (unsigned long int) yyi));
1406 return yyok;
1407 }
1408 yyp = yyp->yypred;
1409 }
1410 }
1411 yystackp->yytops.yystates[yyk] = yys;
1412 yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
1413 }
1414 return yyok;
1415}
1416
1417static size_t
1418yysplitStack (yyGLRStack* yystackp, size_t yyk)
1419{
1420 if (yystackp->yysplitPoint == YY_NULLPTR)
1421 {
1422 YYASSERT (yyk == 0);
1423 yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
1424 }
1425 if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
1426 {
1427 yyGLRState** yynewStates;
1428 yybool* yynewLookaheadNeeds;
1429
1430 yynewStates = YY_NULLPTR;
1431
1432 if (yystackp->yytops.yycapacity
1433 > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1434 yyMemoryExhausted (yystackp);
1435 yystackp->yytops.yycapacity *= 2;
1436
1437 yynewStates =
1438 (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
1439 (yystackp->yytops.yycapacity
1440 * sizeof yynewStates[0]));
1441 if (yynewStates == YY_NULLPTR)
1442 yyMemoryExhausted (yystackp);
1443 yystackp->yytops.yystates = yynewStates;
1444
1445 yynewLookaheadNeeds =
1446 (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
1447 (yystackp->yytops.yycapacity
1448 * sizeof yynewLookaheadNeeds[0]));
1449 if (yynewLookaheadNeeds == YY_NULLPTR)
1450 yyMemoryExhausted (yystackp);
1451 yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
1452 }
1453 yystackp->yytops.yystates[yystackp->yytops.yysize]
1454 = yystackp->yytops.yystates[yyk];
1455 yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
1456 = yystackp->yytops.yylookaheadNeeds[yyk];
1457 yystackp->yytops.yysize += 1;
1458 return yystackp->yytops.yysize-1;
1459}
1460
1461/** True iff YYY0 and YYY1 represent identical options at the top level.
1462 * That is, they represent the same rule applied to RHS symbols
1463 * that produce the same terminal symbols. */
1464static yybool
1465yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1466{
1467 if (yyy0->yyrule == yyy1->yyrule)
1468 {
1469 yyGLRState *yys0, *yys1;
1470 int yyn;
1471 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1472 yyn = yyrhsLength (yyy0->yyrule);
1473 yyn > 0;
1474 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1475 if (yys0->yyposn != yys1->yyposn)
1476 return yyfalse;
1477 return yytrue;
1478 }
1479 else
1480 return yyfalse;
1481}
1482
1483/** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1484 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1485static void
1486yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1487{
1488 yyGLRState *yys0, *yys1;
1489 int yyn;
1490 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1491 yyn = yyrhsLength (yyy0->yyrule);
1492 yyn > 0;
1493 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1494 {
1495 if (yys0 == yys1)
1496 break;
1497 else if (yys0->yyresolved)
1498 {
1499 yys1->yyresolved = yytrue;
1500 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1501 }
1502 else if (yys1->yyresolved)
1503 {
1504 yys0->yyresolved = yytrue;
1505 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1506 }
1507 else
1508 {
1509 yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
1510 yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
1511 while (yytrue)
1512 {
1513 if (yyz1 == *yyz0p || yyz1 == YY_NULLPTR)
1514 break;
1515 else if (*yyz0p == YY_NULLPTR)
1516 {
1517 *yyz0p = yyz1;
1518 break;
1519 }
1520 else if (*yyz0p < yyz1)
1521 {
1522 yySemanticOption* yyz = *yyz0p;
1523 *yyz0p = yyz1;
1524 yyz1 = yyz1->yynext;
1525 (*yyz0p)->yynext = yyz;
1526 }
1527 yyz0p = &(*yyz0p)->yynext;
1528 }
1529 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
1530 }
1531 }
1532}
1533
1534/** Y0 and Y1 represent two possible actions to take in a given
1535 * parsing state; return 0 if no combination is possible,
1536 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1537static int
1538yypreference (yySemanticOption* y0, yySemanticOption* y1)
1539{
1540 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1541 int p0 = yydprec[r0], p1 = yydprec[r1];
1542
1543 if (p0 == p1)
1544 {
1545 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1546 return 0;
1547 else
1548 return 1;
1549 }
1550 if (p0 == 0 || p1 == 0)
1551 return 0;
1552 if (p0 < p1)
1553 return 3;
1554 if (p1 < p0)
1555 return 2;
1556 return 0;
1557}
1558
1559static YYRESULTTAG yyresolveValue (yyGLRState* yys,
1560 yyGLRStack* yystackp]b4_user_formals[);
1561
1562
1563/** Resolve the previous YYN states starting at and including state YYS
1564 * on *YYSTACKP. If result != yyok, some states may have been left
1565 * unresolved possibly with empty semantic option chains. Regardless
1566 * of whether result = yyok, each state has been left with consistent
1567 * data so that yydestroyGLRState can be invoked if necessary. */
1568static YYRESULTTAG
1569yyresolveStates (yyGLRState* yys, int yyn,
1570 yyGLRStack* yystackp]b4_user_formals[)
1571{
1572 if (0 < yyn)
1573 {
1574 YYASSERT (yys->yypred);
1575 YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
1576 if (! yys->yyresolved)
1577 YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
1578 }
1579 return yyok;
1580}
1581
1582/** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1583 * user action, and return the semantic value and location in *YYVALP
1584 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1585 * have been destroyed (assuming the user action destroys all RHS
1586 * semantic values if invoked). */
1587static YYRESULTTAG
1588yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
1589 YYSTYPE* yyvalp]b4_locuser_formals[)
1590{
1591 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1592 int yynrhs = yyrhsLength (yyopt->yyrule);
1593 YYRESULTTAG yyflag =
1594 yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
1595 if (yyflag != yyok)
1596 {
1597 yyGLRState *yys;
1598 for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
1599 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
1600 return yyflag;
1601 }
1602
1603 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[
1604 if (yynrhs == 0)
1605 /* Set default location. */
1606 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
1607 {
1608 int yychar_current = yychar;
1609 YYSTYPE yylval_current = yylval;]b4_locations_if([
1610 YYLTYPE yylloc_current = yylloc;])[
1611 yychar = yyopt->yyrawchar;
1612 yylval = yyopt->yyval;]b4_locations_if([
1613 yylloc = yyopt->yyloc;])[
1614 yyflag = yyuserAction (yyopt->yyrule, yynrhs,
1615 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1616 yystackp, yyvalp]b4_locuser_args[);
1617 yychar = yychar_current;
1618 yylval = yylval_current;]b4_locations_if([
1619 yylloc = yylloc_current;])[
1620 }
1621 return yyflag;
1622}
1623
1624#if ]b4_api_PREFIX[DEBUG
1625static void
1626yyreportTree (yySemanticOption* yyx, int yyindent)
1627{
1628 int yynrhs = yyrhsLength (yyx->yyrule);
1629 int yyi;
1630 yyGLRState* yys;
1631 yyGLRState* yystates[1 + YYMAXRHS];
1632 yyGLRState yyleftmost_state;
1633
1634 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1635 yystates[yyi] = yys;
1636 if (yys == YY_NULLPTR)
1637 {
1638 yyleftmost_state.yyposn = 0;
1639 yystates[0] = &yyleftmost_state;
1640 }
1641 else
1642 yystates[0] = yys;
1643
1644 if (yyx->yystate->yyposn < yys->yyposn + 1)
1645 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1646 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1647 yyx->yyrule - 1);
1648 else
1649 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1650 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1651 yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
1652 (unsigned long int) yyx->yystate->yyposn);
1653 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1654 {
1655 if (yystates[yyi]->yyresolved)
1656 {
1657 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1658 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1659 yytokenName (yystos[yystates[yyi]->yylrState]));
1660 else
1661 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
1662 yytokenName (yystos[yystates[yyi]->yylrState]),
1663 (unsigned long int) (yystates[yyi-1]->yyposn + 1),
1664 (unsigned long int) yystates[yyi]->yyposn);
1665 }
1666 else
1667 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1668 }
1669}
1670#endif
1671
1672static YYRESULTTAG
1673yyreportAmbiguity (yySemanticOption* yyx0,
1674 yySemanticOption* yyx1]b4_pure_formals[)
1675{
1676 YYUSE (yyx0);
1677 YYUSE (yyx1);
1678
1679#if ]b4_api_PREFIX[DEBUG
1680 YYFPRINTF (stderr, "Ambiguity detected.\n");
1681 YYFPRINTF (stderr, "Option 1,\n");
1682 yyreportTree (yyx0, 2);
1683 YYFPRINTF (stderr, "\nOption 2,\n");
1684 yyreportTree (yyx1, 2);
1685 YYFPRINTF (stderr, "\n");
1686#endif
1687
1688 yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
1689 return yyabort;
1690}]b4_locations_if([[
1691
1692/** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1693 * ending at YYS1. Has no effect on previously resolved states.
1694 * The first semantic option of a state is always chosen. */
1695static void
1696yyresolveLocations (yyGLRState* yys1, int yyn1,
1697 yyGLRStack *yystackp]b4_user_formals[)
1698{
1699 if (0 < yyn1)
1700 {
1701 yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
1702 if (!yys1->yyresolved)
1703 {
1704 yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
1705 int yynrhs;
1706 yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
1707 YYASSERT (yyoption != YY_NULLPTR);
1708 yynrhs = yyrhsLength (yyoption->yyrule);
1709 if (yynrhs > 0)
1710 {
1711 yyGLRState *yys;
1712 int yyn;
1713 yyresolveLocations (yyoption->yystate, yynrhs,
1714 yystackp]b4_user_args[);
1715 for (yys = yyoption->yystate, yyn = yynrhs;
1716 yyn > 0;
1717 yys = yys->yypred, yyn -= 1)
1718 yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
1719 }
1720 else
1721 {
1722 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1723 in reverse rightmost order. It is only necessary to invoke
1724 yyresolveLocations on a subforest for which yyresolveAction
1725 would have been invoked next had an ambiguity not been
1726 detected. Thus the location of the previous state (but not
1727 necessarily the previous state itself) is guaranteed to be
1728 resolved already. */
1729 yyGLRState *yyprevious = yyoption->yystate;
1730 yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
1731 }
1732 {
1733 int yychar_current = yychar;
1734 YYSTYPE yylval_current = yylval;
1735 YYLTYPE yylloc_current = yylloc;
1736 yychar = yyoption->yyrawchar;
1737 yylval = yyoption->yyval;
1738 yylloc = yyoption->yyloc;
1739 YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
1740 yychar = yychar_current;
1741 yylval = yylval_current;
1742 yylloc = yylloc_current;
1743 }
1744 }
1745 }
1746}]])[
1747
1748/** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1749 * perform the indicated actions, and set the semantic value of YYS.
1750 * If result != yyok, the chain of semantic options in YYS has been
1751 * cleared instead or it has been left unmodified except that
1752 * redundant options may have been removed. Regardless of whether
1753 * result = yyok, YYS has been left with consistent data so that
1754 * yydestroyGLRState can be invoked if necessary. */
1755static YYRESULTTAG
1756yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
1757{
1758 yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
1759 yySemanticOption* yybest = yyoptionList;
1760 yySemanticOption** yypp;
1761 yybool yymerge = yyfalse;
1762 YYSTYPE yysval;
1763 YYRESULTTAG yyflag;]b4_locations_if([
1764 YYLTYPE *yylocp = &yys->yyloc;])[
1765
1766 for (yypp = &yyoptionList->yynext; *yypp != YY_NULLPTR; )
1767 {
1768 yySemanticOption* yyp = *yypp;
1769
1770 if (yyidenticalOptions (yybest, yyp))
1771 {
1772 yymergeOptionSets (yybest, yyp);
1773 *yypp = yyp->yynext;
1774 }
1775 else
1776 {
1777 switch (yypreference (yybest, yyp))
1778 {
1779 case 0:]b4_locations_if([[
1780 yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[
1781 return yyreportAmbiguity (yybest, yyp]b4_pure_args[);
1782 break;
1783 case 1:
1784 yymerge = yytrue;
1785 break;
1786 case 2:
1787 break;
1788 case 3:
1789 yybest = yyp;
1790 yymerge = yyfalse;
1791 break;
1792 default:
1793 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1794 but some compilers complain if the default case is
1795 omitted. */
1796 break;
1797 }
1798 yypp = &yyp->yynext;
1799 }
1800 }
1801
1802 if (yymerge)
1803 {
1804 yySemanticOption* yyp;
1805 int yyprec = yydprec[yybest->yyrule];
1806 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
1807 if (yyflag == yyok)
1808 for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext)
1809 {
1810 if (yyprec == yydprec[yyp->yyrule])
1811 {
1812 YYSTYPE yysval_other;]b4_locations_if([
1813 YYLTYPE yydummy;])[
1814 yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
1815 if (yyflag != yyok)
1816 {
1817 yydestruct ("Cleanup: discarding incompletely merged value for",
1818 yystos[yys->yylrState],
1819 &yysval]b4_locuser_args[);
1820 break;
1821 }
1822 yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
1823 }
1824 }
1825 }
1826 else
1827 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
1828
1829 if (yyflag == yyok)
1830 {
1831 yys->yyresolved = yytrue;
1832 yys->yysemantics.yysval = yysval;
1833 }
1834 else
1835 yys->yysemantics.yyfirstVal = YY_NULLPTR;
1836 return yyflag;
1837}
1838
1839static YYRESULTTAG
1840yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
1841{
1842 if (yystackp->yysplitPoint != YY_NULLPTR)
1843 {
1844 yyGLRState* yys;
1845 int yyn;
1846
1847 for (yyn = 0, yys = yystackp->yytops.yystates[0];
1848 yys != yystackp->yysplitPoint;
1849 yys = yys->yypred, yyn += 1)
1850 continue;
1851 YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
1852 ]b4_user_args[));
1853 }
1854 return yyok;
1855}
1856
1857static void
1858yycompressStack (yyGLRStack* yystackp)
1859{
1860 yyGLRState* yyp, *yyq, *yyr;
1861
1862 if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR)
1863 return;
1864
1865 for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR;
1866 yyp != yystackp->yysplitPoint;
1867 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1868 yyp->yypred = yyr;
1869
1870 yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
1871 yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
1872 yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
1873 yystackp->yysplitPoint = YY_NULLPTR;
1874 yystackp->yylastDeleted = YY_NULLPTR;
1875
1876 while (yyr != YY_NULLPTR)
1877 {
1878 yystackp->yynextFree->yystate = *yyr;
1879 yyr = yyr->yypred;
1880 yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
1881 yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
1882 yystackp->yynextFree += 1;
1883 yystackp->yyspaceLeft -= 1;
1884 }
1885}
1886
1887static YYRESULTTAG
1888yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
1889 size_t yyposn]b4_pure_formals[)
1890{
1891 while (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
1892 {
1893 yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
1894 YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
1895 (unsigned long int) yyk, yystate));
1896
1897 YYASSERT (yystate != YYFINAL);
1898
1899 if (yyisDefaultedState (yystate))
1900 {
1901 YYRESULTTAG yyflag;
1902 yyRuleNum yyrule = yydefaultAction (yystate);
1903 if (yyrule == 0)
1904 {
1905 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1906 (unsigned long int) yyk));
1907 yymarkStackDeleted (yystackp, yyk);
1908 return yyok;
1909 }
1910 yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[);
1911 if (yyflag == yyerr)
1912 {
1913 YYDPRINTF ((stderr,
1914 "Stack %lu dies "
1915 "(predicate failure or explicit user error).\n",
1916 (unsigned long int) yyk));
1917 yymarkStackDeleted (yystackp, yyk);
1918 return yyok;
1919 }
1920 if (yyflag != yyok)
1921 return yyflag;
1922 }
1923 else
1924 {
1925 yySymbol yytoken;
1926 int yyaction;
1927 const short int* yyconflicts;
1928
1929 yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
1930 if (yychar == YYEMPTY)
1931 {
1932 YYDPRINTF ((stderr, "Reading a token: "));
1933 yychar = ]b4_lex[;
1934 }
1935
1936 if (yychar <= YYEOF)
1937 {
1938 yychar = yytoken = YYEOF;
1939 YYDPRINTF ((stderr, "Now at end of input.\n"));
1940 }
1941 else
1942 {
1943 yytoken = YYTRANSLATE (yychar);
1944 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1945 }
1946
1947 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
1948
1949 while (*yyconflicts != 0)
1950 {
1951 YYRESULTTAG yyflag;
1952 size_t yynewStack = yysplitStack (yystackp, yyk);
1953 YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
1954 (unsigned long int) yynewStack,
1955 (unsigned long int) yyk));
1956 yyflag = yyglrReduce (yystackp, yynewStack,
1957 *yyconflicts,
1958 yyimmediate[*yyconflicts]]b4_user_args[);
1959 if (yyflag == yyok)
1960 YYCHK (yyprocessOneStack (yystackp, yynewStack,
1961 yyposn]b4_pure_args[));
1962 else if (yyflag == yyerr)
1963 {
1964 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1965 (unsigned long int) yynewStack));
1966 yymarkStackDeleted (yystackp, yynewStack);
1967 }
1968 else
1969 return yyflag;
1970 yyconflicts += 1;
1971 }
1972
1973 if (yyisShiftAction (yyaction))
1974 break;
1975 else if (yyisErrorAction (yyaction))
1976 {
1977 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1978 (unsigned long int) yyk));
1979 yymarkStackDeleted (yystackp, yyk);
1980 break;
1981 }
1982 else
1983 {
1984 YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction,
1985 yyimmediate[-yyaction]]b4_user_args[);
1986 if (yyflag == yyerr)
1987 {
1988 YYDPRINTF ((stderr,
1989 "Stack %lu dies "
1990 "(predicate failure or explicit user error).\n",
1991 (unsigned long int) yyk));
1992 yymarkStackDeleted (yystackp, yyk);
1993 break;
1994 }
1995 else if (yyflag != yyok)
1996 return yyflag;
1997 }
1998 }
1999 }
2000 return yyok;
2001}
2002
2003static void
2004yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
2005{
2006 if (yystackp->yyerrState != 0)
2007 return;
2008#if ! YYERROR_VERBOSE
2009 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2010#else
2011 {
2012 yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2013 size_t yysize0 = yytnamerr (YY_NULLPTR, yytokenName (yytoken));
2014 size_t yysize = yysize0;
2015 yybool yysize_overflow = yyfalse;
2016 char* yymsg = YY_NULLPTR;
2017 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
2018 /* Internationalized format string. */
2019 const char *yyformat = YY_NULLPTR;
2020 /* Arguments of yyformat. */
2021 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
2022 /* Number of reported tokens (one for the "unexpected", one per
2023 "expected"). */
2024 int yycount = 0;
2025
2026 /* There are many possibilities here to consider:
2027 - If this state is a consistent state with a default action, then
2028 the only way this function was invoked is if the default action
2029 is an error action. In that case, don't check for expected
2030 tokens because there are none.
2031 - The only way there can be no lookahead present (in yychar) is if
2032 this state is a consistent state with a default action. Thus,
2033 detecting the absence of a lookahead is sufficient to determine
2034 that there is no unexpected or expected token to report. In that
2035 case, just report a simple "syntax error".
2036 - Don't assume there isn't a lookahead just because this state is a
2037 consistent state with a default action. There might have been a
2038 previous inconsistent state, consistent state with a non-default
2039 action, or user semantic action that manipulated yychar.
2040 - Of course, the expected token list depends on states to have
2041 correct lookahead information, and it depends on the parser not
2042 to perform extra reductions after fetching a lookahead from the
2043 scanner and before detecting a syntax error. Thus, state merging
2044 (from LALR or IELR) and default reductions corrupt the expected
2045 token list. However, the list is correct for canonical LR with
2046 one exception: it will still contain any token that will not be
2047 accepted due to an error action in a later state.
2048 */
2049 if (yytoken != YYEMPTY)
2050 {
2051 int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
2052 yyarg[yycount++] = yytokenName (yytoken);
2053 if (!yypact_value_is_default (yyn))
2054 {
2055 /* Start YYX at -YYN if negative to avoid negative indexes in
2056 YYCHECK. In other words, skip the first -YYN actions for this
2057 state because they are default actions. */
2058 int yyxbegin = yyn < 0 ? -yyn : 0;
2059 /* Stay within bounds of both yycheck and yytname. */
2060 int yychecklim = YYLAST - yyn + 1;
2061 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2062 int yyx;
2063 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
2064 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
2065 && !yytable_value_is_error (yytable[yyx + yyn]))
2066 {
2067 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
2068 {
2069 yycount = 1;
2070 yysize = yysize0;
2071 break;
2072 }
2073 yyarg[yycount++] = yytokenName (yyx);
2074 {
2075 size_t yysz = yysize + yytnamerr (YY_NULLPTR, yytokenName (yyx));
2076 yysize_overflow |= yysz < yysize;
2077 yysize = yysz;
2078 }
2079 }
2080 }
2081 }
2082
2083 switch (yycount)
2084 {
2085#define YYCASE_(N, S) \
2086 case N: \
2087 yyformat = S; \
2088 break
2089 YYCASE_(0, YY_("syntax error"));
2090 YYCASE_(1, YY_("syntax error, unexpected %s"));
2091 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2092 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2093 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2094 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2095#undef YYCASE_
2096 }
2097
2098 {
2099 size_t yysz = yysize + strlen (yyformat);
2100 yysize_overflow |= yysz < yysize;
2101 yysize = yysz;
2102 }
2103
2104 if (!yysize_overflow)
2105 yymsg = (char *) YYMALLOC (yysize);
2106
2107 if (yymsg)
2108 {
2109 char *yyp = yymsg;
2110 int yyi = 0;
2111 while ((*yyp = *yyformat))
2112 {
2113 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
2114 {
2115 yyp += yytnamerr (yyp, yyarg[yyi++]);
2116 yyformat += 2;
2117 }
2118 else
2119 {
2120 yyp++;
2121 yyformat++;
2122 }
2123 }
2124 yyerror (]b4_lyyerror_args[yymsg);
2125 YYFREE (yymsg);
2126 }
2127 else
2128 {
2129 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2130 yyMemoryExhausted (yystackp);
2131 }
2132 }
2133#endif /* YYERROR_VERBOSE */
2134 yynerrs += 1;
2135}
2136
2137/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2138 yylval, and yylloc are the syntactic category, semantic value, and location
2139 of the lookahead. */
2140static void
2141yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
2142{
2143 size_t yyk;
2144 int yyj;
2145
2146 if (yystackp->yyerrState == 3)
2147 /* We just shifted the error token and (perhaps) took some
2148 reductions. Skip tokens until we can proceed. */
2149 while (yytrue)
2150 {
2151 yySymbol yytoken;
2152 if (yychar == YYEOF)
2153 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
2154 if (yychar != YYEMPTY)
2155 {]b4_locations_if([[
2156 /* We throw away the lookahead, but the error range
2157 of the shifted error token must take it into account. */
2158 yyGLRState *yys = yystackp->yytops.yystates[0];
2159 yyGLRStackItem yyerror_range[3];
2160 yyerror_range[1].yystate.yyloc = yys->yyloc;
2161 yyerror_range[2].yystate.yyloc = yylloc;
2162 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2163 yytoken = YYTRANSLATE (yychar);
2164 yydestruct ("Error: discarding",
2165 yytoken, &yylval]b4_locuser_args([&yylloc])[);
2166 }
2167 YYDPRINTF ((stderr, "Reading a token: "));
2168 yychar = ]b4_lex[;
2169 if (yychar <= YYEOF)
2170 {
2171 yychar = yytoken = YYEOF;
2172 YYDPRINTF ((stderr, "Now at end of input.\n"));
2173 }
2174 else
2175 {
2176 yytoken = YYTRANSLATE (yychar);
2177 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2178 }
2179 yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
2180 if (yypact_value_is_default (yyj))
2181 return;
2182 yyj += yytoken;
2183 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
2184 {
2185 if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
2186 return;
2187 }
2188 else if (! yytable_value_is_error (yytable[yyj]))
2189 return;
2190 }
2191
2192 /* Reduce to one stack. */
2193 for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
2194 if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
2195 break;
2196 if (yyk >= yystackp->yytops.yysize)
2197 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
2198 for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
2199 yymarkStackDeleted (yystackp, yyk);
2200 yyremoveDeletes (yystackp);
2201 yycompressStack (yystackp);
2202
2203 /* Now pop stack until we find a state that shifts the error token. */
2204 yystackp->yyerrState = 3;
2205 while (yystackp->yytops.yystates[0] != YY_NULLPTR)
2206 {
2207 yyGLRState *yys = yystackp->yytops.yystates[0];
2208 yyj = yypact[yys->yylrState];
2209 if (! yypact_value_is_default (yyj))
2210 {
2211 yyj += YYTERROR;
2212 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2213 && yyisShiftAction (yytable[yyj]))
2214 {
2215 /* Shift the error token. */]b4_locations_if([[
2216 /* First adjust its location.*/
2217 YYLTYPE yyerrloc;
2218 yystackp->yyerror_range[2].yystate.yyloc = yylloc;
2219 YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
2220 YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
2221 &yylval, &yyerrloc);
2222 yyglrShift (yystackp, 0, yytable[yyj],
2223 yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
2224 yys = yystackp->yytops.yystates[0];
2225 break;
2226 }
2227 }]b4_locations_if([[
2228 yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
2229 if (yys->yypred != YY_NULLPTR)
2230 yydestroyGLRState ("Error: popping", yys]b4_user_args[);
2231 yystackp->yytops.yystates[0] = yys->yypred;
2232 yystackp->yynextFree -= 1;
2233 yystackp->yyspaceLeft += 1;
2234 }
2235 if (yystackp->yytops.yystates[0] == YY_NULLPTR)
2236 yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
2237}
2238
2239#define YYCHK1(YYE) \
2240 do { \
2241 switch (YYE) { \
2242 case yyok: \
2243 break; \
2244 case yyabort: \
2245 goto yyabortlab; \
2246 case yyaccept: \
2247 goto yyacceptlab; \
2248 case yyerr: \
2249 goto yyuser_error; \
2250 default: \
2251 goto yybuglab; \
2252 } \
2253 } while (0)
2254
2255/*----------.
2256| yyparse. |
2257`----------*/
2258
2259]b4_function_define([yyparse], [int], b4_parse_param)[
2260{
2261 int yyresult;
2262 yyGLRStack yystack;
2263 yyGLRStack* const yystackp = &yystack;
2264 size_t yyposn;
2265
2266 YYDPRINTF ((stderr, "Starting parse\n"));
2267
2268 yychar = YYEMPTY;
2269 yylval = yyval_default;]b4_locations_if([
2270 yylloc = yyloc_default;])[
2271]m4_ifdef([b4_initial_action], [
2272b4_dollar_pushdef([yylval], [], [yylloc])dnl
2273 /* User initialization code. */
2274 b4_user_initial_action
2275b4_dollar_popdef])[]dnl
2276[
2277 if (! yyinitGLRStack (yystackp, YYINITDEPTH))
2278 goto yyexhaustedlab;
2279 switch (YYSETJMP (yystack.yyexception_buffer))
2280 {
2281 case 0: break;
2282 case 1: goto yyabortlab;
2283 case 2: goto yyexhaustedlab;
2284 default: goto yybuglab;
2285 }
2286 yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[);
2287 yyposn = 0;
2288
2289 while (yytrue)
2290 {
2291 /* For efficiency, we have two loops, the first of which is
2292 specialized to deterministic operation (single stack, no
2293 potential ambiguity). */
2294 /* Standard mode */
2295 while (yytrue)
2296 {
2297 yyRuleNum yyrule;
2298 int yyaction;
2299 const short int* yyconflicts;
2300
2301 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
2302 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2303 if (yystate == YYFINAL)
2304 goto yyacceptlab;
2305 if (yyisDefaultedState (yystate))
2306 {
2307 yyrule = yydefaultAction (yystate);
2308 if (yyrule == 0)
2309 {]b4_locations_if([[
2310 yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2311 yyreportSyntaxError (&yystack]b4_user_args[);
2312 goto yyuser_error;
2313 }
2314 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
2315 }
2316 else
2317 {
2318 yySymbol yytoken;
2319 if (yychar == YYEMPTY)
2320 {
2321 YYDPRINTF ((stderr, "Reading a token: "));
2322 yychar = ]b4_lex[;
2323 }
2324
2325 if (yychar <= YYEOF)
2326 {
2327 yychar = yytoken = YYEOF;
2328 YYDPRINTF ((stderr, "Now at end of input.\n"));
2329 }
2330 else
2331 {
2332 yytoken = YYTRANSLATE (yychar);
2333 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2334 }
2335
2336 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
2337 if (*yyconflicts != 0)
2338 break;
2339 if (yyisShiftAction (yyaction))
2340 {
2341 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2342 yychar = YYEMPTY;
2343 yyposn += 1;
2344 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
2345 if (0 < yystack.yyerrState)
2346 yystack.yyerrState -= 1;
2347 }
2348 else if (yyisErrorAction (yyaction))
2349 {]b4_locations_if([[
2350 yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2351 yyreportSyntaxError (&yystack]b4_user_args[);
2352 goto yyuser_error;
2353 }
2354 else
2355 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
2356 }
2357 }
2358
2359 while (yytrue)
2360 {
2361 yySymbol yytoken_to_shift;
2362 size_t yys;
2363
2364 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2365 yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
2366
2367 /* yyprocessOneStack returns one of three things:
2368
2369 - An error flag. If the caller is yyprocessOneStack, it
2370 immediately returns as well. When the caller is finally
2371 yyparse, it jumps to an error label via YYCHK1.
2372
2373 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2374 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2375 yyparse's following invocation of yyremoveDeletes will remove
2376 the stack.
2377
2378 - yyok, when ready to shift a token.
2379
2380 Except in the first case, yyparse will invoke yyremoveDeletes and
2381 then shift the next token onto all remaining stacks. This
2382 synchronization of the shift (that is, after all preceding
2383 reductions on all stacks) helps prevent double destructor calls
2384 on yylval in the event of memory exhaustion. */
2385
2386 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2387 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
2388 yyremoveDeletes (&yystack);
2389 if (yystack.yytops.yysize == 0)
2390 {
2391 yyundeleteLastStack (&yystack);
2392 if (yystack.yytops.yysize == 0)
2393 yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
2394 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2395 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));]b4_locations_if([[
2396 yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2397 yyreportSyntaxError (&yystack]b4_user_args[);
2398 goto yyuser_error;
2399 }
2400
2401 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2402 a copy of yylval will already be on stack 0 in the event of a
2403 failure in the following loop. Thus, yychar is set to YYEMPTY
2404 before the loop to make sure the user destructor for yylval isn't
2405 called twice. */
2406 yytoken_to_shift = YYTRANSLATE (yychar);
2407 yychar = YYEMPTY;
2408 yyposn += 1;
2409 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2410 {
2411 int yyaction;
2412 const short int* yyconflicts;
2413 yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
2414 yygetLRActions (yystate, yytoken_to_shift, &yyaction,
2415 &yyconflicts);
2416 /* Note that yyconflicts were handled by yyprocessOneStack. */
2417 YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
2418 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
2419 yyglrShift (&yystack, yys, yyaction, yyposn,
2420 &yylval]b4_locations_if([, &yylloc])[);
2421 YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
2422 (unsigned long int) yys,
2423 yystack.yytops.yystates[yys]->yylrState));
2424 }
2425
2426 if (yystack.yytops.yysize == 1)
2427 {
2428 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2429 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2430 yycompressStack (&yystack);
2431 break;
2432 }
2433 }
2434 continue;
2435 yyuser_error:
2436 yyrecoverSyntaxError (&yystack]b4_user_args[);
2437 yyposn = yystack.yytops.yystates[0]->yyposn;
2438 }
2439
2440 yyacceptlab:
2441 yyresult = 0;
2442 goto yyreturn;
2443
2444 yybuglab:
2445 YYASSERT (yyfalse);
2446 goto yyabortlab;
2447
2448 yyabortlab:
2449 yyresult = 1;
2450 goto yyreturn;
2451
2452 yyexhaustedlab:
2453 yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
2454 yyresult = 2;
2455 goto yyreturn;
2456
2457 yyreturn:
2458 if (yychar != YYEMPTY)
2459 yydestruct ("Cleanup: discarding lookahead",
2460 YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
2461
2462 /* If the stack is well-formed, pop the stack until it is empty,
2463 destroying its entries as we go. But free the stack regardless
2464 of whether it is well-formed. */
2465 if (yystack.yyitems)
2466 {
2467 yyGLRState** yystates = yystack.yytops.yystates;
2468 if (yystates)
2469 {
2470 size_t yysize = yystack.yytops.yysize;
2471 size_t yyk;
2472 for (yyk = 0; yyk < yysize; yyk += 1)
2473 if (yystates[yyk])
2474 {
2475 while (yystates[yyk])
2476 {
2477 yyGLRState *yys = yystates[yyk];]b4_locations_if([[
2478 yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
2479 if (yys->yypred != YY_NULLPTR)
2480 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
2481 yystates[yyk] = yys->yypred;
2482 yystack.yynextFree -= 1;
2483 yystack.yyspaceLeft += 1;
2484 }
2485 break;
2486 }
2487 }
2488 yyfreeGLRStack (&yystack);
2489 }
2490
2491 return yyresult;
2492}
2493
2494/* DEBUGGING ONLY */
2495#if ]b4_api_PREFIX[DEBUG
2496static void
2497yy_yypstack (yyGLRState* yys)
2498{
2499 if (yys->yypred)
2500 {
2501 yy_yypstack (yys->yypred);
2502 YYFPRINTF (stderr, " -> ");
2503 }
2504 YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
2505 (unsigned long int) yys->yyposn);
2506}
2507
2508static void
2509yypstates (yyGLRState* yyst)
2510{
2511 if (yyst == YY_NULLPTR)
2512 YYFPRINTF (stderr, "<null>");
2513 else
2514 yy_yypstack (yyst);
2515 YYFPRINTF (stderr, "\n");
2516}
2517
2518static void
2519yypstack (yyGLRStack* yystackp, size_t yyk)
2520{
2521 yypstates (yystackp->yytops.yystates[yyk]);
2522}
2523
2524#define YYINDEX(YYX) \
2525 ((YYX) == YY_NULLPTR ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2526
2527
2528static void
2529yypdumpstack (yyGLRStack* yystackp)
2530{
2531 yyGLRStackItem* yyp;
2532 size_t yyi;
2533 for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
2534 {
2535 YYFPRINTF (stderr, "%3lu. ",
2536 (unsigned long int) (yyp - yystackp->yyitems));
2537 if (*(yybool *) yyp)
2538 {
2539 YYASSERT (yyp->yystate.yyisState);
2540 YYASSERT (yyp->yyoption.yyisState);
2541 YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2542 yyp->yystate.yyresolved, yyp->yystate.yylrState,
2543 (unsigned long int) yyp->yystate.yyposn,
2544 (long int) YYINDEX (yyp->yystate.yypred));
2545 if (! yyp->yystate.yyresolved)
2546 YYFPRINTF (stderr, ", firstVal: %ld",
2547 (long int) YYINDEX (yyp->yystate
2548 .yysemantics.yyfirstVal));
2549 }
2550 else
2551 {
2552 YYASSERT (!yyp->yystate.yyisState);
2553 YYASSERT (!yyp->yyoption.yyisState);
2554 YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
2555 yyp->yyoption.yyrule - 1,
2556 (long int) YYINDEX (yyp->yyoption.yystate),
2557 (long int) YYINDEX (yyp->yyoption.yynext));
2558 }
2559 YYFPRINTF (stderr, "\n");
2560 }
2561 YYFPRINTF (stderr, "Tops:");
2562 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
2563 YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
2564 (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
2565 YYFPRINTF (stderr, "\n");
2566}
2567#endif
2568
2569#undef yylval
2570#undef yychar
2571#undef yynerrs]b4_locations_if([
2572#undef yylloc])
2573
2574m4_if(b4_prefix, [yy], [],
2575[[/* Substitute the variable and function names. */
2576#define yyparse ]b4_prefix[parse
2577#define yylex ]b4_prefix[lex
2578#define yyerror ]b4_prefix[error
2579#define yylval ]b4_prefix[lval
2580#define yychar ]b4_prefix[char
2581#define yydebug ]b4_prefix[debug
2582#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
2583#define yylloc ]b4_prefix[lloc]])])[
2584
2585]b4_epilogue[]dnl
2586b4_output_end()