glr2.cc: remove remains from glr.cc
[bison.git] / data / skeletons / glr2.cc
blob5f2f836eb873492f427af27ff547583ae773732e
1 # C++ GLR skeleton for Bison
3 # Copyright (C) 2002-2015, 2018-2020 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 <http://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))
45 ## ---------------- ##
46 ## Default values. ##
47 ## ---------------- ##
49 # Stack parameters.
50 m4_define_default([b4_stack_depth_max], [10000])
51 m4_define_default([b4_stack_depth_init], [200])
55 ## ------------ ##
56 ## Interfaces. ##
57 ## ------------ ##
59 # b4_user_formals
60 # ---------------
61 # The possible parse-params formal arguments preceded by a comma.
63 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
64 # formal argument declarations.
65 m4_define([b4_user_formals],
66 [m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
69 # b4_symbol_kind(NUM)
70 # -------------------
71 m4_define([b4_symbol_kind],
72 [symbol_kind::b4_symbol_kind_base($@)])
75 ## ----------------- ##
76 ## Semantic Values. ##
77 ## ----------------- ##
80 # b4_lhs_value(SYMBOL-NUM, [TYPE])
81 # --------------------------------
82 # See README.
83 m4_define([b4_lhs_value],
84 [b4_symbol_value([(*yyvalp)], [$1], [$2])])
87 # b4_rhs_data(RULE-LENGTH, POS)
88 # -----------------------------
89 # See README.
90 m4_define([b4_rhs_data],
91 [(static_cast<glr_stack_item const *>(yyvsp))@{YYFILL (b4_subtract([$2], [$1]))@}.getState()])
94 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
95 # --------------------------------------------------
96 # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
97 m4_define([b4_rhs_value],
98 [b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])])
102 ## ----------- ##
103 ## Locations. ##
104 ## ----------- ##
106 # b4_lhs_location()
107 # -----------------
108 # Expansion of @$.
109 m4_define([b4_lhs_location],
110 [(*yylocp)])
113 # b4_rhs_location(RULE-LENGTH, NUM)
114 # ---------------------------------
115 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
116 # on RHS.
117 m4_define([b4_rhs_location],
118 [(b4_rhs_data([$1], [$2]).yyloc)])
121 # b4_symbol_action(SYMBOL-NUM, KIND)
122 # ----------------------------------
123 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
124 # Same as in C, but using references instead of pointers.
125 m4_define([b4_symbol_action],
126 [b4_symbol_if([$1], [has_$2],
127 [b4_dollar_pushdef([yyval],
128 [$1],
130 [yyloc])dnl
131 _b4_symbol_case([$1])[]dnl
132 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
133 b4_symbol([$1], [$2])
134 b4_syncline([@oline@], [@ofile@])dnl
135 break;
137 b4_dollar_popdef[]dnl
138 ])])
141 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
142 # ---------------------------------------------------
143 m4_define([b4_call_merger],
144 [b4_case([$1],
145 [ b4_symbol_if([$3], [has_type],
146 [b4_variant_if([yy0.as<b4_symbol($3, type)> () = $2 (yy0.as<b4_symbol($3, type)>(), yy1.as<b4_symbol($3, type)>());],
147 [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])],
148 [yy0 = $2 (yy0, yy1);])])])
150 # b4_lex
151 # ------
152 # Call yylex.
153 m4_define([b4_lex],
154 [b4_token_ctor_if(
155 [b4_function_call([yylex],
156 [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
157 [b4_function_call([yylex], [int],
158 [b4_api_PREFIX[STYPE*], [&yystack.yylval]][]dnl
159 b4_locations_if([, [[location*], [&yystack.yylloc]]])dnl
160 m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
163 # b4_shared_declarations(hh|cc)
164 # -----------------------------
165 # Declaration that might either go into the header (if --header, $1 = hh)
166 # or in the implementation file.
167 m4_define([b4_shared_declarations],
168 [b4_percent_code_get([[requires]])[
169 #include <algorithm>
170 #include <cstddef> // ptrdiff_t
171 #include <cstring> // memcpy
172 #include <iostream>
173 #include <iomanip>
174 #include <limits>
175 #include <stdexcept>
176 #include <stdint.h>
177 #include <string>
178 #include <vector>
180 ]b4_cxx_portability[
181 ]m4_ifdef([b4_location_include],
182 [[# include ]b4_location_include])[
183 ]b4_variant_if([b4_variant_includes])[
185 // Whether we are compiled with exception support.
186 #ifndef YY_EXCEPTIONS
187 # if defined __GNUC__ && !defined __EXCEPTIONS
188 # define YY_EXCEPTIONS 0
189 # else
190 # define YY_EXCEPTIONS 1
191 # endif
192 #endif
194 ]b4_YYDEBUG_define[
196 ]b4_namespace_open[
198 template <typename Parameter>
199 class strong_index_alias
201 public:
202 static strong_index_alias create(std::ptrdiff_t value) {
203 strong_index_alias result;
204 result.value_ = value;
205 return result;
208 std::ptrdiff_t const& get() const { return value_; }
210 size_t uget() const { return static_cast<size_t>(value_); }
212 strong_index_alias operator+(std::ptrdiff_t other) const {
213 return strong_index_alias(get() + other);
216 void operator+=(std::ptrdiff_t other) {
217 value_ += other;
220 strong_index_alias operator-(std::ptrdiff_t other) {
221 return strong_index_alias(get() - other);
224 void operator-=(std::ptrdiff_t other) {
225 value_ -= other;
228 size_t operator-(strong_index_alias other) {
229 return strong_index_alias(get() - other.get());
232 strong_index_alias& operator++() {
233 ++value_;
234 return *this;
237 bool isValid() const {
238 return value_ != INVALID_INDEX;
241 void setInvalid() {
242 value_ = INVALID_INDEX;
245 bool operator==(strong_index_alias other) {
246 return get() == other.get();
249 bool operator!=(strong_index_alias other) {
250 return get() != other.get();
253 bool operator<(strong_index_alias other) {
254 return get() < other.get();
257 private:
258 static const std::ptrdiff_t INVALID_INDEX;
260 // WARNING: 0-initialized.
261 std::ptrdiff_t value_;
264 template<typename T>
265 const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
266 std::numeric_limits<std::ptrdiff_t>::max();
268 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
269 [b4_location_define])])[
271 /// A Bison parser.
272 class ]b4_parser_class[
274 public:
275 ]b4_public_types_declare[
276 ]b4_symbol_type_define[
278 /// Build a parser object.
279 ]b4_parser_class[ (]b4_parse_param_decl[);
280 virtual ~]b4_parser_class[ ();
282 /// Parse. An alias for parse ().
283 /// \returns 0 iff parsing succeeded.
284 int operator() ();
286 /// Parse.
287 /// \returns 0 iff parsing succeeded.
288 virtual int parse ();
290 #if ]b4_api_PREFIX[DEBUG
291 /// The current debugging stream.
292 std::ostream& debug_stream () const;
293 /// Set the current debugging stream.
294 void set_debug_stream (std::ostream &);
296 /// Type for debugging levels.
297 typedef int debug_level_type;
298 /// The current debugging level.
299 debug_level_type debug_level () const;
300 /// Set the current debugging level.
301 void set_debug_level (debug_level_type l);
302 #endif
304 /// Report a syntax error.]b4_locations_if([[
305 /// \param loc where the syntax error is found.]])[
306 /// \param msg a description of the syntax error.
307 virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
309 ]b4_parse_error_bmatch(
310 [custom\|detailed],
311 [[ /// The user-facing name of the symbol whose (internal) number is
312 /// YYSYMBOL. No bounds checking.
313 static const char *symbol_name (symbol_kind_type yysymbol);]],
314 [simple],
315 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
316 /// The user-facing name of the symbol whose (internal) number is
317 /// YYSYMBOL. No bounds checking.
318 static const char *symbol_name (symbol_kind_type yysymbol);
319 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
321 [verbose],
322 [[ /// The user-facing name of the symbol whose (internal) number is
323 /// YYSYMBOL. No bounds checking.
324 static std::string symbol_name (symbol_kind_type yysymbol);]])[
326 ]b4_token_constructor_define[
327 # if ]b4_api_PREFIX[DEBUG
328 public:
329 /// \brief Report a symbol value on the debug stream.
330 /// \param yykind The symbol kind.
331 /// \param yyval Its semantic value.]b4_locations_if([[
332 /// \param yyloc Its location.]])[
333 virtual void yy_symbol_value_print_ (symbol_kind_type yykind,
334 const value_type& yyval]b4_locations_if([[,
335 const location_type& yyloc]])[) const;
336 /// \brief Report a symbol on the debug stream.
337 /// \param yykind The symbol kind.
338 /// \param yyval Its semantic value.]b4_locations_if([[
339 /// \param yyloc Its location.]])[
340 virtual void yy_symbol_print_ (symbol_kind_type yykind,
341 const value_type& yyval]b4_locations_if([[,
342 const location_type& yyloc]])[) const;
343 private:
344 /// Debug stream.
345 std::ostream* yycdebug_;
346 #endif
348 public: // FIXME: Private
349 /// Convert a scanner token kind \a t to a symbol kind.
350 /// In theory \a t should be a token_kind_type, but character literals
351 /// are valid, yet not members of the token_type enum.
352 static symbol_kind_type yytranslate_ (int t);
354 ]b4_parse_error_bmatch(
355 [simple],
356 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
357 /// For a symbol, its name in clear.
358 static const char* const yytname_[];
359 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
361 [verbose],
362 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
363 static std::string yytnamerr_ (const char *yystr);
365 /// For a symbol, its name in clear.
366 static const char* const yytname_[];
367 ]])[
369 /// \brief Reclaim the memory associated to a symbol.
370 /// \param yymsg Why this token is reclaimed.
371 /// If null, print nothing.
372 /// \param yykind The symbol kind.
373 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
374 value_type& yyval]b4_locations_if([[,
375 location_type& yyloc]])[);
377 ]b4_parse_param_vars[
380 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
381 ]b4_public_types_define([$1])])[
382 ]b4_namespace_close[
384 ]b4_percent_code_get([[provides]])[
385 ]])[
388 ## -------------- ##
389 ## Output files. ##
390 ## -------------- ##
393 # ------------- #
394 # Header file. #
395 # ------------- #
397 ]b4_header_if([[
398 ]b4_output_begin([b4_spec_header_file])[
399 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
400 [2002-2015, 2018-2020])[
401 // C++ GLR parser skeleton written by Valentin Tolmer.
403 ]b4_disclaimer[
404 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
405 ]b4_shared_declarations([hh])[
406 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
407 ]b4_output_end])[
410 # --------------------- #
411 # Implementation file. #
412 # --------------------- #
414 ]b4_output_begin([b4_parser_file_name])[
415 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
416 [2002-2015, 2018-2019])[
417 // C++ GLR parser skeleton written by Valentin Tolmer.
419 ]b4_disclaimer[
420 ]b4_identification[
422 ]b4_percent_code_get([[top]])[
423 ]m4_if(b4_prefix, [yy], [],
424 [[/* Substitute the variable and function names. */
425 #define yyparse ]b4_prefix[parse
426 #define yylex ]b4_prefix[lex
427 #define yyerror ]b4_prefix[error
428 #define yydebug ]b4_prefix[debug]])[
430 ]b4_user_pre_prologue[
432 ]b4_null_define[
434 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
435 [b4_shared_declarations([cc])])[
437 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
439 /* Default (constant) value used for initialization for null
440 right-hand sides. Unlike the standard yacc.c template, here we set
441 the default value of $$ to a zeroed-out value. Since the default
442 value is undefined, this behavior is technically correct. */
443 static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;]b4_locations_if([[
444 static ]b4_namespace_ref[::]b4_parser_class[::location_type yyloc_default][]b4_yyloc_default;])[
446 ]b4_user_post_prologue[
447 ]b4_percent_code_get[]dnl
449 [#include <cstdio>
450 #include <cstdlib>
452 #ifndef YY_
453 # if defined YYENABLE_NLS && YYENABLE_NLS
454 # if ENABLE_NLS
455 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
456 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
457 # endif
458 # endif
459 # ifndef YY_
460 # define YY_(Msgid) Msgid
461 # endif
462 #endif
464 #ifndef YYFREE
465 # define YYFREE free
466 #endif
467 #ifndef YYMALLOC
468 # define YYMALLOC malloc
469 #endif
471 #ifndef YYSETJMP
472 # include <setjmp.h>
473 # define YYJMP_BUF jmp_buf
474 # define YYSETJMP(Env) setjmp (Env)
475 /* Pacify Clang and ICC. */
476 # define YYLONGJMP(Env, Val) \
477 do { \
478 longjmp (Env, Val); \
479 YYASSERT (0); \
480 } while (false)
481 #endif
483 ]b4_attribute_define([noreturn])[
485 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
486 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
487 _Pragma ("GCC diagnostic push") \
488 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
489 # define YY_IGNORE_NULL_DEREFERENCE_END \
490 _Pragma ("GCC diagnostic pop")
491 #else
492 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
493 # define YY_IGNORE_NULL_DEREFERENCE_END
494 #endif
496 ]b4_null_define[
497 ]b4_cast_define[
499 // FIXME: Use the same conventions as lalr1.cc.
500 ]b4_parse_assert_if[
501 #ifndef YYASSERT
502 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
503 #endif
505 #ifdef YYDEBUG
506 # define YYDASSERT(Condition) YYASSERT(Condition)
507 #else
508 # define YYDASSERT(Condition)
509 #endif
511 /* YYFINAL -- State number of the termination state. */
512 #define YYFINAL ]b4_final_state_number[
513 /* YYLAST -- Last index in YYTABLE. */
514 #define YYLAST ]b4_last[
516 /* YYNTOKENS -- Number of terminals. */
517 #define YYNTOKENS ]b4_tokens_number[
518 /* YYNNTS -- Number of nonterminals. */
519 #define YYNNTS ]b4_nterms_number[
520 /* YYNRULES -- Number of rules. */
521 #define YYNRULES ]b4_rules_number[
522 /* YYNSTATES -- Number of states. */
523 #define YYNSTATES ]b4_states_number[
524 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
525 #define YYMAXRHS ]b4_r2_max[
526 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
527 accessed by $0, $-1, etc., in any rule. */
528 #define YYMAXLEFT ]b4_max_left_semantic_context[
530 #if ]b4_api_PREFIX[DEBUG
531 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
532 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
534 ]b4_rline[
536 #endif
538 #define YYPACT_NINF ]b4_pact_ninf[
539 #define YYTABLE_NINF ]b4_table_ninf[
541 ]b4_parser_tables_define[
543 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
544 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
546 ]b4_dprec[
549 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
550 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
552 ]b4_merger[
555 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
556 in the case of predicates. */
557 static const bool yyimmediate[] =
559 ]b4_immediate[
562 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
563 list of conflicting reductions corresponding to action entry for
564 state STATE-NUM in yytable. 0 means no conflicts. The list in
565 yyconfl is terminated by a rule number of 0. */
566 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
568 ]b4_conflict_list_heads[
571 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
572 0, pointed into by YYCONFLP. */
573 ]dnl Do not use b4_int_type_for here, since there are places where
574 dnl pointers onto yyconfl are taken, whose type is "short*".
575 dnl We probably ought to introduce a type for confl.
576 [static const short yyconfl[] =
578 ]b4_conflicting_rules[
581 /* Error token number */
582 #define YYTERROR 1
584 ]b4_locations_if([[
585 ]b4_yylloc_default_define[
586 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
587 ]])[
589 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
591 #define YYCHK(YYE) \
592 do { \
593 YYRESULTTAG yychk_flag = YYE; \
594 if (yychk_flag != yyok) \
595 return yychk_flag; \
596 } while (false)
598 #if ]b4_api_PREFIX[DEBUG
600 ]b4_yy_location_print_define[
602 #define YYCDEBUG if (!yydebug) {} else std::cerr
604 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
605 do { \
606 if (yydebug) \
608 std::cerr << Title << ' '; \
609 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
610 std::cerr << '\n'; \
612 } while (false)
614 # define YY_REDUCE_PRINT(Args) \
615 do { \
616 if (yydebug) \
617 yystateStack.yy_reduce_print Args; \
618 } while (false)
620 /* Nonzero means print parse trace. It is left uninitialized so that
621 multiple parsers can coexist. */
622 int yydebug;
624 class glr_stack;
625 static void yypstack (const glr_stack& yystack, size_t yyk)
626 YY_ATTRIBUTE_UNUSED;
627 static void yypdumpstack (const glr_stack& yystack)
628 YY_ATTRIBUTE_UNUSED;
630 #else /* !]b4_api_PREFIX[DEBUG */
632 # define YYCDEBUG if (true) {} else std::cerr
633 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
634 # define YY_REDUCE_PRINT(Args) {}
636 #endif /* !]b4_api_PREFIX[DEBUG */
638 /* YYINITDEPTH -- initial size of the parser's stacks. */
639 #ifndef YYINITDEPTH
640 # define YYINITDEPTH ]b4_stack_depth_init[
641 #endif
643 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
644 if the built-in stack extension method is used).
646 Do not make this value too large; the results are undefined if
647 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
648 evaluated with infinite-precision integer arithmetic. */
650 #ifndef YYMAXDEPTH
651 # define YYMAXDEPTH ]b4_stack_depth_max[
652 #endif
654 /* Minimum number of free items on the stack allowed after an
655 allocation. This is to allow allocation and initialization
656 to be completed by functions that call yyexpandGLRStack before the
657 stack is expanded, thus insuring that all necessary pointers get
658 properly redirected to new data. */
659 #define YYHEADROOM 2
661 #ifndef YYSTACKEXPANDABLE
662 # define YYSTACKEXPANDABLE 1
663 #endif
665 /** State numbers, as in LALR(1) machine */
666 typedef int state_num;
668 /** Rule numbers, as in LALR(1) machine */
669 typedef int rule_num;
671 // Forward declarations.
672 class glr_state;
673 class semantic_option;
674 class glr_stack_item;
675 class glr_stack;
677 typedef ]b4_namespace_ref[::strong_index_alias<struct glr_state_set_tag> state_set_index;
679 state_set_index create_state_set_index(std::ptrdiff_t value)
681 return state_set_index::create(value);
684 #define yypact_value_is_default(Yystate) \
685 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf], [YYPACT_NINF])[
687 #define yytable_value_is_error(Yytable_value) \
688 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[
690 static inline void
691 yygetToken (]b4_namespace_ref[::]b4_parser_class[& yyparser, glr_stack& yystack]b4_user_formals[);
693 static inline bool
694 yyisShiftAction (int yyaction)
696 return 0 < yyaction;
699 static inline bool
700 yyisErrorAction (int yyaction)
702 return yyaction == 0;
705 static inline int
706 yygetLRActions (state_num yystate, yysymbol_kind_t yytoken, const short*& yyconflicts);
708 /** Accessing symbol of state YYSTATE. */
709 static inline yysymbol_kind_t
710 yy_accessing_symbol (state_num yystate)
712 return YY_CAST (yysymbol_kind_t, yystos[yystate]);
715 /** True iff LR state YYSTATE has only a default reduction (regardless
716 * of token). */
717 static inline bool
718 yyisDefaultedState (state_num yystate)
720 return yypact_value_is_default (yypact[yystate]);
723 /** The default reduction for YYSTATE, assuming it has one. */
724 static inline rule_num
725 yydefaultAction (state_num yystate)
727 return yydefact[yystate];
730 /** Left-hand-side symbol for rule #YYRULE. */
731 static inline yysymbol_kind_t
732 yylhsNonterm (rule_num yyrule)
734 return static_cast<yysymbol_kind_t>(yyr1[yyrule]);
737 static inline int
738 yyrhsLength (rule_num yyrule);
741 class glr_state
743 public:
744 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
745 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
746 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
747 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
749 glr_state ()
750 : yyresolved (false)
751 , yylrState (0)
752 , yyposn (0)
753 , yypred (0)
754 , yyfirstVal (0)]b4_locations_if([[
755 , yyloc ()]])[]b4_parse_assert_if([[
756 , magic_ (MAGIC)]])[
759 /// Build with a semantic value.
760 glr_state (state_num lrState, size_t posn, const value_type& val]b4_locations_if([[, const location_type& loc]])[)
761 : yyresolved (true)
762 , yylrState (lrState)
763 , yyposn (posn)
764 , yypred (0)
765 , yyval (]b4_variant_if([], [[val]])[)]b4_locations_if([[
766 , yyloc (loc)]])[]b4_parse_assert_if([[
767 , magic_ (MAGIC)]])[
768 {]b4_variant_if([[
769 ]b4_symbol_variant([yy_accessing_symbol (lrState)],
770 [yyval], [copy], [val])])[}
772 /// Build with a semantic option.
773 glr_state (state_num lrState, size_t posn)
774 : yyresolved (false)
775 , yylrState (lrState)
776 , yyposn (posn)
777 , yypred (0)
778 , yyfirstVal (0)]b4_locations_if([[
779 , yyloc ()]])[]b4_parse_assert_if([[
780 , magic_ (MAGIC)]])[
783 glr_state (const glr_state& other)
784 : yyresolved (other.yyresolved)
785 , yylrState (other.yylrState)
786 , yyposn (other.yyposn)
787 , yypred (0)]b4_locations_if([[
788 , yyloc (other.yyloc)]])[]b4_parse_assert_if([[
789 , magic_ (MAGIC)]])[
791 setPred (other.pred ());
792 if (other.yyresolved)]b4_variant_if([[
794 new (&yyval) value_type ();
795 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
796 [yyval], [copy], [other.value ()])[
797 }]], [[
798 new (&yyval) value_type (other.value ());]])[
799 else
801 yyfirstVal = 0;
802 setFirstVal (other.firstVal ());
803 }]b4_parse_assert_if([[
804 check_();]])[
807 ~glr_state ()
808 {]b4_parse_assert_if([[
809 check_ ();]])[
810 if (yyresolved)
811 {]b4_variant_if([[
812 yysymbol_kind_t yykind = yy_accessing_symbol (yylrState);
813 // FIXME: User destructors.
814 // Value type destructor.
815 ]b4_symbol_variant([[yykind]], [[yyval]], [[template destroy]])])[
816 yyval.~value_type ();
817 }]b4_parse_assert_if([[
818 magic_ = 0;]])[
821 glr_state& operator= (const glr_state& other)
822 {]b4_parse_assert_if([[
823 check_ ();
824 other.check_ ();]])[
825 if (!yyresolved && other.yyresolved)
826 new (&yyval) value_type;
827 yyresolved = other.yyresolved;
828 yylrState = other.yylrState;
829 yyposn = other.yyposn;
830 setPred (other.pred ());
831 if (other.yyresolved)]b4_variant_if([[
832 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
833 [yyval], [copy], [other.value ()])], [[
834 value () = other.value ();]])[
835 else
836 setFirstVal (other.firstVal ());]b4_locations_if([[
837 yyloc = other.yyloc;]])[
838 return *this;
841 /** Type tag for the semantic value. If true, yyval applies, otherwise
842 * yyfirstVal applies. */
843 bool yyresolved;
844 /** Number of corresponding LALR(1) machine state. */
845 state_num yylrState;
846 /** Source position of the last token produced by my symbol */
847 size_t yyposn;
849 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
850 glr_state* pred ();
851 const glr_state* pred () const;
852 void setPred (const glr_state* state);
854 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
855 /// temporaries.
856 semantic_option* firstVal ();
857 const semantic_option* firstVal () const;
858 void setFirstVal (const semantic_option* option);
860 value_type& value ()
861 {]b4_parse_assert_if([[
862 check_ ();]])[
863 return yyval;
866 const value_type& value () const
867 {]b4_parse_assert_if([[
868 check_ ();]])[
869 return yyval;
872 void
873 destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_user_formals[);
875 /* DEBUGGING ONLY */
876 #if ]b4_api_PREFIX[DEBUG
877 void yy_yypstack () const
878 {]b4_parse_assert_if([[
879 check_ ();]])[
880 if (pred () != YY_NULLPTR)
882 pred ()->yy_yypstack ();
883 std::cerr << " -> ";
885 std::cerr << yylrState << "@@" << yyposn;
887 #endif
889 std::ptrdiff_t indexIn (const glr_stack_item* array) const;
891 glr_stack_item* asItem ()
892 {]b4_parse_assert_if([[
893 check_ ();]])[
894 return asItem(this);
897 const glr_stack_item* asItem () const
898 {]b4_parse_assert_if([[
899 check_ ();]])[
900 return asItem (this);
903 private:
904 template <typename T>
905 static const glr_stack_item* asItem (const T* state)
907 return reinterpret_cast<const glr_stack_item*>(state);
909 template <typename T>
910 static glr_stack_item* asItem (T* state)
912 return reinterpret_cast<glr_stack_item*> (state);
914 static const char *as_pointer_ (const glr_state *state)
916 return reinterpret_cast<const char *> (state);
918 static char *as_pointer_ (glr_state *state)
920 return reinterpret_cast<char *> (state);
922 /** Preceding state in this stack */
923 std::ptrdiff_t yypred;
924 union {
925 /** First in a chain of alternative reductions producing the
926 * nonterminal corresponding to this state, threaded through
927 * yyfirstVal. Value "0" means empty. */
928 std::ptrdiff_t yyfirstVal;
929 /** Semantic value for this state. */
930 value_type yyval;
931 };]b4_locations_if([[
932 // FIXME: Why public?
933 public:
934 /** Source location for this state. */
935 location_type yyloc;]])[
937 ]b4_parse_assert_if([[
938 public:
939 // Check invariants.
940 void check_ () const
942 YY_IGNORE_NULL_DEREFERENCE_BEGIN
943 YYASSERT (this->magic_ == MAGIC);
944 YY_IGNORE_NULL_DEREFERENCE_END
947 // A magic number to check our pointer arithmetics is sane.
948 enum { MAGIC = 713705 };
949 unsigned int magic_;]])[
952 /** A stack of GLRState representing the different heads during
953 * nondeterministic evaluation. */
954 class glr_state_set
956 public:
957 /** Initialize YYSET to a singleton set containing an empty stack. */
958 glr_state_set ()
959 : yylastDeleted (YY_NULLPTR)
961 yystates.push_back (YY_NULLPTR);
962 yylookaheadNeeds.push_back (false);
965 // Behave like a vector of states.
966 glr_state*& operator[] (state_set_index index)
968 return yystates[index.uget()];
971 glr_state* operator[] (state_set_index index) const
973 return yystates[index.uget()];
976 size_t size () const
978 return yystates.size ();
981 std::vector<glr_state*>::iterator begin ()
983 return yystates.begin ();
986 std::vector<glr_state*>::iterator end ()
988 return yystates.end ();
991 bool lookaheadNeeds (state_set_index index) const
993 return yylookaheadNeeds[index.uget ()];
996 bool setLookaheadNeeds (state_set_index index, bool value)
998 return yylookaheadNeeds[index.uget ()] = value;
1001 /** Invalidate stack #YYK. */
1002 void
1003 yymarkStackDeleted (state_set_index yyk)
1005 size_t k = yyk.uget ();
1006 if (yystates[k] != YY_NULLPTR)
1007 yylastDeleted = yystates[k];
1008 yystates[k] = YY_NULLPTR;
1011 /** Undelete the last stack in *this that was marked as deleted. Can
1012 only be done once after a deletion, and only when all other stacks have
1013 been deleted. */
1014 void
1015 yyundeleteLastStack ()
1017 if (yylastDeleted == YY_NULLPTR || !yystates.empty ())
1018 return;
1019 yystates.push_back (yylastDeleted);
1020 YYCDEBUG << "Restoring last deleted stack as stack #0.\n";
1021 clearLastDeleted ();
1024 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1025 * ones. */
1026 void
1027 yyremoveDeletes ()
1029 size_t newsize = yystates.size ();
1030 /* j is the number of live stacks we have seen. */
1031 for (size_t i = 0, j = 0; j < newsize; ++i)
1033 if (yystates[i] == YY_NULLPTR)
1035 if (i == j)
1037 YYCDEBUG << "Removing dead stacks.\n";
1039 newsize -= 1;
1041 else
1043 yystates[j] = yystates[i];
1044 /* In the current implementation, it's unnecessary to copy
1045 yylookaheadNeeds[i] since, after
1046 yyremoveDeletes returns, the parser immediately either enters
1047 deterministic operation or shifts a token. However, it doesn't
1048 hurt, and the code might evolve to need it. */
1049 yylookaheadNeeds[j] = yylookaheadNeeds[i];
1050 if (j != i)
1052 YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n";
1054 j += 1;
1057 yystates.resize (newsize);
1058 yylookaheadNeeds.resize (newsize);
1062 state_set_index
1063 yysplitStack (state_set_index yyk)
1065 const size_t k = yyk.uget ();
1066 yystates.push_back (yystates[k]);
1067 yylookaheadNeeds.push_back (yylookaheadNeeds[k]);
1068 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates.size () - 1));
1071 void clearLastDeleted ()
1073 yylastDeleted = YY_NULLPTR;
1076 private:
1078 std::vector<glr_state*> yystates;
1079 /** During nondeterministic operation, yylookaheadNeeds tracks which
1080 * stacks have actually needed the current lookahead. During deterministic
1081 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1082 * duplicate yytoken != ]b4_symbol(empty, kind)[. */
1083 std::vector<bool> yylookaheadNeeds;
1085 /** The last stack we invalidated. */
1086 glr_state* yylastDeleted;
1089 class semantic_option
1091 public:
1092 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
1093 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
1094 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
1095 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
1097 semantic_option ()
1098 : yyrule (0)
1099 , yystate (0)
1100 , yynext (0)
1101 , yytoken (]b4_symbol(empty, kind)[)
1102 , yyval ()]b4_locations_if([[
1103 , yyloc ()]])[]b4_parse_assert_if([[
1104 , magic_ (MAGIC)]])[
1107 semantic_option (rule_num rule, symbol_kind_type token)
1108 : yyrule (rule)
1109 , yystate (0)
1110 , yynext (0)
1111 , yytoken (token)
1112 , yyval ()]b4_locations_if([[
1113 , yyloc ()]])[]b4_parse_assert_if([[
1114 , magic_ (MAGIC)]])[
1117 semantic_option (const semantic_option& that)
1118 : yyrule (that.yyrule)
1119 , yystate (that.yystate)
1120 , yynext (that.yynext)
1121 , yytoken (that.yytoken)
1122 , yyval (]b4_variant_if([], [[that.yyval]])[)]b4_locations_if([[
1123 , yyloc (that.yyloc)]])[]b4_parse_assert_if([[
1124 , magic_ (MAGIC)]])[
1125 {]b4_parse_assert_if([[
1126 that.check_ ();]])[]b4_variant_if([[
1127 ]b4_symbol_variant([yytoken],
1128 [yyval], [copy], [that.yyval])])[
1131 // Needed for the assignment in yynewSemanticOption.
1132 semantic_option& operator= (const semantic_option& that)
1133 {]b4_parse_assert_if([[
1134 check_ ();
1135 that.check_ ();]])[
1136 yyrule = that.yyrule;
1137 yystate = that.yystate;
1138 yynext = that.yynext;
1139 yytoken = that.yytoken;]b4_variant_if([[
1140 ]b4_symbol_variant([yytoken],
1141 [yyval], [copy], [that.yyval])], [[
1142 yyval = that.yyval;]])[]b4_locations_if([[
1143 yyloc = that.yyloc;]])[
1144 return *this;
1147 /// Only call state() and setState() on objects in yyitems, not temporaries.
1148 glr_state* state();
1149 const glr_state* state() const;
1150 void setState(const glr_state* s);
1152 const semantic_option* next () const;
1153 semantic_option* next ();
1154 void setNext (const semantic_option* s);
1156 std::ptrdiff_t indexIn (const glr_stack_item* array) const;
1158 /** True iff YYY0 and YYY1 represent identical options at the top level.
1159 * That is, they represent the same rule applied to RHS symbols
1160 * that produce the same terminal symbols. */
1161 bool
1162 isIdenticalTo (const semantic_option& yyy1) const
1163 {]b4_parse_assert_if([[
1164 check_ ();
1165 yyy1.check_ ();]])[
1166 if (this->yyrule == yyy1.yyrule)
1168 const glr_state *yys0, *yys1;
1169 int yyn;
1170 for (yys0 = this->state(),
1171 yys1 = yyy1.state(),
1172 yyn = yyrhsLength (this->yyrule);
1173 yyn > 0;
1174 yys0 = yys0->pred(),
1175 yys1 = yys1->pred(), yyn -= 1)
1176 if (yys0->yyposn != yys1->yyposn)
1177 return false;
1178 return true;
1180 else
1181 return false;
1184 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1185 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1186 void
1187 mergeWith (semantic_option& yyy1)
1188 {]b4_parse_assert_if([[
1189 check_ ();
1190 yyy1.check_ ();]])[
1191 glr_state *yys0 = this->state ();
1192 glr_state *yys1 = yyy1.state ();
1193 for (int yyn = yyrhsLength (this->yyrule);
1194 yyn > 0;
1195 yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ())
1197 if (yys0 == yys1)
1198 break;
1199 else if (yys0->yyresolved)
1201 yys1->yyresolved = true;]b4_variant_if([[
1202 YYASSERT (yys1->yylrState == yys0->yylrState);
1203 ]b4_symbol_variant([yy_accessing_symbol (yys0->yylrState)],
1204 [yys1->value ()], [copy], [yys0->value ()])], [[
1205 yys1->value () = yys0->value ();]])[
1207 else if (yys1->yyresolved)
1209 yys0->yyresolved = true;]b4_variant_if([[
1210 YYASSERT (yys0->yylrState == yys1->yylrState);
1211 ]b4_symbol_variant([yy_accessing_symbol (yys1->yylrState)],
1212 [yys0->value ()], [copy], [yys1->value ()])], [[
1213 yys0->value () = yys1->value ();]])[
1215 else
1217 semantic_option* yyz0prev = YY_NULLPTR;
1218 semantic_option* yyz0 = yys0->firstVal();
1219 semantic_option* yyz1 = yys1->firstVal();
1220 while (true)
1222 if (yyz1 == yyz0 || yyz1 == YY_NULLPTR)
1223 break;
1224 else if (yyz0 == YY_NULLPTR)
1226 if (yyz0prev != YY_NULLPTR)
1227 yyz0prev->setNext (yyz1);
1228 else
1229 yys0->setFirstVal (yyz1);
1230 break;
1232 else if (yyz0 < yyz1)
1234 semantic_option* yyz = yyz0;
1235 if (yyz0prev != YY_NULLPTR)
1236 yyz0prev->setNext(yyz1);
1237 else
1238 yys0->setFirstVal(yyz1);
1239 yyz1 = yyz1->next();
1240 yyz0->setNext(yyz);
1242 yyz0prev = yyz0;
1243 yyz0 = yyz0->next();
1245 yys1->setFirstVal(yys0->firstVal());
1250 #if ]b4_api_PREFIX[DEBUG
1251 void yyreportTree (size_t yyindent = 2) const
1252 {]b4_parse_assert_if([[
1253 check_ ();]])[
1254 int yynrhs = yyrhsLength (this->yyrule);
1255 const glr_state* yystates[1 + YYMAXRHS];
1256 glr_state yyleftmost_state;
1259 const glr_state* yys = this->state();
1260 for (int yyi = yynrhs; 0 < yyi; yyi -= 1)
1262 yystates[yyi] = yys;
1263 yys = yys->pred();
1265 if (yys == YY_NULLPTR)
1267 yyleftmost_state.yyposn = 0;
1268 yystates[0] = &yyleftmost_state;
1270 else
1271 yystates[0] = yys;
1274 std::string yylhs = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yylhsNonterm (this->yyrule));
1275 YYASSERT(this->state());
1276 if (this->state()->yyposn < yystates[0]->yyposn + 1)
1277 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1278 << this->yyrule - 1 << ", empty>\n";
1279 else
1280 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1281 << this->yyrule - 1 << ", tokens "
1282 << yystates[0]->yyposn + 1 << " .. "
1283 << this->state()->yyposn << ">\n";
1284 for (int yyi = 1; yyi <= yynrhs; yyi += 1)
1286 if (yystates[yyi]->yyresolved)
1288 std::string yysym = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yy_accessing_symbol (yystates[yyi]->yylrState));
1289 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1290 std::cerr << std::string(yyindent + 2, ' ') << yysym
1291 << " <empty>\n";
1292 else
1293 std::cerr << std::string(yyindent + 2, ' ') << yysym
1294 << " <tokens " << yystates[yyi-1]->yyposn + 1
1295 << " .. " << yystates[yyi]->yyposn << ">\n";
1297 else
1298 yystates[yyi]->firstVal ()->yyreportTree (yyindent+2);
1301 #endif
1303 /** Rule number for this reduction */
1304 rule_num yyrule;
1306 private:
1307 template <typename T>
1308 static const glr_stack_item* asItem(const T* state)
1310 return reinterpret_cast<const glr_stack_item*>(state);
1312 template <typename T>
1313 static glr_stack_item* asItem(T* state)
1315 return reinterpret_cast<glr_stack_item*>(state);
1317 /** The last RHS state in the list of states to be reduced. */
1318 std::ptrdiff_t yystate;
1319 /** Next sibling in chain of options. To facilitate merging,
1320 * options are chained in decreasing order by address. */
1321 std::ptrdiff_t yynext;
1323 public:
1324 /** The lookahead for this reduction. */
1325 symbol_kind_type yytoken;
1326 value_type yyval;]b4_locations_if([[
1327 location_type yyloc;]])[
1329 ]b4_parse_assert_if([[
1330 public:
1331 // Check invariants.
1332 void check_ () const
1334 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1335 YYASSERT (this->magic_ == MAGIC);
1336 YY_IGNORE_NULL_DEREFERENCE_END
1339 // A magic number to check our pointer arithmetics is sane.
1340 enum { MAGIC = 0xeff1cace };
1341 unsigned int magic_;]])[
1344 /** Type of the items in the GLR stack.
1345 * It can be either a glr_state or a semantic_option. The is_state_ field
1346 * indicates which item of the union is valid. */
1347 class glr_stack_item
1349 public:
1350 glr_stack_item (bool state = true)
1351 : is_state_ (state)]b4_parse_assert_if([[
1352 , magic_ (MAGIC)]])[
1354 if (is_state_)
1355 new (&raw_) glr_state;
1356 else
1357 new (&raw_) semantic_option;
1360 glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW
1361 : is_state_ (other.is_state_)]b4_parse_assert_if([[
1362 , magic_ (MAGIC)]])[
1363 {]b4_parse_assert_if([[
1364 other.check_ ();]])[
1365 std::memcpy (raw_, other.raw_, union_size);
1368 glr_stack_item& operator= (glr_stack_item other)
1369 {]b4_parse_assert_if([[
1370 check_ ();
1371 other.check_ ();]])[
1372 std::swap (is_state_, other.is_state_);
1373 // NB: swap on arrays is C++11.
1374 std::swap (raw_, other.raw_);
1375 return *this;
1378 ~glr_stack_item ()
1379 {]b4_parse_assert_if([[
1380 check_ ();]])[
1381 if (is_state ())
1382 getState ().~glr_state ();
1383 else
1384 getOption ().~semantic_option ();
1387 void setState (const glr_state &state)
1388 {]b4_parse_assert_if([[
1389 check_ ();
1390 state.check_ ();]])[
1391 if (this != state.asItem ())
1393 if (is_state_)
1394 getState ().~glr_state ();
1395 else
1396 getOption ().~semantic_option ();
1397 new (&raw_) glr_state (state);
1398 is_state_ = true;
1402 glr_state& getState ()
1403 {]b4_parse_assert_if([[
1404 check_ ();]])[
1405 YYDASSERT (is_state ());
1406 void *yyp = raw_;
1407 glr_state& res = *static_cast<glr_state*> (yyp);]b4_parse_assert_if([[
1408 res.check_ ();]])[
1409 return res;
1412 const glr_state& getState () const
1413 {]b4_parse_assert_if([[
1414 check_ ();]])[
1415 YYDASSERT (is_state ());
1416 const void *yyp = raw_;
1417 const glr_state& res = *static_cast<const glr_state*> (yyp);]b4_parse_assert_if([[
1418 res.check_ ();]])[
1419 return res;
1422 semantic_option& getOption ()
1423 {]b4_parse_assert_if([[
1424 check_ ();]])[
1425 YYDASSERT (!is_state ());
1426 void *yyp = raw_;
1427 return *static_cast<semantic_option*> (yyp);
1429 const semantic_option& getOption () const
1430 {]b4_parse_assert_if([[
1431 check_ ();]])[
1432 YYDASSERT (!is_state ());
1433 const void *yyp = raw_;
1434 return *static_cast<const semantic_option*> (yyp);
1436 bool is_state () const
1437 {]b4_parse_assert_if([[
1438 check_ ();]])[
1439 return is_state_;
1442 private:
1443 /// The possible contents of raw_. Since they have constructors, they cannot
1444 /// be directly included in the union.
1445 union contents
1447 char yystate[sizeof (glr_state)];
1448 char yyoption[sizeof (semantic_option)];
1450 enum { union_size = sizeof (contents) };
1451 union {
1452 /// Strongest alignment constraints.
1453 long double yyalign_me;
1454 /// A buffer large enough to store the contents.
1455 char raw_[union_size];
1457 /** Type tag for the union. */
1458 bool is_state_;
1459 ]b4_parse_assert_if([[
1460 public:
1461 // Check invariants.
1462 void check_ () const
1464 YYASSERT (this->magic_ == MAGIC);
1465 YYASSERT (this->is_state_ == false || this->is_state_ == true);
1467 // A magic number to check our pointer arithmetics is sane.
1468 enum { MAGIC = 0xDEAD1ACC }; // 3735886540.
1469 const unsigned int magic_;]])[
1472 glr_state* glr_state::pred ()
1473 {]b4_parse_assert_if([[
1474 check_ ();]])[
1475 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1476 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1477 YY_IGNORE_NULL_DEREFERENCE_END
1480 const glr_state* glr_state::pred () const
1481 {]b4_parse_assert_if([[
1482 check_ ();]])[
1483 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1484 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1485 YY_IGNORE_NULL_DEREFERENCE_END
1488 void glr_state::setPred (const glr_state* state)
1489 {]b4_parse_assert_if([[
1490 check_ ();
1491 if (state)
1492 state->check_ ();]])[
1493 yypred = state ? as_pointer_ (this) - as_pointer_ (state) : 0;
1496 semantic_option* glr_state::firstVal ()
1497 {]b4_parse_assert_if([[
1498 check_ ();]])[
1499 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1502 const semantic_option* glr_state::firstVal () const
1503 {]b4_parse_assert_if([[
1504 check_ ();]])[
1505 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1508 void glr_state::setFirstVal (const semantic_option* option)
1509 {]b4_parse_assert_if([[
1510 check_ ();]])[
1511 yyfirstVal = option ? asItem(this) - asItem(option) : 0;
1514 std::ptrdiff_t glr_state::indexIn (const glr_stack_item* array) const
1515 {]b4_parse_assert_if([[
1516 check_ ();]])[
1517 return asItem(this) - array;
1520 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item* array) const
1522 return asItem(this) - array;
1525 glr_state* semantic_option::state ()
1527 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1528 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1529 YY_IGNORE_NULL_DEREFERENCE_END
1532 const glr_state* semantic_option::state () const
1534 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1537 void semantic_option::setState (const glr_state* s)
1539 yystate = s ? asItem(this) - asItem(s) : 0;
1542 const semantic_option* semantic_option::next () const
1544 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1547 semantic_option* semantic_option::next ()
1549 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1552 void semantic_option::setNext (const semantic_option* s)
1554 yynext = s ? asItem(this) - asItem(s) : 0;
1557 void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_user_formals[)
1558 {]b4_parse_assert_if([[
1559 check_ ();]])[
1560 if (yyresolved)
1561 yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
1562 value ()]b4_locations_if([, yyloc])[);
1563 else
1565 #if ]b4_api_PREFIX[DEBUG
1566 YYCDEBUG << yymsg
1567 << (firstVal() ? " unresolved " : " incomplete ")
1568 << (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm")
1569 << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState))
1570 << " ("]b4_locations_if([[
1571 << yyloc << ": "]])[
1572 << ")\n";
1573 #endif
1574 if (firstVal() != YY_NULLPTR)
1576 semantic_option& yyoption = *firstVal ();
1577 glr_state *yyrh = yyoption.state ();
1578 for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1)
1580 yyrh->destroy (yymsg, yyparser]b4_user_args[);
1581 yyrh = yyrh->pred();
1588 static int
1589 yypreference (const semantic_option& y0, const semantic_option& y1);
1591 static inline state_num
1592 yyLRgotoState (state_num yystate, yysymbol_kind_t yysym);
1594 #undef YYFILL
1595 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1597 class state_stack
1599 public:
1600 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
1601 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
1602 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
1604 /** Initialize to a single empty stack, with total maximum
1605 * capacity for all stacks of YYSIZE. */
1606 state_stack (size_t yysize)
1607 : yysplitPoint (YY_NULLPTR)
1609 yyitems.reserve (yysize);
1612 #if YYSTACKEXPANDABLE
1613 /** Returns false if it tried to expand but could not. */
1614 bool
1615 yyexpandGLRStackIfNeeded ()
1617 return YYHEADROOM <= spaceLeft () || yyexpandGLRStack ();
1620 private:
1621 /** If *this is expandable, extend it. WARNING: Pointers into the
1622 stack from outside should be considered invalid after this call.
1623 We always expand when there are 1 or fewer items left AFTER an
1624 allocation, so that we can avoid having external pointers exist
1625 across an allocation. */
1626 bool
1627 yyexpandGLRStack ()
1629 const size_t oldsize = yyitems.size();
1630 if (YYMAXDEPTH - YYHEADROOM < oldsize)
1631 return false;
1632 const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize;
1633 const glr_stack_item *oldbase = &yyitems[0];
1635 yyitems.reserve (yynewSize);
1636 const glr_stack_item *newbase = &yyitems[0];
1638 // Adjust the pointers. Perform raw pointer arithmetics, as there
1639 // is no reason for objects to be aligned on their size.
1640 const ptrdiff_t disp
1641 = reinterpret_cast<const char*> (newbase) - reinterpret_cast<const char*> (oldbase);
1642 if (yysplitPoint)
1643 const_cast<glr_state*&> (yysplitPoint)
1644 = reinterpret_cast<glr_state*> (reinterpret_cast<char*> (const_cast<glr_state*> (yysplitPoint)) + disp);
1646 for (std::vector<glr_state*>::iterator
1647 i = yytops.begin (),
1648 yyend = yytops.end ();
1649 i != yyend; ++i)
1650 if (glr_state_not_null (*i))
1651 *i = reinterpret_cast<glr_state*>(reinterpret_cast<char*>(*i) + disp);
1653 return true;
1656 public:
1657 #else
1658 bool yyexpandGLRStackIfNeeded ()
1660 return YYHEADROOM <= spaceLeft ();
1662 #endif
1664 static bool glr_state_not_null (glr_state* s)
1666 return s != YY_NULLPTR;
1669 bool
1670 reduceToOneStack ()
1672 typedef std::vector<glr_state*>::iterator iterator;
1673 const iterator yybegin = yytops.begin();
1674 const iterator yyend = yytops.end();
1675 const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null);
1676 if (yyit == yyend)
1677 return false;
1678 for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin);
1679 yyk.uget() != numTops(); ++yyk)
1680 yytops.yymarkStackDeleted (yyk);
1681 yytops.yyremoveDeletes ();
1682 yycompressStack ();
1683 return true;
1686 /** Called when returning to deterministic operation to clean up the extra
1687 * stacks. */
1688 void
1689 yycompressStack ()
1691 if (yytops.size() != 1 || !isSplit())
1692 return;
1694 // yyr is the state after the split point.
1695 glr_state* yyr = YY_NULLPTR;
1696 for (glr_state *yyp = firstTop(), *yyq = yyp->pred();
1697 yyp != yysplitPoint;
1698 yyr = yyp, yyp = yyq, yyq = yyp->pred())
1699 yyp->setPred(yyr);
1701 // This const_cast is okay, since anyway we have access to the mutable
1702 // yyitems into which yysplitPoint points.
1703 glr_stack_item* nextFreeItem
1704 = const_cast<glr_state*> (yysplitPoint)->asItem () + 1;
1705 yysplitPoint = YY_NULLPTR;
1706 yytops.clearLastDeleted ();
1708 while (yyr != YY_NULLPTR)
1710 nextFreeItem->setState (*yyr);
1711 glr_state& nextFreeState = nextFreeItem->getState();
1712 yyr = yyr->pred();
1713 nextFreeState.setPred(&(nextFreeItem - 1)->getState());
1714 setFirstTop (&nextFreeState);
1715 ++nextFreeItem;
1717 yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data()));
1720 bool isSplit() const {
1721 return yysplitPoint != YY_NULLPTR;
1724 // Present the interface of a vector of glr_stack_item.
1725 std::vector<glr_stack_item>::const_iterator begin () const
1727 return yyitems.begin ();
1730 std::vector<glr_stack_item>::const_iterator end () const
1732 return yyitems.end ();
1735 size_t size() const
1737 return yyitems.size ();
1740 glr_stack_item& operator[] (size_t i)
1742 return yyitems[i];
1745 glr_stack_item& stackItemAt (size_t index)
1747 return yyitems[index];
1750 size_t numTops() const {
1751 return yytops.size();
1754 glr_state* firstTop() const {
1755 return yytops[create_state_set_index(0)];
1758 glr_state* topAt(state_set_index i) const {
1759 return yytops[i];
1762 void setFirstTop(glr_state* value) {
1763 yytops[create_state_set_index(0)] = value;
1766 void setTopAt(state_set_index i, glr_state* value) {
1767 yytops[i] = value;
1770 void pop_back() {
1771 yyitems.pop_back();
1774 void pop_back(size_t n) {
1775 yyitems.resize(yyitems.size() - n);
1778 state_set_index
1779 yysplitStack (state_set_index yyk)
1781 if (!isSplit())
1783 YYASSERT (yyk.get() == 0);
1784 yysplitPoint = topAt(yyk);
1786 return yytops.yysplitStack(yyk);
1789 /** Assuming that YYS is a GLRState somewhere on *this, update the
1790 * splitpoint of *this, if needed, so that it is at least as deep as
1791 * YYS. */
1792 void
1793 yyupdateSplit (glr_state& yys)
1795 if (isSplit() && &yys < yysplitPoint)
1796 yysplitPoint = &yys;
1799 /** Return a fresh GLRState.
1800 * Callers should call yyreserveStack afterwards to make sure there is
1801 * sufficient headroom. */
1802 glr_state& yynewGLRState (const glr_state& newState)
1804 glr_state& state = yyitems[yynewGLRStackItem (true)].getState ();
1805 #if false && 201103L <= YY_CPLUSPLUS
1806 state = std::move (newState);
1807 #else
1808 state = newState;
1809 #endif
1810 return state;
1813 /** Return a fresh SemanticOption.
1814 * Callers should call yyreserveStack afterwards to make sure there is
1815 * sufficient headroom. */
1816 semantic_option& yynewSemanticOption (semantic_option newOption)
1818 semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption ();
1819 #if 201103L <= YY_CPLUSPLUS
1820 option = std::move (newOption);
1821 #else
1822 option = newOption;
1823 #endif
1824 return option;
1827 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1828 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1829 * For convenience, always return YYLOW1. */
1831 yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal)
1833 if (!yynormal && yylow1 < yylow)
1835 yyfillin (yyvsp, yylow, yylow1);
1836 yylow = yylow1;
1838 return yylow1;
1841 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1842 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1843 * containing the pointer to the next state in the chain. */
1844 void
1845 yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1)
1847 glr_state* s = yyvsp[yylow0].getState().pred();
1848 YYASSERT(s != YY_NULLPTR);
1849 for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred())
1851 glr_state& yys = yyvsp[i].getState();
1852 #if ]b4_api_PREFIX[DEBUG
1853 yys.yylrState = s->yylrState;
1854 #endif
1855 yys.yyresolved = s->yyresolved;
1856 if (s->yyresolved)
1857 {]b4_variant_if([[
1858 new (&yys.value ()) value_type ();
1859 ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)],
1860 [yys.value ()], [copy], [s->value ()])], [[
1861 new (&yys.value ()) value_type (s->value ());]])[
1863 else
1864 /* The effect of using yyval or yyloc (in an immediate
1865 * rule) is undefined. */
1866 yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[
1867 yys.yyloc = s->yyloc;]])[
1868 yys.setPred(s->pred());
1872 #if ]b4_api_PREFIX[DEBUG
1874 /*----------------------------------------------------------------------.
1875 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1876 `----------------------------------------------------------------------*/
1878 void
1879 yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk,
1880 rule_num yyrule, ]b4_namespace_ref[::]b4_parser_class[& yyparser)
1882 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1883 int yylow = 1;])[
1884 int yyi;
1885 std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1
1886 << " (line " << int (yyrline[yyrule]) << "):\n";
1887 if (! yynormal)
1888 yyfillin (yyvsp, 1, -yynrhs);
1889 /* The symbols being reduced. */
1890 for (yyi = 0; yyi < yynrhs; yyi++)
1892 std::cerr << " $" << yyi + 1 << " = ";
1893 yyparser.yy_symbol_print_
1894 (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
1895 yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
1896 ]b4_rhs_location(yynrhs, yyi + 1)])[);
1897 if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
1898 std::cerr << " (unresolved)";
1899 std::cerr << '\n';
1904 #define YYINDEX(YYX) \
1905 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1907 void
1908 dumpStack () const
1910 for (size_t yyi = 0; yyi < size(); ++yyi)
1912 const glr_stack_item& item = yyitems[yyi];
1913 std::cerr << std::setw(3) << yyi << ". ";
1914 if (item.is_state())
1916 std::cerr << "Res: " << item.getState().yyresolved
1917 << ", LR State: " << item.getState().yylrState
1918 << ", posn: " << item.getState().yyposn
1919 << ", pred: " << YYINDEX(item.getState().pred());
1920 if (! item.getState().yyresolved)
1921 std::cerr << ", firstVal: "
1922 << YYINDEX(item.getState().firstVal());
1924 else
1926 std::cerr << "Option. rule: " << item.getOption().yyrule - 1
1927 << ", state: " << YYINDEX(item.getOption().state())
1928 << ", next: " << YYINDEX(item.getOption().next());
1930 std::cerr << '\n';
1932 std::cerr << "Tops:";
1933 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) {
1934 std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; ";
1936 std::cerr << '\n';
1939 #undef YYINDEX
1940 #endif
1942 YYRESULTTAG
1943 yyreportAmbiguity (const semantic_option& yyx0,
1944 const semantic_option& yyx1, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_locations_if([, const location_type& yyloc])[)
1946 YY_USE (yyx0);
1947 YY_USE (yyx1);
1949 #if ]b4_api_PREFIX[DEBUG
1950 std::cerr << "Ambiguity detected.\n"
1951 "Option 1,\n";
1952 yyx0.yyreportTree ();
1953 std::cerr << "\nOption 2,\n";
1954 yyx1.yyreportTree ();
1955 std::cerr << '\n';
1956 #endif
1958 yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous"));
1959 return yyabort;
1962 /* DEBUGGING ONLY */
1963 #if ]b4_api_PREFIX[DEBUG
1964 /* Print YYS (possibly NULL) and its predecessors. */
1965 void
1966 yypstates (const glr_state* yys) const
1968 if (yys != YY_NULLPTR)
1969 yys->yy_yypstack();
1970 else
1971 std::cerr << "<null>";
1972 std::cerr << '\n';
1974 #endif
1976 private:
1977 size_t spaceLeft() const
1979 return yyitems.capacity() - yyitems.size();
1982 /** Return a fresh GLRStackItem in this. The item is an LR state
1983 * if YYIS_STATE, and otherwise a semantic option. Callers should call
1984 * yyreserveStack afterwards to make sure there is sufficient
1985 * headroom. */
1986 size_t
1987 yynewGLRStackItem (bool yyis_state)
1989 YYDASSERT(yyitems.size() < yyitems.capacity());
1990 yyitems.push_back(glr_stack_item(yyis_state));
1991 return yyitems.size() - 1;
1995 public:
1997 std::vector<glr_stack_item> yyitems;
1998 // Where the stack splits. Anything below this address is deterministic.
1999 const glr_state* yysplitPoint;
2000 glr_state_set yytops;
2003 #undef YYFILL
2004 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2006 class glr_stack
2008 public:
2009 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
2010 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
2011 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
2012 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
2014 glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
2015 : yyerrState (0)
2016 , yystateStack (yysize)
2017 , yyerrcnt (0)
2018 , yytoken (]b4_symbol(empty, kind)[)
2019 , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
2022 ~glr_stack ()
2024 if (this->yytoken != ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[)
2025 yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
2026 this->yytoken, this->yylval]b4_locations_if([, this->yylloc])[);
2027 popall_ ();
2030 int yyerrState;
2031 ]b4_locations_if([[ /* To compute the location of the error token. */
2032 glr_stack_item yyerror_range[3];]])[
2033 state_stack yystateStack;
2034 int yyerrcnt;
2035 symbol_kind_type yytoken;
2036 value_type yylval;]b4_locations_if([[
2037 location_type yylloc;]])[
2038 YYJMP_BUF yyexception_buffer;
2039 ]b4_namespace_ref[::]b4_parser_class[& yyparser;
2041 void yyreserveGlrStack() {
2042 if (!yystateStack.yyexpandGLRStackIfNeeded ())
2043 yyMemoryExhausted();
2046 _Noreturn void
2047 yyMemoryExhausted ()
2049 YYLONGJMP (yyexception_buffer, 2);
2052 _Noreturn void
2053 yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg)
2055 if (yymsg != YY_NULLPTR)
2056 yyparser.error (]b4_locations_if([*yylocp, ])[yymsg);
2057 YYLONGJMP (yyexception_buffer, 1);
2060 /* GLRStates */
2063 /** Add a new semantic action that will execute the action for rule
2064 * YYRULE on the semantic values in YYRHS to the list of
2065 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2066 * stack #YYK of *this. */
2067 void
2068 yyaddDeferredAction (state_set_index yyk, glr_state* yystate,
2069 glr_state* yyrhs, rule_num yyrule)
2071 semantic_option& yynewOption =
2072 yystateStack.yynewSemanticOption(semantic_option(yyrule, ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[));
2073 yynewOption.setState(yyrhs);
2074 yynewOption.setNext(yystate->firstVal());
2075 if (yystateStack.yytops.lookaheadNeeds(yyk))
2077 yynewOption.yytoken = this->yytoken;]b4_variant_if([[
2078 ]b4_symbol_variant([this->yytoken],
2079 [yynewOption.yyval], [copy], [this->yylval])], [[
2080 yynewOption.yyval = this->yylval;]])[]b4_locations_if([
2081 yynewOption.yyloc = this->yylloc;])[
2083 yystate->setFirstVal(&yynewOption);
2085 yyreserveGlrStack();
2088 #if ]b4_api_PREFIX[DEBUG
2089 void yypdumpstack () const
2091 yystateStack.dumpStack();
2093 #endif
2094 void
2095 yyreportSyntaxError ()
2097 if (yyerrState != 0)
2098 return;
2099 ]b4_parse_error_bmatch(
2100 [simple],
2101 [[ yyparser.error (]b4_locations_if([this->yylloc, ])[YY_("syntax error"));]],
2102 [[ {
2103 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
2104 /* Arguments of yyformat. */
2105 yysymbol_kind_t yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]
2106 = { ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[ };
2107 /* Number of reported tokens (one for the "unexpected", one per
2108 "expected"). */
2109 int yycount = 0;
2111 /* There are many possibilities here to consider:
2112 - If this state is a consistent state with a default action, then
2113 the only way this function was invoked is if the default action
2114 is an error action. In that case, don't check for expected
2115 tokens because there are none.
2116 - The only way there can be no lookahead present (in yytoken) is if
2117 this state is a consistent state with a default action. Thus,
2118 detecting the absence of a lookahead is sufficient to determine
2119 that there is no unexpected or expected token to report. In that
2120 case, just report a simple "syntax error".
2121 - Don't assume there isn't a lookahead just because this state is a
2122 consistent state with a default action. There might have been a
2123 previous inconsistent state, consistent state with a non-default
2124 action, or user semantic action that manipulated yytoken.
2125 - Of course, the expected token list depends on states to have
2126 correct lookahead information, and it depends on the parser not
2127 to perform extra reductions after fetching a lookahead from the
2128 scanner and before detecting a syntax error. Thus, state merging
2129 (from LALR or IELR) and default reductions corrupt the expected
2130 token list. However, the list is correct for canonical LR with
2131 one exception: it will still contain any token that will not be
2132 accepted due to an error action in a later state.
2134 if (yytoken != ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[)
2136 const int yyn = yypact[firstTopState()->yylrState];
2137 yyarg[yycount++] = yytoken;
2138 if (!yypact_value_is_default (yyn))
2140 /* Start YYX at -YYN if negative to avoid negative indexes in
2141 YYCHECK. In other words, skip the first -YYN actions for this
2142 state because they are default actions. */
2143 const int yyxbegin = yyn < 0 ? -yyn : 0;
2144 /* Stay within bounds of both yycheck and yytname. */
2145 const int yychecklim = YYLAST - yyn + 1;
2146 const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2147 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
2148 if (yycheck[yyx + yyn] == yyx && yyx != ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(error, kind)[
2149 && !yytable_value_is_error (yytable[yyx + yyn]))
2151 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
2153 yycount = 1;
2154 break;
2156 yyarg[yycount++] = static_cast<yysymbol_kind_t>(yyx);
2161 /* Internationalized format string. */
2162 const char *yyformat = YY_NULLPTR;
2163 switch (yycount)
2165 #define YYCASE_(N, S) \
2166 case N: \
2167 yyformat = S; \
2168 break
2169 default: /* Avoid compiler warnings. */
2170 YYCASE_(0, YY_("syntax error"));
2171 YYCASE_(1, YY_("syntax error, unexpected %s"));
2172 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2173 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2174 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2175 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2176 #undef YYCASE_
2179 std::string yymsg;
2180 // Argument number.
2181 std::ptrdiff_t yyi = 0;
2182 for (char const* yyp = yyformat; *yyp; ++yyp)
2183 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
2185 yymsg += ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yyarg[yyi++]);
2186 ++yyp;
2188 else
2189 yymsg += *yyp;
2190 yyparser.error (]b4_locations_if([[yylloc, ]])[yymsg);
2192 ]])[
2193 yyerrcnt += 1;
2197 /* Recover from a syntax error on this, assuming that yytoken,
2198 yylval, and yylloc are the syntactic category, semantic value, and location
2199 of the lookahead. */
2200 void
2201 yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[)
2203 if (yyerrState == 3)
2204 /* We just shifted the error token and (perhaps) took some
2205 reductions. Skip tokens until we can proceed. */
2206 while (true)
2208 if (this->yytoken == ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(eof, kind)[)
2209 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2210 if (this->yytoken != ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[)
2211 {]b4_locations_if([[
2212 /* We throw away the lookahead, but the error range
2213 of the shifted error token must take it into account. */
2214 glr_state *yys = firstTopState();
2215 yyerror_range[1].getState().yyloc = yys->yyloc;
2216 yyerror_range[2].getState().yyloc = this->yylloc;
2217 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2218 yyparser.yy_destroy_ ("Error: discarding",
2219 this->yytoken, this->yylval]b4_locations_if([, this->yylloc])[);]b4_variant_if([[
2220 // Value type destructor.
2221 ]b4_symbol_variant([[this->yytoken]], [[this->yylval]], [[template destroy]])])[
2222 this->yytoken = ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[;
2224 yygetToken (yyparser, *this]b4_user_args[);
2225 int yyj = yypact[firstTopState()->yylrState];
2226 if (yypact_value_is_default (yyj))
2227 return;
2228 yyj += this->yytoken;
2229 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yytoken)
2231 if (yydefact[firstTopState()->yylrState] != 0)
2232 return;
2234 else if (! yytable_value_is_error (yytable[yyj]))
2235 return;
2238 if (!yystateStack.reduceToOneStack())
2239 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2241 /* Now pop stack until we find a state that shifts the error token. */
2242 yyerrState = 3;
2243 while (firstTopState () != YY_NULLPTR)
2245 glr_state *yys = firstTopState ();
2246 int yyj = yypact[yys->yylrState];
2247 if (! yypact_value_is_default (yyj))
2249 yyj += YYTERROR;
2250 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2251 && yyisShiftAction (yytable[yyj]))
2253 /* Shift the error token. */]b4_locations_if([[
2254 /* First adjust its location.*/
2255 location_type yyerrloc;
2256 yyerror_range[2].getState().yyloc = this->yylloc;
2257 YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
2258 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
2259 yylval, yyerrloc);
2260 yyglrShift (create_state_set_index(0), yytable[yyj],
2261 yys->yyposn, yylval]b4_locations_if([, yyerrloc])[);
2262 yys = firstTopState();
2263 break;
2265 }]b4_locations_if([[
2266 yyerror_range[1].getState().yyloc = yys->yyloc;]])[
2267 if (yys->pred() != YY_NULLPTR)
2268 yys->destroy ("Error: popping", yyparser]b4_user_args[);
2269 yystateStack.setFirstTop(yys->pred());
2270 yystateStack.pop_back();
2272 if (firstTopState() == YY_NULLPTR)
2273 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2276 YYRESULTTAG
2277 yyprocessOneStack (state_set_index yyk,
2278 size_t yyposn]b4_locations_if([, location_type* yylocp])[)
2280 while (yystateStack.topAt(yyk) != YY_NULLPTR)
2282 const state_num yystate = topState(yyk)->yylrState;
2283 YYCDEBUG << "Stack " << yyk.get()
2284 << " Entering state " << yystate << '\n';
2286 YYASSERT (yystate != YYFINAL);
2288 if (yyisDefaultedState (yystate))
2290 const rule_num yyrule = yydefaultAction (yystate);
2291 if (yyrule == 0)
2293 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2294 yystateStack.yytops.yymarkStackDeleted (yyk);
2295 return yyok;
2297 const YYRESULTTAG yyflag
2298 = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]);
2299 if (yyflag == yyerr)
2301 YYCDEBUG << "Stack " << yyk.get() << " dies"
2302 " (predicate failure or explicit user error).\n";
2303 yystateStack.yytops.yymarkStackDeleted (yyk);
2304 return yyok;
2306 if (yyflag != yyok)
2307 return yyflag;
2309 else
2311 yystateStack.yytops.setLookaheadNeeds(yyk, true);
2312 yygetToken (yyparser, *this]b4_user_args[);
2313 const short* yyconflicts;
2314 const int yyaction = yygetLRActions (yystate, this->yytoken, yyconflicts);
2316 for (; *yyconflicts != 0; ++yyconflicts)
2318 state_set_index yynewStack = yystateStack.yysplitStack (yyk);
2319 YYCDEBUG << "Splitting off stack " << yynewStack.get()
2320 << " from " << yyk.get() << ".\n";
2321 YYRESULTTAG yyflag =
2322 yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]);
2323 if (yyflag == yyok)
2324 YYCHK (yyprocessOneStack (yynewStack,
2325 yyposn]b4_locations_if([, yylocp])[));
2326 else if (yyflag == yyerr)
2328 YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n";
2329 yystateStack.yytops.yymarkStackDeleted (yynewStack);
2331 else
2332 return yyflag;
2335 if (yyisShiftAction (yyaction))
2336 break;
2337 else if (yyisErrorAction (yyaction))
2339 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2340 yystateStack.yytops.yymarkStackDeleted (yyk);
2341 break;
2343 else
2345 YYRESULTTAG yyflag
2346 = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]);
2347 if (yyflag == yyerr)
2349 YYCDEBUG << "Stack " << yyk.get() << " dies"
2350 " (predicate failure or explicit user error).\n";
2351 yystateStack.yytops.yymarkStackDeleted (yyk);
2352 break;
2354 else if (yyflag != yyok)
2355 return yyflag;
2359 return yyok;
2362 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2363 * and top stack item YYVSP. YYVALP points to place to put semantic
2364 * value ($$), and yylocp points to place for location information
2365 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2366 * yyerr for YYERROR, yyabort for YYABORT. */
2367 YYRESULTTAG
2368 yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk,
2369 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2371 bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit();
2372 int yylow = 1;
2373 ]b4_parse_param_use([yyvalp], [yylocp])dnl
2374 [ YY_USE (yyk);
2375 YY_USE (yyrhslen);
2376 # undef yyerrok
2377 # define yyerrok (yyerrState = 0)
2378 # undef YYACCEPT
2379 # define YYACCEPT return yyaccept
2380 # undef YYABORT
2381 # define YYABORT return yyabort
2382 # undef YYERROR
2383 # define YYERROR return yyerrok, yyerr
2384 # undef YYRECOVERING
2385 # define YYRECOVERING() (yyerrState != 0)
2386 # undef yytoken
2387 # define yytoken this->yytoken
2388 # undef yyclearin
2389 # define yyclearin (yytoken = ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[)
2390 # undef YYBACKUP
2391 # define YYBACKUP(Token, Value) \
2392 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2393 yyerrok, yyerr
2395 ]b4_variant_if([[
2396 /* Variants are always initialized to an empty instance of the
2397 correct type. The default '$$ = $1' action is NOT applied
2398 when using variants. */
2399 // However we really need to prepare yyvsp now if we want to get
2400 // correct locations, so invoke YYFILL for $1 anyway.
2401 (void) YYFILL (1-yyrhslen);
2402 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[
2403 if (yyrhslen == 0)
2404 *yyvalp = yyval_default;
2405 else
2406 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[
2407 /* Default location. */
2408 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
2409 yyerror_range[1].getState().yyloc = *yylocp;
2410 ]])[
2411 /* If yyk == -1, we are running a deferred action on a temporary
2412 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2413 so pretend the stack is "normal". */
2414 YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser));
2415 #if YY_EXCEPTIONS
2416 typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error;
2419 #endif // YY_EXCEPTIONS
2420 switch (yyrule)
2422 ]b4_user_actions[
2423 default: break;
2425 #if YY_EXCEPTIONS
2427 catch (const syntax_error& yyexc)
2429 YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([
2430 *yylocp = yyexc.location;])[
2431 yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ());
2432 YYERROR;
2434 #endif // YY_EXCEPTIONS
2435 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp);
2437 return yyok;
2438 # undef yyerrok
2439 # undef YYABORT
2440 # undef YYACCEPT
2441 # undef YYERROR
2442 # undef YYBACKUP
2443 # undef yytoken
2444 # undef yyclearin
2445 # undef YYRECOVERING
2448 YYRESULTTAG
2449 yyresolveStack ()
2451 if (yystateStack.isSplit())
2453 int yyn = 0;
2454 for (glr_state* yys = firstTopState();
2455 yys != yystateStack.yysplitPoint;
2456 yys = yys->pred())
2457 yyn += 1;
2458 YYCHK (yyresolveStates (*firstTopState(), yyn));
2460 return yyok;
2463 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2464 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2465 * semantic values. Assumes that all ambiguities in semantic values
2466 * have been previously resolved. Set *YYVALP to the resulting value,
2467 * and *YYLOCP to the computed location (if any). Return value is as
2468 * for userAction. */
2469 YYRESULTTAG
2470 yydoAction (state_set_index yyk, rule_num yyrule,
2471 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2473 const int yynrhs = yyrhsLength (yyrule);
2475 if (!yystateStack.isSplit())
2477 /* Standard special case: single stack. */
2478 YYASSERT (yyk.get() == 0);
2479 glr_stack_item* yyrhs = yystateStack.firstTop()->asItem();
2480 const YYRESULTTAG res
2481 = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[);
2482 yystateStack.pop_back(static_cast<size_t>(yynrhs));
2483 yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState());
2484 return res;
2486 else
2488 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
2489 glr_state* yys = yystateStack.topAt(yyk);
2490 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[
2491 if (yynrhs == 0)
2492 /* Set default location. */
2493 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[
2494 for (int yyi = 0; yyi < yynrhs; yyi += 1)
2496 yys = yys->pred();
2497 YYASSERT (yys != YY_NULLPTR);
2499 yystateStack.yyupdateSplit (*yys);
2500 yystateStack.setTopAt(yyk, yys);
2501 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
2502 yyk,
2503 yyvalp]b4_locations_if([, yylocp])[);
2507 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2508 * and push back on the resulting nonterminal symbol. Perform the
2509 * semantic action associated with YYRULE and store its value with the
2510 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2511 * unambiguous. Otherwise, store the deferred semantic action with
2512 * the new state. If the new state would have an identical input
2513 * position, LR state, and predecessor to an existing state on the stack,
2514 * it is identified with that existing state, eliminating stack #YYK from
2515 * *YYSTACKP. In this case, the semantic value is
2516 * added to the options for the existing state's semantic value.
2518 YYRESULTTAG
2519 yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval)
2521 size_t yyposn = topState(yyk)->yyposn;
2523 if (yyforceEval || !yystateStack.isSplit())
2525 value_type val;]b4_locations_if([[
2526 location_type loc;]])[
2528 YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[);
2529 if (yyflag == yyerr && yystateStack.isSplit())
2530 {]b4_parse_trace_if([[
2531 YYCDEBUG << "Parse on stack " << yyk.get ()
2532 << " rejected by rule " << yyrule - 1
2533 << " (line " << int (yyrline[yyrule]) << ").\n";
2534 ]])[}
2535 if (yyflag != yyok)
2536 return yyflag;
2537 yyglrShift (yyk,
2538 yyLRgotoState (topState(yyk)->yylrState,
2539 yylhsNonterm (yyrule)),
2540 yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[
2541 // FIXME: User destructors.
2542 // Value type destructor.
2543 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[
2545 else
2547 glr_state *yys = yystateStack.topAt(yyk);
2548 glr_state *yys0 = yys;
2549 for (int yyn = yyrhsLength (yyrule); 0 < yyn; yyn -= 1)
2551 yys = yys->pred();
2552 YYASSERT (yys != YY_NULLPTR);
2554 yystateStack.yyupdateSplit (*yys);
2555 state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[
2556 YYCDEBUG << "Reduced stack " << yyk.get ()
2557 << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule])
2558 << "); action deferred. Now in state " << yynewLRState
2559 << ".\n";]])[
2560 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi)
2561 if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR)
2563 const glr_state* yysplit = yystateStack.yysplitPoint;
2564 glr_state* yyp = yystateStack.topAt(yyi);
2565 while (yyp != yys && yyp != yysplit
2566 && yyp->yyposn >= yyposn)
2568 if (yyp->yylrState == yynewLRState
2569 && yyp->pred() == yys)
2571 yyaddDeferredAction (yyk, yyp, yys0, yyrule);
2572 yystateStack.yytops.yymarkStackDeleted (yyk);
2573 YYCDEBUG << "Merging stack " << yyk.get ()
2574 << " into stack " << yyi.get () << ".\n";
2575 return yyok;
2577 yyp = yyp->pred();
2580 yystateStack.setTopAt(yyk, yys);
2581 yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule);
2583 return yyok;
2586 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2587 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2588 * semantic value of YYRHS under the action for YYRULE. */
2589 void
2590 yyglrShiftDefer (state_set_index yyk, state_num yylrState,
2591 size_t yyposn, glr_state* yyrhs, rule_num yyrule)
2593 glr_state& yynewState = yystateStack.yynewGLRState (
2594 glr_state (yylrState, yyposn));
2595 yynewState.setPred (yystateStack.topAt (yyk));
2596 yystateStack.setTopAt (yyk, &yynewState);
2598 /* Invokes yyreserveStack. */
2599 yyaddDeferredAction (yyk, &yynewState, yyrhs, yyrule);
2602 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2603 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2604 * value YYVAL_ARG and source location YYLOC_ARG. */
2605 void
2606 yyglrShift (state_set_index yyk, state_num yylrState,
2607 size_t yyposn,
2608 const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[)
2610 glr_state& yynewState = yystateStack.yynewGLRState (
2611 glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[));
2612 yynewState.setPred (yystateStack.topAt(yyk));
2613 yystateStack.setTopAt (yyk, &yynewState);
2614 yyreserveGlrStack ();
2617 #if ]b4_api_PREFIX[DEBUG
2618 void
2619 yypstack (state_set_index yyk) const
2621 yystateStack.yypstates (yystateStack.topAt (yyk));
2623 #endif
2625 glr_state* topState(state_set_index i) {
2626 return yystateStack.topAt(i);
2629 glr_state* firstTopState() {
2630 return yystateStack.firstTop();
2633 private:
2635 void popall_ ()
2637 /* If the stack is well-formed, pop the stack until it is empty,
2638 destroying its entries as we go. But free the stack regardless
2639 of whether it is well-formed. */
2640 for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); k += 1)
2641 if (yystateStack.topAt(k) != YY_NULLPTR)
2643 while (yystateStack.topAt(k) != YY_NULLPTR)
2645 glr_state* state = topState(k);]b4_locations_if([[
2646 yyerror_range[1].getState().yyloc = state->yyloc;]])[
2647 if (state->pred() != YY_NULLPTR)
2648 state->destroy ("Cleanup: popping", yyparser]b4_user_args[);
2649 yystateStack.setTopAt(k, state->pred());
2650 yystateStack.pop_back();
2652 break;
2656 /** Resolve the previous YYN states starting at and including state YYS
2657 * on *YYSTACKP. If result != yyok, some states may have been left
2658 * unresolved possibly with empty semantic option chains. Regardless
2659 * of whether result = yyok, each state has been left with consistent
2660 * data so that destroy can be invoked if necessary. */
2661 YYRESULTTAG
2662 yyresolveStates (glr_state& yys, int yyn)
2664 if (0 < yyn)
2666 YYASSERT (yys.pred() != YY_NULLPTR);
2667 YYCHK (yyresolveStates (*yys.pred(), yyn-1));
2668 if (! yys.yyresolved)
2669 YYCHK (yyresolveValue (yys));
2671 return yyok;
2674 static void
2675 yyuserMerge (int yyn, value_type& yy0, value_type& yy1)
2677 YY_USE (yy0);
2678 YY_USE (yy1);
2680 switch (yyn)
2682 ]b4_mergers[
2683 default: break;
2687 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2688 * perform the indicated actions, and set the semantic value of YYS.
2689 * If result != yyok, the chain of semantic options in YYS has been
2690 * cleared instead or it has been left unmodified except that
2691 * redundant options may have been removed. Regardless of whether
2692 * result = yyok, YYS has been left with consistent data so that
2693 * destroy can be invoked if necessary. */
2694 YYRESULTTAG
2695 yyresolveValue (glr_state& yys)
2697 semantic_option* yybest = yys.firstVal();
2698 YYASSERT(yybest != YY_NULLPTR);
2699 bool yymerge = false;
2700 YYRESULTTAG yyflag;]b4_locations_if([
2701 location_type *yylocp = &yys.yyloc;])[
2703 semantic_option* yypPrev = yybest;
2704 for (semantic_option* yyp = yybest->next();
2705 yyp != YY_NULLPTR; )
2707 if (yybest->isIdenticalTo (*yyp))
2709 yybest->mergeWith (*yyp);
2710 yypPrev->setNext(yyp->next());
2711 yyp = yypPrev->next();
2713 else
2715 switch (yypreference (*yybest, *yyp))
2717 case 0:]b4_locations_if([[
2718 yyresolveLocations (yys, 1);]])[
2719 return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[);
2720 break;
2721 case 1:
2722 yymerge = true;
2723 break;
2724 case 2:
2725 break;
2726 case 3:
2727 yybest = yyp;
2728 yymerge = false;
2729 break;
2730 default:
2731 /* This cannot happen so it is not worth a YYASSERT (false),
2732 but some compilers complain if the default case is
2733 omitted. */
2734 break;
2736 yypPrev = yyp;
2737 yyp = yyp->next();
2741 value_type val;
2742 if (yymerge)
2744 int yyprec = yydprec[yybest->yyrule];
2745 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2746 if (yyflag == yyok)
2747 for (semantic_option* yyp = yybest->next();
2748 yyp != YY_NULLPTR;
2749 yyp = yyp->next())
2751 if (yyprec == yydprec[yyp->yyrule])
2753 value_type yyval_other;]b4_locations_if([
2754 location_type yydummy;])[
2755 yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[);
2756 if (yyflag != yyok)
2758 yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2759 yy_accessing_symbol (yys.yylrState),
2760 this->yylval]b4_locations_if([, *yylocp])[);
2761 break;
2763 yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
2764 // FIXME: User destructors.
2765 // Value type destructor.
2766 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[
2770 else
2771 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2773 if (yyflag == yyok)
2775 yys.yyresolved = true;
2776 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[
2777 new (&yys.value ()) value_type ();
2778 ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)],
2779 [yys.value ()], [copy], [val])], [[
2780 new (&yys.value ()) value_type (val);]])[
2782 YY_IGNORE_MAYBE_UNINITIALIZED_END
2784 else
2785 yys.setFirstVal(YY_NULLPTR);
2786 ]b4_variant_if([[
2787 // FIXME: User destructors.
2788 // Value type destructor.
2789 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[
2790 return yyflag;
2793 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2794 * user action, and return the semantic value and location in *YYVALP
2795 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2796 * have been destroyed (assuming the user action destroys all RHS
2797 * semantic values if invoked). */
2798 YYRESULTTAG
2799 yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2801 glr_state* yyoptState = yyopt.state();
2802 YYASSERT(yyoptState != YY_NULLPTR);
2803 int yynrhs = yyrhsLength (yyopt.yyrule);
2804 YYRESULTTAG yyflag = yyresolveStates (*yyoptState, yynrhs);
2805 if (yyflag != yyok)
2807 for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1)
2808 yys->destroy ("Cleanup: popping", yyparser]b4_user_args[);
2809 return yyflag;
2812 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
2813 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[
2814 if (yynrhs == 0)
2815 /* Set default location. */
2816 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
2818 symbol_kind_type yytoken_current = this->yytoken;]b4_variant_if([[
2819 value_type yylval_current;
2820 ]b4_symbol_variant([this->yytoken],
2821 [yylval_current], [move], [this->yylval])], [[
2822 value_type yylval_current = this->yylval;]])[]b4_locations_if([
2823 location_type yylloc_current = this->yylloc;])[
2825 this->yytoken = yyopt.yytoken;]b4_variant_if([[
2826 ]b4_symbol_variant([this->yytoken],
2827 [this->yylval], [move], [yyopt.yyval])], [[
2828 this->yylval = yyopt.yyval;]])[]b4_locations_if([
2829 this->yylloc = yyopt.yyloc;])[
2830 yyflag = yyuserAction (yyopt.yyrule, yynrhs,
2831 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
2832 create_state_set_index (-1),
2833 yyvalp]b4_locations_if([, yylocp])[);
2835 this->yytoken = yytoken_current;]b4_variant_if([[
2836 ]b4_symbol_variant([this->yytoken],
2837 [this->yylval], [move], [yylval_current])], [[
2838 this->yylval = yylval_current;]])[]b4_locations_if([
2839 this->yylloc = yylloc_current;])[
2841 return yyflag;
2842 }]b4_locations_if([[
2844 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
2845 * ending at YYS1. Has no effect on previously resolved states.
2846 * The first semantic option of a state is always chosen. */
2847 void
2848 yyresolveLocations (glr_state &yys1, int yyn1)
2850 if (0 < yyn1)
2852 yyresolveLocations (*yys1.pred(), yyn1 - 1);
2853 if (!yys1.yyresolved)
2855 glr_stack_item yyrhsloc[1 + YYMAXRHS];
2856 YYASSERT (yys1.firstVal() != YY_NULLPTR);
2857 semantic_option& yyoption = *yys1.firstVal();
2858 const int yynrhs = yyrhsLength (yyoption.yyrule);
2859 if (0 < yynrhs)
2861 yyresolveLocations (*yyoption.state(), yynrhs);
2862 const glr_state *yys = yyoption.state();
2863 for (int yyn = yynrhs; yyn > 0; yyn -= 1)
2865 yyrhsloc[yyn].getState().yyloc = yys->yyloc;
2866 yys = yys->pred();
2869 else
2871 /* Both yyresolveAction and yyresolveLocations traverse the GSS
2872 in reverse rightmost order. It is only necessary to invoke
2873 yyresolveLocations on a subforest for which yyresolveAction
2874 would have been invoked next had an ambiguity not been
2875 detected. Thus the location of the previous state (but not
2876 necessarily the previous state itself) is guaranteed to be
2877 resolved already. */
2878 YY_IGNORE_NULL_DEREFERENCE_BEGIN
2879 yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc;
2880 YY_IGNORE_NULL_DEREFERENCE_END
2882 YYLLOC_DEFAULT ((yys1.yyloc), yyrhsloc, yynrhs);
2885 }]])[
2887 ]b4_parse_param_vars[
2891 #undef YYSTACKEXPANDABLE
2894 /** If yytoken is empty, fetch the next token. */
2895 static inline void
2896 yygetToken (]b4_namespace_ref[::]b4_parser_class[& yyparser, glr_stack& yystack]b4_user_formals[)
2898 ]b4_parse_param_use()dnl
2899 [ if (yystack.yytoken == ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[)
2901 YYCDEBUG << "Reading a token\n";
2902 int yychar;
2903 #if YY_EXCEPTIONS
2906 #endif // YY_EXCEPTIONS
2907 {]b4_token_ctor_if([[
2908 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_type symbol_type;
2909 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
2910 symbol_type yylookahead = ]b4_lex[;
2911 yystack.yytoken = yylookahead.kind ();]b4_variant_if([[
2912 ]b4_symbol_variant([yystack.yytoken],
2913 [yystack.yylval], [move], [yylookahead.value])], [[
2914 yystack.yylval = yylookahead.value;]])[]b4_locations_if([
2915 yystack.yylloc = yylookahead.location;
2916 yylookahead.kind_ = symbol_kind::S_YYEMPTY;])[]], [[
2917 yychar = ]b4_lex[;]])[
2919 #if YY_EXCEPTIONS
2921 catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
2923 YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
2924 yystack.yylloc = yyexc.location;])[
2925 yyparser.error (]b4_locations_if([yystack.yylloc, ])[yyexc.what ());
2926 // Map errors caught in the scanner to the error token, so that error
2927 // handling is started.]b4_token_ctor_if([[
2928 yystack.yytoken = ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(error, kind)[;]], [[
2929 yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, id)[;]])[
2931 #endif // YY_EXCEPTIONS]b4_token_ctor_if([], [[
2932 yystack.yytoken
2933 = ]b4_namespace_ref[::]b4_parser_class[::yytranslate_ (yychar);]])[
2935 if (yystack.yytoken == ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(eof, kind)[)
2936 YYCDEBUG << "Now at end of input.\n";
2937 else
2938 YY_SYMBOL_PRINT ("Next token is", yystack.yytoken, yystack.yylval, yystack.yylloc);
2942 /* Bison grammar-table manipulation. */
2944 /** Number of symbols composing the right hand side of rule #RULE. */
2945 static inline int
2946 yyrhsLength (rule_num yyrule)
2948 return yyr2[yyrule];
2951 /** The action to take in YYSTATE on seeing YYTOKEN.
2952 * Result R means
2953 * R < 0: Reduce on rule -R.
2954 * R = 0: Error.
2955 * R > 0: Shift to state R.
2956 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
2957 * of conflicting reductions.
2959 static inline int
2960 yygetLRActions (state_num yystate, yysymbol_kind_t yytoken, const short*& yyconflicts)
2962 int yyindex = yypact[yystate] + yytoken;
2963 if (yytoken == ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(error, kind)[)
2965 // This is the error token.
2966 yyconflicts = yyconfl;
2967 return 0;
2969 else if (yyisDefaultedState (yystate)
2970 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
2972 yyconflicts = yyconfl;
2973 return -yydefact[yystate];
2975 else if (! yytable_value_is_error (yytable[yyindex]))
2977 yyconflicts = yyconfl + yyconflp[yyindex];
2978 return yytable[yyindex];
2980 else
2982 yyconflicts = yyconfl + yyconflp[yyindex];
2983 return 0;
2987 /** Compute post-reduction state.
2988 * \param yystate the current state
2989 * \param yysym the nonterminal to push on the stack
2991 static inline state_num
2992 yyLRgotoState (state_num yystate, yysymbol_kind_t yysym)
2994 const int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
2995 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
2996 return yytable[yyr];
2997 else
2998 return yydefgoto[yysym - YYNTOKENS];
3001 /* GLRStacks */
3003 /** Y0 and Y1 represent two possible actions to take in a given
3004 * parsing state; return 0 if no combination is possible,
3005 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3006 static int
3007 yypreference (const semantic_option& y0, const semantic_option& y1)
3009 rule_num r0 = y0.yyrule, r1 = y1.yyrule;
3010 int p0 = yydprec[r0], p1 = yydprec[r1];
3012 if (p0 == p1)
3014 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
3015 return 0;
3016 else
3017 return 1;
3019 if (p0 == 0 || p1 == 0)
3020 return 0;
3021 if (p0 < p1)
3022 return 3;
3023 if (p1 < p0)
3024 return 2;
3025 return 0;
3028 #define YYCHK1(YYE) \
3029 do { \
3030 switch (YYE) { \
3031 case yyok: \
3032 break; \
3033 case yyabort: \
3034 goto yyabortlab; \
3035 case yyaccept: \
3036 goto yyacceptlab; \
3037 case yyerr: \
3038 goto yyuser_error; \
3039 default: \
3040 goto yybuglab; \
3042 } while (false)
3045 /* DEBUGGING ONLY */
3046 #if ]b4_api_PREFIX[DEBUG
3047 static void
3048 yypstack (const glr_stack& yystack, size_t yyk)
3050 yystack.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk)));
3052 static void yypdumpstack (const glr_stack& yystack)
3054 yystack.yypdumpstack ();
3057 #endif
3059 ]b4_namespace_open[
3060 /// Build a parser object.
3061 ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
3062 :])[
3063 #if ]b4_api_PREFIX[DEBUG
3064 ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
3065 #endif]b4_parse_param_cons[
3068 ]b4_parser_class::~b4_parser_class[ ()
3071 ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3075 ]b4_parser_class[::operator() ()
3077 return parse ();
3081 ]b4_parser_class[::parse ()
3083 ]b4_parser_class[ &yyparser = *this;
3084 int yyresult;
3085 glr_stack yystack(YYINITDEPTH, *this]b4_user_args[);
3086 size_t yyposn;
3088 YYCDEBUG << "Starting parse\n";
3090 yystack.yytoken = ]b4_symbol(empty, kind)[;]b4_variant_if([], [[
3091 yystack.yylval = yyval_default;]])[]b4_locations_if([
3092 yystack.yylloc = yyloc_default;])[
3093 ]m4_ifdef([b4_initial_action], [
3094 b4_dollar_pushdef([yystack.yylval], [], [], [yystack.yylloc])dnl
3095 b4_user_initial_action
3096 b4_dollar_popdef])[]dnl
3098 switch (YYSETJMP (yystack.yyexception_buffer))
3100 case 0: break;
3101 case 1: goto yyabortlab;
3102 case 2: goto yyexhaustedlab;
3103 default: goto yybuglab;
3105 yystack.yyglrShift (create_state_set_index(0), 0, 0, yystack.yylval]b4_locations_if([, yystack.yylloc])[);
3106 yyposn = 0;
3108 while (true)
3110 /* For efficiency, we have two loops, the first of which is
3111 specialized to deterministic operation (single stack, no
3112 potential ambiguity). */
3113 /* Standard mode */
3114 while (true)
3116 const state_num yystate = yystack.firstTopState()->yylrState;
3117 YYCDEBUG << "Entering state " << yystate << '\n';
3118 if (yystate == YYFINAL)
3119 goto yyacceptlab;
3120 if (yyisDefaultedState (yystate))
3122 const rule_num yyrule = yydefaultAction (yystate);
3123 if (yyrule == 0)
3124 {]b4_locations_if([[
3125 yystack.yyerror_range[1].getState().yyloc = yystack.yylloc;]])[
3126 yystack.yyreportSyntaxError ();
3127 goto yyuser_error;
3129 YYCHK1 (yystack.yyglrReduce (create_state_set_index(0), yyrule, true));
3131 else
3133 yygetToken (yyparser, yystack]b4_user_args[);
3134 const short* yyconflicts;
3135 const int yyaction = yygetLRActions (yystate, yystack.yytoken, yyconflicts);
3136 if (*yyconflicts != 0)
3137 break;
3138 if (yyisShiftAction (yyaction))
3140 YY_SYMBOL_PRINT ("Shifting", yystack.yytoken, yystack.yylval, yystack.yylloc);
3141 yyposn += 1;
3142 // FIXME: we should move yylval.
3143 yystack.yyglrShift (create_state_set_index(0), yyaction, yyposn, yystack.yylval]b4_locations_if([, yystack.yylloc])[);]b4_variant_if([[
3144 // FIXME: User destructors.
3145 // Value type destructor.
3146 ]b4_symbol_variant([[yystack.yytoken]], [[yystack.yylval]], [[template destroy]])])[
3147 yystack.yytoken = ]b4_symbol(empty, kind)[;
3148 if (0 < yystack.yyerrState)
3149 yystack.yyerrState -= 1;
3151 else if (yyisErrorAction (yyaction))
3152 {]b4_locations_if([[
3153 yystack.yyerror_range[1].getState().yyloc = yystack.yylloc;]])[
3154 /* Don't issue an error message again for exceptions
3155 thrown from the scanner. */
3156 if (yystack.yytoken != ]b4_symbol(error, kind)[)
3157 yystack.yyreportSyntaxError ();
3158 goto yyuser_error;
3160 else
3161 YYCHK1 (yystack.yyglrReduce (create_state_set_index(0), -yyaction, true));
3165 while (true)
3167 for (state_set_index yys = create_state_set_index(0); yys.uget() < yystack.yystateStack.numTops(); ++yys)
3168 yystack.yystateStack.yytops.setLookaheadNeeds(yys, yystack.yytoken != ]b4_symbol(empty, kind)[);
3170 /* yyprocessOneStack returns one of three things:
3172 - An error flag. If the caller is yyprocessOneStack, it
3173 immediately returns as well. When the caller is finally
3174 yyparse, it jumps to an error label via YYCHK1.
3176 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
3177 (yys), which sets the top state of yys to NULL. Thus,
3178 yyparse's following invocation of yyremoveDeletes will remove
3179 the stack.
3181 - yyok, when ready to shift a token.
3183 Except in the first case, yyparse will invoke yyremoveDeletes and
3184 then shift the next token onto all remaining stacks. This
3185 synchronization of the shift (that is, after all preceding
3186 reductions on all stacks) helps prevent double destructor calls
3187 on yylval in the event of memory exhaustion. */
3189 for (state_set_index yys = create_state_set_index(0); yys.uget() < yystack.yystateStack.numTops(); ++yys)
3190 YYCHK1 (yystack.yyprocessOneStack (yys, yyposn]b4_locations_if([, &yystack.yylloc])[));
3191 yystack.yystateStack.yytops.yyremoveDeletes ();
3192 if (yystack.yystateStack.yytops.size() == 0)
3194 yystack.yystateStack.yytops.yyundeleteLastStack ();
3195 if (yystack.yystateStack.yytops.size() == 0)
3196 yystack.yyFail (]b4_locations_if([&yystack.yylloc, ])[YY_("syntax error"));
3197 YYCHK1 (yystack.yyresolveStack ());
3198 YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[
3199 yystack.yyerror_range[1].getState().yyloc = yystack.yylloc;]])[
3200 yystack.yyreportSyntaxError ();
3201 goto yyuser_error;
3204 /* If any yyglrShift call fails, it will fail after shifting. Thus,
3205 a copy of yylval will already be on stack 0 in the event of a
3206 failure in the following loop. Thus, yytoken is set to ]b4_symbol(empty, kind)[
3207 before the loop to make sure the user destructor for yylval isn't
3208 called twice. */
3209 yysymbol_kind_t yytoken_to_shift = yystack.yytoken;
3210 yystack.yytoken = ]b4_symbol(empty, kind)[;
3211 yyposn += 1;
3212 for (state_set_index yys = create_state_set_index(0); yys.uget() < yystack.yystateStack.numTops(); ++yys)
3214 const state_num yystate = yystack.topState(yys)->yylrState;
3215 const short* yyconflicts;
3216 const int yyaction
3217 = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
3218 /* Note that yyconflicts were handled by yyprocessOneStack. */
3219 YYCDEBUG << "On stack " << yys.get() << ", ";
3220 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, yystack.yylval, yystack.yylloc);
3221 yystack.yyglrShift (yys, yyaction, yyposn, yystack.yylval]b4_locations_if([, yystack.yylloc])[);
3222 YYCDEBUG << "Stack " << yys.get() << " now in state "
3223 << yystack.topState(yys)->yylrState << '\n';
3225 ]b4_variant_if([[
3226 // FIXME: User destructors.
3227 // Value type destructor.
3228 ]b4_symbol_variant([[yytoken_to_shift]], [[yystack.yylval]], [[template destroy]])])[
3230 if (yystack.yystateStack.yytops.size() == 1)
3232 YYCHK1 (yystack.yyresolveStack ());
3233 YYCDEBUG << "Returning to deterministic operation.\n";
3234 yystack.yystateStack.yycompressStack ();
3235 break;
3238 continue;
3239 yyuser_error:
3240 yystack.yyrecoverSyntaxError (]b4_locations_if([&yystack.yylloc])[);
3241 yyposn = yystack.firstTopState()->yyposn;
3244 yyacceptlab:
3245 yyresult = 0;
3246 goto yyreturn;
3248 yybuglab:
3249 YYASSERT (false);
3250 goto yyabortlab;
3252 yyabortlab:
3253 yyresult = 1;
3254 goto yyreturn;
3256 yyexhaustedlab:
3257 error (]b4_locations_if([yystack.yylloc, ])[YY_("memory exhausted"));
3258 yyresult = 2;
3259 goto yyreturn;
3261 yyreturn:
3262 return yyresult;
3265 ]b4_parse_error_bmatch([custom\|detailed],
3266 [[ const char *
3267 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3269 static const char *const yy_sname[] =
3271 ]b4_symbol_names[
3272 };]b4_has_translations_if([[
3273 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3274 internationalizable. */
3275 static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
3277 ]b4_translatable[
3279 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
3280 ? _(yy_sname[yysymbol])
3281 : yy_sname[yysymbol]);]], [[
3282 return yy_sname[yysymbol];]])[
3285 [simple],
3286 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3287 const char *
3288 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3290 return yytname_[yysymbol];
3292 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3294 [verbose],
3295 [[ /* Return YYSTR after stripping away unnecessary quotes and
3296 backslashes, so that it's suitable for yyerror. The heuristic is
3297 that double-quoting is unnecessary unless the string contains an
3298 apostrophe, a comma, or backslash (other than backslash-backslash).
3299 YYSTR is taken from yytname. */
3300 std::string
3301 ]b4_parser_class[::yytnamerr_ (const char *yystr)
3303 if (*yystr == '"')
3305 std::string yyr;
3306 char const *yyp = yystr;
3308 for (;;)
3309 switch (*++yyp)
3311 case '\'':
3312 case ',':
3313 goto do_not_strip_quotes;
3315 case '\\':
3316 if (*++yyp != '\\')
3317 goto do_not_strip_quotes;
3318 else
3319 goto append;
3321 append:
3322 default:
3323 yyr += *yyp;
3324 break;
3326 case '"':
3327 return yyr;
3329 do_not_strip_quotes: ;
3332 return yystr;
3335 std::string
3336 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3338 return yytnamerr_ (yytname_[yysymbol]);
3340 ]])[
3342 ]b4_parse_error_bmatch([simple\|verbose],
3343 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3344 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3345 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3346 const char*
3347 const ]b4_parser_class[::yytname_[] =
3349 ]b4_tname[
3351 #endif
3352 ]])[
3354 void
3355 ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
3356 value_type& yyval]b4_locations_if([[,
3357 location_type& yyloc]])[)
3359 YY_USE (yyval);]b4_locations_if([[
3360 YY_USE (yyloc);]])[
3361 if (!yymsg)
3362 yymsg = "Deleting";
3363 ]b4_parser_class[& yyparser = *this;
3364 YY_USE (yyparser);
3365 YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc);
3367 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3368 ]b4_symbol_actions([destructor])[
3369 YY_IGNORE_MAYBE_UNINITIALIZED_END
3372 #if ]b4_api_PREFIX[DEBUG
3373 /*--------------------.
3374 | Print this symbol. |
3375 `--------------------*/
3377 void
3378 ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
3379 const value_type& yyval]b4_locations_if([[,
3380 const location_type& yyloc]])[) const
3381 {]b4_locations_if([[
3382 YY_USE (yyloc);]])[
3383 YY_USE (yyval);
3384 std::ostream& yyo = debug_stream ();
3385 YY_USE (yyo);
3386 ]b4_symbol_actions([printer])[
3389 void
3390 ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
3391 const value_type& yyval]b4_locations_if([[,
3392 const location_type& yyloc]])[) const
3394 *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
3395 << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
3396 << yyloc << ": "]])[;
3397 yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[);
3398 *yycdebug_ << ')';
3401 std::ostream&
3402 ]b4_parser_class[::debug_stream () const
3404 return *yycdebug_;
3407 void
3408 ]b4_parser_class[::set_debug_stream (std::ostream& o)
3410 yycdebug_ = &o;
3414 ]b4_parser_class[::debug_level_type
3415 ]b4_parser_class[::debug_level () const
3417 return yydebug;
3420 void
3421 ]b4_parser_class[::set_debug_level (debug_level_type l)
3423 // Actually, it is yydebug which is really used.
3424 yydebug = l;
3426 #endif // ]b4_api_PREFIX[DEBUG
3428 ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[
3429 ]b4_namespace_close[]dnl
3430 b4_epilogue[]dnl
3431 b4_output_end