glr2.cc: fix -Wnoexcept issues
[bison.git] / data / skeletons / glr2.cc
blob970ccfdf141e34acb54f94a1bc5ee61498f7573c
1 # C++ GLR skeleton for Bison
3 # Copyright (C) 2002-2015, 2018-2022 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 m4_include(b4_skeletonsdir/[c++.m4])
20 # api.value.type=variant is valid.
21 m4_define([b4_value_type_setup_variant])
23 # b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED)
24 # -------------------------------------------
25 m4_define([b4_tname_if],
26 [m4_case(b4_percent_define_get([[parse.error]]),
27 [verbose], [$1],
28 [b4_token_table_if([$1],
29 [$2])])])
31 b4_bison_locations_if([
32 m4_define([b4_location_constructors])
33 m4_include(b4_skeletonsdir/[location.cc])])
34 b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])])
36 m4_define([b4_parser_class],
37 [b4_percent_define_get([[api.parser.class]])])
39 ]m4_define([b4_define_symbol_kind],
40 [m4_format([#define %-15s %s],
41 b4_symbol($][1, kind_base),
42 b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base))
46 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
47 # -------------------------------------------------------------
48 # Define "yy<TABLE-NAME>" whose contents is CONTENT. Does not use "static",
49 # should be in unnamed namespace.
50 m4_define([b4_integral_parser_table_define],
51 [m4_ifvaln([$3], [ b4_comment([$3])])dnl
52 const b4_int_type_for([$2]) yy$1[[]] =
55 };dnl
59 ## ---------------- ##
60 ## Default values. ##
61 ## ---------------- ##
63 # Stack parameters.
64 m4_define_default([b4_stack_depth_max], [10000])
65 m4_define_default([b4_stack_depth_init], [200])
69 ## ------------ ##
70 ## Interfaces. ##
71 ## ------------ ##
73 # b4_user_formals
74 # ---------------
75 # The possible parse-params formal arguments preceded by a comma.
77 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
78 # formal argument declarations.
79 m4_define([b4_user_formals],
80 [m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
83 # b4_symbol_kind(NUM)
84 # -------------------
85 m4_define([b4_symbol_kind],
86 [symbol_kind::b4_symbol_kind_base($@)])
89 ## ----------------- ##
90 ## Semantic Values. ##
91 ## ----------------- ##
94 # b4_lhs_value(SYMBOL-NUM, [TYPE])
95 # --------------------------------
96 # See README.
97 m4_define([b4_lhs_value],
98 [b4_symbol_value([(*yyvalp)], [$1], [$2])])
101 # b4_rhs_data(RULE-LENGTH, POS)
102 # -----------------------------
103 # See README.
104 m4_define([b4_rhs_data],
105 [(static_cast<glr_stack_item const *>(yyvsp))@{YYFILL (b4_subtract([$2], [$1]))@}.getState()])
108 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
109 # --------------------------------------------------
110 # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
111 m4_define([b4_rhs_value],
112 [b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])])
116 ## ----------- ##
117 ## Locations. ##
118 ## ----------- ##
120 # b4_lhs_location()
121 # -----------------
122 # Expansion of @$.
123 m4_define([b4_lhs_location],
124 [(*yylocp)])
127 # b4_rhs_location(RULE-LENGTH, NUM)
128 # ---------------------------------
129 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
130 # on RHS.
131 m4_define([b4_rhs_location],
132 [(b4_rhs_data([$1], [$2]).yyloc)])
135 # b4_symbol_action(SYMBOL-NUM, KIND)
136 # ----------------------------------
137 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
138 # Same as in C, but using references instead of pointers.
140 # Currently we need two different b4_symbol_action: once for the
141 # self-contained symbols, and another time for yy_destroy_ and
142 # yy_symbol_value_print_, which don't use genuine symbols yet.
143 m4_define([b4_symbol_action],
144 [b4_symbol_if([$1], [has_$2],
145 [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
146 b4_dollar_pushdef([yysym.value],
147 [$1],
149 [yysym.location])dnl
150 _b4_symbol_case([$1])[]dnl
151 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
152 b4_symbol([$1], [$2])
153 b4_syncline([@oline@], [@ofile@])dnl
154 break;
156 m4_popdef([b4_symbol_value])[]dnl
157 b4_dollar_popdef[]dnl
158 ])])
161 # b4_symbol_action_for_yyval(SYMBOL-NUM, KIND)
162 # --------------------------------------------
163 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
164 # Same as in C, but using references instead of pointers.
165 m4_define([b4_symbol_action_for_yyval],
166 [b4_symbol_if([$1], [has_$2],
167 [b4_dollar_pushdef([yyval],
168 [$1],
170 [yyloc])dnl
171 _b4_symbol_case([$1])[]dnl
172 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
173 b4_symbol([$1], [$2])
174 b4_syncline([@oline@], [@ofile@])dnl
175 break;
177 b4_dollar_popdef[]dnl
178 ])])
181 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
182 # ---------------------------------------------------
183 m4_define([b4_call_merger],
184 [b4_case([$1],
185 [ b4_symbol_if([$3], [has_type],
186 [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());],
187 [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])],
188 [yy0 = $2 (yy0, yy1);])])])
190 # b4_yylex
191 # --------
192 # Call yylex.
193 m4_define([b4_yylex],
194 [b4_token_ctor_if(
195 [b4_function_call([yylex],
196 [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
197 [b4_function_call([yylex], [int],
198 [[value_type *], [&this->yyla.value]][]dnl
199 b4_locations_if([, [[location_type *], [&this->yyla.location]]])dnl
200 m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
203 # b4_shared_declarations(hh|cc)
204 # -----------------------------
205 # Declaration that might either go into the header (if --header, $1 = hh)
206 # or in the implementation file.
207 m4_define([b4_shared_declarations],
208 [b4_percent_code_get([[requires]])[
209 #include <algorithm>
210 #include <cstddef> // ptrdiff_t
211 #include <cstring> // memcpy
212 #include <iostream>
213 #include <iomanip>
214 #include <limits>
215 #include <stdexcept>
216 #include <stdint.h>
217 #include <string>
218 #include <vector>
220 ]b4_cxx_portability[
221 ]m4_ifdef([b4_location_include],
222 [[# include ]b4_location_include])[
223 ]b4_variant_if([b4_variant_includes])[
225 ]b4_YYDEBUG_define[
227 ]b4_namespace_open[
229 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
230 [b4_location_define])])[
232 /// A Bison parser.
233 class ]b4_parser_class[
235 public:
236 ]b4_public_types_declare[
237 ]b4_symbol_type_define[
239 // FIXME: should be private eventually.
240 class glr_stack;
241 class glr_state;
243 /// Build a parser object.
244 ]b4_parser_class[ (]b4_parse_param_decl[);
245 ~]b4_parser_class[ ();
247 /// Parse. An alias for parse ().
248 /// \returns 0 iff parsing succeeded.
249 int operator() ();
251 /// Parse.
252 /// \returns 0 iff parsing succeeded.
253 int parse ();
255 #if ]b4_api_PREFIX[DEBUG
256 /// The current debugging stream.
257 std::ostream& debug_stream () const;
258 /// Set the current debugging stream.
259 void set_debug_stream (std::ostream &);
261 /// Type for debugging levels.
262 using debug_level_type = int;
263 /// The current debugging level.
264 debug_level_type debug_level () const;
265 /// Set the current debugging level.
266 void set_debug_level (debug_level_type l);
267 #endif
269 /// Report a syntax error.]b4_locations_if([[
270 /// \param loc where the syntax error is found.]])[
271 /// \param msg a description of the syntax error.
272 void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
274 ]b4_parse_error_bmatch(
275 [custom\|detailed],
276 [[ /// The user-facing name of the symbol whose (internal) number is
277 /// YYSYMBOL. No bounds checking.
278 static const char *symbol_name (symbol_kind_type yysymbol);]],
279 [simple],
280 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
281 /// The user-facing name of the symbol whose (internal) number is
282 /// YYSYMBOL. No bounds checking.
283 static const char *symbol_name (symbol_kind_type yysymbol);
284 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
286 [verbose],
287 [[ /// The user-facing name of the symbol whose (internal) number is
288 /// YYSYMBOL. No bounds checking.
289 static std::string symbol_name (symbol_kind_type yysymbol);]])[
291 ]b4_token_constructor_define[
292 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
293 class context
295 public:
296 context (glr_stack& yystack, const symbol_type& yyla);
297 const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; }
298 symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[
299 const location_type& location () const YY_NOEXCEPT { return yyla_.location; }
300 ]])[
301 /// Put in YYARG at most YYARGN of the expected tokens, and return the
302 /// number of tokens stored in YYARG. If YYARG is null, return the
303 /// number of expected tokens (guaranteed to be less than YYNTOKENS).
304 int expected_tokens (symbol_kind_type yyarg[], int yyargn) const;
306 private:
307 glr_stack& yystack_;
308 const symbol_type& yyla_;
310 ]])[
311 # if ]b4_api_PREFIX[DEBUG
312 public:
313 /// \brief Report a symbol value on the debug stream.
314 /// \param yykind The symbol kind.
315 /// \param yyval Its semantic value.]b4_locations_if([[
316 /// \param yyloc Its location.]])[
317 void yy_symbol_value_print_ (symbol_kind_type yykind,
318 const value_type& yyval]b4_locations_if([[,
319 const location_type& yyloc]])[) const;
320 /// \brief Report a symbol on the debug stream.
321 /// \param yykind The symbol kind.
322 /// \param yyval Its semantic value.]b4_locations_if([[
323 /// \param yyloc Its location.]])[
324 void yy_symbol_print_ (symbol_kind_type yykind,
325 const value_type& yyval]b4_locations_if([[,
326 const location_type& yyloc]])[) const;
327 private:
328 /// Debug stream.
329 std::ostream* yycdebug_;
330 #endif
332 ]b4_parse_error_bmatch(
333 [custom], [[
334 private:
335 /// Report a syntax error
336 /// \param yyctx the context in which the error occurred.
337 void report_syntax_error (const context& yyctx) const;]],
338 [detailed\|verbose], [[
339 private:
340 /// The arguments of the error message.
341 int yy_syntax_error_arguments_ (const context& yyctx,
342 symbol_kind_type yyarg[], int yyargn) const;
344 /// Generate an error message.
345 /// \param yyctx the context in which the error occurred.
346 virtual std::string yysyntax_error_ (const context& yyctx) const;]])[
348 /// Convert a scanner token kind \a t to a symbol kind.
349 /// In theory \a t should be a token_kind_type, but character literals
350 /// are valid, yet not members of the token_kind_type enum.
351 static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT;
353 ]b4_parse_error_bmatch(
354 [simple],
355 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
356 /// For a symbol, its name in clear.
357 static const char* const yytname_[];
358 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
360 [verbose],
361 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
362 static std::string yytnamerr_ (const char *yystr);
364 /// For a symbol, its name in clear.
365 static const char* const yytname_[];
366 ]])[
368 /// \brief Reclaim the memory associated to a symbol.
369 /// \param yymsg Why this token is reclaimed.
370 /// If null, print nothing.
371 /// \param yykind The symbol kind.
372 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
373 value_type& yyval]b4_locations_if([[,
374 location_type& yyloc]])[);
376 ]b4_parse_param_vars[
377 // Needs access to yy_destroy_, report_syntax_error, etc.
378 friend glr_stack;
381 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
382 ]b4_public_types_define([$1])])[
383 ]b4_namespace_close[
385 ]b4_percent_code_get([[provides]])[
386 ]])[
389 ## -------------- ##
390 ## Output files. ##
391 ## -------------- ##
394 # ------------- #
395 # Header file. #
396 # ------------- #
398 ]b4_header_if([[
399 ]b4_output_begin([b4_spec_header_file])[
400 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
401 [2002-2015, 2018-2021])[
402 // C++ GLR parser skeleton written by Valentin Tolmer.
404 ]b4_disclaimer[
405 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
406 ]b4_shared_declarations([hh])[
407 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
408 ]b4_output_end])[
411 # --------------------- #
412 # Implementation file. #
413 # --------------------- #
415 ]b4_output_begin([b4_parser_file_name])[
416 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
417 [2002-2015, 2018-2021])[
418 // C++ GLR parser skeleton written by Valentin Tolmer.
420 ]b4_disclaimer[
421 ]b4_identification[
423 ]b4_percent_code_get([[top]])[
424 ]m4_if(b4_prefix, [yy], [],
425 [[/* Substitute the variable and function names. */
426 #define yyparse ]b4_prefix[parse
427 #define yylex ]b4_prefix[lex
428 #define yyerror ]b4_prefix[error
429 #define yydebug ]b4_prefix[debug]])[
431 ]b4_user_pre_prologue[
433 ]b4_null_define[
435 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
436 [b4_shared_declarations([cc])])[
438 namespace
440 /* Default (constant) value used for initialization for null
441 right-hand sides. Unlike the standard yacc.c template, here we set
442 the default value of $$ to a zeroed-out value. Since the default
443 value is undefined, this behavior is technically correct. */
444 ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;
447 ]b4_user_post_prologue[
448 ]b4_percent_code_get[
450 #include <cstdio>
451 #include <cstdlib>
453 #ifndef YY_
454 # if defined YYENABLE_NLS && YYENABLE_NLS
455 # if ENABLE_NLS
456 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
457 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
458 # endif
459 # endif
460 # ifndef YY_
461 # define YY_(Msgid) Msgid
462 # endif
463 #endif
465 // Whether we are compiled with exception support.
466 #ifndef YY_EXCEPTIONS
467 # if defined __GNUC__ && !defined __EXCEPTIONS
468 # define YY_EXCEPTIONS 0
469 # else
470 # define YY_EXCEPTIONS 1
471 # endif
472 #endif
474 #ifndef YYFREE
475 # define YYFREE free
476 #endif
477 #ifndef YYMALLOC
478 # define YYMALLOC malloc
479 #endif
481 #ifndef YYSETJMP
482 # include <setjmp.h>
483 # define YYJMP_BUF jmp_buf
484 # define YYSETJMP(Env) setjmp (Env)
485 /* Pacify Clang and ICC. */
486 # define YYLONGJMP(Env, Val) \
487 do { \
488 longjmp (Env, Val); \
489 YYASSERT (0); \
490 } while (false)
491 #endif
493 ]b4_attribute_define([noreturn])[
495 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
496 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
497 _Pragma ("GCC diagnostic push") \
498 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
499 # define YY_IGNORE_NULL_DEREFERENCE_END \
500 _Pragma ("GCC diagnostic pop")
501 #else
502 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
503 # define YY_IGNORE_NULL_DEREFERENCE_END
504 #endif
506 ]b4_null_define[
507 ]b4_cast_define[
509 // FIXME: Use the same conventions as lalr1.cc.
510 ]b4_parse_assert_if[
511 #ifndef YYASSERT
512 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
513 #endif
515 #ifdef YYDEBUG
516 # define YYDASSERT(Condition) YYASSERT(Condition)
517 #else
518 # define YYDASSERT(Condition)
519 #endif
521 /* YYFINAL -- State number of the termination state. */
522 #define YYFINAL ]b4_final_state_number[
523 /* YYLAST -- Last index in YYTABLE. */
524 #define YYLAST ]b4_last[
526 /* YYNTOKENS -- Number of terminals. */
527 #define YYNTOKENS ]b4_tokens_number[
528 /* YYNNTS -- Number of nonterminals. */
529 #define YYNNTS ]b4_nterms_number[
530 /* YYNRULES -- Number of rules. */
531 #define YYNRULES ]b4_rules_number[
532 /* YYNSTATES -- Number of states. */
533 #define YYNSTATES ]b4_states_number[
534 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
535 #define YYMAXRHS ]b4_r2_max[
536 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
537 accessed by $0, $-1, etc., in any rule. */
538 #define YYMAXLEFT ]b4_max_left_semantic_context[
540 namespace
542 #if ]b4_api_PREFIX[DEBUG
543 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
544 const ]b4_int_type_for([b4_rline])[ yyrline[] =
546 ]b4_rline[
548 #endif
550 #define YYPACT_NINF ]b4_pact_ninf[
551 #define YYTABLE_NINF ]b4_table_ninf[
553 ]b4_parser_tables_define[
555 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
556 const ]b4_int_type_for([b4_dprec])[ yydprec[] =
558 ]b4_dprec[
561 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
562 const ]b4_int_type_for([b4_merger])[ yymerger[] =
564 ]b4_merger[
567 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
568 in the case of predicates. */
569 const bool yyimmediate[] =
571 ]b4_immediate[
574 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
575 list of conflicting reductions corresponding to action entry for
576 state STATE-NUM in yytable. 0 means no conflicts. The list in
577 yyconfl is terminated by a rule number of 0. */
578 const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
580 ]b4_conflict_list_heads[
583 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
584 0, pointed into by YYCONFLP. */
585 ]dnl Do not use b4_int_type_for here, since there are places where
586 dnl pointers onto yyconfl are taken, whose type is "short*".
587 dnl We probably ought to introduce a type for confl.
588 [const short yyconfl[] =
590 ]b4_conflicting_rules[
592 } // namespace
595 /* Error token number */
596 #define YYTERROR 1
598 ]b4_locations_if([[
599 ]b4_yylloc_default_define[
600 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
601 ]])[
603 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
605 #define YYCHK(YYE) \
606 do { \
607 YYRESULTTAG yychk_flag = YYE; \
608 if (yychk_flag != yyok) \
609 return yychk_flag; \
610 } while (false)
612 #if ]b4_api_PREFIX[DEBUG
614 #define YYCDEBUG if (!yydebug) {} else std::cerr
616 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
617 do { \
618 if (yydebug) \
620 std::cerr << Title << ' '; \
621 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
622 std::cerr << '\n'; \
624 } while (false)
626 # define YY_REDUCE_PRINT(Args) \
627 do { \
628 if (yydebug) \
629 yystateStack.yy_reduce_print Args; \
630 } while (false)
632 /* Nonzero means print parse trace. It is left uninitialized so that
633 multiple parsers can coexist. */
634 int yydebug;
636 namespace
638 using glr_stack = ]b4_namespace_ref[::]b4_parser_class[::glr_stack;
639 using glr_state = ]b4_namespace_ref[::]b4_parser_class[::glr_state;
641 void yypstack (const glr_stack& yystack, size_t yyk)
642 YY_ATTRIBUTE_UNUSED;
643 void yypdumpstack (const glr_stack& yystack)
644 YY_ATTRIBUTE_UNUSED;
647 #else /* !]b4_api_PREFIX[DEBUG */
649 # define YYCDEBUG if (true) {} else std::cerr
650 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
651 # define YY_REDUCE_PRINT(Args) {}
653 #endif /* !]b4_api_PREFIX[DEBUG */
655 /* YYINITDEPTH -- initial size of the parser's stacks. */
656 #ifndef YYINITDEPTH
657 # define YYINITDEPTH ]b4_stack_depth_init[
658 #endif
660 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
661 if the built-in stack extension method is used).
663 Do not make this value too large; the results are undefined if
664 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
665 evaluated with infinite-precision integer arithmetic. */
667 #ifndef YYMAXDEPTH
668 # define YYMAXDEPTH ]b4_stack_depth_max[
669 #endif
671 /* Minimum number of free items on the stack allowed after an
672 allocation. This is to allow allocation and initialization
673 to be completed by functions that call yyexpandGLRStack before the
674 stack is expanded, thus insuring that all necessary pointers get
675 properly redirected to new data. */
676 #define YYHEADROOM 2
678 #ifndef YYSTACKEXPANDABLE
679 # define YYSTACKEXPANDABLE 1
680 #endif
682 namespace
684 template <typename Parameter>
685 class strong_index_alias
687 public:
688 static strong_index_alias create (std::ptrdiff_t value)
690 strong_index_alias result;
691 result.value_ = value;
692 return result;
695 std::ptrdiff_t const& get () const { return value_; }
697 size_t uget () const { return static_cast<size_t> (value_); }
699 strong_index_alias operator+ (std::ptrdiff_t other) const
701 return strong_index_alias (get () + other);
704 void operator+= (std::ptrdiff_t other)
706 value_ += other;
709 strong_index_alias operator- (std::ptrdiff_t other)
711 return strong_index_alias (get () - other);
714 void operator-= (std::ptrdiff_t other)
716 value_ -= other;
719 size_t operator- (strong_index_alias other)
721 return strong_index_alias (get () - other.get ());
724 strong_index_alias& operator++ ()
726 ++value_;
727 return *this;
730 bool isValid () const
732 return value_ != INVALID_INDEX;
735 void setInvalid()
737 value_ = INVALID_INDEX;
740 bool operator== (strong_index_alias other)
742 return get () == other.get ();
745 bool operator!= (strong_index_alias other)
747 return get () != other.get ();
750 bool operator< (strong_index_alias other)
752 return get () < other.get ();
755 private:
756 static const std::ptrdiff_t INVALID_INDEX;
758 // WARNING: 0-initialized.
759 std::ptrdiff_t value_;
760 }; // class strong_index_alias
762 template<typename T>
763 const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
764 std::numeric_limits<std::ptrdiff_t>::max ();
766 using state_set_index = strong_index_alias<struct glr_state_set_tag>;
768 state_set_index create_state_set_index (std::ptrdiff_t value)
770 return state_set_index::create (value);
773 /** State numbers, as in LALR(1) machine */
774 using state_num = int;
776 /** Rule numbers, as in LALR(1) machine */
777 using rule_num = int;
779 using parser_type = ]b4_namespace_ref[::]b4_parser_class[;
780 using glr_state = parser_type::glr_state;
781 using symbol_kind = parser_type::symbol_kind;
782 using symbol_kind_type = parser_type::symbol_kind_type;
783 using symbol_type = parser_type::symbol_type;
784 using value_type = parser_type::value_type;]b4_locations_if([[
785 using location_type = parser_type::location_type;]])[
787 // Forward declarations.
788 class glr_stack_item;
789 class semantic_option;
790 } // namespace
792 namespace
794 /** Accessing symbol of state YYSTATE. */
795 inline symbol_kind_type
796 yy_accessing_symbol (state_num yystate)
798 return YY_CAST (symbol_kind_type, yystos[yystate]);
801 /** Left-hand-side symbol for rule #YYRULE. */
802 inline symbol_kind_type
803 yylhsNonterm (rule_num yyrule)
805 return static_cast<symbol_kind_type>(yyr1[yyrule]);
808 /** Number of symbols composing the right hand side of rule #RULE. */
809 inline int
810 yyrhsLength (rule_num yyrule)
812 return yyr2[yyrule];
816 namespace ]b4_namespace_ref[
818 class ]b4_parser_class[::glr_state
820 public:
821 glr_state () YY_NOEXCEPT
822 : yyresolved (false)
823 , yylrState (0)
824 , yyposn (0)
825 , yypred (0)
826 , yyfirstVal (0)]b4_locations_if([[
827 , yyloc ()]])[]b4_parse_assert_if([[
828 , magic_ (MAGIC)]])[
831 /// Build with a semantic value.
832 glr_state (state_num lrState, size_t posn, const value_type& val]b4_locations_if([[, const location_type& loc]])[)
833 : yyresolved (true)
834 , yylrState (lrState)
835 , yyposn (posn)
836 , yypred (0)
837 , yyval (]b4_variant_if([], [[val]])[)]b4_locations_if([[
838 , yyloc (loc)]])[]b4_parse_assert_if([[
839 , magic_ (MAGIC)]])[
840 {]b4_variant_if([[
841 ]b4_symbol_variant([yy_accessing_symbol (lrState)],
842 [yyval], [copy], [val])])[}
844 /// Build with a semantic option.
845 glr_state (state_num lrState, size_t posn)
846 : yyresolved (false)
847 , yylrState (lrState)
848 , yyposn (posn)
849 , yypred (0)
850 , yyfirstVal (0)]b4_locations_if([[
851 , yyloc ()]])[]b4_parse_assert_if([[
852 , magic_ (MAGIC)]])[
855 glr_state (const glr_state& other)
856 : yyresolved (other.yyresolved)
857 , yylrState (other.yylrState)
858 , yyposn (other.yyposn)
859 , yypred (0)]b4_locations_if([[
860 , yyloc (other.yyloc)]])[]b4_parse_assert_if([[
861 , magic_ (MAGIC)]])[
863 setPred (other.pred ());
864 if (other.yyresolved)]b4_variant_if([[
866 new (&yyval) value_type ();
867 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
868 [yyval], [copy], [other.value ()])[
869 }]], [[
870 new (&yyval) value_type (other.value ());]])[
871 else
873 yyfirstVal = 0;
874 setFirstVal (other.firstVal ());
875 }]b4_parse_assert_if([[
876 check_();]])[
879 ~glr_state ()
880 {]b4_parse_assert_if([[
881 check_ ();]])[
882 if (yyresolved)
883 {]b4_variant_if([[
884 symbol_kind_type yykind = yy_accessing_symbol (yylrState);
885 // FIXME: User destructors.
886 // Value type destructor.
887 ]b4_symbol_variant([[yykind]], [[yyval]], [[template destroy]])])[
888 yyval.~value_type ();
889 }]b4_parse_assert_if([[
890 magic_ = 0;]])[
893 glr_state& operator= (const glr_state& other)
894 {]b4_parse_assert_if([[
895 check_ ();
896 other.check_ ();]])[
897 if (!yyresolved && other.yyresolved)
898 new (&yyval) value_type;
899 yyresolved = other.yyresolved;
900 yylrState = other.yylrState;
901 yyposn = other.yyposn;
902 setPred (other.pred ());
903 if (other.yyresolved)]b4_variant_if([[
904 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
905 [yyval], [copy], [other.value ()])], [[
906 value () = other.value ();]])[
907 else
908 setFirstVal (other.firstVal ());]b4_locations_if([[
909 yyloc = other.yyloc;]])[
910 return *this;
913 /** Type tag for the semantic value. If true, yyval applies, otherwise
914 * yyfirstVal applies. */
915 bool yyresolved;
916 /** Number of corresponding LALR(1) machine state. */
917 state_num yylrState;
918 /** Source position of the last token produced by my symbol */
919 size_t yyposn;
921 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
922 glr_state* pred ();
923 const glr_state* pred () const;
924 void setPred (const glr_state* state);
926 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
927 /// temporaries.
928 semantic_option* firstVal ();
929 const semantic_option* firstVal () const;
930 void setFirstVal (const semantic_option* option);
932 value_type& value ()
933 {]b4_parse_assert_if([[
934 check_ ();]])[
935 return yyval;
938 const value_type& value () const
939 {]b4_parse_assert_if([[
940 check_ ();]])[
941 return yyval;
944 void
945 destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser);
947 /* DEBUGGING ONLY */
948 #if ]b4_api_PREFIX[DEBUG
949 void yy_yypstack () const
950 {]b4_parse_assert_if([[
951 check_ ();]])[
952 if (pred () != YY_NULLPTR)
954 pred ()->yy_yypstack ();
955 std::cerr << " -> ";
957 std::cerr << yylrState << "@@" << yyposn;
959 #endif
961 std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED;
963 glr_stack_item* asItem ()
964 {]b4_parse_assert_if([[
965 check_ ();]])[
966 return asItem(this);
969 const glr_stack_item* asItem () const
970 {]b4_parse_assert_if([[
971 check_ ();]])[
972 return asItem (this);
975 private:
976 template <typename T>
977 static const glr_stack_item* asItem (const T* state)
979 return reinterpret_cast<const glr_stack_item*>(state);
981 template <typename T>
982 static glr_stack_item* asItem (T* state)
984 return reinterpret_cast<glr_stack_item*> (state);
986 static const char *as_pointer_ (const glr_state *state)
988 return reinterpret_cast<const char *> (state);
990 static char *as_pointer_ (glr_state *state)
992 return reinterpret_cast<char *> (state);
994 /** Preceding state in this stack */
995 std::ptrdiff_t yypred;
996 union {
997 /** First in a chain of alternative reductions producing the
998 * nonterminal corresponding to this state, threaded through
999 * yyfirstVal. Value "0" means empty. */
1000 std::ptrdiff_t yyfirstVal;
1001 /** Semantic value for this state. */
1002 value_type yyval;
1003 };]b4_locations_if([[
1004 // FIXME: Why public?
1005 public:
1006 /** Source location for this state. */
1007 location_type yyloc;]])[
1009 ]b4_parse_assert_if([[
1010 public:
1011 // Check invariants.
1012 void check_ () const
1014 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1015 YYASSERT (this->magic_ == MAGIC);
1016 YY_IGNORE_NULL_DEREFERENCE_END
1019 // A magic number to check our pointer arithmetic is sane.
1020 enum { MAGIC = 713705 };
1021 unsigned int magic_;]])[
1022 }; // class ]b4_parser_class[::glr_state
1023 } // namespace ]b4_namespace_ref[
1026 namespace
1028 /** A stack of GLRState representing the different heads during
1029 * nondeterministic evaluation. */
1030 class glr_state_set
1032 public:
1033 /** Initialize YYSET to a singleton set containing an empty stack. */
1034 glr_state_set ()
1035 : yylastDeleted (YY_NULLPTR)
1037 yystates.push_back (YY_NULLPTR);
1038 yylookaheadNeeds.push_back (false);
1041 // Behave like a vector of states.
1042 glr_state*& operator[] (state_set_index index)
1044 return yystates[index.uget()];
1047 glr_state* operator[] (state_set_index index) const
1049 return yystates[index.uget()];
1052 size_t size () const
1054 return yystates.size ();
1057 std::vector<glr_state*>::iterator begin ()
1059 return yystates.begin ();
1062 std::vector<glr_state*>::iterator end ()
1064 return yystates.end ();
1067 bool lookaheadNeeds (state_set_index index) const
1069 return yylookaheadNeeds[index.uget ()];
1072 bool setLookaheadNeeds (state_set_index index, bool value)
1074 return yylookaheadNeeds[index.uget ()] = value;
1077 /** Invalidate stack #YYK. */
1078 void
1079 yymarkStackDeleted (state_set_index yyk)
1081 size_t k = yyk.uget ();
1082 if (yystates[k] != YY_NULLPTR)
1083 yylastDeleted = yystates[k];
1084 yystates[k] = YY_NULLPTR;
1087 /** Undelete the last stack in *this that was marked as deleted. Can
1088 only be done once after a deletion, and only when all other stacks have
1089 been deleted. */
1090 void
1091 yyundeleteLastStack ()
1093 if (yylastDeleted == YY_NULLPTR || !yystates.empty ())
1094 return;
1095 yystates.push_back (yylastDeleted);
1096 YYCDEBUG << "Restoring last deleted stack as stack #0.\n";
1097 clearLastDeleted ();
1100 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1101 * ones. */
1102 void
1103 yyremoveDeletes ()
1105 size_t newsize = yystates.size ();
1106 /* j is the number of live stacks we have seen. */
1107 for (size_t i = 0, j = 0; j < newsize; ++i)
1109 if (yystates[i] == YY_NULLPTR)
1111 if (i == j)
1113 YYCDEBUG << "Removing dead stacks.\n";
1115 newsize -= 1;
1117 else
1119 yystates[j] = yystates[i];
1120 /* In the current implementation, it's unnecessary to copy
1121 yylookaheadNeeds[i] since, after
1122 yyremoveDeletes returns, the parser immediately either enters
1123 deterministic operation or shifts a token. However, it doesn't
1124 hurt, and the code might evolve to need it. */
1125 yylookaheadNeeds[j] = yylookaheadNeeds[i];
1126 if (j != i)
1128 YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n";
1130 j += 1;
1133 yystates.resize (newsize);
1134 yylookaheadNeeds.resize (newsize);
1138 state_set_index
1139 yysplitStack (state_set_index yyk)
1141 const size_t k = yyk.uget ();
1142 yystates.push_back (yystates[k]);
1143 yylookaheadNeeds.push_back (yylookaheadNeeds[k]);
1144 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates.size () - 1));
1147 void clearLastDeleted ()
1149 yylastDeleted = YY_NULLPTR;
1152 private:
1154 std::vector<glr_state*> yystates;
1155 /** During nondeterministic operation, yylookaheadNeeds tracks which
1156 * stacks have actually needed the current lookahead. During deterministic
1157 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1158 * duplicate !yyla.empty (). */
1159 std::vector<bool> yylookaheadNeeds;
1161 /** The last stack we invalidated. */
1162 glr_state* yylastDeleted;
1163 }; // class glr_state_set
1164 } // namespace
1166 namespace
1168 class semantic_option
1170 public:
1171 semantic_option ()
1172 : yyrule (0)
1173 , yystate (0)
1174 , yynext (0)
1175 , yyla ()]b4_parse_assert_if([[
1176 , magic_ (MAGIC)]])[
1179 semantic_option (rule_num rule)
1180 : yyrule (rule)
1181 , yystate (0)
1182 , yynext (0)
1183 , yyla ()]b4_parse_assert_if([[
1184 , magic_ (MAGIC)]])[
1187 semantic_option (const semantic_option& that)
1188 : yyrule (that.yyrule)
1189 , yystate (that.yystate)
1190 , yynext (that.yynext)
1191 , yyla (that.yyla)]b4_parse_assert_if([[
1192 , magic_ (MAGIC)]])[
1193 {]b4_parse_assert_if([[
1194 that.check_ ();]])[
1197 // Needed for the assignment in yynewSemanticOption.
1198 semantic_option& operator= (const semantic_option& that)
1199 {]b4_parse_assert_if([[
1200 check_ ();
1201 that.check_ ();]])[
1202 yyrule = that.yyrule;
1203 yystate = that.yystate;
1204 yynext = that.yynext;
1205 yyla = that.yyla;
1206 return *this;
1209 /// Only call state() and setState() on objects in yyitems, not temporaries.
1210 glr_state* state();
1211 const glr_state* state() const;
1212 void setState(const glr_state* s);
1214 const semantic_option* next () const YY_ATTRIBUTE_UNUSED;
1215 semantic_option* next ();
1216 void setNext (const semantic_option* s);
1218 std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED;
1220 /** True iff YYY0 and YYY1 represent identical options at the top level.
1221 * That is, they represent the same rule applied to RHS symbols
1222 * that produce the same terminal symbols. */
1223 bool
1224 isIdenticalTo (const semantic_option& yyy1) const
1225 {]b4_parse_assert_if([[
1226 check_ ();
1227 yyy1.check_ ();]])[
1228 if (this->yyrule == yyy1.yyrule)
1230 const glr_state *yys0, *yys1;
1231 int yyn;
1232 for (yys0 = this->state(),
1233 yys1 = yyy1.state(),
1234 yyn = yyrhsLength (this->yyrule);
1235 yyn > 0;
1236 yys0 = yys0->pred(),
1237 yys1 = yys1->pred(), yyn -= 1)
1238 if (yys0->yyposn != yys1->yyposn)
1239 return false;
1240 return true;
1242 else
1243 return false;
1246 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1247 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1248 void
1249 mergeWith (semantic_option& yyy1)
1250 {]b4_parse_assert_if([[
1251 check_ ();
1252 yyy1.check_ ();]])[
1253 glr_state *yys0 = this->state ();
1254 glr_state *yys1 = yyy1.state ();
1255 for (int yyn = yyrhsLength (this->yyrule);
1256 yyn > 0;
1257 yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ())
1259 if (yys0 == yys1)
1260 break;
1261 else if (yys0->yyresolved)
1263 yys1->yyresolved = true;]b4_variant_if([[
1264 YYASSERT (yys1->yylrState == yys0->yylrState);
1265 ]b4_symbol_variant([yy_accessing_symbol (yys0->yylrState)],
1266 [yys1->value ()], [copy], [yys0->value ()])], [[
1267 yys1->value () = yys0->value ();]])[
1269 else if (yys1->yyresolved)
1271 yys0->yyresolved = true;]b4_variant_if([[
1272 YYASSERT (yys0->yylrState == yys1->yylrState);
1273 ]b4_symbol_variant([yy_accessing_symbol (yys1->yylrState)],
1274 [yys0->value ()], [copy], [yys1->value ()])], [[
1275 yys0->value () = yys1->value ();]])[
1277 else
1279 semantic_option* yyz0prev = YY_NULLPTR;
1280 semantic_option* yyz0 = yys0->firstVal();
1281 semantic_option* yyz1 = yys1->firstVal();
1282 while (true)
1284 if (yyz1 == yyz0 || yyz1 == YY_NULLPTR)
1285 break;
1286 else if (yyz0 == YY_NULLPTR)
1288 if (yyz0prev != YY_NULLPTR)
1289 yyz0prev->setNext (yyz1);
1290 else
1291 yys0->setFirstVal (yyz1);
1292 break;
1294 else if (yyz0 < yyz1)
1296 semantic_option* yyz = yyz0;
1297 if (yyz0prev != YY_NULLPTR)
1298 yyz0prev->setNext(yyz1);
1299 else
1300 yys0->setFirstVal(yyz1);
1301 yyz1 = yyz1->next();
1302 yyz0->setNext(yyz);
1304 yyz0prev = yyz0;
1305 yyz0 = yyz0->next();
1307 yys1->setFirstVal(yys0->firstVal());
1312 #if ]b4_api_PREFIX[DEBUG
1313 void yyreportTree (size_t yyindent = 2) const
1314 {]b4_parse_assert_if([[
1315 check_ ();]])[
1316 int yynrhs = yyrhsLength (this->yyrule);
1317 const glr_state* yystates[1 + YYMAXRHS];
1318 glr_state yyleftmost_state;
1321 const glr_state* yys = this->state();
1322 for (int yyi = yynrhs; 0 < yyi; yyi -= 1)
1324 yystates[yyi] = yys;
1325 yys = yys->pred();
1327 if (yys == YY_NULLPTR)
1329 yyleftmost_state.yyposn = 0;
1330 yystates[0] = &yyleftmost_state;
1332 else
1333 yystates[0] = yys;
1336 std::string yylhs = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yylhsNonterm (this->yyrule));
1337 YYASSERT(this->state());
1338 if (this->state()->yyposn < yystates[0]->yyposn + 1)
1339 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1340 << this->yyrule - 1 << ", empty>\n";
1341 else
1342 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1343 << this->yyrule - 1 << ", tokens "
1344 << yystates[0]->yyposn + 1 << " .. "
1345 << this->state()->yyposn << ">\n";
1346 for (int yyi = 1; yyi <= yynrhs; yyi += 1)
1348 if (yystates[yyi]->yyresolved)
1350 std::string yysym = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yy_accessing_symbol (yystates[yyi]->yylrState));
1351 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1352 std::cerr << std::string(yyindent + 2, ' ') << yysym
1353 << " <empty>\n";
1354 else
1355 std::cerr << std::string(yyindent + 2, ' ') << yysym
1356 << " <tokens " << yystates[yyi-1]->yyposn + 1
1357 << " .. " << yystates[yyi]->yyposn << ">\n";
1359 else
1360 yystates[yyi]->firstVal ()->yyreportTree (yyindent+2);
1363 #endif
1365 /** Rule number for this reduction */
1366 rule_num yyrule;
1368 private:
1369 template <typename T>
1370 static const glr_stack_item* asItem(const T* state)
1372 return reinterpret_cast<const glr_stack_item*>(state);
1374 template <typename T>
1375 static glr_stack_item* asItem(T* state)
1377 return reinterpret_cast<glr_stack_item*>(state);
1379 /** The last RHS state in the list of states to be reduced. */
1380 std::ptrdiff_t yystate;
1381 /** Next sibling in chain of options. To facilitate merging,
1382 * options are chained in decreasing order by address. */
1383 std::ptrdiff_t yynext;
1385 public:
1386 /** The lookahead for this reduction. */
1387 symbol_type yyla;
1389 ]b4_parse_assert_if([[
1390 public:
1391 // Check invariants.
1392 void check_ () const
1394 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1395 YYASSERT (this->magic_ == MAGIC);
1396 YY_IGNORE_NULL_DEREFERENCE_END
1399 // A magic number to check our pointer arithmetic is sane.
1400 enum { MAGIC = 0xeff1cace };
1401 unsigned int magic_;]])[
1402 }; // class semantic_option
1403 } // namespace
1405 namespace
1407 /** Type of the items in the GLR stack.
1408 * It can be either a glr_state or a semantic_option. The is_state_ field
1409 * indicates which item of the union is valid. */
1410 class glr_stack_item
1412 public:
1413 glr_stack_item (bool state = true) YY_NOEXCEPT
1414 : is_state_ (state)]b4_parse_assert_if([[
1415 , magic_ (MAGIC)]])[
1417 if (is_state_)
1418 new (&raw_) glr_state;
1419 else
1420 new (&raw_) semantic_option;
1423 glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW
1424 : is_state_ (other.is_state_)]b4_parse_assert_if([[
1425 , magic_ (MAGIC)]])[
1426 {]b4_parse_assert_if([[
1427 other.check_ ();]])[
1428 std::memcpy (raw_, other.raw_, union_size);
1431 glr_stack_item& operator= (glr_stack_item other)
1432 {]b4_parse_assert_if([[
1433 check_ ();
1434 other.check_ ();]])[
1435 std::swap (is_state_, other.is_state_);
1436 std::swap (raw_, other.raw_);
1437 return *this;
1440 ~glr_stack_item ()
1441 {]b4_parse_assert_if([[
1442 check_ ();]])[
1443 if (is_state ())
1444 getState ().~glr_state ();
1445 else
1446 getOption ().~semantic_option ();
1449 void setState (const glr_state &state)
1450 {]b4_parse_assert_if([[
1451 check_ ();
1452 state.check_ ();]])[
1453 if (this != state.asItem ())
1455 if (is_state_)
1456 getState ().~glr_state ();
1457 else
1458 getOption ().~semantic_option ();
1459 new (&raw_) glr_state (state);
1460 is_state_ = true;
1464 glr_state& getState ()
1465 {]b4_parse_assert_if([[
1466 check_ ();]])[
1467 YYDASSERT (is_state ());
1468 void *yyp = raw_;
1469 glr_state& res = *static_cast<glr_state*> (yyp);]b4_parse_assert_if([[
1470 res.check_ ();]])[
1471 return res;
1474 const glr_state& getState () const
1475 {]b4_parse_assert_if([[
1476 check_ ();]])[
1477 YYDASSERT (is_state ());
1478 const void *yyp = raw_;
1479 const glr_state& res = *static_cast<const glr_state*> (yyp);]b4_parse_assert_if([[
1480 res.check_ ();]])[
1481 return res;
1484 semantic_option& getOption ()
1485 {]b4_parse_assert_if([[
1486 check_ ();]])[
1487 YYDASSERT (!is_state ());
1488 void *yyp = raw_;
1489 return *static_cast<semantic_option*> (yyp);
1491 const semantic_option& getOption () const
1492 {]b4_parse_assert_if([[
1493 check_ ();]])[
1494 YYDASSERT (!is_state ());
1495 const void *yyp = raw_;
1496 return *static_cast<const semantic_option*> (yyp);
1498 bool is_state () const
1499 {]b4_parse_assert_if([[
1500 check_ ();]])[
1501 return is_state_;
1504 private:
1505 /// The possible contents of raw_. Since they have constructors, they cannot
1506 /// be directly included in the union.
1507 union contents
1509 char yystate[sizeof (glr_state)];
1510 char yyoption[sizeof (semantic_option)];
1512 enum { union_size = sizeof (contents) };
1513 union {
1514 /// Strongest alignment constraints.
1515 long double yyalign_me;
1516 /// A buffer large enough to store the contents.
1517 char raw_[union_size];
1519 /** Type tag for the union. */
1520 bool is_state_;
1521 ]b4_parse_assert_if([[
1522 public:
1523 // Check invariants.
1524 void check_ () const
1526 YYASSERT (this->magic_ == MAGIC);
1527 YYASSERT (this->is_state_ == false || this->is_state_ == true);
1529 // A magic number to check our pointer arithmetic is sane.
1530 enum { MAGIC = 0xDEAD1ACC }; // 3735886540.
1531 const unsigned int magic_;]])[
1532 }; // class glr_stack_item
1533 } // namespace
1535 glr_state* glr_state::pred ()
1536 {]b4_parse_assert_if([[
1537 check_ ();]])[
1538 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1539 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1540 YY_IGNORE_NULL_DEREFERENCE_END
1543 const glr_state* glr_state::pred () const
1544 {]b4_parse_assert_if([[
1545 check_ ();]])[
1546 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1547 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1548 YY_IGNORE_NULL_DEREFERENCE_END
1551 void glr_state::setPred (const glr_state* state)
1552 {]b4_parse_assert_if([[
1553 check_ ();
1554 if (state)
1555 state->check_ ();]])[
1556 yypred = state ? as_pointer_ (this) - as_pointer_ (state) : 0;
1559 semantic_option* glr_state::firstVal ()
1560 {]b4_parse_assert_if([[
1561 check_ ();]])[
1562 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1565 const semantic_option* glr_state::firstVal () const
1566 {]b4_parse_assert_if([[
1567 check_ ();]])[
1568 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1571 void glr_state::setFirstVal (const semantic_option* option)
1572 {]b4_parse_assert_if([[
1573 check_ ();]])[
1574 yyfirstVal = option ? asItem(this) - asItem(option) : 0;
1577 std::ptrdiff_t glr_state::indexIn (const glr_stack_item* array) const
1578 {]b4_parse_assert_if([[
1579 check_ ();]])[
1580 return asItem(this) - array;
1583 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item* array) const
1585 return asItem(this) - array;
1588 glr_state* semantic_option::state ()
1590 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1591 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1592 YY_IGNORE_NULL_DEREFERENCE_END
1595 const glr_state* semantic_option::state () const
1597 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1600 void semantic_option::setState (const glr_state* s)
1602 yystate = s ? asItem(this) - asItem(s) : 0;
1605 const semantic_option* semantic_option::next () const
1607 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1610 semantic_option* semantic_option::next ()
1612 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1615 void semantic_option::setNext (const semantic_option* s)
1617 yynext = s ? asItem(this) - asItem(s) : 0;
1620 void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser)
1621 {]b4_parse_assert_if([[
1622 check_ ();]])[
1623 if (yyresolved)
1624 yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
1625 value ()]b4_locations_if([, yyloc])[);
1626 else
1628 #if ]b4_api_PREFIX[DEBUG
1629 YYCDEBUG << yymsg
1630 << (firstVal() ? " unresolved " : " incomplete ")
1631 << (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm")
1632 << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState))
1633 << " ("]b4_locations_if([[
1634 << yyloc << ": "]])[
1635 << ")\n";
1636 #endif
1637 if (firstVal() != YY_NULLPTR)
1639 semantic_option& yyoption = *firstVal ();
1640 glr_state *yyrh = yyoption.state ();
1641 for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1)
1643 yyrh->destroy (yymsg, yyparser);
1644 yyrh = yyrh->pred();
1651 #undef YYFILL
1652 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1654 namespace
1656 class state_stack
1658 public:
1659 using parser_type = ]b4_namespace_ref[::]b4_parser_class[;
1660 using symbol_kind = parser_type::symbol_kind;
1661 using value_type = parser_type::value_type;]b4_locations_if([[
1662 using location_type = parser_type::location_type;]])[
1664 /** Initialize to a single empty stack, with total maximum
1665 * capacity for all stacks of YYSIZE. */
1666 state_stack (size_t yysize)
1667 : yysplitPoint (YY_NULLPTR)
1669 yyitems.reserve (yysize);
1672 #if YYSTACKEXPANDABLE
1673 /** Returns false if it tried to expand but could not. */
1674 bool
1675 yyexpandGLRStackIfNeeded ()
1677 return YYHEADROOM <= spaceLeft () || yyexpandGLRStack ();
1680 private:
1681 /** If *this is expandable, extend it. WARNING: Pointers into the
1682 stack from outside should be considered invalid after this call.
1683 We always expand when there are 1 or fewer items left AFTER an
1684 allocation, so that we can avoid having external pointers exist
1685 across an allocation. */
1686 bool
1687 yyexpandGLRStack ()
1689 const size_t oldsize = yyitems.size();
1690 if (YYMAXDEPTH - YYHEADROOM < oldsize)
1691 return false;
1692 const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize;
1693 const glr_stack_item *oldbase = &yyitems[0];
1695 yyitems.reserve (yynewSize);
1696 const glr_stack_item *newbase = &yyitems[0];
1698 // Adjust the pointers. Perform raw pointer arithmetic, as there
1699 // is no reason for objects to be aligned on their size.
1700 const ptrdiff_t disp
1701 = reinterpret_cast<const char*> (newbase) - reinterpret_cast<const char*> (oldbase);
1702 if (yysplitPoint)
1703 const_cast<glr_state*&> (yysplitPoint)
1704 = reinterpret_cast<glr_state*> (reinterpret_cast<char*> (const_cast<glr_state*> (yysplitPoint)) + disp);
1706 for (std::vector<glr_state*>::iterator
1707 i = yytops.begin (),
1708 yyend = yytops.end ();
1709 i != yyend; ++i)
1710 if (glr_state_not_null (*i))
1711 *i = reinterpret_cast<glr_state*>(reinterpret_cast<char*>(*i) + disp);
1713 return true;
1716 public:
1717 #else
1718 bool yyexpandGLRStackIfNeeded ()
1720 return YYHEADROOM <= spaceLeft ();
1722 #endif
1723 #undef YYSTACKEXPANDABLE
1725 static bool glr_state_not_null (glr_state* s)
1727 return s != YY_NULLPTR;
1730 bool
1731 reduceToOneStack ()
1733 using iterator = std::vector<glr_state*>::iterator;
1734 const iterator yybegin = yytops.begin();
1735 const iterator yyend = yytops.end();
1736 const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null);
1737 if (yyit == yyend)
1738 return false;
1739 for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin);
1740 yyk.uget() != numTops(); ++yyk)
1741 yytops.yymarkStackDeleted (yyk);
1742 yytops.yyremoveDeletes ();
1743 yycompressStack ();
1744 return true;
1747 /** Called when returning to deterministic operation to clean up the extra
1748 * stacks. */
1749 void
1750 yycompressStack ()
1752 if (yytops.size() != 1 || !isSplit())
1753 return;
1755 // yyr is the state after the split point.
1756 glr_state* yyr = YY_NULLPTR;
1757 for (glr_state *yyp = firstTop(), *yyq = yyp->pred();
1758 yyp != yysplitPoint;
1759 yyr = yyp, yyp = yyq, yyq = yyp->pred())
1760 yyp->setPred(yyr);
1762 // This const_cast is okay, since anyway we have access to the mutable
1763 // yyitems into which yysplitPoint points.
1764 glr_stack_item* nextFreeItem
1765 = const_cast<glr_state*> (yysplitPoint)->asItem () + 1;
1766 yysplitPoint = YY_NULLPTR;
1767 yytops.clearLastDeleted ();
1769 while (yyr != YY_NULLPTR)
1771 nextFreeItem->setState (*yyr);
1772 glr_state& nextFreeState = nextFreeItem->getState();
1773 yyr = yyr->pred();
1774 nextFreeState.setPred(&(nextFreeItem - 1)->getState());
1775 setFirstTop (&nextFreeState);
1776 ++nextFreeItem;
1778 yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data()));
1781 bool isSplit() const {
1782 return yysplitPoint != YY_NULLPTR;
1785 // Present the interface of a vector of glr_stack_item.
1786 std::vector<glr_stack_item>::const_iterator begin () const
1788 return yyitems.begin ();
1791 std::vector<glr_stack_item>::const_iterator end () const
1793 return yyitems.end ();
1796 size_t size() const
1798 return yyitems.size ();
1801 glr_stack_item& operator[] (size_t i)
1803 return yyitems[i];
1806 glr_stack_item& stackItemAt (size_t index)
1808 return yyitems[index];
1811 size_t numTops () const
1813 return yytops.size ();
1816 glr_state* firstTop () const
1818 return yytops[create_state_set_index (0)];
1821 glr_state* topAt (state_set_index i) const
1823 return yytops[i];
1826 void setFirstTop (glr_state* value)
1828 yytops[create_state_set_index (0)] = value;
1831 void setTopAt (state_set_index i, glr_state* value)
1833 yytops[i] = value;
1836 void pop_back ()
1838 yyitems.pop_back ();
1841 void pop_back (size_t n)
1843 yyitems.resize (yyitems.size () - n);
1846 state_set_index
1847 yysplitStack (state_set_index yyk)
1849 if (!isSplit ())
1851 YYASSERT (yyk.get () == 0);
1852 yysplitPoint = topAt (yyk);
1854 return yytops.yysplitStack (yyk);
1857 /** Assuming that YYS is a GLRState somewhere on *this, update the
1858 * splitpoint of *this, if needed, so that it is at least as deep as
1859 * YYS. */
1860 void
1861 yyupdateSplit (glr_state& yys)
1863 if (isSplit() && &yys < yysplitPoint)
1864 yysplitPoint = &yys;
1867 /** Return a fresh GLRState.
1868 * Callers should call yyreserveStack afterwards to make sure there is
1869 * sufficient headroom. */
1870 glr_state& yynewGLRState (const glr_state& newState)
1872 glr_state& state = yyitems[yynewGLRStackItem (true)].getState ();
1873 #if false && 201103L <= YY_CPLUSPLUS
1874 state = std::move (newState);
1875 #else
1876 state = newState;
1877 #endif
1878 return state;
1881 /** Return a fresh SemanticOption.
1882 * Callers should call yyreserveStack afterwards to make sure there is
1883 * sufficient headroom. */
1884 semantic_option& yynewSemanticOption (semantic_option newOption)
1886 semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption ();
1887 option = std::move (newOption);
1888 return option;
1891 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1892 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1893 * For convenience, always return YYLOW1. */
1895 yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal)
1897 if (!yynormal && yylow1 < yylow)
1899 yyfillin (yyvsp, yylow, yylow1);
1900 yylow = yylow1;
1902 return yylow1;
1905 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1906 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1907 * containing the pointer to the next state in the chain. */
1908 void
1909 yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1)
1911 glr_state* s = yyvsp[yylow0].getState().pred();
1912 YYASSERT(s != YY_NULLPTR);
1913 for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred())
1915 glr_state& yys = yyvsp[i].getState();
1916 #if ]b4_api_PREFIX[DEBUG
1917 yys.yylrState = s->yylrState;
1918 #endif
1919 yys.yyresolved = s->yyresolved;
1920 if (s->yyresolved)
1921 {]b4_variant_if([[
1922 new (&yys.value ()) value_type ();
1923 ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)],
1924 [yys.value ()], [copy], [s->value ()])], [[
1925 new (&yys.value ()) value_type (s->value ());]])[
1927 else
1928 /* The effect of using yyval or yyloc (in an immediate
1929 * rule) is undefined. */
1930 yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[
1931 yys.yyloc = s->yyloc;]])[
1932 yys.setPred(s->pred());
1936 #if ]b4_api_PREFIX[DEBUG
1938 /*----------------------------------------------------------------------.
1939 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1940 `----------------------------------------------------------------------*/
1942 void
1943 yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk,
1944 rule_num yyrule, parser_type& yyparser)
1946 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1947 int yylow = 1;])[
1948 int yyi;
1949 std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1
1950 << " (line " << int (yyrline[yyrule]) << "):\n";
1951 if (! yynormal)
1952 yyfillin (yyvsp, 1, -yynrhs);
1953 /* The symbols being reduced. */
1954 for (yyi = 0; yyi < yynrhs; yyi++)
1956 std::cerr << " $" << yyi + 1 << " = ";
1957 yyparser.yy_symbol_print_
1958 (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
1959 yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
1960 ]b4_rhs_location(yynrhs, yyi + 1)])[);
1961 if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
1962 std::cerr << " (unresolved)";
1963 std::cerr << '\n';
1968 #define YYINDEX(YYX) \
1969 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1971 void
1972 dumpStack () const
1974 for (size_t yyi = 0; yyi < size(); ++yyi)
1976 const glr_stack_item& item = yyitems[yyi];
1977 std::cerr << std::setw(3) << yyi << ". ";
1978 if (item.is_state())
1980 std::cerr << "Res: " << item.getState().yyresolved
1981 << ", LR State: " << item.getState().yylrState
1982 << ", posn: " << item.getState().yyposn
1983 << ", pred: " << YYINDEX(item.getState().pred());
1984 if (! item.getState().yyresolved)
1985 std::cerr << ", firstVal: "
1986 << YYINDEX(item.getState().firstVal());
1988 else
1990 std::cerr << "Option. rule: " << item.getOption().yyrule - 1
1991 << ", state: " << YYINDEX(item.getOption().state())
1992 << ", next: " << YYINDEX(item.getOption().next());
1994 std::cerr << '\n';
1996 std::cerr << "Tops:";
1997 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) {
1998 std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; ";
2000 std::cerr << '\n';
2003 #undef YYINDEX
2004 #endif
2006 YYRESULTTAG
2007 yyreportAmbiguity (const semantic_option& yyx0,
2008 const semantic_option& yyx1, parser_type& yyparser]b4_locations_if([, const location_type& yyloc])[)
2010 YY_USE (yyx0);
2011 YY_USE (yyx1);
2013 #if ]b4_api_PREFIX[DEBUG
2014 std::cerr << "Ambiguity detected.\n"
2015 "Option 1,\n";
2016 yyx0.yyreportTree ();
2017 std::cerr << "\nOption 2,\n";
2018 yyx1.yyreportTree ();
2019 std::cerr << '\n';
2020 #endif
2022 yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous"));
2023 return yyabort;
2026 #if ]b4_api_PREFIX[DEBUG
2027 /* Print YYS (possibly NULL) and its predecessors. */
2028 void
2029 yypstates (const glr_state* yys) const
2031 if (yys != YY_NULLPTR)
2032 yys->yy_yypstack();
2033 else
2034 std::cerr << "<null>";
2035 std::cerr << '\n';
2037 #endif
2039 private:
2040 size_t spaceLeft() const
2042 return yyitems.capacity() - yyitems.size();
2045 /** Return a fresh GLRStackItem in this. The item is an LR state
2046 * if YYIS_STATE, and otherwise a semantic option. Callers should call
2047 * yyreserveStack afterwards to make sure there is sufficient
2048 * headroom. */
2049 size_t
2050 yynewGLRStackItem (bool yyis_state)
2052 YYDASSERT(yyitems.size() < yyitems.capacity());
2053 yyitems.push_back(glr_stack_item(yyis_state));
2054 return yyitems.size() - 1;
2058 public:
2059 std::vector<glr_stack_item> yyitems;
2060 // Where the stack splits. Anything below this address is deterministic.
2061 const glr_state* yysplitPoint;
2062 glr_state_set yytops;
2063 }; // class state_stack
2064 } // namespace
2066 #undef YYFILL
2067 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2069 namespace ]b4_namespace_ref[
2071 class ]b4_parser_class[::glr_stack
2073 public:
2074 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
2075 // Needs access to yypact_value_is_default, etc.
2076 friend context;
2077 ]])[
2079 glr_stack (size_t yysize, parser_type& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
2080 : yyerrState (0)
2081 , yystateStack (yysize)
2082 , yyerrcnt (0)
2083 , yyla ()
2084 , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
2087 ~glr_stack ()
2089 if (!this->yyla.empty ())
2090 yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
2091 this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);
2092 popall_ ();
2095 int yyerrState;
2096 ]b4_locations_if([[ /* To compute the location of the error token. */
2097 glr_stack_item yyerror_range[3];]])[
2098 state_stack yystateStack;
2099 int yyerrcnt;
2100 symbol_type yyla;
2101 YYJMP_BUF yyexception_buffer;
2102 parser_type& yyparser;
2104 #define YYCHK1(YYE) \
2105 do { \
2106 switch (YYE) { \
2107 case yyok: \
2108 break; \
2109 case yyabort: \
2110 goto yyabortlab; \
2111 case yyaccept: \
2112 goto yyacceptlab; \
2113 case yyerr: \
2114 goto yyuser_error; \
2115 default: \
2116 goto yybuglab; \
2118 } while (false)
2121 parse ()
2123 int yyresult;
2124 size_t yyposn;
2126 YYCDEBUG << "Starting parse\n";
2128 this->yyla.clear ();
2129 ]m4_ifdef([b4_initial_action], [
2130 b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl
2131 b4_user_initial_action
2132 b4_dollar_popdef])[]dnl
2134 switch (YYSETJMP (this->yyexception_buffer))
2136 case 0: break;
2137 case 1: goto yyabortlab;
2138 case 2: goto yyexhaustedlab;
2139 default: goto yybuglab;
2141 this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2142 yyposn = 0;
2144 while (true)
2146 /* For efficiency, we have two loops, the first of which is
2147 specialized to deterministic operation (single stack, no
2148 potential ambiguity). */
2149 /* Standard mode */
2150 while (true)
2152 const state_num yystate = this->firstTopState()->yylrState;
2153 YYCDEBUG << "Entering state " << yystate << '\n';
2154 if (yystate == YYFINAL)
2155 goto yyacceptlab;
2156 if (yy_is_defaulted_state (yystate))
2158 const rule_num yyrule = yy_default_action (yystate);
2159 if (yyrule == 0)
2160 {]b4_locations_if([[
2161 this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[
2162 this->yyreportSyntaxError ();
2163 goto yyuser_error;
2165 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule, true));
2167 else
2169 yyget_token ();
2170 const short* yyconflicts;
2171 const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
2172 if (*yyconflicts != 0)
2173 break;
2174 if (yy_is_shift_action (yyaction))
2176 YY_SYMBOL_PRINT ("Shifting", this->yyla.kind (), this->yyla.value, this->yyla.location);
2177 yyposn += 1;
2178 // FIXME: we should move yylval.
2179 this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2180 yyla.clear ();
2181 if (0 < this->yyerrState)
2182 this->yyerrState -= 1;
2184 else if (yy_is_error_action (yyaction))
2185 {]b4_locations_if([[
2186 this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[
2187 /* Don't issue an error message again for exceptions
2188 thrown from the scanner. */
2189 if (this->yyla.kind () != ]b4_symbol(error, kind)[)
2190 this->yyreportSyntaxError ();
2191 goto yyuser_error;
2193 else
2194 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction, true));
2198 while (true)
2200 for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys)
2201 this->yystateStack.yytops.setLookaheadNeeds(yys, !this->yyla.empty ());
2203 /* yyprocessOneStack returns one of three things:
2205 - An error flag. If the caller is yyprocessOneStack, it
2206 immediately returns as well. When the caller is finally
2207 yyparse, it jumps to an error label via YYCHK1.
2209 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2210 (yys), which sets the top state of yys to NULL. Thus,
2211 yyparse's following invocation of yyremoveDeletes will remove
2212 the stack.
2214 - yyok, when ready to shift a token.
2216 Except in the first case, yyparse will invoke yyremoveDeletes and
2217 then shift the next token onto all remaining stacks. This
2218 synchronization of the shift (that is, after all preceding
2219 reductions on all stacks) helps prevent double destructor calls
2220 on yylval in the event of memory exhaustion. */
2222 for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
2223 YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yyla.location])[));
2224 this->yystateStack.yytops.yyremoveDeletes ();
2225 if (this->yystateStack.yytops.size() == 0)
2227 this->yystateStack.yytops.yyundeleteLastStack ();
2228 if (this->yystateStack.yytops.size() == 0)
2229 this->yyFail (]b4_locations_if([&this->yyla.location, ])[YY_("syntax error"));
2230 YYCHK1 (this->yyresolveStack ());
2231 YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[
2232 this->yyerror_range[1].getState ().yyloc = this->yyla.location;]])[
2233 this->yyreportSyntaxError ();
2234 goto yyuser_error;
2237 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2238 a copy of yylval will already be on stack 0 in the event of a
2239 failure in the following loop. Thus, yyla is emptied
2240 before the loop to make sure the user destructor for yylval isn't
2241 called twice. */
2242 symbol_kind_type yytoken_to_shift = this->yyla.kind ();
2243 this->yyla.kind_ = ]b4_symbol(empty, kind)[;
2244 yyposn += 1;
2245 for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
2247 const state_num yystate = this->topState (yys)->yylrState;
2248 const short* yyconflicts;
2249 const int yyaction = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
2250 /* Note that yyconflicts were handled by yyprocessOneStack. */
2251 YYCDEBUG << "On stack " << yys.get() << ", ";
2252 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yyla.value, this->yyla.location);
2253 this->yyglrShift (yys, yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2254 YYCDEBUG << "Stack " << yys.get() << " now in state "
2255 << this->topState(yys)->yylrState << '\n';
2257 ]b4_variant_if([[
2258 // FIXME: User destructors.
2259 // Value type destructor.
2260 ]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[
2262 if (this->yystateStack.yytops.size () == 1)
2264 YYCHK1 (this->yyresolveStack ());
2265 YYCDEBUG << "Returning to deterministic operation.\n";
2266 this->yystateStack.yycompressStack ();
2267 break;
2270 continue;
2271 yyuser_error:
2272 this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla.location])[);
2273 yyposn = this->firstTopState()->yyposn;
2276 yyacceptlab:
2277 yyresult = 0;
2278 goto yyreturn;
2280 yybuglab:
2281 YYASSERT (false);
2282 goto yyabortlab;
2284 yyabortlab:
2285 yyresult = 1;
2286 goto yyreturn;
2288 yyexhaustedlab:
2289 yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("memory exhausted"));
2290 yyresult = 2;
2291 goto yyreturn;
2293 yyreturn:
2294 return yyresult;
2296 #undef YYCHK1
2298 void yyreserveGlrStack ()
2300 if (!yystateStack.yyexpandGLRStackIfNeeded ())
2301 yyMemoryExhausted ();
2304 _Noreturn void
2305 yyMemoryExhausted ()
2307 YYLONGJMP (yyexception_buffer, 2);
2310 _Noreturn void
2311 yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg)
2313 if (yymsg != YY_NULLPTR)
2314 yyparser.error (]b4_locations_if([*yylocp, ])[yymsg);
2315 YYLONGJMP (yyexception_buffer, 1);
2318 /* GLRStates */
2321 /** Add a new semantic action that will execute the action for rule
2322 * YYRULE on the semantic values in YYRHS to the list of
2323 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2324 * stack #YYK of *this. */
2325 void
2326 yyaddDeferredAction (state_set_index yyk, glr_state* yystate,
2327 glr_state* yyrhs, rule_num yyrule)
2329 semantic_option& yyopt = yystateStack.yynewSemanticOption (semantic_option (yyrule));
2330 yyopt.setState (yyrhs);
2331 yyopt.setNext (yystate->firstVal ());
2332 if (yystateStack.yytops.lookaheadNeeds (yyk))
2333 yyopt.yyla = this->yyla;
2334 yystate->setFirstVal (&yyopt);
2336 yyreserveGlrStack ();
2339 #if ]b4_api_PREFIX[DEBUG
2340 void yypdumpstack () const
2342 yystateStack.dumpStack();
2344 #endif
2346 void
2347 yyreportSyntaxError ()
2349 if (yyerrState != 0)
2350 return;
2351 ]b4_parse_error_case(
2352 [simple], [[
2353 std::string msg = YY_("syntax error");
2354 yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]],
2355 [custom], [[
2356 context yyctx (*this, yyla);
2357 yyparser.report_syntax_error (yyctx);]],
2359 context yyctx (*this, yyla);
2360 std::string msg = yyparser.yysyntax_error_ (yyctx);
2361 yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[
2362 yyerrcnt += 1;
2365 /* Recover from a syntax error on this, assuming that yytoken,
2366 yylval, and yylloc are the syntactic category, semantic value, and location
2367 of the lookahead. */
2368 void
2369 yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[)
2371 if (yyerrState == 3)
2372 /* We just shifted the error token and (perhaps) took some
2373 reductions. Skip tokens until we can proceed. */
2374 while (true)
2376 if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
2377 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2378 if (this->yyla.kind () != ]b4_symbol(empty, kind)[)
2379 {]b4_locations_if([[
2380 /* We throw away the lookahead, but the error range
2381 of the shifted error token must take it into account. */
2382 glr_state *yys = firstTopState();
2383 yyerror_range[1].getState().yyloc = yys->yyloc;
2384 yyerror_range[2].getState().yyloc = this->yyla.location;
2385 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2386 yyparser.yy_destroy_ ("Error: discarding",
2387 this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);]b4_variant_if([[
2388 // Value type destructor.
2389 ]b4_symbol_variant([[this->yyla.kind ()]], [[this->yyla.value]], [[template destroy]])])[
2390 this->yyla.kind_ = ]b4_symbol(empty, kind)[;
2392 yyget_token ();
2393 int yyj = yypact[firstTopState()->yylrState];
2394 if (yypact_value_is_default (yyj))
2395 return;
2396 yyj += this->yyla.kind ();
2397 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yyla.kind ())
2399 if (yydefact[firstTopState()->yylrState] != 0)
2400 return;
2402 else if (! yytable_value_is_error (yytable[yyj]))
2403 return;
2406 if (!yystateStack.reduceToOneStack())
2407 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2409 /* Now pop stack until we find a state that shifts the error token. */
2410 yyerrState = 3;
2411 while (firstTopState () != YY_NULLPTR)
2413 glr_state *yys = firstTopState ();
2414 int yyj = yypact[yys->yylrState];
2415 if (! yypact_value_is_default (yyj))
2417 yyj += YYTERROR;
2418 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2419 && yy_is_shift_action (yytable[yyj]))
2421 /* Shift the error token. */]b4_locations_if([[
2422 /* First adjust its location.*/
2423 location_type yyerrloc;
2424 yyerror_range[2].getState().yyloc = this->yyla.location;
2425 YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
2426 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
2427 this->yyla.value, yyerrloc);
2428 yyglrShift (create_state_set_index(0), yytable[yyj],
2429 yys->yyposn, yyla.value]b4_locations_if([, yyerrloc])[);
2430 yys = firstTopState();
2431 break;
2433 }]b4_locations_if([[
2434 yyerror_range[1].getState().yyloc = yys->yyloc;]])[
2435 if (yys->pred() != YY_NULLPTR)
2436 yys->destroy ("Error: popping", yyparser);
2437 yystateStack.setFirstTop(yys->pred());
2438 yystateStack.pop_back();
2440 if (firstTopState() == YY_NULLPTR)
2441 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2444 YYRESULTTAG
2445 yyprocessOneStack (state_set_index yyk,
2446 size_t yyposn]b4_locations_if([, location_type* yylocp])[)
2448 while (yystateStack.topAt(yyk) != YY_NULLPTR)
2450 const state_num yystate = topState(yyk)->yylrState;
2451 YYCDEBUG << "Stack " << yyk.get()
2452 << " Entering state " << yystate << '\n';
2454 YYASSERT (yystate != YYFINAL);
2456 if (yy_is_defaulted_state (yystate))
2458 const rule_num yyrule = yy_default_action (yystate);
2459 if (yyrule == 0)
2461 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2462 yystateStack.yytops.yymarkStackDeleted (yyk);
2463 return yyok;
2465 const YYRESULTTAG yyflag
2466 = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]);
2467 if (yyflag == yyerr)
2469 YYCDEBUG << "Stack " << yyk.get() << " dies"
2470 " (predicate failure or explicit user error).\n";
2471 yystateStack.yytops.yymarkStackDeleted (yyk);
2472 return yyok;
2474 if (yyflag != yyok)
2475 return yyflag;
2477 else
2479 yystateStack.yytops.setLookaheadNeeds(yyk, true);
2480 yyget_token ();
2481 const short* yyconflicts;
2482 const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
2484 for (; *yyconflicts != 0; ++yyconflicts)
2486 state_set_index yynewStack = yystateStack.yysplitStack (yyk);
2487 YYCDEBUG << "Splitting off stack " << yynewStack.get()
2488 << " from " << yyk.get() << ".\n";
2489 YYRESULTTAG yyflag =
2490 yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]);
2491 if (yyflag == yyok)
2492 YYCHK (yyprocessOneStack (yynewStack,
2493 yyposn]b4_locations_if([, yylocp])[));
2494 else if (yyflag == yyerr)
2496 YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n";
2497 yystateStack.yytops.yymarkStackDeleted (yynewStack);
2499 else
2500 return yyflag;
2503 if (yy_is_shift_action (yyaction))
2504 break;
2505 else if (yy_is_error_action (yyaction))
2507 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2508 yystateStack.yytops.yymarkStackDeleted (yyk);
2509 break;
2511 else
2513 YYRESULTTAG yyflag
2514 = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]);
2515 if (yyflag == yyerr)
2517 YYCDEBUG << "Stack " << yyk.get() << " dies"
2518 " (predicate failure or explicit user error).\n";
2519 yystateStack.yytops.yymarkStackDeleted (yyk);
2520 break;
2522 else if (yyflag != yyok)
2523 return yyflag;
2527 return yyok;
2530 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2531 * and top stack item YYVSP. YYVALP points to place to put semantic
2532 * value ($$), and yylocp points to place for location information
2533 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2534 * yyerr for YYERROR, yyabort for YYABORT. */
2535 YYRESULTTAG
2536 yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk,
2537 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2539 bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit();
2540 int yylow = 1;
2541 ]b4_parse_param_use([yyvalp], [yylocp])dnl
2542 [ YY_USE (yyk);
2543 YY_USE (yyrhslen);
2544 # undef yyerrok
2545 # define yyerrok (yyerrState = 0)
2546 # undef YYACCEPT
2547 # define YYACCEPT return yyaccept
2548 # undef YYABORT
2549 # define YYABORT return yyabort
2550 # undef YYERROR
2551 # define YYERROR return yyerrok, yyerr
2552 # undef YYRECOVERING
2553 # define YYRECOVERING() (yyerrState != 0)
2554 # undef yytoken
2555 # define yytoken this->yyla.kind_
2556 # undef yyclearin
2557 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2558 # undef YYBACKUP
2559 # define YYBACKUP(Token, Value) \
2560 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2561 yyerrok, yyerr
2563 ]b4_variant_if([[
2564 /* Variants are always initialized to an empty instance of the
2565 correct type. The default '$$ = $1' action is NOT applied
2566 when using variants. */
2567 // However we really need to prepare yyvsp now if we want to get
2568 // correct locations, so invoke YYFILL for $1 anyway.
2569 (void) YYFILL (1-yyrhslen);
2570 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[
2571 if (yyrhslen == 0)
2572 *yyvalp = yyval_default;
2573 else
2574 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[
2575 /* Default location. */
2576 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
2577 yyerror_range[1].getState().yyloc = *yylocp;
2578 ]])[
2579 /* If yyk == -1, we are running a deferred action on a temporary
2580 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2581 so pretend the stack is "normal". */
2582 YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser));
2583 #if YY_EXCEPTIONS
2586 #endif // YY_EXCEPTIONS
2587 switch (yyrule)
2589 ]b4_user_actions[
2590 default: break;
2592 #if YY_EXCEPTIONS
2594 catch (const syntax_error& yyexc)
2596 YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([
2597 *yylocp = yyexc.location;])[
2598 yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ());
2599 YYERROR;
2601 #endif // YY_EXCEPTIONS
2602 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp);
2604 return yyok;
2605 # undef yyerrok
2606 # undef YYABORT
2607 # undef YYACCEPT
2608 # undef YYERROR
2609 # undef YYBACKUP
2610 # undef yytoken
2611 # undef yyclearin
2612 # undef YYRECOVERING
2615 YYRESULTTAG
2616 yyresolveStack ()
2618 if (yystateStack.isSplit ())
2620 int yyn = 0;
2621 for (glr_state* yys = firstTopState ();
2622 yys != yystateStack.yysplitPoint;
2623 yys = yys->pred ())
2624 yyn += 1;
2625 YYCHK (yyresolveStates (*firstTopState (), yyn));
2627 return yyok;
2630 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2631 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2632 * semantic values. Assumes that all ambiguities in semantic values
2633 * have been previously resolved. Set *YYVALP to the resulting value,
2634 * and *YYLOCP to the computed location (if any). Return value is as
2635 * for userAction. */
2636 YYRESULTTAG
2637 yydoAction (state_set_index yyk, rule_num yyrule,
2638 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2640 const int yynrhs = yyrhsLength (yyrule);
2642 if (!yystateStack.isSplit())
2644 /* Standard special case: single stack. */
2645 YYASSERT (yyk.get() == 0);
2646 glr_stack_item* yyrhs = yystateStack.firstTop()->asItem();
2647 const YYRESULTTAG res
2648 = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[);
2649 yystateStack.pop_back(static_cast<size_t>(yynrhs));
2650 yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState());
2651 return res;
2653 else
2655 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
2656 glr_state* yys = yystateStack.topAt(yyk);
2657 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[
2658 if (yynrhs == 0)
2659 /* Set default location. */
2660 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[
2661 for (int yyi = 0; yyi < yynrhs; yyi += 1)
2663 yys = yys->pred();
2664 YYASSERT (yys != YY_NULLPTR);
2666 yystateStack.yyupdateSplit (*yys);
2667 yystateStack.setTopAt(yyk, yys);
2668 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
2669 yyk,
2670 yyvalp]b4_locations_if([, yylocp])[);
2674 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2675 * and push back on the resulting nonterminal symbol. Perform the
2676 * semantic action associated with YYRULE and store its value with the
2677 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2678 * unambiguous. Otherwise, store the deferred semantic action with
2679 * the new state. If the new state would have an identical input
2680 * position, LR state, and predecessor to an existing state on the stack,
2681 * it is identified with that existing state, eliminating stack #YYK from
2682 * *YYSTACKP. In this case, the semantic value is
2683 * added to the options for the existing state's semantic value.
2685 YYRESULTTAG
2686 yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval)
2688 size_t yyposn = topState(yyk)->yyposn;
2690 if (yyforceEval || !yystateStack.isSplit())
2692 value_type val;]b4_locations_if([[
2693 location_type loc;]])[
2695 YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[);
2696 if (yyflag == yyerr && yystateStack.isSplit())
2697 {]b4_parse_trace_if([[
2698 YYCDEBUG << "Parse on stack " << yyk.get ()
2699 << " rejected by rule " << yyrule - 1
2700 << " (line " << int (yyrline[yyrule]) << ").\n";
2701 ]])[}
2702 if (yyflag != yyok)
2703 return yyflag;
2704 yyglrShift (yyk,
2705 yyLRgotoState (topState(yyk)->yylrState,
2706 yylhsNonterm (yyrule)),
2707 yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[
2708 // FIXME: User destructors.
2709 // Value type destructor.
2710 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[
2712 else
2714 glr_state *yys = yystateStack.topAt(yyk);
2715 glr_state *yys0 = yys;
2716 for (int yyn = yyrhsLength (yyrule); 0 < yyn; yyn -= 1)
2718 yys = yys->pred();
2719 YYASSERT (yys != YY_NULLPTR);
2721 yystateStack.yyupdateSplit (*yys);
2722 state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[
2723 YYCDEBUG << "Reduced stack " << yyk.get ()
2724 << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule])
2725 << "); action deferred. Now in state " << yynewLRState
2726 << ".\n";]])[
2727 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi)
2728 if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR)
2730 const glr_state* yysplit = yystateStack.yysplitPoint;
2731 glr_state* yyp = yystateStack.topAt(yyi);
2732 while (yyp != yys && yyp != yysplit
2733 && yyp->yyposn >= yyposn)
2735 if (yyp->yylrState == yynewLRState
2736 && yyp->pred() == yys)
2738 yyaddDeferredAction (yyk, yyp, yys0, yyrule);
2739 yystateStack.yytops.yymarkStackDeleted (yyk);
2740 YYCDEBUG << "Merging stack " << yyk.get ()
2741 << " into stack " << yyi.get () << ".\n";
2742 return yyok;
2744 yyp = yyp->pred();
2747 yystateStack.setTopAt(yyk, yys);
2748 yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule);
2750 return yyok;
2753 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2754 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2755 * semantic value of YYRHS under the action for YYRULE. */
2756 void
2757 yyglrShiftDefer (state_set_index yyk, state_num yylrState,
2758 size_t yyposn, glr_state* yyrhs, rule_num yyrule)
2760 glr_state& yynewState = yystateStack.yynewGLRState (
2761 glr_state (yylrState, yyposn));
2762 yynewState.setPred (yystateStack.topAt (yyk));
2763 yystateStack.setTopAt (yyk, &yynewState);
2765 /* Invokes yyreserveStack. */
2766 yyaddDeferredAction (yyk, &yynewState, yyrhs, yyrule);
2769 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2770 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2771 * value YYVAL_ARG and source location YYLOC_ARG. */
2772 void
2773 yyglrShift (state_set_index yyk, state_num yylrState,
2774 size_t yyposn,
2775 const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[)
2777 glr_state& yynewState = yystateStack.yynewGLRState (
2778 glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[));
2779 yynewState.setPred (yystateStack.topAt(yyk));
2780 yystateStack.setTopAt (yyk, &yynewState);
2781 yyreserveGlrStack ();
2784 #if ]b4_api_PREFIX[DEBUG
2785 void
2786 yypstack (state_set_index yyk) const
2788 yystateStack.yypstates (yystateStack.topAt (yyk));
2790 #endif
2792 glr_state* topState(state_set_index i) {
2793 return yystateStack.topAt(i);
2796 glr_state* firstTopState() {
2797 return yystateStack.firstTop();
2800 private:
2802 void popall_ ()
2804 /* If the stack is well-formed, pop the stack until it is empty,
2805 destroying its entries as we go. But free the stack regardless
2806 of whether it is well-formed. */
2807 for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); k += 1)
2808 if (yystateStack.topAt(k) != YY_NULLPTR)
2810 while (yystateStack.topAt(k) != YY_NULLPTR)
2812 glr_state* state = topState(k);]b4_locations_if([[
2813 yyerror_range[1].getState().yyloc = state->yyloc;]])[
2814 if (state->pred() != YY_NULLPTR)
2815 state->destroy ("Cleanup: popping", yyparser);
2816 yystateStack.setTopAt(k, state->pred());
2817 yystateStack.pop_back();
2819 break;
2823 /** Resolve the previous YYN states starting at and including state YYS
2824 * on *YYSTACKP. If result != yyok, some states may have been left
2825 * unresolved possibly with empty semantic option chains. Regardless
2826 * of whether result = yyok, each state has been left with consistent
2827 * data so that destroy can be invoked if necessary. */
2828 YYRESULTTAG
2829 yyresolveStates (glr_state& yys, int yyn)
2831 if (0 < yyn)
2833 YYASSERT (yys.pred() != YY_NULLPTR);
2834 YYCHK (yyresolveStates (*yys.pred(), yyn-1));
2835 if (! yys.yyresolved)
2836 YYCHK (yyresolveValue (yys));
2838 return yyok;
2841 static void
2842 yyuserMerge (int yyn, value_type& yy0, value_type& yy1)
2844 YY_USE (yy0);
2845 YY_USE (yy1);
2847 switch (yyn)
2849 ]b4_mergers[
2850 default: break;
2854 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2855 * perform the indicated actions, and set the semantic value of YYS.
2856 * If result != yyok, the chain of semantic options in YYS has been
2857 * cleared instead or it has been left unmodified except that
2858 * redundant options may have been removed. Regardless of whether
2859 * result = yyok, YYS has been left with consistent data so that
2860 * destroy can be invoked if necessary. */
2861 YYRESULTTAG
2862 yyresolveValue (glr_state& yys)
2864 semantic_option* yybest = yys.firstVal();
2865 YYASSERT(yybest != YY_NULLPTR);
2866 bool yymerge = false;
2867 YYRESULTTAG yyflag;]b4_locations_if([
2868 location_type *yylocp = &yys.yyloc;])[
2870 semantic_option* yypPrev = yybest;
2871 for (semantic_option* yyp = yybest->next();
2872 yyp != YY_NULLPTR; )
2874 if (yybest->isIdenticalTo (*yyp))
2876 yybest->mergeWith (*yyp);
2877 yypPrev->setNext(yyp->next());
2878 yyp = yypPrev->next();
2880 else
2882 switch (yypreference (*yybest, *yyp))
2884 case 0:]b4_locations_if([[
2885 yyresolveLocations (yys, 1);]])[
2886 return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[);
2887 break;
2888 case 1:
2889 yymerge = true;
2890 break;
2891 case 2:
2892 break;
2893 case 3:
2894 yybest = yyp;
2895 yymerge = false;
2896 break;
2897 default:
2898 /* This cannot happen so it is not worth a YYASSERT (false),
2899 but some compilers complain if the default case is
2900 omitted. */
2901 break;
2903 yypPrev = yyp;
2904 yyp = yyp->next();
2908 value_type val;
2909 if (yymerge)
2911 int yyprec = yydprec[yybest->yyrule];
2912 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2913 if (yyflag == yyok)
2914 for (semantic_option* yyp = yybest->next();
2915 yyp != YY_NULLPTR;
2916 yyp = yyp->next())
2918 if (yyprec == yydprec[yyp->yyrule])
2920 value_type yyval_other;]b4_locations_if([
2921 location_type yydummy;])[
2922 yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[);
2923 if (yyflag != yyok)
2925 yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2926 yy_accessing_symbol (yys.yylrState),
2927 this->yyla.value]b4_locations_if([, *yylocp])[);
2928 break;
2930 yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
2931 // FIXME: User destructors.
2932 // Value type destructor.
2933 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[
2937 else
2938 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2940 if (yyflag == yyok)
2942 yys.yyresolved = true;
2943 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[
2944 new (&yys.value ()) value_type ();
2945 ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)],
2946 [yys.value ()], [copy], [val])], [[
2947 new (&yys.value ()) value_type (val);]])[
2949 YY_IGNORE_MAYBE_UNINITIALIZED_END
2951 else
2952 yys.setFirstVal(YY_NULLPTR);
2953 ]b4_variant_if([[
2954 // FIXME: User destructors.
2955 // Value type destructor.
2956 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[
2957 return yyflag;
2960 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2961 * user action, and return the semantic value and location in *YYVALP
2962 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2963 * have been destroyed (assuming the user action destroys all RHS
2964 * semantic values if invoked). */
2965 YYRESULTTAG
2966 yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2968 glr_state* yyoptState = yyopt.state();
2969 YYASSERT(yyoptState != YY_NULLPTR);
2970 int yynrhs = yyrhsLength (yyopt.yyrule);
2971 YYRESULTTAG yyflag = yyresolveStates (*yyoptState, yynrhs);
2972 if (yyflag != yyok)
2974 for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1)
2975 yys->destroy ("Cleanup: popping", yyparser);
2976 return yyflag;
2979 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
2980 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[
2981 if (yynrhs == 0)
2982 /* Set default location. */
2983 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
2985 symbol_type yyla_current = std::move (this->yyla);
2986 this->yyla = std::move (yyopt.yyla);
2987 yyflag = yyuserAction (yyopt.yyrule, yynrhs,
2988 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
2989 create_state_set_index (-1),
2990 yyvalp]b4_locations_if([, yylocp])[);
2991 this->yyla = std::move (yyla_current);
2993 return yyflag;
2994 }]b4_locations_if([[
2996 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
2997 * ending at YYS1. Has no effect on previously resolved states.
2998 * The first semantic option of a state is always chosen. */
2999 void
3000 yyresolveLocations (glr_state &yys1, int yyn1)
3002 if (0 < yyn1)
3004 yyresolveLocations (*yys1.pred(), yyn1 - 1);
3005 if (!yys1.yyresolved)
3007 glr_stack_item yyrhsloc[1 + YYMAXRHS];
3008 YYASSERT (yys1.firstVal() != YY_NULLPTR);
3009 semantic_option& yyoption = *yys1.firstVal();
3010 const int yynrhs = yyrhsLength (yyoption.yyrule);
3011 if (0 < yynrhs)
3013 yyresolveLocations (*yyoption.state(), yynrhs);
3014 const glr_state *yys = yyoption.state();
3015 for (int yyn = yynrhs; yyn > 0; yyn -= 1)
3017 yyrhsloc[yyn].getState().yyloc = yys->yyloc;
3018 yys = yys->pred();
3021 else
3023 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3024 in reverse rightmost order. It is only necessary to invoke
3025 yyresolveLocations on a subforest for which yyresolveAction
3026 would have been invoked next had an ambiguity not been
3027 detected. Thus the location of the previous state (but not
3028 necessarily the previous state itself) is guaranteed to be
3029 resolved already. */
3030 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3031 yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc;
3032 YY_IGNORE_NULL_DEREFERENCE_END
3034 YYLLOC_DEFAULT ((yys1.yyloc), yyrhsloc, yynrhs);
3037 }]])[
3039 /** If yytoken is empty, fetch the next token. */
3040 void
3041 yyget_token ()
3043 ]b4_parse_param_use()dnl
3044 [ if (this->yyla.empty ())
3046 YYCDEBUG << "Reading a token\n";
3047 #if YY_EXCEPTIONS
3049 #endif // YY_EXCEPTIONS
3050 {]b4_token_ctor_if([[
3051 symbol_type yylookahead (]b4_yylex[);
3052 yyla.move (yylookahead);]], [[
3053 yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[
3055 #if YY_EXCEPTIONS
3056 catch (const parser_type::syntax_error& yyexc)
3058 YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
3059 this->yyla.location = yyexc.location;])[
3060 yyparser.error (]b4_locations_if([this->yyla.location, ])[yyexc.what ());
3061 // Map errors caught in the scanner to the error token, so that error
3062 // handling is started.
3063 this->yyla.kind_ = ]b4_symbol(error, kind)[;
3066 #endif // YY_EXCEPTIONS
3067 if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
3068 YYCDEBUG << "Now at end of input.\n";
3069 else
3070 YY_SYMBOL_PRINT ("Next token is", this->yyla.kind (), this->yyla.value, this->yyla.location);
3074 /* Bison grammar-table manipulation. */
3076 /** The action to take in YYSTATE on seeing YYTOKEN.
3077 * Result R means
3078 * R < 0: Reduce on rule -R.
3079 * R = 0: Error.
3080 * R > 0: Shift to state R.
3081 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3082 * of conflicting reductions.
3084 static int
3085 yygetLRActions (state_num yystate, symbol_kind_type yytoken, const short*& yyconflicts)
3087 int yyindex = yypact[yystate] + yytoken;
3088 if (yytoken == ]b4_symbol(error, kind)[)
3090 // This is the error token.
3091 yyconflicts = yyconfl;
3092 return 0;
3094 else if (yy_is_defaulted_state (yystate)
3095 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
3097 yyconflicts = yyconfl;
3098 return -yydefact[yystate];
3100 else if (! yytable_value_is_error (yytable[yyindex]))
3102 yyconflicts = yyconfl + yyconflp[yyindex];
3103 return yytable[yyindex];
3105 else
3107 yyconflicts = yyconfl + yyconflp[yyindex];
3108 return 0;
3112 /** Compute post-reduction state.
3113 * \param yystate the current state
3114 * \param yysym the nonterminal to push on the stack
3116 static state_num
3117 yyLRgotoState (state_num yystate, symbol_kind_type yysym)
3119 const int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
3120 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
3121 return yytable[yyr];
3122 else
3123 return yydefgoto[yysym - YYNTOKENS];
3126 static bool
3127 yypact_value_is_default (state_num yystate)
3129 return ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf], [YYPACT_NINF])[;
3132 static bool
3133 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED)
3135 return ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[;
3138 static bool
3139 yy_is_shift_action (int yyaction) YY_NOEXCEPT
3141 return 0 < yyaction;
3144 static bool
3145 yy_is_error_action (int yyaction) YY_NOEXCEPT
3147 return yyaction == 0;
3150 /** Whether LR state YYSTATE has only a default reduction
3151 * (regardless of token). */
3152 static bool
3153 yy_is_defaulted_state (state_num yystate)
3155 return yypact_value_is_default (yypact[yystate]);
3158 /** The default reduction for YYSTATE, assuming it has one. */
3159 static rule_num
3160 yy_default_action (state_num yystate)
3162 return yydefact[yystate];
3165 /* GLRStacks */
3167 /** Y0 and Y1 represent two possible actions to take in a given
3168 * parsing state; return 0 if no combination is possible,
3169 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3170 static int
3171 yypreference (const semantic_option& y0, const semantic_option& y1)
3173 const rule_num r0 = y0.yyrule, r1 = y1.yyrule;
3174 const int p0 = yydprec[r0], p1 = yydprec[r1];
3176 if (p0 == p1)
3178 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
3179 return 0;
3180 else
3181 return 1;
3183 else if (p0 == 0 || p1 == 0)
3184 return 0;
3185 else if (p0 < p1)
3186 return 3;
3187 else if (p1 < p0)
3188 return 2;
3189 else
3190 return 0;
3193 ]b4_parse_param_vars[
3194 }; // class ]b4_parser_class[::glr_stack
3195 } // namespace ]b4_namespace_ref[
3198 #if ]b4_api_PREFIX[DEBUG
3199 namespace
3201 void
3202 yypstack (const glr_stack& yystack, size_t yyk)
3204 yystack.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk)));
3207 void
3208 yypdumpstack (const glr_stack& yystack)
3210 yystack.yypdumpstack ();
3213 #endif
3215 ]b4_namespace_open[
3216 /// Build a parser object.
3217 ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
3218 :])[
3219 #if ]b4_api_PREFIX[DEBUG
3220 ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
3221 #endif]b4_parse_param_cons[
3224 ]b4_parser_class::~b4_parser_class[ ()
3227 ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3231 ]b4_parser_class[::operator() ()
3233 return parse ();
3237 ]b4_parser_class[::parse ()
3239 glr_stack yystack(YYINITDEPTH, *this]b4_user_args[);
3240 return yystack.parse ();
3243 ]b4_parse_error_bmatch([custom\|detailed],
3244 [[ const char *
3245 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3247 static const char *const yy_sname[] =
3249 ]b4_symbol_names[
3250 };]b4_has_translations_if([[
3251 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3252 internationalizable. */
3253 static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
3255 ]b4_translatable[
3257 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
3258 ? _(yy_sname[yysymbol])
3259 : yy_sname[yysymbol]);]], [[
3260 return yy_sname[yysymbol];]])[
3263 [simple],
3264 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3265 const char *
3266 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3268 return yytname_[yysymbol];
3270 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3272 [verbose],
3273 [[ /* Return YYSTR after stripping away unnecessary quotes and
3274 backslashes, so that it's suitable for yyerror. The heuristic is
3275 that double-quoting is unnecessary unless the string contains an
3276 apostrophe, a comma, or backslash (other than backslash-backslash).
3277 YYSTR is taken from yytname. */
3278 std::string
3279 ]b4_parser_class[::yytnamerr_ (const char *yystr)
3281 if (*yystr == '"')
3283 std::string yyr;
3284 char const *yyp = yystr;
3286 for (;;)
3287 switch (*++yyp)
3289 case '\'':
3290 case ',':
3291 goto do_not_strip_quotes;
3293 case '\\':
3294 if (*++yyp != '\\')
3295 goto do_not_strip_quotes;
3296 else
3297 goto append;
3299 append:
3300 default:
3301 yyr += *yyp;
3302 break;
3304 case '"':
3305 return yyr;
3307 do_not_strip_quotes: ;
3310 return yystr;
3313 std::string
3314 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3316 return yytnamerr_ (yytname_[yysymbol]);
3318 ]])[
3320 ]b4_parse_error_bmatch([simple\|verbose],
3321 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3322 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3323 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3324 const char*
3325 const ]b4_parser_class[::yytname_[] =
3327 ]b4_tname[
3329 #endif
3330 ]])[
3332 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
3333 // ]b4_parser_class[::context.
3334 ]b4_parser_class[::context::context (glr_stack& yystack, const symbol_type& yyla)
3335 : yystack_ (yystack)
3336 , yyla_ (yyla)
3340 ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const
3342 // Actual number of expected tokens
3343 int yycount = 0;
3344 const int yyn = yypact[yystack_.firstTopState()->yylrState];
3345 if (!yystack_.yypact_value_is_default (yyn))
3347 /* Start YYX at -YYN if negative to avoid negative indexes in
3348 YYCHECK. In other words, skip the first -YYN actions for this
3349 state because they are default actions. */
3350 const int yyxbegin = yyn < 0 ? -yyn : 0;
3351 /* Stay within bounds of both yycheck and yytname. */
3352 const int yychecklim = YYLAST - yyn + 1;
3353 const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
3354 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
3355 if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
3356 && !yystack_.yytable_value_is_error (yytable[yyx + yyn]))
3358 if (!yyarg)
3359 ++yycount;
3360 else if (yycount == yyargn)
3361 return 0;
3362 else
3363 yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx);
3366 if (yyarg && yycount == 0 && 0 < yyargn)
3367 yyarg[0] = ]b4_symbol(empty, kind)[;
3368 return yycount;
3371 ]])[
3373 ]b4_parse_error_bmatch([detailed\|verbose], [[
3375 ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx,
3376 symbol_kind_type yyarg[], int yyargn) const
3378 /* There are many possibilities here to consider:
3379 - If this state is a consistent state with a default action, then
3380 the only way this function was invoked is if the default action
3381 is an error action. In that case, don't check for expected
3382 tokens because there are none.
3383 - The only way there can be no lookahead present (in yyla) is
3384 if this state is a consistent state with a default action.
3385 Thus, detecting the absence of a lookahead is sufficient to
3386 determine that there is no unexpected or expected token to
3387 report. In that case, just report a simple "syntax error".
3388 - Don't assume there isn't a lookahead just because this state is
3389 a consistent state with a default action. There might have
3390 been a previous inconsistent state, consistent state with a
3391 non-default action, or user semantic action that manipulated
3392 yyla. (However, yyla is currently not documented for users.)
3395 if (!yyctx.lookahead ().empty ())
3397 if (yyarg)
3398 yyarg[0] = yyctx.token ();
3399 int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1);
3400 return yyn + 1;
3402 return 0;
3405 // Generate an error message.
3406 std::string
3407 ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const
3409 // Its maximum.
3410 enum { YYARGS_MAX = 5 };
3411 // Arguments of yyformat.
3412 symbol_kind_type yyarg[YYARGS_MAX];
3413 int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX);
3415 char const* yyformat = YY_NULLPTR;
3416 switch (yycount)
3418 #define YYCASE_(N, S) \
3419 case N: \
3420 yyformat = S; \
3421 break
3422 default: // Avoid compiler warnings.
3423 YYCASE_ (0, YY_("syntax error"));
3424 YYCASE_ (1, YY_("syntax error, unexpected %s"));
3425 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
3426 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
3427 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
3428 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
3429 #undef YYCASE_
3432 std::string yyres;
3433 // Argument number.
3434 std::ptrdiff_t yyi = 0;
3435 for (char const* yyp = yyformat; *yyp; ++yyp)
3436 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
3438 yyres += symbol_name (yyarg[yyi++]);
3439 ++yyp;
3441 else
3442 yyres += *yyp;
3443 return yyres;
3444 }]])[
3446 void
3447 ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
3448 value_type& yyval]b4_locations_if([[,
3449 location_type& yyloc]])[)
3451 YY_USE (yyval);]b4_locations_if([[
3452 YY_USE (yyloc);]])[
3453 if (!yymsg)
3454 yymsg = "Deleting";
3455 ]b4_parser_class[& yyparser = *this;
3456 YY_USE (yyparser);
3457 YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc);
3459 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3460 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3461 [b4_symbol_actions([destructor])],
3462 [m4_popdef([b4_symbol_action])])[
3463 YY_IGNORE_MAYBE_UNINITIALIZED_END
3466 #if ]b4_api_PREFIX[DEBUG
3467 /*--------------------.
3468 | Print this symbol. |
3469 `--------------------*/
3471 void
3472 ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
3473 const value_type& yyval]b4_locations_if([[,
3474 const location_type& yyloc]])[) const
3475 {]b4_locations_if([[
3476 YY_USE (yyloc);]])[
3477 YY_USE (yyval);
3478 std::ostream& yyo = debug_stream ();
3479 YY_USE (yyo);
3480 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3481 [b4_symbol_actions([printer])],
3482 [m4_popdef([b4_symbol_action])])[
3485 void
3486 ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
3487 const value_type& yyval]b4_locations_if([[,
3488 const location_type& yyloc]])[) const
3490 *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
3491 << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
3492 << yyloc << ": "]])[;
3493 yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[);
3494 *yycdebug_ << ')';
3497 std::ostream&
3498 ]b4_parser_class[::debug_stream () const
3500 return *yycdebug_;
3503 void
3504 ]b4_parser_class[::set_debug_stream (std::ostream& o)
3506 yycdebug_ = &o;
3510 ]b4_parser_class[::debug_level_type
3511 ]b4_parser_class[::debug_level () const
3513 return yydebug;
3516 void
3517 ]b4_parser_class[::set_debug_level (debug_level_type l)
3519 // Actually, it is yydebug which is really used.
3520 yydebug = l;
3522 #endif // ]b4_api_PREFIX[DEBUG
3524 ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[
3526 ]b4_token_ctor_if([], [[
3527 /*---------.
3528 | symbol. |
3529 `---------*/
3530 ]b4_public_types_define([cc])])[
3531 ]b4_namespace_close[]dnl
3532 b4_epilogue[]dnl
3533 b4_output_end