gnulib: update
[bison.git] / data / skeletons / glr2.cc
blobedd05d897f0a22adc9d11381660165a318866b1a
1 # C++ GLR skeleton for Bison
3 # Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 m4_include(b4_skeletonsdir/[c++.m4])
20 # api.value.type=variant is valid.
21 m4_define([b4_value_type_setup_variant])
23 # b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED)
24 # -------------------------------------------
25 m4_define([b4_tname_if],
26 [m4_case(b4_percent_define_get([[parse.error]]),
27 [verbose], [$1],
28 [b4_token_table_if([$1],
29 [$2])])])
31 b4_bison_locations_if([
32 m4_define([b4_location_constructors])
33 m4_include(b4_skeletonsdir/[location.cc])])
34 b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])])
36 m4_define([b4_parser_class],
37 [b4_percent_define_get([[api.parser.class]])])
39 ]m4_define([b4_define_symbol_kind],
40 [m4_format([#define %-15s %s],
41 b4_symbol($][1, kind_base),
42 b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base))
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.
126 # Currently we need two different b4_symbol_action: once for the
127 # self-contained symbols, and another time for yy_destroy_ and
128 # yy_symbol_value_print_, which don't use genuine symbols yet.
129 m4_define([b4_symbol_action],
130 [b4_symbol_if([$1], [has_$2],
131 [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
132 b4_dollar_pushdef([yysym.value],
133 [$1],
135 [yysym.location])dnl
136 _b4_symbol_case([$1])[]dnl
137 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
138 b4_symbol([$1], [$2])
139 b4_syncline([@oline@], [@ofile@])dnl
140 break;
142 m4_popdef([b4_symbol_value])[]dnl
143 b4_dollar_popdef[]dnl
144 ])])
147 # b4_symbol_action_for_yyval(SYMBOL-NUM, KIND)
148 # --------------------------------------------
149 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
150 # Same as in C, but using references instead of pointers.
151 m4_define([b4_symbol_action_for_yyval],
152 [b4_symbol_if([$1], [has_$2],
153 [b4_dollar_pushdef([yyval],
154 [$1],
156 [yyloc])dnl
157 _b4_symbol_case([$1])[]dnl
158 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
159 b4_symbol([$1], [$2])
160 b4_syncline([@oline@], [@ofile@])dnl
161 break;
163 b4_dollar_popdef[]dnl
164 ])])
167 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
168 # ---------------------------------------------------
169 m4_define([b4_call_merger],
170 [b4_case([$1],
171 [ b4_symbol_if([$3], [has_type],
172 [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());],
173 [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])],
174 [yy0 = $2 (yy0, yy1);])])])
176 # b4_yylex
177 # --------
178 # Call yylex.
179 m4_define([b4_yylex],
180 [b4_token_ctor_if(
181 [b4_function_call([yylex],
182 [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
183 [b4_function_call([yylex], [int],
184 [[value_type *], [&this->yylval]][]dnl
185 b4_locations_if([, [[location_type *], [&this->yylloc]]])dnl
186 m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
189 # b4_shared_declarations(hh|cc)
190 # -----------------------------
191 # Declaration that might either go into the header (if --header, $1 = hh)
192 # or in the implementation file.
193 m4_define([b4_shared_declarations],
194 [b4_percent_code_get([[requires]])[
195 #include <algorithm>
196 #include <cstddef> // ptrdiff_t
197 #include <cstring> // memcpy
198 #include <iostream>
199 #include <iomanip>
200 #include <limits>
201 #include <stdexcept>
202 #include <stdint.h>
203 #include <string>
204 #include <vector>
206 ]b4_cxx_portability[
207 ]m4_ifdef([b4_location_include],
208 [[# include ]b4_location_include])[
209 ]b4_variant_if([b4_variant_includes])[
211 // Whether we are compiled with exception support.
212 #ifndef YY_EXCEPTIONS
213 # if defined __GNUC__ && !defined __EXCEPTIONS
214 # define YY_EXCEPTIONS 0
215 # else
216 # define YY_EXCEPTIONS 1
217 # endif
218 #endif
220 ]b4_YYDEBUG_define[
222 ]b4_namespace_open[
224 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
225 [b4_location_define])])[
227 /// A Bison parser.
228 class ]b4_parser_class[
230 public:
231 ]b4_public_types_declare[
232 ]b4_symbol_type_define[
234 /// Build a parser object.
235 ]b4_parser_class[ (]b4_parse_param_decl[);
236 ~]b4_parser_class[ ();
238 /// Parse. An alias for parse ().
239 /// \returns 0 iff parsing succeeded.
240 int operator() ();
242 /// Parse.
243 /// \returns 0 iff parsing succeeded.
244 int parse ();
246 #if ]b4_api_PREFIX[DEBUG
247 /// The current debugging stream.
248 std::ostream& debug_stream () const;
249 /// Set the current debugging stream.
250 void set_debug_stream (std::ostream &);
252 /// Type for debugging levels.
253 typedef int debug_level_type;
254 /// The current debugging level.
255 debug_level_type debug_level () const;
256 /// Set the current debugging level.
257 void set_debug_level (debug_level_type l);
258 #endif
260 /// Report a syntax error.]b4_locations_if([[
261 /// \param loc where the syntax error is found.]])[
262 /// \param msg a description of the syntax error.
263 void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
265 ]b4_parse_error_bmatch(
266 [custom\|detailed],
267 [[ /// The user-facing name of the symbol whose (internal) number is
268 /// YYSYMBOL. No bounds checking.
269 static const char *symbol_name (symbol_kind_type yysymbol);]],
270 [simple],
271 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
272 /// The user-facing name of the symbol whose (internal) number is
273 /// YYSYMBOL. No bounds checking.
274 static const char *symbol_name (symbol_kind_type yysymbol);
275 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
277 [verbose],
278 [[ /// The user-facing name of the symbol whose (internal) number is
279 /// YYSYMBOL. No bounds checking.
280 static std::string symbol_name (symbol_kind_type yysymbol);]])[
282 ]b4_token_constructor_define[
283 # if ]b4_api_PREFIX[DEBUG
284 public:
285 /// \brief Report a symbol value on the debug stream.
286 /// \param yykind The symbol kind.
287 /// \param yyval Its semantic value.]b4_locations_if([[
288 /// \param yyloc Its location.]])[
289 void yy_symbol_value_print_ (symbol_kind_type yykind,
290 const value_type& yyval]b4_locations_if([[,
291 const location_type& yyloc]])[) const;
292 /// \brief Report a symbol on the debug stream.
293 /// \param yykind The symbol kind.
294 /// \param yyval Its semantic value.]b4_locations_if([[
295 /// \param yyloc Its location.]])[
296 void yy_symbol_print_ (symbol_kind_type yykind,
297 const value_type& yyval]b4_locations_if([[,
298 const location_type& yyloc]])[) const;
299 private:
300 /// Debug stream.
301 std::ostream* yycdebug_;
302 #endif
304 public: // FIXME: Private
305 /// Convert a scanner token kind \a t to a symbol kind.
306 /// In theory \a t should be a token_kind_type, but character literals
307 /// are valid, yet not members of the token_type enum.
308 static symbol_kind_type yytranslate_ (int t);
310 ]b4_parse_error_bmatch(
311 [simple],
312 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
313 /// For a symbol, its name in clear.
314 static const char* const yytname_[];
315 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
317 [verbose],
318 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
319 static std::string yytnamerr_ (const char *yystr);
321 /// For a symbol, its name in clear.
322 static const char* const yytname_[];
323 ]])[
325 /// \brief Reclaim the memory associated to a symbol.
326 /// \param yymsg Why this token is reclaimed.
327 /// If null, print nothing.
328 /// \param yykind The symbol kind.
329 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
330 value_type& yyval]b4_locations_if([[,
331 location_type& yyloc]])[);
333 ]b4_parse_param_vars[
336 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
337 ]b4_public_types_define([$1])])[
338 ]b4_namespace_close[
340 ]b4_percent_code_get([[provides]])[
341 ]])[
344 ## -------------- ##
345 ## Output files. ##
346 ## -------------- ##
349 # ------------- #
350 # Header file. #
351 # ------------- #
353 ]b4_header_if([[
354 ]b4_output_begin([b4_spec_header_file])[
355 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
356 [2002-2015, 2018-2021])[
357 // C++ GLR parser skeleton written by Valentin Tolmer.
359 ]b4_disclaimer[
360 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
361 ]b4_shared_declarations([hh])[
362 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
363 ]b4_output_end])[
366 # --------------------- #
367 # Implementation file. #
368 # --------------------- #
370 ]b4_output_begin([b4_parser_file_name])[
371 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
372 [2002-2015, 2018-2021])[
373 // C++ GLR parser skeleton written by Valentin Tolmer.
375 ]b4_disclaimer[
376 ]b4_identification[
378 ]b4_percent_code_get([[top]])[
379 ]m4_if(b4_prefix, [yy], [],
380 [[/* Substitute the variable and function names. */
381 #define yyparse ]b4_prefix[parse
382 #define yylex ]b4_prefix[lex
383 #define yyerror ]b4_prefix[error
384 #define yydebug ]b4_prefix[debug]])[
386 ]b4_user_pre_prologue[
388 ]b4_null_define[
390 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
391 [b4_shared_declarations([cc])])[
393 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
395 /* Default (constant) value used for initialization for null
396 right-hand sides. Unlike the standard yacc.c template, here we set
397 the default value of $$ to a zeroed-out value. Since the default
398 value is undefined, this behavior is technically correct. */
399 static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;]b4_locations_if([[
400 static ]b4_namespace_ref[::]b4_parser_class[::location_type yyloc_default][]b4_yyloc_default;])[
402 ]b4_user_post_prologue[
403 ]b4_percent_code_get[]dnl
405 [#include <cstdio>
406 #include <cstdlib>
408 #ifndef YY_
409 # if defined YYENABLE_NLS && YYENABLE_NLS
410 # if ENABLE_NLS
411 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
412 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
413 # endif
414 # endif
415 # ifndef YY_
416 # define YY_(Msgid) Msgid
417 # endif
418 #endif
420 #ifndef YYFREE
421 # define YYFREE free
422 #endif
423 #ifndef YYMALLOC
424 # define YYMALLOC malloc
425 #endif
427 #ifndef YYSETJMP
428 # include <setjmp.h>
429 # define YYJMP_BUF jmp_buf
430 # define YYSETJMP(Env) setjmp (Env)
431 /* Pacify Clang and ICC. */
432 # define YYLONGJMP(Env, Val) \
433 do { \
434 longjmp (Env, Val); \
435 YYASSERT (0); \
436 } while (false)
437 #endif
439 ]b4_attribute_define([noreturn])[
441 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
442 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
443 _Pragma ("GCC diagnostic push") \
444 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
445 # define YY_IGNORE_NULL_DEREFERENCE_END \
446 _Pragma ("GCC diagnostic pop")
447 #else
448 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
449 # define YY_IGNORE_NULL_DEREFERENCE_END
450 #endif
452 ]b4_null_define[
453 ]b4_cast_define[
455 // FIXME: Use the same conventions as lalr1.cc.
456 ]b4_parse_assert_if[
457 #ifndef YYASSERT
458 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
459 #endif
461 #ifdef YYDEBUG
462 # define YYDASSERT(Condition) YYASSERT(Condition)
463 #else
464 # define YYDASSERT(Condition)
465 #endif
467 /* YYFINAL -- State number of the termination state. */
468 #define YYFINAL ]b4_final_state_number[
469 /* YYLAST -- Last index in YYTABLE. */
470 #define YYLAST ]b4_last[
472 /* YYNTOKENS -- Number of terminals. */
473 #define YYNTOKENS ]b4_tokens_number[
474 /* YYNNTS -- Number of nonterminals. */
475 #define YYNNTS ]b4_nterms_number[
476 /* YYNRULES -- Number of rules. */
477 #define YYNRULES ]b4_rules_number[
478 /* YYNSTATES -- Number of states. */
479 #define YYNSTATES ]b4_states_number[
480 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
481 #define YYMAXRHS ]b4_r2_max[
482 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
483 accessed by $0, $-1, etc., in any rule. */
484 #define YYMAXLEFT ]b4_max_left_semantic_context[
486 #if ]b4_api_PREFIX[DEBUG
487 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
488 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
490 ]b4_rline[
492 #endif
494 #define YYPACT_NINF ]b4_pact_ninf[
495 #define YYTABLE_NINF ]b4_table_ninf[
497 ]b4_parser_tables_define[
499 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
500 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
502 ]b4_dprec[
505 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
506 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
508 ]b4_merger[
511 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
512 in the case of predicates. */
513 static const bool yyimmediate[] =
515 ]b4_immediate[
518 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
519 list of conflicting reductions corresponding to action entry for
520 state STATE-NUM in yytable. 0 means no conflicts. The list in
521 yyconfl is terminated by a rule number of 0. */
522 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
524 ]b4_conflict_list_heads[
527 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
528 0, pointed into by YYCONFLP. */
529 ]dnl Do not use b4_int_type_for here, since there are places where
530 dnl pointers onto yyconfl are taken, whose type is "short*".
531 dnl We probably ought to introduce a type for confl.
532 [static const short yyconfl[] =
534 ]b4_conflicting_rules[
537 /* Error token number */
538 #define YYTERROR 1
540 ]b4_locations_if([[
541 ]b4_yylloc_default_define[
542 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
543 ]])[
545 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
547 #define YYCHK(YYE) \
548 do { \
549 YYRESULTTAG yychk_flag = YYE; \
550 if (yychk_flag != yyok) \
551 return yychk_flag; \
552 } while (false)
554 #if ]b4_api_PREFIX[DEBUG
556 #define YYCDEBUG if (!yydebug) {} else std::cerr
558 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
559 do { \
560 if (yydebug) \
562 std::cerr << Title << ' '; \
563 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
564 std::cerr << '\n'; \
566 } while (false)
568 # define YY_REDUCE_PRINT(Args) \
569 do { \
570 if (yydebug) \
571 yystateStack.yy_reduce_print Args; \
572 } while (false)
574 /* Nonzero means print parse trace. It is left uninitialized so that
575 multiple parsers can coexist. */
576 int yydebug;
578 class glr_stack;
579 static void yypstack (const glr_stack& yystack, size_t yyk)
580 YY_ATTRIBUTE_UNUSED;
581 static void yypdumpstack (const glr_stack& yystack)
582 YY_ATTRIBUTE_UNUSED;
584 #else /* !]b4_api_PREFIX[DEBUG */
586 # define YYCDEBUG if (true) {} else std::cerr
587 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
588 # define YY_REDUCE_PRINT(Args) {}
590 #endif /* !]b4_api_PREFIX[DEBUG */
592 /* YYINITDEPTH -- initial size of the parser's stacks. */
593 #ifndef YYINITDEPTH
594 # define YYINITDEPTH ]b4_stack_depth_init[
595 #endif
597 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
598 if the built-in stack extension method is used).
600 Do not make this value too large; the results are undefined if
601 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
602 evaluated with infinite-precision integer arithmetic. */
604 #ifndef YYMAXDEPTH
605 # define YYMAXDEPTH ]b4_stack_depth_max[
606 #endif
608 /* Minimum number of free items on the stack allowed after an
609 allocation. This is to allow allocation and initialization
610 to be completed by functions that call yyexpandGLRStack before the
611 stack is expanded, thus insuring that all necessary pointers get
612 properly redirected to new data. */
613 #define YYHEADROOM 2
615 #ifndef YYSTACKEXPANDABLE
616 # define YYSTACKEXPANDABLE 1
617 #endif
619 template <typename Parameter>
620 class strong_index_alias
622 public:
623 static strong_index_alias create (std::ptrdiff_t value)
625 strong_index_alias result;
626 result.value_ = value;
627 return result;
630 std::ptrdiff_t const& get () const { return value_; }
632 size_t uget () const { return static_cast<size_t> (value_); }
634 strong_index_alias operator+ (std::ptrdiff_t other) const
636 return strong_index_alias (get () + other);
639 void operator+= (std::ptrdiff_t other)
641 value_ += other;
644 strong_index_alias operator- (std::ptrdiff_t other)
646 return strong_index_alias (get () - other);
649 void operator-= (std::ptrdiff_t other)
651 value_ -= other;
654 size_t operator- (strong_index_alias other)
656 return strong_index_alias (get () - other.get ());
659 strong_index_alias& operator++ ()
661 ++value_;
662 return *this;
665 bool isValid () const
667 return value_ != INVALID_INDEX;
670 void setInvalid()
672 value_ = INVALID_INDEX;
675 bool operator== (strong_index_alias other)
677 return get () == other.get ();
680 bool operator!= (strong_index_alias other)
682 return get () != other.get ();
685 bool operator< (strong_index_alias other)
687 return get () < other.get ();
690 private:
691 static const std::ptrdiff_t INVALID_INDEX;
693 // WARNING: 0-initialized.
694 std::ptrdiff_t value_;
697 template<typename T>
698 const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
699 std::numeric_limits<std::ptrdiff_t>::max ();
701 typedef strong_index_alias<struct glr_state_set_tag> state_set_index;
703 state_set_index create_state_set_index (std::ptrdiff_t value)
705 return state_set_index::create (value);
708 /** State numbers, as in LALR(1) machine */
709 typedef int state_num;
711 /** Rule numbers, as in LALR(1) machine */
712 typedef int rule_num;
714 // Forward declarations.
715 class glr_state;
716 class semantic_option;
717 class glr_stack_item;
718 class glr_stack;
720 /** Accessing symbol of state YYSTATE. */
721 static inline yysymbol_kind_t
722 yy_accessing_symbol (state_num yystate)
724 return YY_CAST (yysymbol_kind_t, yystos[yystate]);
727 /** Left-hand-side symbol for rule #YYRULE. */
728 static inline yysymbol_kind_t
729 yylhsNonterm (rule_num yyrule)
731 return static_cast<yysymbol_kind_t>(yyr1[yyrule]);
734 /** Number of symbols composing the right hand side of rule #RULE. */
735 static inline int
736 yyrhsLength (rule_num yyrule)
738 return yyr2[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 arithmetic 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 arithmetic 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 arithmetic 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 #undef YYFILL
1589 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1591 class state_stack
1593 public:
1594 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
1595 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
1596 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
1598 /** Initialize to a single empty stack, with total maximum
1599 * capacity for all stacks of YYSIZE. */
1600 state_stack (size_t yysize)
1601 : yysplitPoint (YY_NULLPTR)
1603 yyitems.reserve (yysize);
1606 #if YYSTACKEXPANDABLE
1607 /** Returns false if it tried to expand but could not. */
1608 bool
1609 yyexpandGLRStackIfNeeded ()
1611 return YYHEADROOM <= spaceLeft () || yyexpandGLRStack ();
1614 private:
1615 /** If *this is expandable, extend it. WARNING: Pointers into the
1616 stack from outside should be considered invalid after this call.
1617 We always expand when there are 1 or fewer items left AFTER an
1618 allocation, so that we can avoid having external pointers exist
1619 across an allocation. */
1620 bool
1621 yyexpandGLRStack ()
1623 const size_t oldsize = yyitems.size();
1624 if (YYMAXDEPTH - YYHEADROOM < oldsize)
1625 return false;
1626 const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize;
1627 const glr_stack_item *oldbase = &yyitems[0];
1629 yyitems.reserve (yynewSize);
1630 const glr_stack_item *newbase = &yyitems[0];
1632 // Adjust the pointers. Perform raw pointer arithmetic, as there
1633 // is no reason for objects to be aligned on their size.
1634 const ptrdiff_t disp
1635 = reinterpret_cast<const char*> (newbase) - reinterpret_cast<const char*> (oldbase);
1636 if (yysplitPoint)
1637 const_cast<glr_state*&> (yysplitPoint)
1638 = reinterpret_cast<glr_state*> (reinterpret_cast<char*> (const_cast<glr_state*> (yysplitPoint)) + disp);
1640 for (std::vector<glr_state*>::iterator
1641 i = yytops.begin (),
1642 yyend = yytops.end ();
1643 i != yyend; ++i)
1644 if (glr_state_not_null (*i))
1645 *i = reinterpret_cast<glr_state*>(reinterpret_cast<char*>(*i) + disp);
1647 return true;
1650 public:
1651 #else
1652 bool yyexpandGLRStackIfNeeded ()
1654 return YYHEADROOM <= spaceLeft ();
1656 #endif
1657 #undef YYSTACKEXPANDABLE
1659 static bool glr_state_not_null (glr_state* s)
1661 return s != YY_NULLPTR;
1664 bool
1665 reduceToOneStack ()
1667 typedef std::vector<glr_state*>::iterator iterator;
1668 const iterator yybegin = yytops.begin();
1669 const iterator yyend = yytops.end();
1670 const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null);
1671 if (yyit == yyend)
1672 return false;
1673 for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin);
1674 yyk.uget() != numTops(); ++yyk)
1675 yytops.yymarkStackDeleted (yyk);
1676 yytops.yyremoveDeletes ();
1677 yycompressStack ();
1678 return true;
1681 /** Called when returning to deterministic operation to clean up the extra
1682 * stacks. */
1683 void
1684 yycompressStack ()
1686 if (yytops.size() != 1 || !isSplit())
1687 return;
1689 // yyr is the state after the split point.
1690 glr_state* yyr = YY_NULLPTR;
1691 for (glr_state *yyp = firstTop(), *yyq = yyp->pred();
1692 yyp != yysplitPoint;
1693 yyr = yyp, yyp = yyq, yyq = yyp->pred())
1694 yyp->setPred(yyr);
1696 // This const_cast is okay, since anyway we have access to the mutable
1697 // yyitems into which yysplitPoint points.
1698 glr_stack_item* nextFreeItem
1699 = const_cast<glr_state*> (yysplitPoint)->asItem () + 1;
1700 yysplitPoint = YY_NULLPTR;
1701 yytops.clearLastDeleted ();
1703 while (yyr != YY_NULLPTR)
1705 nextFreeItem->setState (*yyr);
1706 glr_state& nextFreeState = nextFreeItem->getState();
1707 yyr = yyr->pred();
1708 nextFreeState.setPred(&(nextFreeItem - 1)->getState());
1709 setFirstTop (&nextFreeState);
1710 ++nextFreeItem;
1712 yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data()));
1715 bool isSplit() const {
1716 return yysplitPoint != YY_NULLPTR;
1719 // Present the interface of a vector of glr_stack_item.
1720 std::vector<glr_stack_item>::const_iterator begin () const
1722 return yyitems.begin ();
1725 std::vector<glr_stack_item>::const_iterator end () const
1727 return yyitems.end ();
1730 size_t size() const
1732 return yyitems.size ();
1735 glr_stack_item& operator[] (size_t i)
1737 return yyitems[i];
1740 glr_stack_item& stackItemAt (size_t index)
1742 return yyitems[index];
1745 size_t numTops () const
1747 return yytops.size ();
1750 glr_state* firstTop () const
1752 return yytops[create_state_set_index (0)];
1755 glr_state* topAt (state_set_index i) const
1757 return yytops[i];
1760 void setFirstTop (glr_state* value)
1762 yytops[create_state_set_index (0)] = value;
1765 void setTopAt (state_set_index i, glr_state* value)
1767 yytops[i] = value;
1770 void pop_back ()
1772 yyitems.pop_back ();
1775 void pop_back (size_t n)
1777 yyitems.resize (yyitems.size () - n);
1780 state_set_index
1781 yysplitStack (state_set_index yyk)
1783 if (!isSplit ())
1785 YYASSERT (yyk.get () == 0);
1786 yysplitPoint = topAt (yyk);
1788 return yytops.yysplitStack (yyk);
1791 /** Assuming that YYS is a GLRState somewhere on *this, update the
1792 * splitpoint of *this, if needed, so that it is at least as deep as
1793 * YYS. */
1794 void
1795 yyupdateSplit (glr_state& yys)
1797 if (isSplit() && &yys < yysplitPoint)
1798 yysplitPoint = &yys;
1801 /** Return a fresh GLRState.
1802 * Callers should call yyreserveStack afterwards to make sure there is
1803 * sufficient headroom. */
1804 glr_state& yynewGLRState (const glr_state& newState)
1806 glr_state& state = yyitems[yynewGLRStackItem (true)].getState ();
1807 #if false && 201103L <= YY_CPLUSPLUS
1808 state = std::move (newState);
1809 #else
1810 state = newState;
1811 #endif
1812 return state;
1815 /** Return a fresh SemanticOption.
1816 * Callers should call yyreserveStack afterwards to make sure there is
1817 * sufficient headroom. */
1818 semantic_option& yynewSemanticOption (semantic_option newOption)
1820 semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption ();
1821 #if 201103L <= YY_CPLUSPLUS
1822 option = std::move (newOption);
1823 #else
1824 option = newOption;
1825 #endif
1826 return option;
1829 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1830 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1831 * For convenience, always return YYLOW1. */
1833 yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal)
1835 if (!yynormal && yylow1 < yylow)
1837 yyfillin (yyvsp, yylow, yylow1);
1838 yylow = yylow1;
1840 return yylow1;
1843 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1844 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1845 * containing the pointer to the next state in the chain. */
1846 void
1847 yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1)
1849 glr_state* s = yyvsp[yylow0].getState().pred();
1850 YYASSERT(s != YY_NULLPTR);
1851 for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred())
1853 glr_state& yys = yyvsp[i].getState();
1854 #if ]b4_api_PREFIX[DEBUG
1855 yys.yylrState = s->yylrState;
1856 #endif
1857 yys.yyresolved = s->yyresolved;
1858 if (s->yyresolved)
1859 {]b4_variant_if([[
1860 new (&yys.value ()) value_type ();
1861 ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)],
1862 [yys.value ()], [copy], [s->value ()])], [[
1863 new (&yys.value ()) value_type (s->value ());]])[
1865 else
1866 /* The effect of using yyval or yyloc (in an immediate
1867 * rule) is undefined. */
1868 yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[
1869 yys.yyloc = s->yyloc;]])[
1870 yys.setPred(s->pred());
1874 #if ]b4_api_PREFIX[DEBUG
1876 /*----------------------------------------------------------------------.
1877 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1878 `----------------------------------------------------------------------*/
1880 void
1881 yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk,
1882 rule_num yyrule, ]b4_namespace_ref[::]b4_parser_class[& yyparser)
1884 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1885 int yylow = 1;])[
1886 int yyi;
1887 std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1
1888 << " (line " << int (yyrline[yyrule]) << "):\n";
1889 if (! yynormal)
1890 yyfillin (yyvsp, 1, -yynrhs);
1891 /* The symbols being reduced. */
1892 for (yyi = 0; yyi < yynrhs; yyi++)
1894 std::cerr << " $" << yyi + 1 << " = ";
1895 yyparser.yy_symbol_print_
1896 (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
1897 yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
1898 ]b4_rhs_location(yynrhs, yyi + 1)])[);
1899 if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
1900 std::cerr << " (unresolved)";
1901 std::cerr << '\n';
1906 #define YYINDEX(YYX) \
1907 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1909 void
1910 dumpStack () const
1912 for (size_t yyi = 0; yyi < size(); ++yyi)
1914 const glr_stack_item& item = yyitems[yyi];
1915 std::cerr << std::setw(3) << yyi << ". ";
1916 if (item.is_state())
1918 std::cerr << "Res: " << item.getState().yyresolved
1919 << ", LR State: " << item.getState().yylrState
1920 << ", posn: " << item.getState().yyposn
1921 << ", pred: " << YYINDEX(item.getState().pred());
1922 if (! item.getState().yyresolved)
1923 std::cerr << ", firstVal: "
1924 << YYINDEX(item.getState().firstVal());
1926 else
1928 std::cerr << "Option. rule: " << item.getOption().yyrule - 1
1929 << ", state: " << YYINDEX(item.getOption().state())
1930 << ", next: " << YYINDEX(item.getOption().next());
1932 std::cerr << '\n';
1934 std::cerr << "Tops:";
1935 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) {
1936 std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; ";
1938 std::cerr << '\n';
1941 #undef YYINDEX
1942 #endif
1944 YYRESULTTAG
1945 yyreportAmbiguity (const semantic_option& yyx0,
1946 const semantic_option& yyx1, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_locations_if([, const location_type& yyloc])[)
1948 YY_USE (yyx0);
1949 YY_USE (yyx1);
1951 #if ]b4_api_PREFIX[DEBUG
1952 std::cerr << "Ambiguity detected.\n"
1953 "Option 1,\n";
1954 yyx0.yyreportTree ();
1955 std::cerr << "\nOption 2,\n";
1956 yyx1.yyreportTree ();
1957 std::cerr << '\n';
1958 #endif
1960 yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous"));
1961 return yyabort;
1964 /* DEBUGGING ONLY */
1965 #if ]b4_api_PREFIX[DEBUG
1966 /* Print YYS (possibly NULL) and its predecessors. */
1967 void
1968 yypstates (const glr_state* yys) const
1970 if (yys != YY_NULLPTR)
1971 yys->yy_yypstack();
1972 else
1973 std::cerr << "<null>";
1974 std::cerr << '\n';
1976 #endif
1978 private:
1979 size_t spaceLeft() const
1981 return yyitems.capacity() - yyitems.size();
1984 /** Return a fresh GLRStackItem in this. The item is an LR state
1985 * if YYIS_STATE, and otherwise a semantic option. Callers should call
1986 * yyreserveStack afterwards to make sure there is sufficient
1987 * headroom. */
1988 size_t
1989 yynewGLRStackItem (bool yyis_state)
1991 YYDASSERT(yyitems.size() < yyitems.capacity());
1992 yyitems.push_back(glr_stack_item(yyis_state));
1993 return yyitems.size() - 1;
1997 public:
1999 std::vector<glr_stack_item> yyitems;
2000 // Where the stack splits. Anything below this address is deterministic.
2001 const glr_state* yysplitPoint;
2002 glr_state_set yytops;
2005 #undef YYFILL
2006 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2008 class glr_stack
2010 public:
2011 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
2012 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
2013 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
2014 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
2016 glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
2017 : yyerrState (0)
2018 , yystateStack (yysize)
2019 , yyerrcnt (0)
2020 , yytoken (]b4_symbol(empty, kind)[)
2021 , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
2024 ~glr_stack ()
2026 if (this->yytoken != ]b4_symbol(empty, kind)[)
2027 yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
2028 this->yytoken, this->yylval]b4_locations_if([, this->yylloc])[);
2029 popall_ ();
2032 int yyerrState;
2033 ]b4_locations_if([[ /* To compute the location of the error token. */
2034 glr_stack_item yyerror_range[3];]])[
2035 state_stack yystateStack;
2036 int yyerrcnt;
2037 symbol_kind_type yytoken;
2038 value_type yylval;]b4_locations_if([[
2039 location_type yylloc;]])[
2040 YYJMP_BUF yyexception_buffer;
2041 ]b4_namespace_ref[::]b4_parser_class[& yyparser;
2043 #define YYCHK1(YYE) \
2044 do { \
2045 switch (YYE) { \
2046 case yyok: \
2047 break; \
2048 case yyabort: \
2049 goto yyabortlab; \
2050 case yyaccept: \
2051 goto yyacceptlab; \
2052 case yyerr: \
2053 goto yyuser_error; \
2054 default: \
2055 goto yybuglab; \
2057 } while (false)
2060 parse ()
2062 int yyresult;
2063 size_t yyposn;
2065 YYCDEBUG << "Starting parse\n";
2067 this->yytoken = ]b4_symbol(empty, kind)[;]b4_variant_if([], [[
2068 this->yylval = yyval_default;]])[]b4_locations_if([
2069 this->yylloc = yyloc_default;])[
2070 ]m4_ifdef([b4_initial_action], [
2071 b4_dollar_pushdef([this->yylval], [], [], [this->yylloc])dnl
2072 b4_user_initial_action
2073 b4_dollar_popdef])[]dnl
2075 switch (YYSETJMP (this->yyexception_buffer))
2077 case 0: break;
2078 case 1: goto yyabortlab;
2079 case 2: goto yyexhaustedlab;
2080 default: goto yybuglab;
2082 this->yyglrShift (create_state_set_index(0), 0, 0, this->yylval]b4_locations_if([, this->yylloc])[);
2083 yyposn = 0;
2085 while (true)
2087 /* For efficiency, we have two loops, the first of which is
2088 specialized to deterministic operation (single stack, no
2089 potential ambiguity). */
2090 /* Standard mode */
2091 while (true)
2093 const state_num yystate = this->firstTopState()->yylrState;
2094 YYCDEBUG << "Entering state " << yystate << '\n';
2095 if (yystate == YYFINAL)
2096 goto yyacceptlab;
2097 if (yy_is_defaulted_state (yystate))
2099 const rule_num yyrule = yy_default_action (yystate);
2100 if (yyrule == 0)
2101 {]b4_locations_if([[
2102 this->yyerror_range[1].getState().yyloc = this->yylloc;]])[
2103 this->yyreportSyntaxError ();
2104 goto yyuser_error;
2106 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule, true));
2108 else
2110 yyget_token ();
2111 const short* yyconflicts;
2112 const int yyaction = yygetLRActions (yystate, this->yytoken, yyconflicts);
2113 if (*yyconflicts != 0)
2114 break;
2115 if (yy_is_shift_action (yyaction))
2117 YY_SYMBOL_PRINT ("Shifting", this->yytoken, this->yylval, this->yylloc);
2118 yyposn += 1;
2119 // FIXME: we should move yylval.
2120 this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yylval]b4_locations_if([, this->yylloc])[);]b4_variant_if([[
2121 // FIXME: User destructors.
2122 // Value type destructor.
2123 ]b4_symbol_variant([[this->yytoken]], [[this->yylval]], [[template destroy]])])[
2124 this->yytoken = ]b4_symbol(empty, kind)[;
2125 if (0 < this->yyerrState)
2126 this->yyerrState -= 1;
2128 else if (yy_is_error_action (yyaction))
2129 {]b4_locations_if([[
2130 this->yyerror_range[1].getState().yyloc = this->yylloc;]])[
2131 /* Don't issue an error message again for exceptions
2132 thrown from the scanner. */
2133 if (this->yytoken != ]b4_symbol(error, kind)[)
2134 this->yyreportSyntaxError ();
2135 goto yyuser_error;
2137 else
2138 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction, true));
2142 while (true)
2144 for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys)
2145 this->yystateStack.yytops.setLookaheadNeeds(yys, this->yytoken != ]b4_symbol(empty, kind)[);
2147 /* yyprocessOneStack returns one of three things:
2149 - An error flag. If the caller is yyprocessOneStack, it
2150 immediately returns as well. When the caller is finally
2151 yyparse, it jumps to an error label via YYCHK1.
2153 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2154 (yys), which sets the top state of yys to NULL. Thus,
2155 yyparse's following invocation of yyremoveDeletes will remove
2156 the stack.
2158 - yyok, when ready to shift a token.
2160 Except in the first case, yyparse will invoke yyremoveDeletes and
2161 then shift the next token onto all remaining stacks. This
2162 synchronization of the shift (that is, after all preceding
2163 reductions on all stacks) helps prevent double destructor calls
2164 on yylval in the event of memory exhaustion. */
2166 for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys)
2167 YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yylloc])[));
2168 this->yystateStack.yytops.yyremoveDeletes ();
2169 if (this->yystateStack.yytops.size() == 0)
2171 this->yystateStack.yytops.yyundeleteLastStack ();
2172 if (this->yystateStack.yytops.size() == 0)
2173 this->yyFail (]b4_locations_if([&this->yylloc, ])[YY_("syntax error"));
2174 YYCHK1 (this->yyresolveStack ());
2175 YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[
2176 this->yyerror_range[1].getState().yyloc = this->yylloc;]])[
2177 this->yyreportSyntaxError ();
2178 goto yyuser_error;
2181 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2182 a copy of yylval will already be on stack 0 in the event of a
2183 failure in the following loop. Thus, yytoken is set to ]b4_symbol(empty, kind)[
2184 before the loop to make sure the user destructor for yylval isn't
2185 called twice. */
2186 yysymbol_kind_t yytoken_to_shift = this->yytoken;
2187 this->yytoken = ]b4_symbol(empty, kind)[;
2188 yyposn += 1;
2189 for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys)
2191 const state_num yystate = this->topState(yys)->yylrState;
2192 const short* yyconflicts;
2193 const int yyaction
2194 = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
2195 /* Note that yyconflicts were handled by yyprocessOneStack. */
2196 YYCDEBUG << "On stack " << yys.get() << ", ";
2197 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yylval, this->yylloc);
2198 this->yyglrShift (yys, yyaction, yyposn, this->yylval]b4_locations_if([, this->yylloc])[);
2199 YYCDEBUG << "Stack " << yys.get() << " now in state "
2200 << this->topState(yys)->yylrState << '\n';
2202 ]b4_variant_if([[
2203 // FIXME: User destructors.
2204 // Value type destructor.
2205 ]b4_symbol_variant([[yytoken_to_shift]], [[this->yylval]], [[template destroy]])])[
2207 if (this->yystateStack.yytops.size() == 1)
2209 YYCHK1 (this->yyresolveStack ());
2210 YYCDEBUG << "Returning to deterministic operation.\n";
2211 this->yystateStack.yycompressStack ();
2212 break;
2215 continue;
2216 yyuser_error:
2217 this->yyrecoverSyntaxError (]b4_locations_if([&this->yylloc])[);
2218 yyposn = this->firstTopState()->yyposn;
2221 yyacceptlab:
2222 yyresult = 0;
2223 goto yyreturn;
2225 yybuglab:
2226 YYASSERT (false);
2227 goto yyabortlab;
2229 yyabortlab:
2230 yyresult = 1;
2231 goto yyreturn;
2233 yyexhaustedlab:
2234 yyparser.error (]b4_locations_if([this->yylloc, ])[YY_("memory exhausted"));
2235 yyresult = 2;
2236 goto yyreturn;
2238 yyreturn:
2239 return yyresult;
2241 #undef YYCHK1
2243 void yyreserveGlrStack ()
2245 if (!yystateStack.yyexpandGLRStackIfNeeded ())
2246 yyMemoryExhausted ();
2249 _Noreturn void
2250 yyMemoryExhausted ()
2252 YYLONGJMP (yyexception_buffer, 2);
2255 _Noreturn void
2256 yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg)
2258 if (yymsg != YY_NULLPTR)
2259 yyparser.error (]b4_locations_if([*yylocp, ])[yymsg);
2260 YYLONGJMP (yyexception_buffer, 1);
2263 /* GLRStates */
2266 /** Add a new semantic action that will execute the action for rule
2267 * YYRULE on the semantic values in YYRHS to the list of
2268 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2269 * stack #YYK of *this. */
2270 void
2271 yyaddDeferredAction (state_set_index yyk, glr_state* yystate,
2272 glr_state* yyrhs, rule_num yyrule)
2274 semantic_option& yynewOption =
2275 yystateStack.yynewSemanticOption(semantic_option(yyrule, ]b4_symbol(empty, kind)[));
2276 yynewOption.setState(yyrhs);
2277 yynewOption.setNext(yystate->firstVal());
2278 if (yystateStack.yytops.lookaheadNeeds(yyk))
2280 yynewOption.yytoken = this->yytoken;]b4_variant_if([[
2281 ]b4_symbol_variant([this->yytoken],
2282 [yynewOption.yyval], [copy], [this->yylval])], [[
2283 yynewOption.yyval = this->yylval;]])[]b4_locations_if([
2284 yynewOption.yyloc = this->yylloc;])[
2286 yystate->setFirstVal(&yynewOption);
2288 yyreserveGlrStack();
2291 #if ]b4_api_PREFIX[DEBUG
2292 void yypdumpstack () const
2294 yystateStack.dumpStack();
2296 #endif
2297 void
2298 yyreportSyntaxError ()
2300 if (yyerrState != 0)
2301 return;
2302 ]b4_parse_error_bmatch(
2303 [simple],
2304 [[ yyparser.error (]b4_locations_if([this->yylloc, ])[YY_("syntax error"));]],
2305 [[ {
2306 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
2307 /* Arguments of yyformat. */
2308 yysymbol_kind_t yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]
2309 = { ]b4_symbol(empty, kind)[ };
2310 /* Number of reported tokens (one for the "unexpected", one per
2311 "expected"). */
2312 int yycount = 0;
2314 /* There are many possibilities here to consider:
2315 - If this state is a consistent state with a default action, then
2316 the only way this function was invoked is if the default action
2317 is an error action. In that case, don't check for expected
2318 tokens because there are none.
2319 - The only way there can be no lookahead present (in yytoken) is if
2320 this state is a consistent state with a default action. Thus,
2321 detecting the absence of a lookahead is sufficient to determine
2322 that there is no unexpected or expected token to report. In that
2323 case, just report a simple "syntax error".
2324 - Don't assume there isn't a lookahead just because this state is a
2325 consistent state with a default action. There might have been a
2326 previous inconsistent state, consistent state with a non-default
2327 action, or user semantic action that manipulated yytoken.
2328 - Of course, the expected token list depends on states to have
2329 correct lookahead information, and it depends on the parser not
2330 to perform extra reductions after fetching a lookahead from the
2331 scanner and before detecting a syntax error. Thus, state merging
2332 (from LALR or IELR) and default reductions corrupt the expected
2333 token list. However, the list is correct for canonical LR with
2334 one exception: it will still contain any token that will not be
2335 accepted due to an error action in a later state.
2337 if (yytoken != ]b4_symbol(empty, kind)[)
2339 const int yyn = yypact[firstTopState()->yylrState];
2340 yyarg[yycount++] = yytoken;
2341 if (!yypact_value_is_default (yyn))
2343 /* Start YYX at -YYN if negative to avoid negative indexes in
2344 YYCHECK. In other words, skip the first -YYN actions for this
2345 state because they are default actions. */
2346 const int yyxbegin = yyn < 0 ? -yyn : 0;
2347 /* Stay within bounds of both yycheck and yytname. */
2348 const int yychecklim = YYLAST - yyn + 1;
2349 const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2350 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
2351 if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
2352 && !yytable_value_is_error (yytable[yyx + yyn]))
2354 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
2356 yycount = 1;
2357 break;
2359 yyarg[yycount++] = static_cast<yysymbol_kind_t>(yyx);
2364 /* Internationalized format string. */
2365 const char *yyformat = YY_NULLPTR;
2366 switch (yycount)
2368 #define YYCASE_(N, S) \
2369 case N: \
2370 yyformat = S; \
2371 break
2372 default: /* Avoid compiler warnings. */
2373 YYCASE_(0, YY_("syntax error"));
2374 YYCASE_(1, YY_("syntax error, unexpected %s"));
2375 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2376 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2377 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2378 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2379 #undef YYCASE_
2382 std::string yymsg;
2383 // Argument number.
2384 std::ptrdiff_t yyi = 0;
2385 for (char const* yyp = yyformat; *yyp; ++yyp)
2386 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
2388 yymsg += ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yyarg[yyi++]);
2389 ++yyp;
2391 else
2392 yymsg += *yyp;
2393 yyparser.error (]b4_locations_if([[yylloc, ]])[yymsg);
2395 ]])[
2396 yyerrcnt += 1;
2400 /* Recover from a syntax error on this, assuming that yytoken,
2401 yylval, and yylloc are the syntactic category, semantic value, and location
2402 of the lookahead. */
2403 void
2404 yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[)
2406 if (yyerrState == 3)
2407 /* We just shifted the error token and (perhaps) took some
2408 reductions. Skip tokens until we can proceed. */
2409 while (true)
2411 if (this->yytoken == ]b4_symbol(eof, kind)[)
2412 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2413 if (this->yytoken != ]b4_symbol(empty, kind)[)
2414 {]b4_locations_if([[
2415 /* We throw away the lookahead, but the error range
2416 of the shifted error token must take it into account. */
2417 glr_state *yys = firstTopState();
2418 yyerror_range[1].getState().yyloc = yys->yyloc;
2419 yyerror_range[2].getState().yyloc = this->yylloc;
2420 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2421 yyparser.yy_destroy_ ("Error: discarding",
2422 this->yytoken, this->yylval]b4_locations_if([, this->yylloc])[);]b4_variant_if([[
2423 // Value type destructor.
2424 ]b4_symbol_variant([[this->yytoken]], [[this->yylval]], [[template destroy]])])[
2425 this->yytoken = ]b4_symbol(empty, kind)[;
2427 yyget_token ();
2428 int yyj = yypact[firstTopState()->yylrState];
2429 if (yypact_value_is_default (yyj))
2430 return;
2431 yyj += this->yytoken;
2432 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yytoken)
2434 if (yydefact[firstTopState()->yylrState] != 0)
2435 return;
2437 else if (! yytable_value_is_error (yytable[yyj]))
2438 return;
2441 if (!yystateStack.reduceToOneStack())
2442 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2444 /* Now pop stack until we find a state that shifts the error token. */
2445 yyerrState = 3;
2446 while (firstTopState () != YY_NULLPTR)
2448 glr_state *yys = firstTopState ();
2449 int yyj = yypact[yys->yylrState];
2450 if (! yypact_value_is_default (yyj))
2452 yyj += YYTERROR;
2453 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2454 && yy_is_shift_action (yytable[yyj]))
2456 /* Shift the error token. */]b4_locations_if([[
2457 /* First adjust its location.*/
2458 location_type yyerrloc;
2459 yyerror_range[2].getState().yyloc = this->yylloc;
2460 YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
2461 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
2462 yylval, yyerrloc);
2463 yyglrShift (create_state_set_index(0), yytable[yyj],
2464 yys->yyposn, yylval]b4_locations_if([, yyerrloc])[);
2465 yys = firstTopState();
2466 break;
2468 }]b4_locations_if([[
2469 yyerror_range[1].getState().yyloc = yys->yyloc;]])[
2470 if (yys->pred() != YY_NULLPTR)
2471 yys->destroy ("Error: popping", yyparser]b4_user_args[);
2472 yystateStack.setFirstTop(yys->pred());
2473 yystateStack.pop_back();
2475 if (firstTopState() == YY_NULLPTR)
2476 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2479 YYRESULTTAG
2480 yyprocessOneStack (state_set_index yyk,
2481 size_t yyposn]b4_locations_if([, location_type* yylocp])[)
2483 while (yystateStack.topAt(yyk) != YY_NULLPTR)
2485 const state_num yystate = topState(yyk)->yylrState;
2486 YYCDEBUG << "Stack " << yyk.get()
2487 << " Entering state " << yystate << '\n';
2489 YYASSERT (yystate != YYFINAL);
2491 if (yy_is_defaulted_state (yystate))
2493 const rule_num yyrule = yy_default_action (yystate);
2494 if (yyrule == 0)
2496 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2497 yystateStack.yytops.yymarkStackDeleted (yyk);
2498 return yyok;
2500 const YYRESULTTAG yyflag
2501 = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]);
2502 if (yyflag == yyerr)
2504 YYCDEBUG << "Stack " << yyk.get() << " dies"
2505 " (predicate failure or explicit user error).\n";
2506 yystateStack.yytops.yymarkStackDeleted (yyk);
2507 return yyok;
2509 if (yyflag != yyok)
2510 return yyflag;
2512 else
2514 yystateStack.yytops.setLookaheadNeeds(yyk, true);
2515 yyget_token ();
2516 const short* yyconflicts;
2517 const int yyaction = yygetLRActions (yystate, this->yytoken, yyconflicts);
2519 for (; *yyconflicts != 0; ++yyconflicts)
2521 state_set_index yynewStack = yystateStack.yysplitStack (yyk);
2522 YYCDEBUG << "Splitting off stack " << yynewStack.get()
2523 << " from " << yyk.get() << ".\n";
2524 YYRESULTTAG yyflag =
2525 yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]);
2526 if (yyflag == yyok)
2527 YYCHK (yyprocessOneStack (yynewStack,
2528 yyposn]b4_locations_if([, yylocp])[));
2529 else if (yyflag == yyerr)
2531 YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n";
2532 yystateStack.yytops.yymarkStackDeleted (yynewStack);
2534 else
2535 return yyflag;
2538 if (yy_is_shift_action (yyaction))
2539 break;
2540 else if (yy_is_error_action (yyaction))
2542 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2543 yystateStack.yytops.yymarkStackDeleted (yyk);
2544 break;
2546 else
2548 YYRESULTTAG yyflag
2549 = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]);
2550 if (yyflag == yyerr)
2552 YYCDEBUG << "Stack " << yyk.get() << " dies"
2553 " (predicate failure or explicit user error).\n";
2554 yystateStack.yytops.yymarkStackDeleted (yyk);
2555 break;
2557 else if (yyflag != yyok)
2558 return yyflag;
2562 return yyok;
2565 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2566 * and top stack item YYVSP. YYVALP points to place to put semantic
2567 * value ($$), and yylocp points to place for location information
2568 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2569 * yyerr for YYERROR, yyabort for YYABORT. */
2570 YYRESULTTAG
2571 yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk,
2572 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2574 bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit();
2575 int yylow = 1;
2576 ]b4_parse_param_use([yyvalp], [yylocp])dnl
2577 [ YY_USE (yyk);
2578 YY_USE (yyrhslen);
2579 # undef yyerrok
2580 # define yyerrok (yyerrState = 0)
2581 # undef YYACCEPT
2582 # define YYACCEPT return yyaccept
2583 # undef YYABORT
2584 # define YYABORT return yyabort
2585 # undef YYERROR
2586 # define YYERROR return yyerrok, yyerr
2587 # undef YYRECOVERING
2588 # define YYRECOVERING() (yyerrState != 0)
2589 # undef yytoken
2590 # define yytoken this->yytoken
2591 # undef yyclearin
2592 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2593 # undef YYBACKUP
2594 # define YYBACKUP(Token, Value) \
2595 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2596 yyerrok, yyerr
2598 ]b4_variant_if([[
2599 /* Variants are always initialized to an empty instance of the
2600 correct type. The default '$$ = $1' action is NOT applied
2601 when using variants. */
2602 // However we really need to prepare yyvsp now if we want to get
2603 // correct locations, so invoke YYFILL for $1 anyway.
2604 (void) YYFILL (1-yyrhslen);
2605 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[
2606 if (yyrhslen == 0)
2607 *yyvalp = yyval_default;
2608 else
2609 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[
2610 /* Default location. */
2611 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
2612 yyerror_range[1].getState().yyloc = *yylocp;
2613 ]])[
2614 /* If yyk == -1, we are running a deferred action on a temporary
2615 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2616 so pretend the stack is "normal". */
2617 YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser));
2618 #if YY_EXCEPTIONS
2619 typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error;
2622 #endif // YY_EXCEPTIONS
2623 switch (yyrule)
2625 ]b4_user_actions[
2626 default: break;
2628 #if YY_EXCEPTIONS
2630 catch (const syntax_error& yyexc)
2632 YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([
2633 *yylocp = yyexc.location;])[
2634 yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ());
2635 YYERROR;
2637 #endif // YY_EXCEPTIONS
2638 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp);
2640 return yyok;
2641 # undef yyerrok
2642 # undef YYABORT
2643 # undef YYACCEPT
2644 # undef YYERROR
2645 # undef YYBACKUP
2646 # undef yytoken
2647 # undef yyclearin
2648 # undef YYRECOVERING
2651 YYRESULTTAG
2652 yyresolveStack ()
2654 if (yystateStack.isSplit ())
2656 int yyn = 0;
2657 for (glr_state* yys = firstTopState ();
2658 yys != yystateStack.yysplitPoint;
2659 yys = yys->pred ())
2660 yyn += 1;
2661 YYCHK (yyresolveStates (*firstTopState (), yyn));
2663 return yyok;
2666 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2667 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2668 * semantic values. Assumes that all ambiguities in semantic values
2669 * have been previously resolved. Set *YYVALP to the resulting value,
2670 * and *YYLOCP to the computed location (if any). Return value is as
2671 * for userAction. */
2672 YYRESULTTAG
2673 yydoAction (state_set_index yyk, rule_num yyrule,
2674 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2676 const int yynrhs = yyrhsLength (yyrule);
2678 if (!yystateStack.isSplit())
2680 /* Standard special case: single stack. */
2681 YYASSERT (yyk.get() == 0);
2682 glr_stack_item* yyrhs = yystateStack.firstTop()->asItem();
2683 const YYRESULTTAG res
2684 = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[);
2685 yystateStack.pop_back(static_cast<size_t>(yynrhs));
2686 yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState());
2687 return res;
2689 else
2691 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
2692 glr_state* yys = yystateStack.topAt(yyk);
2693 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[
2694 if (yynrhs == 0)
2695 /* Set default location. */
2696 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[
2697 for (int yyi = 0; yyi < yynrhs; yyi += 1)
2699 yys = yys->pred();
2700 YYASSERT (yys != YY_NULLPTR);
2702 yystateStack.yyupdateSplit (*yys);
2703 yystateStack.setTopAt(yyk, yys);
2704 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
2705 yyk,
2706 yyvalp]b4_locations_if([, yylocp])[);
2710 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2711 * and push back on the resulting nonterminal symbol. Perform the
2712 * semantic action associated with YYRULE and store its value with the
2713 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2714 * unambiguous. Otherwise, store the deferred semantic action with
2715 * the new state. If the new state would have an identical input
2716 * position, LR state, and predecessor to an existing state on the stack,
2717 * it is identified with that existing state, eliminating stack #YYK from
2718 * *YYSTACKP. In this case, the semantic value is
2719 * added to the options for the existing state's semantic value.
2721 YYRESULTTAG
2722 yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval)
2724 size_t yyposn = topState(yyk)->yyposn;
2726 if (yyforceEval || !yystateStack.isSplit())
2728 value_type val;]b4_locations_if([[
2729 location_type loc;]])[
2731 YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[);
2732 if (yyflag == yyerr && yystateStack.isSplit())
2733 {]b4_parse_trace_if([[
2734 YYCDEBUG << "Parse on stack " << yyk.get ()
2735 << " rejected by rule " << yyrule - 1
2736 << " (line " << int (yyrline[yyrule]) << ").\n";
2737 ]])[}
2738 if (yyflag != yyok)
2739 return yyflag;
2740 yyglrShift (yyk,
2741 yyLRgotoState (topState(yyk)->yylrState,
2742 yylhsNonterm (yyrule)),
2743 yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[
2744 // FIXME: User destructors.
2745 // Value type destructor.
2746 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[
2748 else
2750 glr_state *yys = yystateStack.topAt(yyk);
2751 glr_state *yys0 = yys;
2752 for (int yyn = yyrhsLength (yyrule); 0 < yyn; yyn -= 1)
2754 yys = yys->pred();
2755 YYASSERT (yys != YY_NULLPTR);
2757 yystateStack.yyupdateSplit (*yys);
2758 state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[
2759 YYCDEBUG << "Reduced stack " << yyk.get ()
2760 << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule])
2761 << "); action deferred. Now in state " << yynewLRState
2762 << ".\n";]])[
2763 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi)
2764 if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR)
2766 const glr_state* yysplit = yystateStack.yysplitPoint;
2767 glr_state* yyp = yystateStack.topAt(yyi);
2768 while (yyp != yys && yyp != yysplit
2769 && yyp->yyposn >= yyposn)
2771 if (yyp->yylrState == yynewLRState
2772 && yyp->pred() == yys)
2774 yyaddDeferredAction (yyk, yyp, yys0, yyrule);
2775 yystateStack.yytops.yymarkStackDeleted (yyk);
2776 YYCDEBUG << "Merging stack " << yyk.get ()
2777 << " into stack " << yyi.get () << ".\n";
2778 return yyok;
2780 yyp = yyp->pred();
2783 yystateStack.setTopAt(yyk, yys);
2784 yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule);
2786 return yyok;
2789 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2790 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2791 * semantic value of YYRHS under the action for YYRULE. */
2792 void
2793 yyglrShiftDefer (state_set_index yyk, state_num yylrState,
2794 size_t yyposn, glr_state* yyrhs, rule_num yyrule)
2796 glr_state& yynewState = yystateStack.yynewGLRState (
2797 glr_state (yylrState, yyposn));
2798 yynewState.setPred (yystateStack.topAt (yyk));
2799 yystateStack.setTopAt (yyk, &yynewState);
2801 /* Invokes yyreserveStack. */
2802 yyaddDeferredAction (yyk, &yynewState, yyrhs, yyrule);
2805 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2806 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2807 * value YYVAL_ARG and source location YYLOC_ARG. */
2808 void
2809 yyglrShift (state_set_index yyk, state_num yylrState,
2810 size_t yyposn,
2811 const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[)
2813 glr_state& yynewState = yystateStack.yynewGLRState (
2814 glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[));
2815 yynewState.setPred (yystateStack.topAt(yyk));
2816 yystateStack.setTopAt (yyk, &yynewState);
2817 yyreserveGlrStack ();
2820 #if ]b4_api_PREFIX[DEBUG
2821 void
2822 yypstack (state_set_index yyk) const
2824 yystateStack.yypstates (yystateStack.topAt (yyk));
2826 #endif
2828 glr_state* topState(state_set_index i) {
2829 return yystateStack.topAt(i);
2832 glr_state* firstTopState() {
2833 return yystateStack.firstTop();
2836 private:
2838 void popall_ ()
2840 /* If the stack is well-formed, pop the stack until it is empty,
2841 destroying its entries as we go. But free the stack regardless
2842 of whether it is well-formed. */
2843 for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); k += 1)
2844 if (yystateStack.topAt(k) != YY_NULLPTR)
2846 while (yystateStack.topAt(k) != YY_NULLPTR)
2848 glr_state* state = topState(k);]b4_locations_if([[
2849 yyerror_range[1].getState().yyloc = state->yyloc;]])[
2850 if (state->pred() != YY_NULLPTR)
2851 state->destroy ("Cleanup: popping", yyparser]b4_user_args[);
2852 yystateStack.setTopAt(k, state->pred());
2853 yystateStack.pop_back();
2855 break;
2859 /** Resolve the previous YYN states starting at and including state YYS
2860 * on *YYSTACKP. If result != yyok, some states may have been left
2861 * unresolved possibly with empty semantic option chains. Regardless
2862 * of whether result = yyok, each state has been left with consistent
2863 * data so that destroy can be invoked if necessary. */
2864 YYRESULTTAG
2865 yyresolveStates (glr_state& yys, int yyn)
2867 if (0 < yyn)
2869 YYASSERT (yys.pred() != YY_NULLPTR);
2870 YYCHK (yyresolveStates (*yys.pred(), yyn-1));
2871 if (! yys.yyresolved)
2872 YYCHK (yyresolveValue (yys));
2874 return yyok;
2877 static void
2878 yyuserMerge (int yyn, value_type& yy0, value_type& yy1)
2880 YY_USE (yy0);
2881 YY_USE (yy1);
2883 switch (yyn)
2885 ]b4_mergers[
2886 default: break;
2890 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2891 * perform the indicated actions, and set the semantic value of YYS.
2892 * If result != yyok, the chain of semantic options in YYS has been
2893 * cleared instead or it has been left unmodified except that
2894 * redundant options may have been removed. Regardless of whether
2895 * result = yyok, YYS has been left with consistent data so that
2896 * destroy can be invoked if necessary. */
2897 YYRESULTTAG
2898 yyresolveValue (glr_state& yys)
2900 semantic_option* yybest = yys.firstVal();
2901 YYASSERT(yybest != YY_NULLPTR);
2902 bool yymerge = false;
2903 YYRESULTTAG yyflag;]b4_locations_if([
2904 location_type *yylocp = &yys.yyloc;])[
2906 semantic_option* yypPrev = yybest;
2907 for (semantic_option* yyp = yybest->next();
2908 yyp != YY_NULLPTR; )
2910 if (yybest->isIdenticalTo (*yyp))
2912 yybest->mergeWith (*yyp);
2913 yypPrev->setNext(yyp->next());
2914 yyp = yypPrev->next();
2916 else
2918 switch (yypreference (*yybest, *yyp))
2920 case 0:]b4_locations_if([[
2921 yyresolveLocations (yys, 1);]])[
2922 return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[);
2923 break;
2924 case 1:
2925 yymerge = true;
2926 break;
2927 case 2:
2928 break;
2929 case 3:
2930 yybest = yyp;
2931 yymerge = false;
2932 break;
2933 default:
2934 /* This cannot happen so it is not worth a YYASSERT (false),
2935 but some compilers complain if the default case is
2936 omitted. */
2937 break;
2939 yypPrev = yyp;
2940 yyp = yyp->next();
2944 value_type val;
2945 if (yymerge)
2947 int yyprec = yydprec[yybest->yyrule];
2948 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2949 if (yyflag == yyok)
2950 for (semantic_option* yyp = yybest->next();
2951 yyp != YY_NULLPTR;
2952 yyp = yyp->next())
2954 if (yyprec == yydprec[yyp->yyrule])
2956 value_type yyval_other;]b4_locations_if([
2957 location_type yydummy;])[
2958 yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[);
2959 if (yyflag != yyok)
2961 yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2962 yy_accessing_symbol (yys.yylrState),
2963 this->yylval]b4_locations_if([, *yylocp])[);
2964 break;
2966 yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
2967 // FIXME: User destructors.
2968 // Value type destructor.
2969 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[
2973 else
2974 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2976 if (yyflag == yyok)
2978 yys.yyresolved = true;
2979 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[
2980 new (&yys.value ()) value_type ();
2981 ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)],
2982 [yys.value ()], [copy], [val])], [[
2983 new (&yys.value ()) value_type (val);]])[
2985 YY_IGNORE_MAYBE_UNINITIALIZED_END
2987 else
2988 yys.setFirstVal(YY_NULLPTR);
2989 ]b4_variant_if([[
2990 // FIXME: User destructors.
2991 // Value type destructor.
2992 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[
2993 return yyflag;
2996 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2997 * user action, and return the semantic value and location in *YYVALP
2998 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2999 * have been destroyed (assuming the user action destroys all RHS
3000 * semantic values if invoked). */
3001 YYRESULTTAG
3002 yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
3004 glr_state* yyoptState = yyopt.state();
3005 YYASSERT(yyoptState != YY_NULLPTR);
3006 int yynrhs = yyrhsLength (yyopt.yyrule);
3007 YYRESULTTAG yyflag = yyresolveStates (*yyoptState, yynrhs);
3008 if (yyflag != yyok)
3010 for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1)
3011 yys->destroy ("Cleanup: popping", yyparser]b4_user_args[);
3012 return yyflag;
3015 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
3016 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[
3017 if (yynrhs == 0)
3018 /* Set default location. */
3019 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
3021 symbol_kind_type yytoken_current = this->yytoken;]b4_variant_if([[
3022 value_type yylval_current;
3023 ]b4_symbol_variant([this->yytoken],
3024 [yylval_current], [move], [this->yylval])], [[
3025 value_type yylval_current = this->yylval;]])[]b4_locations_if([
3026 location_type yylloc_current = this->yylloc;])[
3028 this->yytoken = yyopt.yytoken;]b4_variant_if([[
3029 ]b4_symbol_variant([this->yytoken],
3030 [this->yylval], [move], [yyopt.yyval])], [[
3031 this->yylval = yyopt.yyval;]])[]b4_locations_if([
3032 this->yylloc = yyopt.yyloc;])[
3033 yyflag = yyuserAction (yyopt.yyrule, yynrhs,
3034 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
3035 create_state_set_index (-1),
3036 yyvalp]b4_locations_if([, yylocp])[);
3038 this->yytoken = yytoken_current;]b4_variant_if([[
3039 ]b4_symbol_variant([this->yytoken],
3040 [this->yylval], [move], [yylval_current])], [[
3041 this->yylval = yylval_current;]])[]b4_locations_if([
3042 this->yylloc = yylloc_current;])[
3044 return yyflag;
3045 }]b4_locations_if([[
3047 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
3048 * ending at YYS1. Has no effect on previously resolved states.
3049 * The first semantic option of a state is always chosen. */
3050 void
3051 yyresolveLocations (glr_state &yys1, int yyn1)
3053 if (0 < yyn1)
3055 yyresolveLocations (*yys1.pred(), yyn1 - 1);
3056 if (!yys1.yyresolved)
3058 glr_stack_item yyrhsloc[1 + YYMAXRHS];
3059 YYASSERT (yys1.firstVal() != YY_NULLPTR);
3060 semantic_option& yyoption = *yys1.firstVal();
3061 const int yynrhs = yyrhsLength (yyoption.yyrule);
3062 if (0 < yynrhs)
3064 yyresolveLocations (*yyoption.state(), yynrhs);
3065 const glr_state *yys = yyoption.state();
3066 for (int yyn = yynrhs; yyn > 0; yyn -= 1)
3068 yyrhsloc[yyn].getState().yyloc = yys->yyloc;
3069 yys = yys->pred();
3072 else
3074 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3075 in reverse rightmost order. It is only necessary to invoke
3076 yyresolveLocations on a subforest for which yyresolveAction
3077 would have been invoked next had an ambiguity not been
3078 detected. Thus the location of the previous state (but not
3079 necessarily the previous state itself) is guaranteed to be
3080 resolved already. */
3081 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3082 yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc;
3083 YY_IGNORE_NULL_DEREFERENCE_END
3085 YYLLOC_DEFAULT ((yys1.yyloc), yyrhsloc, yynrhs);
3088 }]])[
3090 /** If yytoken is empty, fetch the next token. */
3091 void
3092 yyget_token ()
3094 ]b4_parse_param_use()dnl
3095 [ if (this->yytoken == ]b4_symbol(empty, kind)[)
3097 YYCDEBUG << "Reading a token\n";
3098 int yychar;
3099 #if YY_EXCEPTIONS
3102 #endif // YY_EXCEPTIONS
3103 {]b4_token_ctor_if([[
3104 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_type symbol_type;
3105 symbol_type yylookahead = ]b4_yylex[;
3106 this->yytoken = yylookahead.kind ();]b4_variant_if([[
3107 ]b4_symbol_variant([this->yytoken],
3108 [this->yylval], [move], [yylookahead.value])], [[
3109 this->yylval = yylookahead.value;]])[]b4_locations_if([
3110 this->yylloc = yylookahead.location;
3111 yylookahead.kind_ = symbol_kind::S_YYEMPTY;])[]], [[
3112 yychar = ]b4_yylex[;]])[
3114 #if YY_EXCEPTIONS
3116 catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
3118 YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
3119 this->yylloc = yyexc.location;])[
3120 yyparser.error (]b4_locations_if([this->yylloc, ])[yyexc.what ());
3121 // Map errors caught in the scanner to the error token, so that error
3122 // handling is started.]b4_token_ctor_if([[
3123 this->yytoken = ]b4_symbol(error, kind)[;]], [[
3124 yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, id)[;]])[
3126 #endif // YY_EXCEPTIONS]b4_token_ctor_if([], [[
3127 this->yytoken
3128 = ]b4_namespace_ref[::]b4_parser_class[::yytranslate_ (yychar);]])[
3130 if (this->yytoken == ]b4_symbol(eof, kind)[)
3131 YYCDEBUG << "Now at end of input.\n";
3132 else
3133 YY_SYMBOL_PRINT ("Next token is", this->yytoken, this->yylval, this->yylloc);
3137 /* Bison grammar-table manipulation. */
3139 /** The action to take in YYSTATE on seeing YYTOKEN.
3140 * Result R means
3141 * R < 0: Reduce on rule -R.
3142 * R = 0: Error.
3143 * R > 0: Shift to state R.
3144 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3145 * of conflicting reductions.
3147 static int
3148 yygetLRActions (state_num yystate, yysymbol_kind_t yytoken, const short*& yyconflicts)
3150 int yyindex = yypact[yystate] + yytoken;
3151 if (yytoken == ]b4_symbol(error, kind)[)
3153 // This is the error token.
3154 yyconflicts = yyconfl;
3155 return 0;
3157 else if (yy_is_defaulted_state (yystate)
3158 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
3160 yyconflicts = yyconfl;
3161 return -yydefact[yystate];
3163 else if (! yytable_value_is_error (yytable[yyindex]))
3165 yyconflicts = yyconfl + yyconflp[yyindex];
3166 return yytable[yyindex];
3168 else
3170 yyconflicts = yyconfl + yyconflp[yyindex];
3171 return 0;
3175 /** Compute post-reduction state.
3176 * \param yystate the current state
3177 * \param yysym the nonterminal to push on the stack
3179 static state_num
3180 yyLRgotoState (state_num yystate, yysymbol_kind_t yysym)
3182 const int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
3183 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
3184 return yytable[yyr];
3185 else
3186 return yydefgoto[yysym - YYNTOKENS];
3189 static bool
3190 yypact_value_is_default (state_num yystate)
3192 return ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf], [YYPACT_NINF])[;
3195 static bool
3196 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED)
3198 return ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[;
3201 static bool
3202 yy_is_shift_action (int yyaction)
3204 return 0 < yyaction;
3207 static bool
3208 yy_is_error_action (int yyaction)
3210 return yyaction == 0;
3213 /** Whether LR state YYSTATE has only a default reduction
3214 * (regardless of token). */
3215 static bool
3216 yy_is_defaulted_state (state_num yystate)
3218 return yypact_value_is_default (yypact[yystate]);
3221 /** The default reduction for YYSTATE, assuming it has one. */
3222 static rule_num
3223 yy_default_action (state_num yystate)
3225 return yydefact[yystate];
3228 /* GLRStacks */
3230 /** Y0 and Y1 represent two possible actions to take in a given
3231 * parsing state; return 0 if no combination is possible,
3232 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3233 static int
3234 yypreference (const semantic_option& y0, const semantic_option& y1)
3236 rule_num r0 = y0.yyrule, r1 = y1.yyrule;
3237 int p0 = yydprec[r0], p1 = yydprec[r1];
3239 if (p0 == p1)
3241 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
3242 return 0;
3243 else
3244 return 1;
3246 if (p0 == 0 || p1 == 0)
3247 return 0;
3248 if (p0 < p1)
3249 return 3;
3250 if (p1 < p0)
3251 return 2;
3252 return 0;
3255 ]b4_parse_param_vars[
3260 /* DEBUGGING ONLY */
3261 #if ]b4_api_PREFIX[DEBUG
3262 static void
3263 yypstack (const glr_stack& yystack, size_t yyk)
3265 yystack.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk)));
3267 static void yypdumpstack (const glr_stack& yystack)
3269 yystack.yypdumpstack ();
3272 #endif
3274 ]b4_namespace_open[
3275 /// Build a parser object.
3276 ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
3277 :])[
3278 #if ]b4_api_PREFIX[DEBUG
3279 ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
3280 #endif]b4_parse_param_cons[
3283 ]b4_parser_class::~b4_parser_class[ ()
3286 ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3290 ]b4_parser_class[::operator() ()
3292 return parse ();
3296 ]b4_parser_class[::parse ()
3298 glr_stack yystack(YYINITDEPTH, *this]b4_user_args[);
3299 return yystack.parse ();
3302 ]b4_parse_error_bmatch([custom\|detailed],
3303 [[ const char *
3304 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3306 static const char *const yy_sname[] =
3308 ]b4_symbol_names[
3309 };]b4_has_translations_if([[
3310 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3311 internationalizable. */
3312 static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
3314 ]b4_translatable[
3316 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
3317 ? _(yy_sname[yysymbol])
3318 : yy_sname[yysymbol]);]], [[
3319 return yy_sname[yysymbol];]])[
3322 [simple],
3323 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3324 const char *
3325 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3327 return yytname_[yysymbol];
3329 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3331 [verbose],
3332 [[ /* Return YYSTR after stripping away unnecessary quotes and
3333 backslashes, so that it's suitable for yyerror. The heuristic is
3334 that double-quoting is unnecessary unless the string contains an
3335 apostrophe, a comma, or backslash (other than backslash-backslash).
3336 YYSTR is taken from yytname. */
3337 std::string
3338 ]b4_parser_class[::yytnamerr_ (const char *yystr)
3340 if (*yystr == '"')
3342 std::string yyr;
3343 char const *yyp = yystr;
3345 for (;;)
3346 switch (*++yyp)
3348 case '\'':
3349 case ',':
3350 goto do_not_strip_quotes;
3352 case '\\':
3353 if (*++yyp != '\\')
3354 goto do_not_strip_quotes;
3355 else
3356 goto append;
3358 append:
3359 default:
3360 yyr += *yyp;
3361 break;
3363 case '"':
3364 return yyr;
3366 do_not_strip_quotes: ;
3369 return yystr;
3372 std::string
3373 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3375 return yytnamerr_ (yytname_[yysymbol]);
3377 ]])[
3379 ]b4_parse_error_bmatch([simple\|verbose],
3380 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3381 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3382 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3383 const char*
3384 const ]b4_parser_class[::yytname_[] =
3386 ]b4_tname[
3388 #endif
3389 ]])[
3391 void
3392 ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
3393 value_type& yyval]b4_locations_if([[,
3394 location_type& yyloc]])[)
3396 YY_USE (yyval);]b4_locations_if([[
3397 YY_USE (yyloc);]])[
3398 if (!yymsg)
3399 yymsg = "Deleting";
3400 ]b4_parser_class[& yyparser = *this;
3401 YY_USE (yyparser);
3402 YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc);
3404 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3405 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3406 [b4_symbol_actions([destructor])],
3407 [m4_popdef([b4_symbol_action])])[
3408 YY_IGNORE_MAYBE_UNINITIALIZED_END
3411 #if ]b4_api_PREFIX[DEBUG
3412 /*--------------------.
3413 | Print this symbol. |
3414 `--------------------*/
3416 void
3417 ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
3418 const value_type& yyval]b4_locations_if([[,
3419 const location_type& yyloc]])[) const
3420 {]b4_locations_if([[
3421 YY_USE (yyloc);]])[
3422 YY_USE (yyval);
3423 std::ostream& yyo = debug_stream ();
3424 YY_USE (yyo);
3425 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3426 [b4_symbol_actions([printer])],
3427 [m4_popdef([b4_symbol_action])])[
3430 void
3431 ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
3432 const value_type& yyval]b4_locations_if([[,
3433 const location_type& yyloc]])[) const
3435 *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
3436 << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
3437 << yyloc << ": "]])[;
3438 yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[);
3439 *yycdebug_ << ')';
3442 std::ostream&
3443 ]b4_parser_class[::debug_stream () const
3445 return *yycdebug_;
3448 void
3449 ]b4_parser_class[::set_debug_stream (std::ostream& o)
3451 yycdebug_ = &o;
3455 ]b4_parser_class[::debug_level_type
3456 ]b4_parser_class[::debug_level () const
3458 return yydebug;
3461 void
3462 ]b4_parser_class[::set_debug_level (debug_level_type l)
3464 // Actually, it is yydebug which is really used.
3465 yydebug = l;
3467 #endif // ]b4_api_PREFIX[DEBUG
3469 ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[
3470 ]b4_namespace_close[]dnl
3471 b4_epilogue[]dnl
3472 b4_output_end