3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
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.
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.
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/>.
21 # If we are loaded by glr.cc, do not override c++.m4 definitions by
23 m4_if(b4_skeleton
, ["glr.c"],
24 [m4_include(b4_pkgdatadir
/[c
.m4
])])
26 ## ---------------- ##
28 ## ---------------- ##
31 m4_define_default([b4_stack_depth_max
], [10000])
32 m4_define_default([b4_stack_depth_init
], [200])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
40 b4_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.
43 m4_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]])])])
50 # The possible parse-params formal arguments preceded by a comma.
52 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
53 # formal argument declarations.
54 m4_define([b4_user_formals
],
55 [m4_ifset([b4_parse_param
], [, b4_formals(b4_parse_param
)])])
60 # All the yylex formal arguments.
61 m4_define([b4_lex_formals
],
62 m4_dquote(b4_pure_if([[[[YYSTYPE
*yylvalp
]], [[&yylval
]]][]dnl
63 b4_locations_if([, [[YYLTYPE
*yyllocp
], [&yylloc
]]])])dnl
64 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
69 # Optional effective arguments passed to yyerror: user args plus yylloc, and
71 m4_define([b4_yyerror_args
],
72 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
73 m4_ifset([b4_parse_param
], [b4_args(b4_parse_param
), ])])
78 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
79 m4_define([b4_lyyerror_args
],
80 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
81 m4_ifset([b4_parse_param
], [b4_args(b4_parse_param
), ])])
86 # Same as b4_yyerror_args, but with a leading comma.
87 m4_define([b4_pure_args
],
88 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
93 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
94 m4_define([b4_lpure_args
],
95 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
101 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
102 m4_define([b4_pure_formals
],
103 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
106 # b4_locuser_formals(LOC = yylocp)
107 # --------------------------------
108 m4_define([b4_locuser_formals
],
109 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
112 # b4_locuser_args(LOC = yylocp)
113 # -----------------------------
114 m4_define([b4_locuser_args
],
115 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
119 ## ----------------- ##
120 ## Semantic Values. ##
121 ## ----------------- ##
124 # b4_lhs_value([TYPE])
125 # --------------------
126 # Expansion of $<TYPE>$.
127 m4_define([b4_lhs_value
],
128 [b4_symbol_value([(*yyvalp
)], [$
1])])
131 # b4_rhs_data(RULE-LENGTH, NUM)
132 # -----------------------------
133 # Expand to the semantic stack place that contains value and location
134 # of symbol number NUM in a rule of length RULE-LENGTH.
135 m4_define([b4_rhs_data
],
136 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
139 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
140 # --------------------------------------
141 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
143 m4_define([b4_rhs_value
],
144 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
155 m4_define([b4_lhs_location
],
159 # b4_rhs_location(RULE-LENGTH, NUM)
160 # ---------------------------------
161 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
163 m4_define([b4_rhs_location
],
164 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
171 # b4_shared_declarations
172 # ----------------------
173 # Declaration that might either go into the header (if --defines)
174 # or open coded in the parser body. glr.cc has its own definition.
175 m4_if(b4_skeleton
, ["glr.c"],
176 [m4_define([b4_shared_declarations
],
178 ]b4_percent_code_get([[requires]])[
180 ]b4_declare_yylstype
[
181 ]b4_function_declare(b4_prefix
[parse
], [int], b4_parse_param
)[
182 ]b4_percent_code_get([[provides]])[]dnl
190 b4_output_begin([b4_parser_file_name
])
191 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
194 /* C GLR parser skeleton written by Paul Hilfinger. */
198 b4_percent_code_get([[top]])[
199 ]m4_if(b4_api_prefix
, [yy
], [],
200 [[/* Substitute the type names. */
201 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
202 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
203 ]m4_if(b4_prefix
, [yy
], [],
204 [[/* Substitute the variable and function names. */
205 #define yyparse ]b4_prefix[parse
206 #define yylex ]b4_prefix[lex
207 #define yyerror ]b4_prefix[error
208 #define yylval ]b4_prefix[lval
209 #define yychar ]b4_prefix[char
210 #define yydebug ]b4_prefix[debug
211 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
212 #define yylloc ]b4_prefix[lloc]])])[
214 /* First part of user declarations. */
215 ]b4_user_pre_prologue
[
219 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
220 [b4_shared_declarations
])[
222 /* Enabling verbose error messages. */
223 #ifdef YYERROR_VERBOSE
224 # undef YYERROR_VERBOSE
225 # define YYERROR_VERBOSE 1
227 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
230 /* Default (constant) value used for initialization for null
231 right-hand sides. Unlike the standard yacc.c template, here we set
232 the default value of $$ to a zeroed-out value. Since the default
233 value is undefined, this behavior is technically correct. */
234 static YYSTYPE yyval_default
;]b4_locations_if([[
235 static YYLTYPE yyloc_default
][]b4_yyloc_default
;])[
237 /* Copy the second part of user declarations. */
238 ]b4_user_post_prologue
239 b4_percent_code_get
[]dnl
246 # if defined YYENABLE_NLS && YYENABLE_NLS
248 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
249 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
253 # define YY_(Msgid) Msgid
257 /* Suppress unused-variable warnings by "using" E. */
259 # define YYUSE(E) ((void) (E))
261 # define YYUSE(E) /* empty */
268 # define YYMALLOC malloc
271 # define YYREALLOC realloc
274 #define YYSIZEMAX ((size_t) -1)
279 typedef unsigned char yybool
;
286 # define YYJMP_BUF jmp_buf
287 # define YYSETJMP(Env) setjmp (Env)
289 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
296 #ifndef __attribute__
297 /* This feature is available in gcc versions 2.5 and later. */
298 # if (! defined __GNUC__ || __GNUC__ < 2 \
299 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
300 # define __attribute__(Spec) /* empty */
305 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
308 /* YYFINAL -- State number of the termination state. */
309 #define YYFINAL ]b4_final_state_number[
310 /* YYLAST -- Last index in YYTABLE. */
311 #define YYLAST ]b4_last[
313 /* YYNTOKENS -- Number of terminals. */
314 #define YYNTOKENS ]b4_tokens_number[
315 /* YYNNTS -- Number of nonterminals. */
316 #define YYNNTS ]b4_nterms_number[
317 /* YYNRULES -- Number of rules. */
318 #define YYNRULES ]b4_rules_number[
319 /* YYNRULES -- Number of states. */
320 #define YYNSTATES ]b4_states_number[
321 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
322 #define YYMAXRHS ]b4_r2_max[
323 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
324 accessed by $0, $-1, etc., in any rule. */
325 #define YYMAXLEFT ]b4_max_left_semantic_context[
327 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
328 #define YYUNDEFTOK ]b4_undef_token_number[
329 #define YYMAXUTOK ]b4_user_token_number_max[
331 #define YYTRANSLATE(YYX) \
332 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
334 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
335 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
340 #if ]b4_api_PREFIX[DEBUG
341 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
342 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
348 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
349 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
350 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
351 static const char *const yytname
[] =
357 #define YYPACT_NINF ]b4_pact_ninf[
358 #define YYTABLE_NINF ]b4_table_ninf[
360 ]b4_parser_tables_define
[
362 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
363 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
368 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
369 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
374 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
375 in the case of predicates. */
376 static const yybool yyimmediate
[] =
381 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
382 list of conflicting reductions corresponding to action entry for
383 state STATE-NUM in yytable. 0 means no conflicts. The list in
384 yyconfl is terminated by a rule number of 0. */
385 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
387 ]b4_conflict_list_heads
[
390 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
391 0, pointed into by YYCONFLP. */
392 ]dnl Do
not use b4_int_type_for here
, since there are places where
393 dnl pointers onto yyconfl are taken
, which type is
"short int *".
394 dnl We probably ought to introduce a type
for confl
.
395 [static const short int yyconfl
[] =
397 ]b4_conflicting_rules
[
400 /* Error token number */
404 ]b4_yylloc_default_define
[
405 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
407 ]b4_yy_location_print_define
[
409 /* YYLEX -- calling `yylex' with the right arguments. */
411 # define YYLEX ]b4_function_call([yylex], [int], b4_lex_formals)[
417 #define yynerrs (yystackp->yyerrcnt)
419 #define yychar (yystackp->yyrawchar)
421 #define yylval (yystackp->yyval)
423 #define yylloc (yystackp->yyloc)
424 m4_if(b4_prefix
[], [yy
], [],
425 [#define b4_prefix[]nerrs yynerrs
426 #define b4_prefix[]char yychar
427 #define b4_prefix[]lval yylval
428 #define b4_prefix[]lloc yylloc])],
429 [YYSTYPE yylval
;]b4_locations_if([[
435 static const int YYEOF
= 0;
436 static const int YYEMPTY
= -2;
438 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
442 YYRESULTTAG yychk_flag = YYE; \
443 if (yychk_flag != yyok) \
447 #if ]b4_api_PREFIX[DEBUG
450 # define YYFPRINTF fprintf
453 # define YYDPRINTF(Args) \
459 ]b4_yy_symbol_print_define
[
461 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
465 YYFPRINTF (stderr, "%s ", Title); \
466 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
467 YYFPRINTF (stderr, "\n"); \
471 /* Nonzero means print parse trace. It is left uninitialized so that
472 multiple parsers can coexist. */
476 static void yypstack (struct yyGLRStack
* yystackp
, size_t yyk
)
477 __attribute__ ((__unused__
));
478 static void yypdumpstack (struct yyGLRStack
* yystackp
)
479 __attribute__ ((__unused__
));
481 #else /* !]b4_api_PREFIX[DEBUG */
483 # define YYDPRINTF(Args)
484 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
486 #endif /* !]b4_api_PREFIX[DEBUG */
488 /* YYINITDEPTH -- initial size of the parser's stacks. */
490 # define YYINITDEPTH ]b4_stack_depth_init[
493 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
494 if the built-in stack extension method is used).
496 Do not make this value too large; the results are undefined if
497 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
498 evaluated with infinite-precision integer arithmetic. */
501 # define YYMAXDEPTH ]b4_stack_depth_max[
504 /* Minimum number of free items on the stack allowed after an
505 allocation. This is to allow allocation and initialization
506 to be completed by functions that call yyexpandGLRStack before the
507 stack is expanded, thus insuring that all necessary pointers get
508 properly redirected to new data. */
511 #ifndef YYSTACKEXPANDABLE
512 # define YYSTACKEXPANDABLE 1
515 #if YYSTACKEXPANDABLE
516 # define YY_RESERVE_GLRSTACK(Yystack) \
518 if (Yystack->yyspaceLeft < YYHEADROOM) \
519 yyexpandGLRStack (Yystack); \
522 # define YY_RESERVE_GLRSTACK(Yystack) \
524 if (Yystack->yyspaceLeft < YYHEADROOM) \
525 yyMemoryExhausted (Yystack); \
533 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
534 # define yystpcpy stpcpy
536 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
539 yystpcpy (char *yydest
, const char *yysrc
)
542 const char *yys
= yysrc
;
544 while ((*yyd
++ = *yys
++) != '\0')
553 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
554 quotes and backslashes, so that it's suitable for yyerror. The
555 heuristic is that double-quoting is unnecessary unless the string
556 contains an apostrophe, a comma, or backslash (other than
557 backslash-backslash). YYSTR is taken from yytname. If YYRES is
558 null, do not copy; instead, return the length of what the result
561 yytnamerr (char *yyres
, const char *yystr
)
566 char const *yyp
= yystr
;
573 goto do_not_strip_quotes
;
577 goto do_not_strip_quotes
;
590 do_not_strip_quotes
: ;
594 return strlen (yystr
);
596 return yystpcpy (yyres
, yystr
) - yyres
;
600 #endif /* !YYERROR_VERBOSE */
602 /** State numbers, as in LALR(1) machine */
603 typedef int yyStateNum
;
605 /** Rule numbers, as in LALR(1) machine */
606 typedef int yyRuleNum
;
608 /** Grammar symbol */
609 typedef int yySymbol
;
611 /** Item references, as in LALR(1) machine */
612 typedef short int yyItemNum
;
614 typedef struct yyGLRState yyGLRState
;
615 typedef struct yyGLRStateSet yyGLRStateSet
;
616 typedef struct yySemanticOption yySemanticOption
;
617 typedef union yyGLRStackItem yyGLRStackItem
;
618 typedef struct yyGLRStack yyGLRStack
;
621 /** Type tag: always true. */
623 /** Type tag for yysemantics. If true, yysval applies, otherwise
624 * yyfirstVal applies. */
626 /** Number of corresponding LALR(1) machine state. */
627 yyStateNum yylrState
;
628 /** Preceding state in this stack */
630 /** Source position of the last token produced by my symbol */
633 /** First in a chain of alternative reductions producing the
634 * non-terminal corresponding to this state, threaded through
636 yySemanticOption
* yyfirstVal
;
637 /** Semantic value for this state. */
639 } yysemantics
;]b4_locations_if([[
640 /** Source location for this state. */
644 struct yyGLRStateSet
{
645 yyGLRState
** yystates
;
646 /** During nondeterministic operation, yylookaheadNeeds tracks which
647 * stacks have actually needed the current lookahead. During deterministic
648 * operation, yylookaheadNeeds[0] is not maintained since it would merely
649 * duplicate yychar != YYEMPTY. */
650 yybool
* yylookaheadNeeds
;
651 size_t yysize
, yycapacity
;
654 struct yySemanticOption
{
655 /** Type tag: always false. */
657 /** Rule number for this reduction */
659 /** The last RHS state in the list of states to be reduced. */
661 /** The lookahead for this reduction. */
663 YYSTYPE yyval
;]b4_locations_if([[
665 /** Next sibling in chain of options. To facilitate merging,
666 * options are chained in decreasing order by address. */
667 yySemanticOption
* yynext
;
670 /** Type of the items in the GLR stack. The yyisState field
671 * indicates which item of the union is valid. */
672 union yyGLRStackItem
{
674 yySemanticOption yyoption
;
679 ]b4_locations_if([[ /* To compute the location of the error token. */
680 yyGLRStackItem yyerror_range
[3];]])[
685 YYSTYPE yyval
;]b4_locations_if([[
688 YYJMP_BUF yyexception_buffer
;
689 yyGLRStackItem
* yyitems
;
690 yyGLRStackItem
* yynextFree
;
692 yyGLRState
* yysplitPoint
;
693 yyGLRState
* yylastDeleted
;
694 yyGLRStateSet yytops
;
697 #if YYSTACKEXPANDABLE
698 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
701 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
702 __attribute__ ((__noreturn__
));
704 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
706 if (yymsg
!= YY_NULL
)
707 yyerror (]b4_yyerror_args
[yymsg
);
708 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
711 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
712 __attribute__ ((__noreturn__
));
714 yyMemoryExhausted (yyGLRStack
* yystackp
)
716 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
719 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
720 /** A printable representation of TOKEN. */
721 static inline const char*
722 yytokenName (yySymbol yytoken
)
724 if (yytoken
== YYEMPTY
)
727 return yytname
[yytoken
];
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. */
734 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
736 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
739 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
740 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
742 #if ]b4_api_PREFIX[DEBUG
743 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
745 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
747 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
749 /* The effect of using yysval or yyloc (in an immediate rule) is
751 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
752 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
753 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
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. */
760 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
761 __attribute__ ((__unused__
));
763 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
765 if (!yynormal
&& yylow1
< *yylow
)
767 yyfillin (yyvsp
, *yylow
, yylow1
);
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. */
779 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
780 yyGLRStack
* yystackp
,
781 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
783 yybool yynormal
__attribute__ ((__unused__
)) =
784 (yystackp
->yysplitPoint
== YY_NULL
);
786 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
788 # define yyerrok (yystackp->yyerrState = 0)
790 # define YYACCEPT return yyaccept
792 # define YYABORT return yyabort
794 # define YYERROR return yyerrok, yyerr
796 # define YYRECOVERING() (yystackp->yyerrState != 0)
798 # define yyclearin (yychar = YYEMPTY)
800 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
802 # define YYBACKUP(Token, Value) \
803 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
808 *yyvalp
= yyval_default
;
810 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
811 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
812 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
832 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
844 /* Bison grammar-table manipulation. */
846 ]b4_yydestruct_define
[
848 /** Number of symbols composing the right hand side of rule #RULE. */
850 yyrhsLength (yyRuleNum yyrule
)
856 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
859 yydestruct (yymsg
, yystos
[yys
->yylrState
],
860 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
863 #if ]b4_api_PREFIX[DEBUG
866 if (yys
->yysemantics
.yyfirstVal
)
867 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
869 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
870 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
871 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
872 YYFPRINTF (stderr
, "\n");
876 if (yys
->yysemantics
.yyfirstVal
)
878 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
881 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
883 yyrh
= yyrh
->yypred
, yyn
-= 1)
884 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
889 /** Left-hand-side symbol for rule #YYRULE. */
890 static inline yySymbol
891 yylhsNonterm (yyRuleNum yyrule
)
896 #define yypact_value_is_default(Yystate) \
897 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
899 /** True iff LR state YYSTATE has only a default reduction (regardless
902 yyisDefaultedState (yyStateNum yystate
)
904 return yypact_value_is_default (yypact
[yystate
]);
907 /** The default reduction for YYSTATE, assuming it has one. */
908 static inline yyRuleNum
909 yydefaultAction (yyStateNum yystate
)
911 return yydefact
[yystate
];
914 #define yytable_value_is_error(Yytable_value) \
915 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
917 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
919 * R < 0: Reduce on rule -R.
921 * R > 0: Shift to state R.
922 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
923 * of conflicting reductions.
926 yygetLRActions (yyStateNum yystate
, int yytoken
,
927 int* yyaction
, const short int** yyconflicts
)
929 int yyindex
= yypact
[yystate
] + yytoken
;
930 if (yypact_value_is_default (yypact
[yystate
])
931 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
933 *yyaction
= -yydefact
[yystate
];
934 *yyconflicts
= yyconfl
;
936 else if (! yytable_value_is_error (yytable
[yyindex
]))
938 *yyaction
= yytable
[yyindex
];
939 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
944 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
948 static inline yyStateNum
949 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
951 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
952 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
955 return yydefgoto
[yylhs
- YYNTOKENS
];
959 yyisShiftAction (int yyaction
)
965 yyisErrorAction (int yyaction
)
967 return yyaction
== 0;
972 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
973 * if YYISSTATE, and otherwise a semantic option. Callers should call
974 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
977 static inline yyGLRStackItem
*
978 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
980 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
981 yystackp
->yyspaceLeft
-= 1;
982 yystackp
->yynextFree
+= 1;
983 yynewItem
->yystate
.yyisState
= yyisState
;
987 /** Add a new semantic action that will execute the action for rule
988 * YYRULE on the semantic values in YYRHS to the list of
989 * alternative actions for YYSTATE. Assumes that YYRHS comes from
990 * stack #YYK of *YYSTACKP. */
992 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
993 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
995 yySemanticOption
* yynewOption
=
996 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
997 yynewOption
->yystate
= yyrhs
;
998 yynewOption
->yyrule
= yyrule
;
999 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1001 yynewOption
->yyrawchar
= yychar
;
1002 yynewOption
->yyval
= yylval
;]b4_locations_if([
1003 yynewOption
->yyloc
= yylloc
;])[
1006 yynewOption
->yyrawchar
= YYEMPTY
;
1007 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1008 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1010 YY_RESERVE_GLRSTACK (yystackp
);
1015 /** Initialize YYSET to a singleton set containing an empty stack. */
1017 yyinitStateSet (yyGLRStateSet
* yyset
)
1020 yyset
->yycapacity
= 16;
1021 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1022 if (! yyset
->yystates
)
1024 yyset
->yystates
[0] = YY_NULL
;
1025 yyset
->yylookaheadNeeds
=
1026 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1027 if (! yyset
->yylookaheadNeeds
)
1029 YYFREE (yyset
->yystates
);
1035 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1037 YYFREE (yyset
->yystates
);
1038 YYFREE (yyset
->yylookaheadNeeds
);
1041 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1042 * capacity for all stacks of YYSIZE. */
1044 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1046 yystackp
->yyerrState
= 0;
1048 yystackp
->yyspaceLeft
= yysize
;
1050 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1051 if (!yystackp
->yyitems
)
1053 yystackp
->yynextFree
= yystackp
->yyitems
;
1054 yystackp
->yysplitPoint
= YY_NULL
;
1055 yystackp
->yylastDeleted
= YY_NULL
;
1056 return yyinitStateSet (&yystackp
->yytops
);
1060 #if YYSTACKEXPANDABLE
1061 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1062 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1064 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1065 stack from outside should be considered invalid after this call.
1066 We always expand when there are 1 or fewer items left AFTER an
1067 allocation, so that we can avoid having external pointers exist
1068 across an allocation. */
1070 yyexpandGLRStack (yyGLRStack
* yystackp
)
1072 yyGLRStackItem
* yynewItems
;
1073 yyGLRStackItem
* yyp0
, *yyp1
;
1076 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1077 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1078 yyMemoryExhausted (yystackp
);
1079 yynewSize
= 2*yysize
;
1080 if (YYMAXDEPTH
< yynewSize
)
1081 yynewSize
= YYMAXDEPTH
;
1082 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1084 yyMemoryExhausted (yystackp
);
1085 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1087 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1090 if (*(yybool
*) yyp0
)
1092 yyGLRState
* yys0
= &yyp0
->yystate
;
1093 yyGLRState
* yys1
= &yyp1
->yystate
;
1094 if (yys0
->yypred
!= YY_NULL
)
1096 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1097 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1098 yys1
->yysemantics
.yyfirstVal
=
1099 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1103 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1104 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1105 if (yyv0
->yystate
!= YY_NULL
)
1106 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1107 if (yyv0
->yynext
!= YY_NULL
)
1108 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1111 if (yystackp
->yysplitPoint
!= YY_NULL
)
1112 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1113 yystackp
->yysplitPoint
, yystate
);
1115 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1116 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1117 yystackp
->yytops
.yystates
[yyn
] =
1118 YYRELOC (yystackp
->yyitems
, yynewItems
,
1119 yystackp
->yytops
.yystates
[yyn
], yystate
);
1120 YYFREE (yystackp
->yyitems
);
1121 yystackp
->yyitems
= yynewItems
;
1122 yystackp
->yynextFree
= yynewItems
+ yysize
;
1123 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1128 yyfreeGLRStack (yyGLRStack
* yystackp
)
1130 YYFREE (yystackp
->yyitems
);
1131 yyfreeStateSet (&yystackp
->yytops
);
1134 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1135 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1138 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1140 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1141 yystackp
->yysplitPoint
= yys
;
1144 /** Invalidate stack #YYK in *YYSTACKP. */
1146 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1148 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1149 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1150 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1153 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1154 only be done once after a deletion, and only when all other stacks have
1157 yyundeleteLastStack (yyGLRStack
* yystackp
)
1159 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1161 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1162 yystackp
->yytops
.yysize
= 1;
1163 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1164 yystackp
->yylastDeleted
= YY_NULL
;
1168 yyremoveDeletes (yyGLRStack
* yystackp
)
1172 while (yyj
< yystackp
->yytops
.yysize
)
1174 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1178 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1180 yystackp
->yytops
.yysize
-= 1;
1184 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1185 /* In the current implementation, it's unnecessary to copy
1186 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1187 yyremoveDeletes returns, the parser immediately either enters
1188 deterministic operation or shifts a token. However, it doesn't
1189 hurt, and the code might evolve to need it. */
1190 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1191 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1194 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1195 (unsigned long int) yyi
, (unsigned long int) yyj
));
1203 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1204 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1205 * value *YYVALP and source location *YYLOCP. */
1207 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1209 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1211 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1213 yynewState
->yylrState
= yylrState
;
1214 yynewState
->yyposn
= yyposn
;
1215 yynewState
->yyresolved
= yytrue
;
1216 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1217 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1218 yynewState
->yyloc
= *yylocp
;])[
1219 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1221 YY_RESERVE_GLRSTACK (yystackp
);
1224 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1225 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1226 * semantic value of YYRHS under the action for YYRULE. */
1228 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1229 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1231 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1233 yynewState
->yylrState
= yylrState
;
1234 yynewState
->yyposn
= yyposn
;
1235 yynewState
->yyresolved
= yyfalse
;
1236 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1237 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1238 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1240 /* Invokes YY_RESERVE_GLRSTACK. */
1241 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1244 #if !]b4_api_PREFIX[DEBUG
1245 # define YY_REDUCE_PRINT(Args)
1247 # define YY_REDUCE_PRINT(Args) \
1250 yy_reduce_print Args; \
1253 /*----------------------------------------------------------------------.
1254 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1255 `----------------------------------------------------------------------*/
1258 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1259 yyRuleNum yyrule
]b4_user_formals
[)
1261 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1264 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1265 (unsigned long int) yyk
, yyrule
- 1,
1266 (unsigned long int) yyrline
[yyrule
]);
1268 yyfillin (yyvsp
, 1, -yynrhs
);
1269 /* The symbols being reduced. */
1270 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1272 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1273 yy_symbol_print (stderr
,
1274 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1275 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1276 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1278 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1279 YYFPRINTF (stderr
, " (unresolved)");
1280 YYFPRINTF (stderr
, "\n");
1285 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1286 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1287 * semantic values. Assumes that all ambiguities in semantic values
1288 * have been previously resolved. Set *YYVALP to the resulting value,
1289 * and *YYLOCP to the computed location (if any). Return value is as
1290 * for userAction. */
1291 static inline YYRESULTTAG
1292 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1293 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1295 int yynrhs
= yyrhsLength (yyrule
);
1297 if (yystackp
->yysplitPoint
== YY_NULL
)
1299 /* Standard special case: single stack. */
1300 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1301 YYASSERT (yyk
== 0);
1302 yystackp
->yynextFree
-= yynrhs
;
1303 yystackp
->yyspaceLeft
+= yynrhs
;
1304 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1305 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1306 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1307 yyvalp
]b4_locuser_args
[);
1313 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1314 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1315 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1317 /* Set default location. */
1318 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1319 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1324 yyupdateSplit (yystackp
, yys
);
1325 yystackp
->yytops
.yystates
[yyk
] = yys
;
1326 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1327 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1328 yystackp
, yyvalp
]b4_locuser_args
[);
1332 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1333 * and push back on the resulting nonterminal symbol. Perform the
1334 * semantic action associated with YYRULE and store its value with the
1335 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1336 * unambiguous. Otherwise, store the deferred semantic action with
1337 * the new state. If the new state would have an identical input
1338 * position, LR state, and predecessor to an existing state on the stack,
1339 * it is identified with that existing state, eliminating stack #YYK from
1340 * *YYSTACKP. In this case, the semantic value is
1341 * added to the options for the existing state's semantic value.
1343 static inline YYRESULTTAG
1344 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1345 yybool yyforceEval
]b4_user_formals
[)
1347 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1349 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1352 YYSTYPE yysval
;]b4_locations_if([
1355 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1356 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1358 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1359 (unsigned long int) yyk
, yyrule
- 1));
1363 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1364 yyglrShift (yystackp
, yyk
,
1365 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1366 yylhsNonterm (yyrule
)),
1367 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1373 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1374 yyStateNum yynewLRState
;
1376 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1382 yyupdateSplit (yystackp
, yys
);
1383 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1385 "Reduced stack %lu by rule #%d; action deferred. "
1386 "Now in state %d.\n",
1387 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1388 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1389 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1391 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1392 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1393 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1395 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1397 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1398 yymarkStackDeleted (yystackp
, yyk
);
1399 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1400 (unsigned long int) yyk
,
1401 (unsigned long int) yyi
));
1407 yystackp
->yytops
.yystates
[yyk
] = yys
;
1408 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1414 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1416 if (yystackp
->yysplitPoint
== YY_NULL
)
1418 YYASSERT (yyk
== 0);
1419 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1421 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1423 yyGLRState
** yynewStates
;
1424 yybool
* yynewLookaheadNeeds
;
1426 yynewStates
= YY_NULL
;
1428 if (yystackp
->yytops
.yycapacity
1429 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1430 yyMemoryExhausted (yystackp
);
1431 yystackp
->yytops
.yycapacity
*= 2;
1434 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1435 (yystackp
->yytops
.yycapacity
1436 * sizeof yynewStates
[0]));
1437 if (yynewStates
== YY_NULL
)
1438 yyMemoryExhausted (yystackp
);
1439 yystackp
->yytops
.yystates
= yynewStates
;
1441 yynewLookaheadNeeds
=
1442 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1443 (yystackp
->yytops
.yycapacity
1444 * sizeof yynewLookaheadNeeds
[0]));
1445 if (yynewLookaheadNeeds
== YY_NULL
)
1446 yyMemoryExhausted (yystackp
);
1447 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1449 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1450 = yystackp
->yytops
.yystates
[yyk
];
1451 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1452 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1453 yystackp
->yytops
.yysize
+= 1;
1454 return yystackp
->yytops
.yysize
-1;
1457 /** True iff YYY0 and YYY1 represent identical options at the top level.
1458 * That is, they represent the same rule applied to RHS symbols
1459 * that produce the same terminal symbols. */
1461 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1463 if (yyy0
->yyrule
== yyy1
->yyrule
)
1465 yyGLRState
*yys0
, *yys1
;
1467 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1468 yyn
= yyrhsLength (yyy0
->yyrule
);
1470 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1471 if (yys0
->yyposn
!= yys1
->yyposn
)
1479 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1480 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1482 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1484 yyGLRState
*yys0
, *yys1
;
1486 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1487 yyn
= yyrhsLength (yyy0
->yyrule
);
1489 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1493 else if (yys0
->yyresolved
)
1495 yys1
->yyresolved
= yytrue
;
1496 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1498 else if (yys1
->yyresolved
)
1500 yys0
->yyresolved
= yytrue
;
1501 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1505 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1506 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1509 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1511 else if (*yyz0p
== YY_NULL
)
1516 else if (*yyz0p
< yyz1
)
1518 yySemanticOption
* yyz
= *yyz0p
;
1520 yyz1
= yyz1
->yynext
;
1521 (*yyz0p
)->yynext
= yyz
;
1523 yyz0p
= &(*yyz0p
)->yynext
;
1525 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1530 /** Y0 and Y1 represent two possible actions to take in a given
1531 * parsing state; return 0 if no combination is possible,
1532 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1534 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1536 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1537 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1541 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1546 if (p0
== 0 || p1
== 0)
1555 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1556 yyGLRStack
* yystackp
]b4_user_formals
[);
1559 /** Resolve the previous YYN states starting at and including state YYS
1560 * on *YYSTACKP. If result != yyok, some states may have been left
1561 * unresolved possibly with empty semantic option chains. Regardless
1562 * of whether result = yyok, each state has been left with consistent
1563 * data so that yydestroyGLRState can be invoked if necessary. */
1565 yyresolveStates (yyGLRState
* yys
, int yyn
,
1566 yyGLRStack
* yystackp
]b4_user_formals
[)
1570 YYASSERT (yys
->yypred
);
1571 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1572 if (! yys
->yyresolved
)
1573 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1578 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1579 * user action, and return the semantic value and location in *YYVALP
1580 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1581 * have been destroyed (assuming the user action destroys all RHS
1582 * semantic values if invoked). */
1584 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1585 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1587 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1588 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1589 YYRESULTTAG yyflag
=
1590 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1594 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1595 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1599 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1601 /* Set default location. */
1602 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1604 int yychar_current
= yychar
;
1605 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1606 YYLTYPE yylloc_current
= yylloc
;])[
1607 yychar
= yyopt
->yyrawchar
;
1608 yylval
= yyopt
->yyval
;]b4_locations_if([
1609 yylloc
= yyopt
->yyloc
;])[
1610 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1611 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1612 yystackp
, yyvalp
]b4_locuser_args
[);
1613 yychar
= yychar_current
;
1614 yylval
= yylval_current
;]b4_locations_if([
1615 yylloc
= yylloc_current
;])[
1620 #if ]b4_api_PREFIX[DEBUG
1622 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1624 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1627 yyGLRState
* yystates
[1 + YYMAXRHS
];
1628 yyGLRState yyleftmost_state
;
1630 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1631 yystates
[yyi
] = yys
;
1634 yyleftmost_state
.yyposn
= 0;
1635 yystates
[0] = &yyleftmost_state
;
1640 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1641 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1642 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1645 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1646 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1647 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1648 (unsigned long int) yyx
->yystate
->yyposn
);
1649 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1651 if (yystates
[yyi
]->yyresolved
)
1653 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1654 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1655 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1657 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1658 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1659 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1660 (unsigned long int) yystates
[yyi
]->yyposn
);
1663 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1669 yyreportAmbiguity (yySemanticOption
* yyx0
,
1670 yySemanticOption
* yyx1
]b4_pure_formals
[)
1675 #if ]b4_api_PREFIX[DEBUG
1676 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1677 YYFPRINTF (stderr
, "Option 1,\n");
1678 yyreportTree (yyx0
, 2);
1679 YYFPRINTF (stderr
, "\nOption 2,\n");
1680 yyreportTree (yyx1
, 2);
1681 YYFPRINTF (stderr
, "\n");
1684 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1686 }]b4_locations_if([[
1688 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1689 * ending at YYS1. Has no effect on previously resolved states.
1690 * The first semantic option of a state is always chosen. */
1692 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1693 yyGLRStack
*yystackp
]b4_user_formals
[)
1697 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1698 if (!yys1
->yyresolved
)
1700 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1702 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1703 YYASSERT (yyoption
!= YY_NULL
);
1704 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1709 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1710 yystackp
]b4_user_args
[);
1711 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1713 yys
= yys
->yypred
, yyn
-= 1)
1714 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1718 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1719 in reverse rightmost order. It is only necessary to invoke
1720 yyresolveLocations on a subforest for which yyresolveAction
1721 would have been invoked next had an ambiguity not been
1722 detected. Thus the location of the previous state (but not
1723 necessarily the previous state itself) is guaranteed to be
1724 resolved already. */
1725 yyGLRState
*yyprevious
= yyoption
->yystate
;
1726 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1729 int yychar_current
= yychar
;
1730 YYSTYPE yylval_current
= yylval
;
1731 YYLTYPE yylloc_current
= yylloc
;
1732 yychar
= yyoption
->yyrawchar
;
1733 yylval
= yyoption
->yyval
;
1734 yylloc
= yyoption
->yyloc
;
1735 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1736 yychar
= yychar_current
;
1737 yylval
= yylval_current
;
1738 yylloc
= yylloc_current
;
1744 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1745 * perform the indicated actions, and set the semantic value of YYS.
1746 * If result != yyok, the chain of semantic options in YYS has been
1747 * cleared instead or it has been left unmodified except that
1748 * redundant options may have been removed. Regardless of whether
1749 * result = yyok, YYS has been left with consistent data so that
1750 * yydestroyGLRState can be invoked if necessary. */
1752 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1754 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1755 yySemanticOption
* yybest
= yyoptionList
;
1756 yySemanticOption
** yypp
;
1757 yybool yymerge
= yyfalse
;
1759 YYRESULTTAG yyflag
;]b4_locations_if([
1760 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1762 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1764 yySemanticOption
* yyp
= *yypp
;
1766 if (yyidenticalOptions (yybest
, yyp
))
1768 yymergeOptionSets (yybest
, yyp
);
1769 *yypp
= yyp
->yynext
;
1773 switch (yypreference (yybest
, yyp
))
1775 case 0:]b4_locations_if([[
1776 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1777 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1789 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1790 but some compilers complain if the default case is
1794 yypp
= &yyp
->yynext
;
1800 yySemanticOption
* yyp
;
1801 int yyprec
= yydprec
[yybest
->yyrule
];
1802 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1804 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1806 if (yyprec
== yydprec
[yyp
->yyrule
])
1808 YYSTYPE yysval_other
;]b4_locations_if([
1810 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1813 yydestruct ("Cleanup: discarding incompletely merged value for",
1814 yystos
[yys
->yylrState
],
1815 &yysval
]b4_locuser_args
[);
1818 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1823 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1827 yys
->yyresolved
= yytrue
;
1828 yys
->yysemantics
.yysval
= yysval
;
1831 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1836 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1838 if (yystackp
->yysplitPoint
!= YY_NULL
)
1843 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1844 yys
!= yystackp
->yysplitPoint
;
1845 yys
= yys
->yypred
, yyn
+= 1)
1847 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1854 yycompressStack (yyGLRStack
* yystackp
)
1856 yyGLRState
* yyp
, *yyq
, *yyr
;
1858 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1861 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1862 yyp
!= yystackp
->yysplitPoint
;
1863 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1866 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1867 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1868 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1869 yystackp
->yysplitPoint
= YY_NULL
;
1870 yystackp
->yylastDeleted
= YY_NULL
;
1872 while (yyr
!= YY_NULL
)
1874 yystackp
->yynextFree
->yystate
= *yyr
;
1876 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1877 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1878 yystackp
->yynextFree
+= 1;
1879 yystackp
->yyspaceLeft
-= 1;
1884 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1885 size_t yyposn
]b4_pure_formals
[)
1887 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1889 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1890 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1891 (unsigned long int) yyk
, yystate
));
1893 YYASSERT (yystate
!= YYFINAL
);
1895 if (yyisDefaultedState (yystate
))
1898 yyRuleNum yyrule
= yydefaultAction (yystate
);
1901 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1902 (unsigned long int) yyk
));
1903 yymarkStackDeleted (yystackp
, yyk
);
1906 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1907 if (yyflag
== yyerr
)
1911 "(predicate failure or explicit user error).\n",
1912 (unsigned long int) yyk
));
1913 yymarkStackDeleted (yystackp
, yyk
);
1923 const short int* yyconflicts
;
1925 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1926 if (yychar
== YYEMPTY
)
1928 YYDPRINTF ((stderr
, "Reading a token: "));
1932 if (yychar
<= YYEOF
)
1934 yychar
= yytoken
= YYEOF
;
1935 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1939 yytoken
= YYTRANSLATE (yychar
);
1940 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1943 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1945 while (*yyconflicts
!= 0)
1948 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1949 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1950 (unsigned long int) yynewStack
,
1951 (unsigned long int) yyk
));
1952 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1954 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1956 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1957 yyposn
]b4_pure_args
[));
1958 else if (yyflag
== yyerr
)
1960 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1961 (unsigned long int) yynewStack
));
1962 yymarkStackDeleted (yystackp
, yynewStack
);
1969 if (yyisShiftAction (yyaction
))
1971 else if (yyisErrorAction (yyaction
))
1973 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1974 (unsigned long int) yyk
));
1975 yymarkStackDeleted (yystackp
, yyk
);
1980 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
1981 yyimmediate
[-yyaction
]]b4_user_args
[);
1982 if (yyflag
== yyerr
)
1986 "(predicate failure or explicit user error).\n",
1987 (unsigned long int) yyk
));
1988 yymarkStackDeleted (yystackp
, yyk
);
1991 else if (yyflag
!= yyok
)
2000 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2002 if (yystackp
->yyerrState
!= 0)
2004 #if ! YYERROR_VERBOSE
2005 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2008 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2009 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2010 size_t yysize
= yysize0
;
2011 yybool yysize_overflow
= yyfalse
;
2012 char* yymsg
= YY_NULL
;
2013 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2014 /* Internationalized format string. */
2015 const char *yyformat
= YY_NULL
;
2016 /* Arguments of yyformat. */
2017 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2018 /* Number of reported tokens (one for the "unexpected", one per
2022 /* There are many possibilities here to consider:
2023 - If this state is a consistent state with a default action, then
2024 the only way this function was invoked is if the default action
2025 is an error action. In that case, don't check for expected
2026 tokens because there are none.
2027 - The only way there can be no lookahead present (in yychar) is if
2028 this state is a consistent state with a default action. Thus,
2029 detecting the absence of a lookahead is sufficient to determine
2030 that there is no unexpected or expected token to report. In that
2031 case, just report a simple "syntax error".
2032 - Don't assume there isn't a lookahead just because this state is a
2033 consistent state with a default action. There might have been a
2034 previous inconsistent state, consistent state with a non-default
2035 action, or user semantic action that manipulated yychar.
2036 - Of course, the expected token list depends on states to have
2037 correct lookahead information, and it depends on the parser not
2038 to perform extra reductions after fetching a lookahead from the
2039 scanner and before detecting a syntax error. Thus, state merging
2040 (from LALR or IELR) and default reductions corrupt the expected
2041 token list. However, the list is correct for canonical LR with
2042 one exception: it will still contain any token that will not be
2043 accepted due to an error action in a later state.
2045 if (yytoken
!= YYEMPTY
)
2047 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2048 yyarg
[yycount
++] = yytokenName (yytoken
);
2049 if (!yypact_value_is_default (yyn
))
2051 /* Start YYX at -YYN if negative to avoid negative indexes in
2052 YYCHECK. In other words, skip the first -YYN actions for this
2053 state because they are default actions. */
2054 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2055 /* Stay within bounds of both yycheck and yytname. */
2056 int yychecklim
= YYLAST
- yyn
+ 1;
2057 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2059 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2060 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2061 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2063 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2069 yyarg
[yycount
++] = yytokenName (yyx
);
2071 size_t yysz
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2072 yysize_overflow
|= yysz
< yysize
;
2081 #define YYCASE_(N, S) \
2085 YYCASE_(0, YY_("syntax error"));
2086 YYCASE_(1, YY_("syntax error, unexpected %s"));
2087 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2088 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2089 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2090 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2095 size_t yysz
= yysize
+ strlen (yyformat
);
2096 yysize_overflow
|= yysz
< yysize
;
2100 if (!yysize_overflow
)
2101 yymsg
= (char *) YYMALLOC (yysize
);
2107 while ((*yyp
= *yyformat
))
2109 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2111 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2120 yyerror (]b4_lyyerror_args
[yymsg
);
2125 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2126 yyMemoryExhausted (yystackp
);
2129 #endif /* YYERROR_VERBOSE */
2133 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2134 yylval, and yylloc are the syntactic category, semantic value, and location
2135 of the lookahead. */
2137 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2142 if (yystackp
->yyerrState
== 3)
2143 /* We just shifted the error token and (perhaps) took some
2144 reductions. Skip tokens until we can proceed. */
2148 if (yychar
== YYEOF
)
2149 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2150 if (yychar
!= YYEMPTY
)
2151 {]b4_locations_if([[
2152 /* We throw away the lookahead, but the error range
2153 of the shifted error token must take it into account. */
2154 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2155 yyGLRStackItem yyerror_range
[3];
2156 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2157 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2158 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2159 yytoken
= YYTRANSLATE (yychar
);
2160 yydestruct ("Error: discarding",
2161 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2163 YYDPRINTF ((stderr
, "Reading a token: "));
2165 if (yychar
<= YYEOF
)
2167 yychar
= yytoken
= YYEOF
;
2168 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2172 yytoken
= YYTRANSLATE (yychar
);
2173 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2175 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2176 if (yypact_value_is_default (yyj
))
2179 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2181 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2184 else if (! yytable_value_is_error (yytable
[yyj
]))
2188 /* Reduce to one stack. */
2189 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2190 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2192 if (yyk
>= yystackp
->yytops
.yysize
)
2193 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2194 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2195 yymarkStackDeleted (yystackp
, yyk
);
2196 yyremoveDeletes (yystackp
);
2197 yycompressStack (yystackp
);
2199 /* Now pop stack until we find a state that shifts the error token. */
2200 yystackp
->yyerrState
= 3;
2201 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2203 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2204 yyj
= yypact
[yys
->yylrState
];
2205 if (! yypact_value_is_default (yyj
))
2208 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2209 && yyisShiftAction (yytable
[yyj
]))
2211 /* Shift the error token. */]b4_locations_if([[
2212 /* First adjust its location.*/
2214 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2215 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2216 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2217 &yylval
, &yyerrloc
);
2218 yyglrShift (yystackp
, 0, yytable
[yyj
],
2219 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2220 yys
= yystackp
->yytops
.yystates
[0];
2223 }]b4_locations_if([[
2224 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2225 if (yys
->yypred
!= YY_NULL
)
2226 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2227 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2228 yystackp
->yynextFree
-= 1;
2229 yystackp
->yyspaceLeft
+= 1;
2231 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2232 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2235 #define YYCHK1(YYE) \
2245 goto yyuser_error; \
2255 ]b4_function_define([yyparse
], [int], b4_parse_param
)[
2259 yyGLRStack
* const yystackp
= &yystack
;
2262 YYDPRINTF ((stderr
, "Starting parse\n"));
2265 yylval
= yyval_default
;]b4_locations_if([
2266 yylloc
= yyloc_default
;])[
2267 ]m4_ifdef([b4_initial_action
], [
2268 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2269 /* User initialization code. */
2270 b4_user_initial_action
2271 b4_dollar_popdef
])[]dnl
2273 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2274 goto yyexhaustedlab
;
2275 switch (YYSETJMP (yystack
.yyexception_buffer
))
2278 case 1: goto yyabortlab
;
2279 case 2: goto yyexhaustedlab
;
2280 default: goto yybuglab
;
2282 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2287 /* For efficiency, we have two loops, the first of which is
2288 specialized to deterministic operation (single stack, no
2289 potential ambiguity). */
2295 const short int* yyconflicts
;
2297 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2298 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2299 if (yystate
== YYFINAL
)
2301 if (yyisDefaultedState (yystate
))
2303 yyrule
= yydefaultAction (yystate
);
2306 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2307 yyreportSyntaxError (&yystack
]b4_user_args
[);
2310 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2315 if (yychar
== YYEMPTY
)
2317 YYDPRINTF ((stderr
, "Reading a token: "));
2321 if (yychar
<= YYEOF
)
2323 yychar
= yytoken
= YYEOF
;
2324 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2328 yytoken
= YYTRANSLATE (yychar
);
2329 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2332 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2333 if (*yyconflicts
!= 0)
2335 if (yyisShiftAction (yyaction
))
2337 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2340 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2341 if (0 < yystack
.yyerrState
)
2342 yystack
.yyerrState
-= 1;
2344 else if (yyisErrorAction (yyaction
))
2346 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2347 yyreportSyntaxError (&yystack
]b4_user_args
[);
2351 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2357 yySymbol yytoken_to_shift
;
2360 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2361 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2363 /* yyprocessOneStack returns one of three things:
2365 - An error flag. If the caller is yyprocessOneStack, it
2366 immediately returns as well. When the caller is finally
2367 yyparse, it jumps to an error label via YYCHK1.
2369 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2370 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2371 yyparse's following invocation of yyremoveDeletes will remove
2374 - yyok, when ready to shift a token.
2376 Except in the first case, yyparse will invoke yyremoveDeletes and
2377 then shift the next token onto all remaining stacks. This
2378 synchronization of the shift (that is, after all preceding
2379 reductions on all stacks) helps prevent double destructor calls
2380 on yylval in the event of memory exhaustion. */
2382 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2383 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2384 yyremoveDeletes (&yystack
);
2385 if (yystack
.yytops
.yysize
== 0)
2387 yyundeleteLastStack (&yystack
);
2388 if (yystack
.yytops
.yysize
== 0)
2389 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2390 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2391 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2392 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2393 yyreportSyntaxError (&yystack
]b4_user_args
[);
2397 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2398 a copy of yylval will already be on stack 0 in the event of a
2399 failure in the following loop. Thus, yychar is set to YYEMPTY
2400 before the loop to make sure the user destructor for yylval isn't
2402 yytoken_to_shift
= YYTRANSLATE (yychar
);
2405 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2408 const short int* yyconflicts
;
2409 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2410 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2412 /* Note that yyconflicts were handled by yyprocessOneStack. */
2413 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2414 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2415 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2416 &yylval
]b4_locations_if([, &yylloc
])[);
2417 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2418 (unsigned long int) yys
,
2419 yystack
.yytops
.yystates
[yys
]->yylrState
));
2422 if (yystack
.yytops
.yysize
== 1)
2424 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2425 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2426 yycompressStack (&yystack
);
2432 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2433 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2449 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2454 if (yychar
!= YYEMPTY
)
2455 yydestruct ("Cleanup: discarding lookahead",
2456 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2458 /* If the stack is well-formed, pop the stack until it is empty,
2459 destroying its entries as we go. But free the stack regardless
2460 of whether it is well-formed. */
2461 if (yystack
.yyitems
)
2463 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2466 size_t yysize
= yystack
.yytops
.yysize
;
2468 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2471 while (yystates
[yyk
])
2473 yyGLRState
*yys
= yystates
[yyk
];
2474 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2475 )[ if (yys
->yypred
!= YY_NULL
)
2476 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2477 yystates
[yyk
] = yys
->yypred
;
2478 yystack
.yynextFree
-= 1;
2479 yystack
.yyspaceLeft
+= 1;
2484 yyfreeGLRStack (&yystack
);
2490 /* DEBUGGING ONLY */
2491 #if ]b4_api_PREFIX[DEBUG
2493 yy_yypstack (yyGLRState
* yys
)
2497 yy_yypstack (yys
->yypred
);
2498 YYFPRINTF (stderr
, " -> ");
2500 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2501 (unsigned long int) yys
->yyposn
);
2505 yypstates (yyGLRState
* yyst
)
2507 if (yyst
== YY_NULL
)
2508 YYFPRINTF (stderr
, "<null>");
2511 YYFPRINTF (stderr
, "\n");
2515 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2517 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2520 #define YYINDEX(YYX) \
2521 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2525 yypdumpstack (yyGLRStack
* yystackp
)
2527 yyGLRStackItem
* yyp
;
2529 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2531 YYFPRINTF (stderr
, "%3lu. ",
2532 (unsigned long int) (yyp
- yystackp
->yyitems
));
2533 if (*(yybool
*) yyp
)
2535 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2536 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2537 (unsigned long int) yyp
->yystate
.yyposn
,
2538 (long int) YYINDEX (yyp
->yystate
.yypred
));
2539 if (! yyp
->yystate
.yyresolved
)
2540 YYFPRINTF (stderr
, ", firstVal: %ld",
2541 (long int) YYINDEX (yyp
->yystate
2542 .yysemantics
.yyfirstVal
));
2546 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2547 yyp
->yyoption
.yyrule
- 1,
2548 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2549 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2551 YYFPRINTF (stderr
, "\n");
2553 YYFPRINTF (stderr
, "Tops:");
2554 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2555 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2556 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2557 YYFPRINTF (stderr
, "\n");
2563 # glr.cc produces its own header.
2564 m4_if(b4_skeleton
, ["glr.c"],
2566 [b4_output_begin([b4_spec_defines_file
])
2567 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2570 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2571 ]b4_shared_declarations
[
2572 ]b4_cpp_guard_close([b4_spec_defines_file
])[