glr2.cc: start the transition to using symbol_type
[bison.git] / data / skeletons / glr2.cc
blob55bf8648b1e6956b12b69e7cb771232357f1f9d1
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->yyla.value]][]dnl
185 b4_locations_if([, [[location_type *], [&this->yyla.location]]])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 class glr_stack;
223 class glr_state;
225 ]b4_namespace_open[
227 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
228 [b4_location_define])])[
230 /// A Bison parser.
231 class ]b4_parser_class[
233 public:
234 ]b4_public_types_declare[
235 ]b4_symbol_type_define[
237 /// Build a parser object.
238 ]b4_parser_class[ (]b4_parse_param_decl[);
239 ~]b4_parser_class[ ();
241 /// Parse. An alias for parse ().
242 /// \returns 0 iff parsing succeeded.
243 int operator() ();
245 /// Parse.
246 /// \returns 0 iff parsing succeeded.
247 int parse ();
249 #if ]b4_api_PREFIX[DEBUG
250 /// The current debugging stream.
251 std::ostream& debug_stream () const;
252 /// Set the current debugging stream.
253 void set_debug_stream (std::ostream &);
255 /// Type for debugging levels.
256 typedef int debug_level_type;
257 /// The current debugging level.
258 debug_level_type debug_level () const;
259 /// Set the current debugging level.
260 void set_debug_level (debug_level_type l);
261 #endif
263 /// Report a syntax error.]b4_locations_if([[
264 /// \param loc where the syntax error is found.]])[
265 /// \param msg a description of the syntax error.
266 void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
268 ]b4_parse_error_bmatch(
269 [custom\|detailed],
270 [[ /// The user-facing name of the symbol whose (internal) number is
271 /// YYSYMBOL. No bounds checking.
272 static const char *symbol_name (symbol_kind_type yysymbol);]],
273 [simple],
274 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
275 /// The user-facing name of the symbol whose (internal) number is
276 /// YYSYMBOL. No bounds checking.
277 static const char *symbol_name (symbol_kind_type yysymbol);
278 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
280 [verbose],
281 [[ /// The user-facing name of the symbol whose (internal) number is
282 /// YYSYMBOL. No bounds checking.
283 static std::string symbol_name (symbol_kind_type yysymbol);]])[
285 ]b4_token_constructor_define[
286 # if ]b4_api_PREFIX[DEBUG
287 public:
288 /// \brief Report a symbol value on the debug stream.
289 /// \param yykind The symbol kind.
290 /// \param yyval Its semantic value.]b4_locations_if([[
291 /// \param yyloc Its location.]])[
292 void yy_symbol_value_print_ (symbol_kind_type yykind,
293 const value_type& yyval]b4_locations_if([[,
294 const location_type& yyloc]])[) const;
295 /// \brief Report a symbol on the debug stream.
296 /// \param yykind The symbol kind.
297 /// \param yyval Its semantic value.]b4_locations_if([[
298 /// \param yyloc Its location.]])[
299 void yy_symbol_print_ (symbol_kind_type yykind,
300 const value_type& yyval]b4_locations_if([[,
301 const location_type& yyloc]])[) const;
302 private:
303 /// Debug stream.
304 std::ostream* yycdebug_;
305 #endif
307 public: // FIXME: Private
308 /// Convert a scanner token kind \a t to a symbol kind.
309 /// In theory \a t should be a token_kind_type, but character literals
310 /// are valid, yet not members of the token_kind_type enum.
311 static symbol_kind_type yytranslate_ (int t);
313 ]b4_parse_error_bmatch(
314 [simple],
315 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
316 /// For a symbol, its name in clear.
317 static const char* const yytname_[];
318 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
320 [verbose],
321 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
322 static std::string yytnamerr_ (const char *yystr);
324 /// For a symbol, its name in clear.
325 static const char* const yytname_[];
326 ]])[
328 /// \brief Reclaim the memory associated to a symbol.
329 /// \param yymsg Why this token is reclaimed.
330 /// If null, print nothing.
331 /// \param yykind The symbol kind.
332 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
333 value_type& yyval]b4_locations_if([[,
334 location_type& yyloc]])[);
336 ]b4_parse_param_vars[
337 // Needs access to report_syntax_error, etc.
338 friend glr_stack;
339 // Needs access to yy_destroy_.
340 friend glr_state;
343 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
344 ]b4_public_types_define([$1])])[
345 ]b4_namespace_close[
347 ]b4_percent_code_get([[provides]])[
348 ]])[
351 ## -------------- ##
352 ## Output files. ##
353 ## -------------- ##
356 # ------------- #
357 # Header file. #
358 # ------------- #
360 ]b4_header_if([[
361 ]b4_output_begin([b4_spec_header_file])[
362 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
363 [2002-2015, 2018-2021])[
364 // C++ GLR parser skeleton written by Valentin Tolmer.
366 ]b4_disclaimer[
367 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
368 ]b4_shared_declarations([hh])[
369 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
370 ]b4_output_end])[
373 # --------------------- #
374 # Implementation file. #
375 # --------------------- #
377 ]b4_output_begin([b4_parser_file_name])[
378 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
379 [2002-2015, 2018-2021])[
380 // C++ GLR parser skeleton written by Valentin Tolmer.
382 ]b4_disclaimer[
383 ]b4_identification[
385 ]b4_percent_code_get([[top]])[
386 ]m4_if(b4_prefix, [yy], [],
387 [[/* Substitute the variable and function names. */
388 #define yyparse ]b4_prefix[parse
389 #define yylex ]b4_prefix[lex
390 #define yyerror ]b4_prefix[error
391 #define yydebug ]b4_prefix[debug]])[
393 ]b4_user_pre_prologue[
395 ]b4_null_define[
397 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
398 [b4_shared_declarations([cc])])[
400 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
402 /* Default (constant) value used for initialization for null
403 right-hand sides. Unlike the standard yacc.c template, here we set
404 the default value of $$ to a zeroed-out value. Since the default
405 value is undefined, this behavior is technically correct. */
406 static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;
408 ]b4_user_post_prologue[
409 ]b4_percent_code_get[]dnl
411 [#include <cstdio>
412 #include <cstdlib>
414 #ifndef YY_
415 # if defined YYENABLE_NLS && YYENABLE_NLS
416 # if ENABLE_NLS
417 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
418 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
419 # endif
420 # endif
421 # ifndef YY_
422 # define YY_(Msgid) Msgid
423 # endif
424 #endif
426 #ifndef YYFREE
427 # define YYFREE free
428 #endif
429 #ifndef YYMALLOC
430 # define YYMALLOC malloc
431 #endif
433 #ifndef YYSETJMP
434 # include <setjmp.h>
435 # define YYJMP_BUF jmp_buf
436 # define YYSETJMP(Env) setjmp (Env)
437 /* Pacify Clang and ICC. */
438 # define YYLONGJMP(Env, Val) \
439 do { \
440 longjmp (Env, Val); \
441 YYASSERT (0); \
442 } while (false)
443 #endif
445 ]b4_attribute_define([noreturn])[
447 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
448 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
449 _Pragma ("GCC diagnostic push") \
450 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
451 # define YY_IGNORE_NULL_DEREFERENCE_END \
452 _Pragma ("GCC diagnostic pop")
453 #else
454 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
455 # define YY_IGNORE_NULL_DEREFERENCE_END
456 #endif
458 ]b4_null_define[
459 ]b4_cast_define[
461 // FIXME: Use the same conventions as lalr1.cc.
462 ]b4_parse_assert_if[
463 #ifndef YYASSERT
464 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
465 #endif
467 #ifdef YYDEBUG
468 # define YYDASSERT(Condition) YYASSERT(Condition)
469 #else
470 # define YYDASSERT(Condition)
471 #endif
473 /* YYFINAL -- State number of the termination state. */
474 #define YYFINAL ]b4_final_state_number[
475 /* YYLAST -- Last index in YYTABLE. */
476 #define YYLAST ]b4_last[
478 /* YYNTOKENS -- Number of terminals. */
479 #define YYNTOKENS ]b4_tokens_number[
480 /* YYNNTS -- Number of nonterminals. */
481 #define YYNNTS ]b4_nterms_number[
482 /* YYNRULES -- Number of rules. */
483 #define YYNRULES ]b4_rules_number[
484 /* YYNSTATES -- Number of states. */
485 #define YYNSTATES ]b4_states_number[
486 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
487 #define YYMAXRHS ]b4_r2_max[
488 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
489 accessed by $0, $-1, etc., in any rule. */
490 #define YYMAXLEFT ]b4_max_left_semantic_context[
492 #if ]b4_api_PREFIX[DEBUG
493 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
494 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
496 ]b4_rline[
498 #endif
500 #define YYPACT_NINF ]b4_pact_ninf[
501 #define YYTABLE_NINF ]b4_table_ninf[
503 ]b4_parser_tables_define[
505 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
506 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
508 ]b4_dprec[
511 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
512 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
514 ]b4_merger[
517 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
518 in the case of predicates. */
519 static const bool yyimmediate[] =
521 ]b4_immediate[
524 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
525 list of conflicting reductions corresponding to action entry for
526 state STATE-NUM in yytable. 0 means no conflicts. The list in
527 yyconfl is terminated by a rule number of 0. */
528 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
530 ]b4_conflict_list_heads[
533 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
534 0, pointed into by YYCONFLP. */
535 ]dnl Do not use b4_int_type_for here, since there are places where
536 dnl pointers onto yyconfl are taken, whose type is "short*".
537 dnl We probably ought to introduce a type for confl.
538 [static const short yyconfl[] =
540 ]b4_conflicting_rules[
543 /* Error token number */
544 #define YYTERROR 1
546 ]b4_locations_if([[
547 ]b4_yylloc_default_define[
548 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
549 ]])[
551 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
553 #define YYCHK(YYE) \
554 do { \
555 YYRESULTTAG yychk_flag = YYE; \
556 if (yychk_flag != yyok) \
557 return yychk_flag; \
558 } while (false)
560 #if ]b4_api_PREFIX[DEBUG
562 #define YYCDEBUG if (!yydebug) {} else std::cerr
564 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
565 do { \
566 if (yydebug) \
568 std::cerr << Title << ' '; \
569 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
570 std::cerr << '\n'; \
572 } while (false)
574 # define YY_REDUCE_PRINT(Args) \
575 do { \
576 if (yydebug) \
577 yystateStack.yy_reduce_print Args; \
578 } while (false)
580 /* Nonzero means print parse trace. It is left uninitialized so that
581 multiple parsers can coexist. */
582 int yydebug;
584 class glr_stack;
585 static void yypstack (const glr_stack& yystack, size_t yyk)
586 YY_ATTRIBUTE_UNUSED;
587 static void yypdumpstack (const glr_stack& yystack)
588 YY_ATTRIBUTE_UNUSED;
590 #else /* !]b4_api_PREFIX[DEBUG */
592 # define YYCDEBUG if (true) {} else std::cerr
593 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
594 # define YY_REDUCE_PRINT(Args) {}
596 #endif /* !]b4_api_PREFIX[DEBUG */
598 /* YYINITDEPTH -- initial size of the parser's stacks. */
599 #ifndef YYINITDEPTH
600 # define YYINITDEPTH ]b4_stack_depth_init[
601 #endif
603 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
604 if the built-in stack extension method is used).
606 Do not make this value too large; the results are undefined if
607 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
608 evaluated with infinite-precision integer arithmetic. */
610 #ifndef YYMAXDEPTH
611 # define YYMAXDEPTH ]b4_stack_depth_max[
612 #endif
614 /* Minimum number of free items on the stack allowed after an
615 allocation. This is to allow allocation and initialization
616 to be completed by functions that call yyexpandGLRStack before the
617 stack is expanded, thus insuring that all necessary pointers get
618 properly redirected to new data. */
619 #define YYHEADROOM 2
621 #ifndef YYSTACKEXPANDABLE
622 # define YYSTACKEXPANDABLE 1
623 #endif
625 template <typename Parameter>
626 class strong_index_alias
628 public:
629 static strong_index_alias create (std::ptrdiff_t value)
631 strong_index_alias result;
632 result.value_ = value;
633 return result;
636 std::ptrdiff_t const& get () const { return value_; }
638 size_t uget () const { return static_cast<size_t> (value_); }
640 strong_index_alias operator+ (std::ptrdiff_t other) const
642 return strong_index_alias (get () + other);
645 void operator+= (std::ptrdiff_t other)
647 value_ += other;
650 strong_index_alias operator- (std::ptrdiff_t other)
652 return strong_index_alias (get () - other);
655 void operator-= (std::ptrdiff_t other)
657 value_ -= other;
660 size_t operator- (strong_index_alias other)
662 return strong_index_alias (get () - other.get ());
665 strong_index_alias& operator++ ()
667 ++value_;
668 return *this;
671 bool isValid () const
673 return value_ != INVALID_INDEX;
676 void setInvalid()
678 value_ = INVALID_INDEX;
681 bool operator== (strong_index_alias other)
683 return get () == other.get ();
686 bool operator!= (strong_index_alias other)
688 return get () != other.get ();
691 bool operator< (strong_index_alias other)
693 return get () < other.get ();
696 private:
697 static const std::ptrdiff_t INVALID_INDEX;
699 // WARNING: 0-initialized.
700 std::ptrdiff_t value_;
703 template<typename T>
704 const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
705 std::numeric_limits<std::ptrdiff_t>::max ();
707 typedef strong_index_alias<struct glr_state_set_tag> state_set_index;
709 state_set_index create_state_set_index (std::ptrdiff_t value)
711 return state_set_index::create (value);
714 /** State numbers, as in LALR(1) machine */
715 typedef int state_num;
717 /** Rule numbers, as in LALR(1) machine */
718 typedef int rule_num;
720 // Forward declarations.
721 class glr_state;
722 class semantic_option;
723 class glr_stack_item;
724 class glr_stack;
726 /** Accessing symbol of state YYSTATE. */
727 static inline yysymbol_kind_t
728 yy_accessing_symbol (state_num yystate)
730 return YY_CAST (yysymbol_kind_t, yystos[yystate]);
733 /** Left-hand-side symbol for rule #YYRULE. */
734 static inline yysymbol_kind_t
735 yylhsNonterm (rule_num yyrule)
737 return static_cast<yysymbol_kind_t>(yyr1[yyrule]);
740 /** Number of symbols composing the right hand side of rule #RULE. */
741 static inline int
742 yyrhsLength (rule_num yyrule)
744 return yyr2[yyrule];
747 class glr_state
749 public:
750 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
751 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
752 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
753 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
755 glr_state ()
756 : yyresolved (false)
757 , yylrState (0)
758 , yyposn (0)
759 , yypred (0)
760 , yyfirstVal (0)]b4_locations_if([[
761 , yyloc ()]])[]b4_parse_assert_if([[
762 , magic_ (MAGIC)]])[
765 /// Build with a semantic value.
766 glr_state (state_num lrState, size_t posn, const value_type& val]b4_locations_if([[, const location_type& loc]])[)
767 : yyresolved (true)
768 , yylrState (lrState)
769 , yyposn (posn)
770 , yypred (0)
771 , yyval (]b4_variant_if([], [[val]])[)]b4_locations_if([[
772 , yyloc (loc)]])[]b4_parse_assert_if([[
773 , magic_ (MAGIC)]])[
774 {]b4_variant_if([[
775 ]b4_symbol_variant([yy_accessing_symbol (lrState)],
776 [yyval], [copy], [val])])[}
778 /// Build with a semantic option.
779 glr_state (state_num lrState, size_t posn)
780 : yyresolved (false)
781 , yylrState (lrState)
782 , yyposn (posn)
783 , yypred (0)
784 , yyfirstVal (0)]b4_locations_if([[
785 , yyloc ()]])[]b4_parse_assert_if([[
786 , magic_ (MAGIC)]])[
789 glr_state (const glr_state& other)
790 : yyresolved (other.yyresolved)
791 , yylrState (other.yylrState)
792 , yyposn (other.yyposn)
793 , yypred (0)]b4_locations_if([[
794 , yyloc (other.yyloc)]])[]b4_parse_assert_if([[
795 , magic_ (MAGIC)]])[
797 setPred (other.pred ());
798 if (other.yyresolved)]b4_variant_if([[
800 new (&yyval) value_type ();
801 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
802 [yyval], [copy], [other.value ()])[
803 }]], [[
804 new (&yyval) value_type (other.value ());]])[
805 else
807 yyfirstVal = 0;
808 setFirstVal (other.firstVal ());
809 }]b4_parse_assert_if([[
810 check_();]])[
813 ~glr_state ()
814 {]b4_parse_assert_if([[
815 check_ ();]])[
816 if (yyresolved)
817 {]b4_variant_if([[
818 yysymbol_kind_t yykind = yy_accessing_symbol (yylrState);
819 // FIXME: User destructors.
820 // Value type destructor.
821 ]b4_symbol_variant([[yykind]], [[yyval]], [[template destroy]])])[
822 yyval.~value_type ();
823 }]b4_parse_assert_if([[
824 magic_ = 0;]])[
827 glr_state& operator= (const glr_state& other)
828 {]b4_parse_assert_if([[
829 check_ ();
830 other.check_ ();]])[
831 if (!yyresolved && other.yyresolved)
832 new (&yyval) value_type;
833 yyresolved = other.yyresolved;
834 yylrState = other.yylrState;
835 yyposn = other.yyposn;
836 setPred (other.pred ());
837 if (other.yyresolved)]b4_variant_if([[
838 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
839 [yyval], [copy], [other.value ()])], [[
840 value () = other.value ();]])[
841 else
842 setFirstVal (other.firstVal ());]b4_locations_if([[
843 yyloc = other.yyloc;]])[
844 return *this;
847 /** Type tag for the semantic value. If true, yyval applies, otherwise
848 * yyfirstVal applies. */
849 bool yyresolved;
850 /** Number of corresponding LALR(1) machine state. */
851 state_num yylrState;
852 /** Source position of the last token produced by my symbol */
853 size_t yyposn;
855 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
856 glr_state* pred ();
857 const glr_state* pred () const;
858 void setPred (const glr_state* state);
860 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
861 /// temporaries.
862 semantic_option* firstVal ();
863 const semantic_option* firstVal () const;
864 void setFirstVal (const semantic_option* option);
866 value_type& value ()
867 {]b4_parse_assert_if([[
868 check_ ();]])[
869 return yyval;
872 const value_type& value () const
873 {]b4_parse_assert_if([[
874 check_ ();]])[
875 return yyval;
878 void
879 destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_user_formals[);
881 /* DEBUGGING ONLY */
882 #if ]b4_api_PREFIX[DEBUG
883 void yy_yypstack () const
884 {]b4_parse_assert_if([[
885 check_ ();]])[
886 if (pred () != YY_NULLPTR)
888 pred ()->yy_yypstack ();
889 std::cerr << " -> ";
891 std::cerr << yylrState << "@@" << yyposn;
893 #endif
895 std::ptrdiff_t indexIn (const glr_stack_item* array) const;
897 glr_stack_item* asItem ()
898 {]b4_parse_assert_if([[
899 check_ ();]])[
900 return asItem(this);
903 const glr_stack_item* asItem () const
904 {]b4_parse_assert_if([[
905 check_ ();]])[
906 return asItem (this);
909 private:
910 template <typename T>
911 static const glr_stack_item* asItem (const T* state)
913 return reinterpret_cast<const glr_stack_item*>(state);
915 template <typename T>
916 static glr_stack_item* asItem (T* state)
918 return reinterpret_cast<glr_stack_item*> (state);
920 static const char *as_pointer_ (const glr_state *state)
922 return reinterpret_cast<const char *> (state);
924 static char *as_pointer_ (glr_state *state)
926 return reinterpret_cast<char *> (state);
928 /** Preceding state in this stack */
929 std::ptrdiff_t yypred;
930 union {
931 /** First in a chain of alternative reductions producing the
932 * nonterminal corresponding to this state, threaded through
933 * yyfirstVal. Value "0" means empty. */
934 std::ptrdiff_t yyfirstVal;
935 /** Semantic value for this state. */
936 value_type yyval;
937 };]b4_locations_if([[
938 // FIXME: Why public?
939 public:
940 /** Source location for this state. */
941 location_type yyloc;]])[
943 ]b4_parse_assert_if([[
944 public:
945 // Check invariants.
946 void check_ () const
948 YY_IGNORE_NULL_DEREFERENCE_BEGIN
949 YYASSERT (this->magic_ == MAGIC);
950 YY_IGNORE_NULL_DEREFERENCE_END
953 // A magic number to check our pointer arithmetic is sane.
954 enum { MAGIC = 713705 };
955 unsigned int magic_;]])[
958 /** A stack of GLRState representing the different heads during
959 * nondeterministic evaluation. */
960 class glr_state_set
962 public:
963 /** Initialize YYSET to a singleton set containing an empty stack. */
964 glr_state_set ()
965 : yylastDeleted (YY_NULLPTR)
967 yystates.push_back (YY_NULLPTR);
968 yylookaheadNeeds.push_back (false);
971 // Behave like a vector of states.
972 glr_state*& operator[] (state_set_index index)
974 return yystates[index.uget()];
977 glr_state* operator[] (state_set_index index) const
979 return yystates[index.uget()];
982 size_t size () const
984 return yystates.size ();
987 std::vector<glr_state*>::iterator begin ()
989 return yystates.begin ();
992 std::vector<glr_state*>::iterator end ()
994 return yystates.end ();
997 bool lookaheadNeeds (state_set_index index) const
999 return yylookaheadNeeds[index.uget ()];
1002 bool setLookaheadNeeds (state_set_index index, bool value)
1004 return yylookaheadNeeds[index.uget ()] = value;
1007 /** Invalidate stack #YYK. */
1008 void
1009 yymarkStackDeleted (state_set_index yyk)
1011 size_t k = yyk.uget ();
1012 if (yystates[k] != YY_NULLPTR)
1013 yylastDeleted = yystates[k];
1014 yystates[k] = YY_NULLPTR;
1017 /** Undelete the last stack in *this that was marked as deleted. Can
1018 only be done once after a deletion, and only when all other stacks have
1019 been deleted. */
1020 void
1021 yyundeleteLastStack ()
1023 if (yylastDeleted == YY_NULLPTR || !yystates.empty ())
1024 return;
1025 yystates.push_back (yylastDeleted);
1026 YYCDEBUG << "Restoring last deleted stack as stack #0.\n";
1027 clearLastDeleted ();
1030 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1031 * ones. */
1032 void
1033 yyremoveDeletes ()
1035 size_t newsize = yystates.size ();
1036 /* j is the number of live stacks we have seen. */
1037 for (size_t i = 0, j = 0; j < newsize; ++i)
1039 if (yystates[i] == YY_NULLPTR)
1041 if (i == j)
1043 YYCDEBUG << "Removing dead stacks.\n";
1045 newsize -= 1;
1047 else
1049 yystates[j] = yystates[i];
1050 /* In the current implementation, it's unnecessary to copy
1051 yylookaheadNeeds[i] since, after
1052 yyremoveDeletes returns, the parser immediately either enters
1053 deterministic operation or shifts a token. However, it doesn't
1054 hurt, and the code might evolve to need it. */
1055 yylookaheadNeeds[j] = yylookaheadNeeds[i];
1056 if (j != i)
1058 YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n";
1060 j += 1;
1063 yystates.resize (newsize);
1064 yylookaheadNeeds.resize (newsize);
1068 state_set_index
1069 yysplitStack (state_set_index yyk)
1071 const size_t k = yyk.uget ();
1072 yystates.push_back (yystates[k]);
1073 yylookaheadNeeds.push_back (yylookaheadNeeds[k]);
1074 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates.size () - 1));
1077 void clearLastDeleted ()
1079 yylastDeleted = YY_NULLPTR;
1082 private:
1084 std::vector<glr_state*> yystates;
1085 /** During nondeterministic operation, yylookaheadNeeds tracks which
1086 * stacks have actually needed the current lookahead. During deterministic
1087 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1088 * duplicate !yyla.empty (). */
1089 std::vector<bool> yylookaheadNeeds;
1091 /** The last stack we invalidated. */
1092 glr_state* yylastDeleted;
1095 class semantic_option
1097 public:
1098 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
1099 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
1100 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
1101 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
1103 semantic_option ()
1104 : yyrule (0)
1105 , yystate (0)
1106 , yynext (0)
1107 , yytoken (]b4_symbol(empty, kind)[)
1108 , yyval ()]b4_locations_if([[
1109 , yyloc ()]])[]b4_parse_assert_if([[
1110 , magic_ (MAGIC)]])[
1113 semantic_option (rule_num rule, symbol_kind_type token)
1114 : yyrule (rule)
1115 , yystate (0)
1116 , yynext (0)
1117 , yytoken (token)
1118 , yyval ()]b4_locations_if([[
1119 , yyloc ()]])[]b4_parse_assert_if([[
1120 , magic_ (MAGIC)]])[
1123 semantic_option (const semantic_option& that)
1124 : yyrule (that.yyrule)
1125 , yystate (that.yystate)
1126 , yynext (that.yynext)
1127 , yytoken (that.yytoken)
1128 , yyval (]b4_variant_if([], [[that.yyval]])[)]b4_locations_if([[
1129 , yyloc (that.yyloc)]])[]b4_parse_assert_if([[
1130 , magic_ (MAGIC)]])[
1131 {]b4_parse_assert_if([[
1132 that.check_ ();]])[]b4_variant_if([[
1133 ]b4_symbol_variant([yytoken],
1134 [yyval], [copy], [that.yyval])])[
1137 // Needed for the assignment in yynewSemanticOption.
1138 semantic_option& operator= (const semantic_option& that)
1139 {]b4_parse_assert_if([[
1140 check_ ();
1141 that.check_ ();]])[
1142 yyrule = that.yyrule;
1143 yystate = that.yystate;
1144 yynext = that.yynext;
1145 yytoken = that.yytoken;]b4_variant_if([[
1146 ]b4_symbol_variant([yytoken],
1147 [yyval], [copy], [that.yyval])], [[
1148 yyval = that.yyval;]])[]b4_locations_if([[
1149 yyloc = that.yyloc;]])[
1150 return *this;
1153 /// Only call state() and setState() on objects in yyitems, not temporaries.
1154 glr_state* state();
1155 const glr_state* state() const;
1156 void setState(const glr_state* s);
1158 const semantic_option* next () const;
1159 semantic_option* next ();
1160 void setNext (const semantic_option* s);
1162 std::ptrdiff_t indexIn (const glr_stack_item* array) const;
1164 /** True iff YYY0 and YYY1 represent identical options at the top level.
1165 * That is, they represent the same rule applied to RHS symbols
1166 * that produce the same terminal symbols. */
1167 bool
1168 isIdenticalTo (const semantic_option& yyy1) const
1169 {]b4_parse_assert_if([[
1170 check_ ();
1171 yyy1.check_ ();]])[
1172 if (this->yyrule == yyy1.yyrule)
1174 const glr_state *yys0, *yys1;
1175 int yyn;
1176 for (yys0 = this->state(),
1177 yys1 = yyy1.state(),
1178 yyn = yyrhsLength (this->yyrule);
1179 yyn > 0;
1180 yys0 = yys0->pred(),
1181 yys1 = yys1->pred(), yyn -= 1)
1182 if (yys0->yyposn != yys1->yyposn)
1183 return false;
1184 return true;
1186 else
1187 return false;
1190 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1191 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1192 void
1193 mergeWith (semantic_option& yyy1)
1194 {]b4_parse_assert_if([[
1195 check_ ();
1196 yyy1.check_ ();]])[
1197 glr_state *yys0 = this->state ();
1198 glr_state *yys1 = yyy1.state ();
1199 for (int yyn = yyrhsLength (this->yyrule);
1200 yyn > 0;
1201 yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ())
1203 if (yys0 == yys1)
1204 break;
1205 else if (yys0->yyresolved)
1207 yys1->yyresolved = true;]b4_variant_if([[
1208 YYASSERT (yys1->yylrState == yys0->yylrState);
1209 ]b4_symbol_variant([yy_accessing_symbol (yys0->yylrState)],
1210 [yys1->value ()], [copy], [yys0->value ()])], [[
1211 yys1->value () = yys0->value ();]])[
1213 else if (yys1->yyresolved)
1215 yys0->yyresolved = true;]b4_variant_if([[
1216 YYASSERT (yys0->yylrState == yys1->yylrState);
1217 ]b4_symbol_variant([yy_accessing_symbol (yys1->yylrState)],
1218 [yys0->value ()], [copy], [yys1->value ()])], [[
1219 yys0->value () = yys1->value ();]])[
1221 else
1223 semantic_option* yyz0prev = YY_NULLPTR;
1224 semantic_option* yyz0 = yys0->firstVal();
1225 semantic_option* yyz1 = yys1->firstVal();
1226 while (true)
1228 if (yyz1 == yyz0 || yyz1 == YY_NULLPTR)
1229 break;
1230 else if (yyz0 == YY_NULLPTR)
1232 if (yyz0prev != YY_NULLPTR)
1233 yyz0prev->setNext (yyz1);
1234 else
1235 yys0->setFirstVal (yyz1);
1236 break;
1238 else if (yyz0 < yyz1)
1240 semantic_option* yyz = yyz0;
1241 if (yyz0prev != YY_NULLPTR)
1242 yyz0prev->setNext(yyz1);
1243 else
1244 yys0->setFirstVal(yyz1);
1245 yyz1 = yyz1->next();
1246 yyz0->setNext(yyz);
1248 yyz0prev = yyz0;
1249 yyz0 = yyz0->next();
1251 yys1->setFirstVal(yys0->firstVal());
1256 #if ]b4_api_PREFIX[DEBUG
1257 void yyreportTree (size_t yyindent = 2) const
1258 {]b4_parse_assert_if([[
1259 check_ ();]])[
1260 int yynrhs = yyrhsLength (this->yyrule);
1261 const glr_state* yystates[1 + YYMAXRHS];
1262 glr_state yyleftmost_state;
1265 const glr_state* yys = this->state();
1266 for (int yyi = yynrhs; 0 < yyi; yyi -= 1)
1268 yystates[yyi] = yys;
1269 yys = yys->pred();
1271 if (yys == YY_NULLPTR)
1273 yyleftmost_state.yyposn = 0;
1274 yystates[0] = &yyleftmost_state;
1276 else
1277 yystates[0] = yys;
1280 std::string yylhs = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yylhsNonterm (this->yyrule));
1281 YYASSERT(this->state());
1282 if (this->state()->yyposn < yystates[0]->yyposn + 1)
1283 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1284 << this->yyrule - 1 << ", empty>\n";
1285 else
1286 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1287 << this->yyrule - 1 << ", tokens "
1288 << yystates[0]->yyposn + 1 << " .. "
1289 << this->state()->yyposn << ">\n";
1290 for (int yyi = 1; yyi <= yynrhs; yyi += 1)
1292 if (yystates[yyi]->yyresolved)
1294 std::string yysym = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yy_accessing_symbol (yystates[yyi]->yylrState));
1295 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1296 std::cerr << std::string(yyindent + 2, ' ') << yysym
1297 << " <empty>\n";
1298 else
1299 std::cerr << std::string(yyindent + 2, ' ') << yysym
1300 << " <tokens " << yystates[yyi-1]->yyposn + 1
1301 << " .. " << yystates[yyi]->yyposn << ">\n";
1303 else
1304 yystates[yyi]->firstVal ()->yyreportTree (yyindent+2);
1307 #endif
1309 /** Rule number for this reduction */
1310 rule_num yyrule;
1312 private:
1313 template <typename T>
1314 static const glr_stack_item* asItem(const T* state)
1316 return reinterpret_cast<const glr_stack_item*>(state);
1318 template <typename T>
1319 static glr_stack_item* asItem(T* state)
1321 return reinterpret_cast<glr_stack_item*>(state);
1323 /** The last RHS state in the list of states to be reduced. */
1324 std::ptrdiff_t yystate;
1325 /** Next sibling in chain of options. To facilitate merging,
1326 * options are chained in decreasing order by address. */
1327 std::ptrdiff_t yynext;
1329 public:
1330 /** The lookahead for this reduction. */
1331 symbol_kind_type yytoken;
1332 value_type yyval;]b4_locations_if([[
1333 location_type yyloc;]])[
1335 ]b4_parse_assert_if([[
1336 public:
1337 // Check invariants.
1338 void check_ () const
1340 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1341 YYASSERT (this->magic_ == MAGIC);
1342 YY_IGNORE_NULL_DEREFERENCE_END
1345 // A magic number to check our pointer arithmetic is sane.
1346 enum { MAGIC = 0xeff1cace };
1347 unsigned int magic_;]])[
1350 /** Type of the items in the GLR stack.
1351 * It can be either a glr_state or a semantic_option. The is_state_ field
1352 * indicates which item of the union is valid. */
1353 class glr_stack_item
1355 public:
1356 glr_stack_item (bool state = true)
1357 : is_state_ (state)]b4_parse_assert_if([[
1358 , magic_ (MAGIC)]])[
1360 if (is_state_)
1361 new (&raw_) glr_state;
1362 else
1363 new (&raw_) semantic_option;
1366 glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW
1367 : is_state_ (other.is_state_)]b4_parse_assert_if([[
1368 , magic_ (MAGIC)]])[
1369 {]b4_parse_assert_if([[
1370 other.check_ ();]])[
1371 std::memcpy (raw_, other.raw_, union_size);
1374 glr_stack_item& operator= (glr_stack_item other)
1375 {]b4_parse_assert_if([[
1376 check_ ();
1377 other.check_ ();]])[
1378 std::swap (is_state_, other.is_state_);
1379 std::swap (raw_, other.raw_);
1380 return *this;
1383 ~glr_stack_item ()
1384 {]b4_parse_assert_if([[
1385 check_ ();]])[
1386 if (is_state ())
1387 getState ().~glr_state ();
1388 else
1389 getOption ().~semantic_option ();
1392 void setState (const glr_state &state)
1393 {]b4_parse_assert_if([[
1394 check_ ();
1395 state.check_ ();]])[
1396 if (this != state.asItem ())
1398 if (is_state_)
1399 getState ().~glr_state ();
1400 else
1401 getOption ().~semantic_option ();
1402 new (&raw_) glr_state (state);
1403 is_state_ = true;
1407 glr_state& getState ()
1408 {]b4_parse_assert_if([[
1409 check_ ();]])[
1410 YYDASSERT (is_state ());
1411 void *yyp = raw_;
1412 glr_state& res = *static_cast<glr_state*> (yyp);]b4_parse_assert_if([[
1413 res.check_ ();]])[
1414 return res;
1417 const glr_state& getState () const
1418 {]b4_parse_assert_if([[
1419 check_ ();]])[
1420 YYDASSERT (is_state ());
1421 const void *yyp = raw_;
1422 const glr_state& res = *static_cast<const glr_state*> (yyp);]b4_parse_assert_if([[
1423 res.check_ ();]])[
1424 return res;
1427 semantic_option& getOption ()
1428 {]b4_parse_assert_if([[
1429 check_ ();]])[
1430 YYDASSERT (!is_state ());
1431 void *yyp = raw_;
1432 return *static_cast<semantic_option*> (yyp);
1434 const semantic_option& getOption () const
1435 {]b4_parse_assert_if([[
1436 check_ ();]])[
1437 YYDASSERT (!is_state ());
1438 const void *yyp = raw_;
1439 return *static_cast<const semantic_option*> (yyp);
1441 bool is_state () const
1442 {]b4_parse_assert_if([[
1443 check_ ();]])[
1444 return is_state_;
1447 private:
1448 /// The possible contents of raw_. Since they have constructors, they cannot
1449 /// be directly included in the union.
1450 union contents
1452 char yystate[sizeof (glr_state)];
1453 char yyoption[sizeof (semantic_option)];
1455 enum { union_size = sizeof (contents) };
1456 union {
1457 /// Strongest alignment constraints.
1458 long double yyalign_me;
1459 /// A buffer large enough to store the contents.
1460 char raw_[union_size];
1462 /** Type tag for the union. */
1463 bool is_state_;
1464 ]b4_parse_assert_if([[
1465 public:
1466 // Check invariants.
1467 void check_ () const
1469 YYASSERT (this->magic_ == MAGIC);
1470 YYASSERT (this->is_state_ == false || this->is_state_ == true);
1472 // A magic number to check our pointer arithmetic is sane.
1473 enum { MAGIC = 0xDEAD1ACC }; // 3735886540.
1474 const unsigned int magic_;]])[
1477 glr_state* glr_state::pred ()
1478 {]b4_parse_assert_if([[
1479 check_ ();]])[
1480 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1481 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1482 YY_IGNORE_NULL_DEREFERENCE_END
1485 const glr_state* glr_state::pred () const
1486 {]b4_parse_assert_if([[
1487 check_ ();]])[
1488 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1489 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1490 YY_IGNORE_NULL_DEREFERENCE_END
1493 void glr_state::setPred (const glr_state* state)
1494 {]b4_parse_assert_if([[
1495 check_ ();
1496 if (state)
1497 state->check_ ();]])[
1498 yypred = state ? as_pointer_ (this) - as_pointer_ (state) : 0;
1501 semantic_option* glr_state::firstVal ()
1502 {]b4_parse_assert_if([[
1503 check_ ();]])[
1504 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1507 const semantic_option* glr_state::firstVal () const
1508 {]b4_parse_assert_if([[
1509 check_ ();]])[
1510 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1513 void glr_state::setFirstVal (const semantic_option* option)
1514 {]b4_parse_assert_if([[
1515 check_ ();]])[
1516 yyfirstVal = option ? asItem(this) - asItem(option) : 0;
1519 std::ptrdiff_t glr_state::indexIn (const glr_stack_item* array) const
1520 {]b4_parse_assert_if([[
1521 check_ ();]])[
1522 return asItem(this) - array;
1525 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item* array) const
1527 return asItem(this) - array;
1530 glr_state* semantic_option::state ()
1532 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1533 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1534 YY_IGNORE_NULL_DEREFERENCE_END
1537 const glr_state* semantic_option::state () const
1539 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1542 void semantic_option::setState (const glr_state* s)
1544 yystate = s ? asItem(this) - asItem(s) : 0;
1547 const semantic_option* semantic_option::next () const
1549 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1552 semantic_option* semantic_option::next ()
1554 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1557 void semantic_option::setNext (const semantic_option* s)
1559 yynext = s ? asItem(this) - asItem(s) : 0;
1562 void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_user_formals[)
1563 {]b4_parse_assert_if([[
1564 check_ ();]])[
1565 if (yyresolved)
1566 yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
1567 value ()]b4_locations_if([, yyloc])[);
1568 else
1570 #if ]b4_api_PREFIX[DEBUG
1571 YYCDEBUG << yymsg
1572 << (firstVal() ? " unresolved " : " incomplete ")
1573 << (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm")
1574 << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState))
1575 << " ("]b4_locations_if([[
1576 << yyloc << ": "]])[
1577 << ")\n";
1578 #endif
1579 if (firstVal() != YY_NULLPTR)
1581 semantic_option& yyoption = *firstVal ();
1582 glr_state *yyrh = yyoption.state ();
1583 for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1)
1585 yyrh->destroy (yymsg, yyparser]b4_user_args[);
1586 yyrh = yyrh->pred();
1593 #undef YYFILL
1594 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1596 class state_stack
1598 public:
1599 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
1600 typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
1601 typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
1603 /** Initialize to a single empty stack, with total maximum
1604 * capacity for all stacks of YYSIZE. */
1605 state_stack (size_t yysize)
1606 : yysplitPoint (YY_NULLPTR)
1608 yyitems.reserve (yysize);
1611 #if YYSTACKEXPANDABLE
1612 /** Returns false if it tried to expand but could not. */
1613 bool
1614 yyexpandGLRStackIfNeeded ()
1616 return YYHEADROOM <= spaceLeft () || yyexpandGLRStack ();
1619 private:
1620 /** If *this is expandable, extend it. WARNING: Pointers into the
1621 stack from outside should be considered invalid after this call.
1622 We always expand when there are 1 or fewer items left AFTER an
1623 allocation, so that we can avoid having external pointers exist
1624 across an allocation. */
1625 bool
1626 yyexpandGLRStack ()
1628 const size_t oldsize = yyitems.size();
1629 if (YYMAXDEPTH - YYHEADROOM < oldsize)
1630 return false;
1631 const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize;
1632 const glr_stack_item *oldbase = &yyitems[0];
1634 yyitems.reserve (yynewSize);
1635 const glr_stack_item *newbase = &yyitems[0];
1637 // Adjust the pointers. Perform raw pointer arithmetic, as there
1638 // is no reason for objects to be aligned on their size.
1639 const ptrdiff_t disp
1640 = reinterpret_cast<const char*> (newbase) - reinterpret_cast<const char*> (oldbase);
1641 if (yysplitPoint)
1642 const_cast<glr_state*&> (yysplitPoint)
1643 = reinterpret_cast<glr_state*> (reinterpret_cast<char*> (const_cast<glr_state*> (yysplitPoint)) + disp);
1645 for (std::vector<glr_state*>::iterator
1646 i = yytops.begin (),
1647 yyend = yytops.end ();
1648 i != yyend; ++i)
1649 if (glr_state_not_null (*i))
1650 *i = reinterpret_cast<glr_state*>(reinterpret_cast<char*>(*i) + disp);
1652 return true;
1655 public:
1656 #else
1657 bool yyexpandGLRStackIfNeeded ()
1659 return YYHEADROOM <= spaceLeft ();
1661 #endif
1662 #undef YYSTACKEXPANDABLE
1664 static bool glr_state_not_null (glr_state* s)
1666 return s != YY_NULLPTR;
1669 bool
1670 reduceToOneStack ()
1672 typedef std::vector<glr_state*>::iterator iterator;
1673 const iterator yybegin = yytops.begin();
1674 const iterator yyend = yytops.end();
1675 const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null);
1676 if (yyit == yyend)
1677 return false;
1678 for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin);
1679 yyk.uget() != numTops(); ++yyk)
1680 yytops.yymarkStackDeleted (yyk);
1681 yytops.yyremoveDeletes ();
1682 yycompressStack ();
1683 return true;
1686 /** Called when returning to deterministic operation to clean up the extra
1687 * stacks. */
1688 void
1689 yycompressStack ()
1691 if (yytops.size() != 1 || !isSplit())
1692 return;
1694 // yyr is the state after the split point.
1695 glr_state* yyr = YY_NULLPTR;
1696 for (glr_state *yyp = firstTop(), *yyq = yyp->pred();
1697 yyp != yysplitPoint;
1698 yyr = yyp, yyp = yyq, yyq = yyp->pred())
1699 yyp->setPred(yyr);
1701 // This const_cast is okay, since anyway we have access to the mutable
1702 // yyitems into which yysplitPoint points.
1703 glr_stack_item* nextFreeItem
1704 = const_cast<glr_state*> (yysplitPoint)->asItem () + 1;
1705 yysplitPoint = YY_NULLPTR;
1706 yytops.clearLastDeleted ();
1708 while (yyr != YY_NULLPTR)
1710 nextFreeItem->setState (*yyr);
1711 glr_state& nextFreeState = nextFreeItem->getState();
1712 yyr = yyr->pred();
1713 nextFreeState.setPred(&(nextFreeItem - 1)->getState());
1714 setFirstTop (&nextFreeState);
1715 ++nextFreeItem;
1717 yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data()));
1720 bool isSplit() const {
1721 return yysplitPoint != YY_NULLPTR;
1724 // Present the interface of a vector of glr_stack_item.
1725 std::vector<glr_stack_item>::const_iterator begin () const
1727 return yyitems.begin ();
1730 std::vector<glr_stack_item>::const_iterator end () const
1732 return yyitems.end ();
1735 size_t size() const
1737 return yyitems.size ();
1740 glr_stack_item& operator[] (size_t i)
1742 return yyitems[i];
1745 glr_stack_item& stackItemAt (size_t index)
1747 return yyitems[index];
1750 size_t numTops () const
1752 return yytops.size ();
1755 glr_state* firstTop () const
1757 return yytops[create_state_set_index (0)];
1760 glr_state* topAt (state_set_index i) const
1762 return yytops[i];
1765 void setFirstTop (glr_state* value)
1767 yytops[create_state_set_index (0)] = value;
1770 void setTopAt (state_set_index i, glr_state* value)
1772 yytops[i] = value;
1775 void pop_back ()
1777 yyitems.pop_back ();
1780 void pop_back (size_t n)
1782 yyitems.resize (yyitems.size () - n);
1785 state_set_index
1786 yysplitStack (state_set_index yyk)
1788 if (!isSplit ())
1790 YYASSERT (yyk.get () == 0);
1791 yysplitPoint = topAt (yyk);
1793 return yytops.yysplitStack (yyk);
1796 /** Assuming that YYS is a GLRState somewhere on *this, update the
1797 * splitpoint of *this, if needed, so that it is at least as deep as
1798 * YYS. */
1799 void
1800 yyupdateSplit (glr_state& yys)
1802 if (isSplit() && &yys < yysplitPoint)
1803 yysplitPoint = &yys;
1806 /** Return a fresh GLRState.
1807 * Callers should call yyreserveStack afterwards to make sure there is
1808 * sufficient headroom. */
1809 glr_state& yynewGLRState (const glr_state& newState)
1811 glr_state& state = yyitems[yynewGLRStackItem (true)].getState ();
1812 #if false && 201103L <= YY_CPLUSPLUS
1813 state = std::move (newState);
1814 #else
1815 state = newState;
1816 #endif
1817 return state;
1820 /** Return a fresh SemanticOption.
1821 * Callers should call yyreserveStack afterwards to make sure there is
1822 * sufficient headroom. */
1823 semantic_option& yynewSemanticOption (semantic_option newOption)
1825 semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption ();
1826 #if 201103L <= YY_CPLUSPLUS
1827 option = std::move (newOption);
1828 #else
1829 option = newOption;
1830 #endif
1831 return option;
1834 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1835 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1836 * For convenience, always return YYLOW1. */
1838 yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal)
1840 if (!yynormal && yylow1 < yylow)
1842 yyfillin (yyvsp, yylow, yylow1);
1843 yylow = yylow1;
1845 return yylow1;
1848 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1849 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1850 * containing the pointer to the next state in the chain. */
1851 void
1852 yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1)
1854 glr_state* s = yyvsp[yylow0].getState().pred();
1855 YYASSERT(s != YY_NULLPTR);
1856 for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred())
1858 glr_state& yys = yyvsp[i].getState();
1859 #if ]b4_api_PREFIX[DEBUG
1860 yys.yylrState = s->yylrState;
1861 #endif
1862 yys.yyresolved = s->yyresolved;
1863 if (s->yyresolved)
1864 {]b4_variant_if([[
1865 new (&yys.value ()) value_type ();
1866 ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)],
1867 [yys.value ()], [copy], [s->value ()])], [[
1868 new (&yys.value ()) value_type (s->value ());]])[
1870 else
1871 /* The effect of using yyval or yyloc (in an immediate
1872 * rule) is undefined. */
1873 yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[
1874 yys.yyloc = s->yyloc;]])[
1875 yys.setPred(s->pred());
1879 #if ]b4_api_PREFIX[DEBUG
1881 /*----------------------------------------------------------------------.
1882 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1883 `----------------------------------------------------------------------*/
1885 void
1886 yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk,
1887 rule_num yyrule, ]b4_namespace_ref[::]b4_parser_class[& yyparser)
1889 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1890 int yylow = 1;])[
1891 int yyi;
1892 std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1
1893 << " (line " << int (yyrline[yyrule]) << "):\n";
1894 if (! yynormal)
1895 yyfillin (yyvsp, 1, -yynrhs);
1896 /* The symbols being reduced. */
1897 for (yyi = 0; yyi < yynrhs; yyi++)
1899 std::cerr << " $" << yyi + 1 << " = ";
1900 yyparser.yy_symbol_print_
1901 (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
1902 yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
1903 ]b4_rhs_location(yynrhs, yyi + 1)])[);
1904 if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
1905 std::cerr << " (unresolved)";
1906 std::cerr << '\n';
1911 #define YYINDEX(YYX) \
1912 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1914 void
1915 dumpStack () const
1917 for (size_t yyi = 0; yyi < size(); ++yyi)
1919 const glr_stack_item& item = yyitems[yyi];
1920 std::cerr << std::setw(3) << yyi << ". ";
1921 if (item.is_state())
1923 std::cerr << "Res: " << item.getState().yyresolved
1924 << ", LR State: " << item.getState().yylrState
1925 << ", posn: " << item.getState().yyposn
1926 << ", pred: " << YYINDEX(item.getState().pred());
1927 if (! item.getState().yyresolved)
1928 std::cerr << ", firstVal: "
1929 << YYINDEX(item.getState().firstVal());
1931 else
1933 std::cerr << "Option. rule: " << item.getOption().yyrule - 1
1934 << ", state: " << YYINDEX(item.getOption().state())
1935 << ", next: " << YYINDEX(item.getOption().next());
1937 std::cerr << '\n';
1939 std::cerr << "Tops:";
1940 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) {
1941 std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; ";
1943 std::cerr << '\n';
1946 #undef YYINDEX
1947 #endif
1949 YYRESULTTAG
1950 yyreportAmbiguity (const semantic_option& yyx0,
1951 const semantic_option& yyx1, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_locations_if([, const location_type& yyloc])[)
1953 YY_USE (yyx0);
1954 YY_USE (yyx1);
1956 #if ]b4_api_PREFIX[DEBUG
1957 std::cerr << "Ambiguity detected.\n"
1958 "Option 1,\n";
1959 yyx0.yyreportTree ();
1960 std::cerr << "\nOption 2,\n";
1961 yyx1.yyreportTree ();
1962 std::cerr << '\n';
1963 #endif
1965 yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous"));
1966 return yyabort;
1969 /* DEBUGGING ONLY */
1970 #if ]b4_api_PREFIX[DEBUG
1971 /* Print YYS (possibly NULL) and its predecessors. */
1972 void
1973 yypstates (const glr_state* yys) const
1975 if (yys != YY_NULLPTR)
1976 yys->yy_yypstack();
1977 else
1978 std::cerr << "<null>";
1979 std::cerr << '\n';
1981 #endif
1983 private:
1984 size_t spaceLeft() const
1986 return yyitems.capacity() - yyitems.size();
1989 /** Return a fresh GLRStackItem in this. The item is an LR state
1990 * if YYIS_STATE, and otherwise a semantic option. Callers should call
1991 * yyreserveStack afterwards to make sure there is sufficient
1992 * headroom. */
1993 size_t
1994 yynewGLRStackItem (bool yyis_state)
1996 YYDASSERT(yyitems.size() < yyitems.capacity());
1997 yyitems.push_back(glr_stack_item(yyis_state));
1998 return yyitems.size() - 1;
2002 public:
2004 std::vector<glr_stack_item> yyitems;
2005 // Where the stack splits. Anything below this address is deterministic.
2006 const glr_state* yysplitPoint;
2007 glr_state_set yytops;
2010 #undef YYFILL
2011 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2013 class glr_stack
2015 public:
2016 typedef ]b4_namespace_ref[::]b4_parser_class[ parser_type;
2017 typedef parser_type::symbol_kind symbol_kind;
2018 typedef parser_type::symbol_kind_type symbol_kind_type;
2019 typedef parser_type::symbol_type symbol_type;
2020 typedef parser_type::value_type value_type;]b4_locations_if([[
2021 typedef parser_type::location_type location_type;]])[
2023 glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
2024 : yyerrState (0)
2025 , yystateStack (yysize)
2026 , yyerrcnt (0)
2027 , yyla ()
2028 , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
2031 ~glr_stack ()
2033 if (!this->yyla.empty ())
2034 yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
2035 this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);
2036 popall_ ();
2039 int yyerrState;
2040 ]b4_locations_if([[ /* To compute the location of the error token. */
2041 glr_stack_item yyerror_range[3];]])[
2042 state_stack yystateStack;
2043 int yyerrcnt;
2044 symbol_type yyla;
2045 YYJMP_BUF yyexception_buffer;
2046 ]b4_namespace_ref[::]b4_parser_class[& yyparser;
2048 #define YYCHK1(YYE) \
2049 do { \
2050 switch (YYE) { \
2051 case yyok: \
2052 break; \
2053 case yyabort: \
2054 goto yyabortlab; \
2055 case yyaccept: \
2056 goto yyacceptlab; \
2057 case yyerr: \
2058 goto yyuser_error; \
2059 default: \
2060 goto yybuglab; \
2062 } while (false)
2065 parse ()
2067 int yyresult;
2068 size_t yyposn;
2070 YYCDEBUG << "Starting parse\n";
2072 this->yyla.clear ();
2073 ]m4_ifdef([b4_initial_action], [
2074 b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl
2075 b4_user_initial_action
2076 b4_dollar_popdef])[]dnl
2078 switch (YYSETJMP (this->yyexception_buffer))
2080 case 0: break;
2081 case 1: goto yyabortlab;
2082 case 2: goto yyexhaustedlab;
2083 default: goto yybuglab;
2085 this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2086 yyposn = 0;
2088 while (true)
2090 /* For efficiency, we have two loops, the first of which is
2091 specialized to deterministic operation (single stack, no
2092 potential ambiguity). */
2093 /* Standard mode */
2094 while (true)
2096 const state_num yystate = this->firstTopState()->yylrState;
2097 YYCDEBUG << "Entering state " << yystate << '\n';
2098 if (yystate == YYFINAL)
2099 goto yyacceptlab;
2100 if (yy_is_defaulted_state (yystate))
2102 const rule_num yyrule = yy_default_action (yystate);
2103 if (yyrule == 0)
2104 {]b4_locations_if([[
2105 this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[
2106 this->yyreportSyntaxError ();
2107 goto yyuser_error;
2109 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule, true));
2111 else
2113 yyget_token ();
2114 const short* yyconflicts;
2115 const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
2116 if (*yyconflicts != 0)
2117 break;
2118 if (yy_is_shift_action (yyaction))
2120 YY_SYMBOL_PRINT ("Shifting", this->yyla.kind (), this->yyla.value, this->yyla.location);
2121 yyposn += 1;
2122 // FIXME: we should move yylval.
2123 this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2124 yyla.clear ();
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->yyla.location;]])[
2131 /* Don't issue an error message again for exceptions
2132 thrown from the scanner. */
2133 if (this->yyla.kind () != ]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->yyla.empty ());
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->yyla.location])[));
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->yyla.location, ])[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->yyla.location;]])[
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, yyla is emptied
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->yyla.kind ();
2187 this->yyla.kind_ = ]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 = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
2194 /* Note that yyconflicts were handled by yyprocessOneStack. */
2195 YYCDEBUG << "On stack " << yys.get() << ", ";
2196 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yyla.value, this->yyla.location);
2197 this->yyglrShift (yys, yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2198 YYCDEBUG << "Stack " << yys.get() << " now in state "
2199 << this->topState(yys)->yylrState << '\n';
2201 ]b4_variant_if([[
2202 // FIXME: User destructors.
2203 // Value type destructor.
2204 ]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[
2206 if (this->yystateStack.yytops.size () == 1)
2208 YYCHK1 (this->yyresolveStack ());
2209 YYCDEBUG << "Returning to deterministic operation.\n";
2210 this->yystateStack.yycompressStack ();
2211 break;
2214 continue;
2215 yyuser_error:
2216 this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla.location])[);
2217 yyposn = this->firstTopState()->yyposn;
2220 yyacceptlab:
2221 yyresult = 0;
2222 goto yyreturn;
2224 yybuglab:
2225 YYASSERT (false);
2226 goto yyabortlab;
2228 yyabortlab:
2229 yyresult = 1;
2230 goto yyreturn;
2232 yyexhaustedlab:
2233 yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("memory exhausted"));
2234 yyresult = 2;
2235 goto yyreturn;
2237 yyreturn:
2238 return yyresult;
2240 #undef YYCHK1
2242 void yyreserveGlrStack ()
2244 if (!yystateStack.yyexpandGLRStackIfNeeded ())
2245 yyMemoryExhausted ();
2248 _Noreturn void
2249 yyMemoryExhausted ()
2251 YYLONGJMP (yyexception_buffer, 2);
2254 _Noreturn void
2255 yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg)
2257 if (yymsg != YY_NULLPTR)
2258 yyparser.error (]b4_locations_if([*yylocp, ])[yymsg);
2259 YYLONGJMP (yyexception_buffer, 1);
2262 /* GLRStates */
2265 /** Add a new semantic action that will execute the action for rule
2266 * YYRULE on the semantic values in YYRHS to the list of
2267 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2268 * stack #YYK of *this. */
2269 void
2270 yyaddDeferredAction (state_set_index yyk, glr_state* yystate,
2271 glr_state* yyrhs, rule_num yyrule)
2273 semantic_option& yynewOption =
2274 yystateStack.yynewSemanticOption(semantic_option(yyrule, ]b4_symbol(empty, kind)[));
2275 yynewOption.setState(yyrhs);
2276 yynewOption.setNext(yystate->firstVal());
2277 if (yystateStack.yytops.lookaheadNeeds(yyk))
2279 yynewOption.yytoken = this->yyla.kind ();]b4_variant_if([[
2280 ]b4_symbol_variant([this->yyla.kind ()],
2281 [yynewOption.yyval], [copy], [this->yyla.value])], [[
2282 yynewOption.yyval = this->yyla.value;]])[]b4_locations_if([
2283 yynewOption.yyloc = this->yyla.location;])[
2285 yystate->setFirstVal (&yynewOption);
2287 yyreserveGlrStack ();
2290 #if ]b4_api_PREFIX[DEBUG
2291 void yypdumpstack () const
2293 yystateStack.dumpStack();
2295 #endif
2296 void
2297 yyreportSyntaxError ()
2299 if (yyerrState != 0)
2300 return;
2301 ]b4_parse_error_bmatch(
2302 [simple],
2303 [[ yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("syntax error"));]],
2304 [[ {
2305 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
2306 /* Arguments of yyformat. */
2307 yysymbol_kind_t yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]
2308 = { ]b4_symbol(empty, kind)[ };
2309 /* Number of reported tokens (one for the "unexpected", one per
2310 "expected"). */
2311 int yycount = 0;
2313 /* There are many possibilities here to consider:
2314 - If this state is a consistent state with a default action, then
2315 the only way this function was invoked is if the default action
2316 is an error action. In that case, don't check for expected
2317 tokens because there are none.
2318 - The only way there can be no lookahead present (in yytoken) is if
2319 this state is a consistent state with a default action. Thus,
2320 detecting the absence of a lookahead is sufficient to determine
2321 that there is no unexpected or expected token to report. In that
2322 case, just report a simple "syntax error".
2323 - Don't assume there isn't a lookahead just because this state is a
2324 consistent state with a default action. There might have been a
2325 previous inconsistent state, consistent state with a non-default
2326 action, or user semantic action that manipulated yytoken.
2327 - Of course, the expected token list depends on states to have
2328 correct lookahead information, and it depends on the parser not
2329 to perform extra reductions after fetching a lookahead from the
2330 scanner and before detecting a syntax error. Thus, state merging
2331 (from LALR or IELR) and default reductions corrupt the expected
2332 token list. However, the list is correct for canonical LR with
2333 one exception: it will still contain any token that will not be
2334 accepted due to an error action in a later state.
2336 if (!yyla.empty ())
2338 const int yyn = yypact[firstTopState()->yylrState];
2339 yyarg[yycount++] = yyla.kind ();
2340 if (!yypact_value_is_default (yyn))
2342 /* Start YYX at -YYN if negative to avoid negative indexes in
2343 YYCHECK. In other words, skip the first -YYN actions for this
2344 state because they are default actions. */
2345 const int yyxbegin = yyn < 0 ? -yyn : 0;
2346 /* Stay within bounds of both yycheck and yytname. */
2347 const int yychecklim = YYLAST - yyn + 1;
2348 const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2349 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
2350 if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
2351 && !yytable_value_is_error (yytable[yyx + yyn]))
2353 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
2355 yycount = 1;
2356 break;
2358 yyarg[yycount++] = static_cast<yysymbol_kind_t>(yyx);
2363 /* Internationalized format string. */
2364 const char *yyformat = YY_NULLPTR;
2365 switch (yycount)
2367 #define YYCASE_(N, S) \
2368 case N: \
2369 yyformat = S; \
2370 break
2371 default: /* Avoid compiler warnings. */
2372 YYCASE_(0, YY_("syntax error"));
2373 YYCASE_(1, YY_("syntax error, unexpected %s"));
2374 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2375 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2376 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2377 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2378 #undef YYCASE_
2381 std::string yymsg;
2382 // Argument number.
2383 std::ptrdiff_t yyi = 0;
2384 for (char const* yyp = yyformat; *yyp; ++yyp)
2385 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
2387 yymsg += ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yyarg[yyi++]);
2388 ++yyp;
2390 else
2391 yymsg += *yyp;
2392 yyparser.error (]b4_locations_if([[yyla.location, ]])[yymsg);
2394 ]])[
2395 yyerrcnt += 1;
2399 /* Recover from a syntax error on this, assuming that yytoken,
2400 yylval, and yylloc are the syntactic category, semantic value, and location
2401 of the lookahead. */
2402 void
2403 yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[)
2405 if (yyerrState == 3)
2406 /* We just shifted the error token and (perhaps) took some
2407 reductions. Skip tokens until we can proceed. */
2408 while (true)
2410 if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
2411 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2412 if (this->yyla.kind () != ]b4_symbol(empty, kind)[)
2413 {]b4_locations_if([[
2414 /* We throw away the lookahead, but the error range
2415 of the shifted error token must take it into account. */
2416 glr_state *yys = firstTopState();
2417 yyerror_range[1].getState().yyloc = yys->yyloc;
2418 yyerror_range[2].getState().yyloc = this->yyla.location;
2419 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2420 yyparser.yy_destroy_ ("Error: discarding",
2421 this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);]b4_variant_if([[
2422 // Value type destructor.
2423 ]b4_symbol_variant([[this->yyla.kind ()]], [[this->yyla.value]], [[template destroy]])])[
2424 this->yyla.kind_ = ]b4_symbol(empty, kind)[;
2426 yyget_token ();
2427 int yyj = yypact[firstTopState()->yylrState];
2428 if (yypact_value_is_default (yyj))
2429 return;
2430 yyj += this->yyla.kind ();
2431 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yyla.kind ())
2433 if (yydefact[firstTopState()->yylrState] != 0)
2434 return;
2436 else if (! yytable_value_is_error (yytable[yyj]))
2437 return;
2440 if (!yystateStack.reduceToOneStack())
2441 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2443 /* Now pop stack until we find a state that shifts the error token. */
2444 yyerrState = 3;
2445 while (firstTopState () != YY_NULLPTR)
2447 glr_state *yys = firstTopState ();
2448 int yyj = yypact[yys->yylrState];
2449 if (! yypact_value_is_default (yyj))
2451 yyj += YYTERROR;
2452 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2453 && yy_is_shift_action (yytable[yyj]))
2455 /* Shift the error token. */]b4_locations_if([[
2456 /* First adjust its location.*/
2457 location_type yyerrloc;
2458 yyerror_range[2].getState().yyloc = this->yyla.location;
2459 YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
2460 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
2461 this->yyla.value, yyerrloc);
2462 yyglrShift (create_state_set_index(0), yytable[yyj],
2463 yys->yyposn, yyla.value]b4_locations_if([, yyerrloc])[);
2464 yys = firstTopState();
2465 break;
2467 }]b4_locations_if([[
2468 yyerror_range[1].getState().yyloc = yys->yyloc;]])[
2469 if (yys->pred() != YY_NULLPTR)
2470 yys->destroy ("Error: popping", yyparser]b4_user_args[);
2471 yystateStack.setFirstTop(yys->pred());
2472 yystateStack.pop_back();
2474 if (firstTopState() == YY_NULLPTR)
2475 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2478 YYRESULTTAG
2479 yyprocessOneStack (state_set_index yyk,
2480 size_t yyposn]b4_locations_if([, location_type* yylocp])[)
2482 while (yystateStack.topAt(yyk) != YY_NULLPTR)
2484 const state_num yystate = topState(yyk)->yylrState;
2485 YYCDEBUG << "Stack " << yyk.get()
2486 << " Entering state " << yystate << '\n';
2488 YYASSERT (yystate != YYFINAL);
2490 if (yy_is_defaulted_state (yystate))
2492 const rule_num yyrule = yy_default_action (yystate);
2493 if (yyrule == 0)
2495 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2496 yystateStack.yytops.yymarkStackDeleted (yyk);
2497 return yyok;
2499 const YYRESULTTAG yyflag
2500 = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]);
2501 if (yyflag == yyerr)
2503 YYCDEBUG << "Stack " << yyk.get() << " dies"
2504 " (predicate failure or explicit user error).\n";
2505 yystateStack.yytops.yymarkStackDeleted (yyk);
2506 return yyok;
2508 if (yyflag != yyok)
2509 return yyflag;
2511 else
2513 yystateStack.yytops.setLookaheadNeeds(yyk, true);
2514 yyget_token ();
2515 const short* yyconflicts;
2516 const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
2518 for (; *yyconflicts != 0; ++yyconflicts)
2520 state_set_index yynewStack = yystateStack.yysplitStack (yyk);
2521 YYCDEBUG << "Splitting off stack " << yynewStack.get()
2522 << " from " << yyk.get() << ".\n";
2523 YYRESULTTAG yyflag =
2524 yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]);
2525 if (yyflag == yyok)
2526 YYCHK (yyprocessOneStack (yynewStack,
2527 yyposn]b4_locations_if([, yylocp])[));
2528 else if (yyflag == yyerr)
2530 YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n";
2531 yystateStack.yytops.yymarkStackDeleted (yynewStack);
2533 else
2534 return yyflag;
2537 if (yy_is_shift_action (yyaction))
2538 break;
2539 else if (yy_is_error_action (yyaction))
2541 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2542 yystateStack.yytops.yymarkStackDeleted (yyk);
2543 break;
2545 else
2547 YYRESULTTAG yyflag
2548 = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]);
2549 if (yyflag == yyerr)
2551 YYCDEBUG << "Stack " << yyk.get() << " dies"
2552 " (predicate failure or explicit user error).\n";
2553 yystateStack.yytops.yymarkStackDeleted (yyk);
2554 break;
2556 else if (yyflag != yyok)
2557 return yyflag;
2561 return yyok;
2564 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2565 * and top stack item YYVSP. YYVALP points to place to put semantic
2566 * value ($$), and yylocp points to place for location information
2567 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2568 * yyerr for YYERROR, yyabort for YYABORT. */
2569 YYRESULTTAG
2570 yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk,
2571 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2573 bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit();
2574 int yylow = 1;
2575 ]b4_parse_param_use([yyvalp], [yylocp])dnl
2576 [ YY_USE (yyk);
2577 YY_USE (yyrhslen);
2578 # undef yyerrok
2579 # define yyerrok (yyerrState = 0)
2580 # undef YYACCEPT
2581 # define YYACCEPT return yyaccept
2582 # undef YYABORT
2583 # define YYABORT return yyabort
2584 # undef YYERROR
2585 # define YYERROR return yyerrok, yyerr
2586 # undef YYRECOVERING
2587 # define YYRECOVERING() (yyerrState != 0)
2588 # undef yytoken
2589 # define yytoken this->yyla.kind_
2590 # undef yyclearin
2591 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2592 # undef YYBACKUP
2593 # define YYBACKUP(Token, Value) \
2594 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2595 yyerrok, yyerr
2597 ]b4_variant_if([[
2598 /* Variants are always initialized to an empty instance of the
2599 correct type. The default '$$ = $1' action is NOT applied
2600 when using variants. */
2601 // However we really need to prepare yyvsp now if we want to get
2602 // correct locations, so invoke YYFILL for $1 anyway.
2603 (void) YYFILL (1-yyrhslen);
2604 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[
2605 if (yyrhslen == 0)
2606 *yyvalp = yyval_default;
2607 else
2608 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[
2609 /* Default location. */
2610 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
2611 yyerror_range[1].getState().yyloc = *yylocp;
2612 ]])[
2613 /* If yyk == -1, we are running a deferred action on a temporary
2614 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2615 so pretend the stack is "normal". */
2616 YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser));
2617 #if YY_EXCEPTIONS
2618 typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error;
2621 #endif // YY_EXCEPTIONS
2622 switch (yyrule)
2624 ]b4_user_actions[
2625 default: break;
2627 #if YY_EXCEPTIONS
2629 catch (const syntax_error& yyexc)
2631 YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([
2632 *yylocp = yyexc.location;])[
2633 yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ());
2634 YYERROR;
2636 #endif // YY_EXCEPTIONS
2637 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp);
2639 return yyok;
2640 # undef yyerrok
2641 # undef YYABORT
2642 # undef YYACCEPT
2643 # undef YYERROR
2644 # undef YYBACKUP
2645 # undef yytoken
2646 # undef yyclearin
2647 # undef YYRECOVERING
2650 YYRESULTTAG
2651 yyresolveStack ()
2653 if (yystateStack.isSplit ())
2655 int yyn = 0;
2656 for (glr_state* yys = firstTopState ();
2657 yys != yystateStack.yysplitPoint;
2658 yys = yys->pred ())
2659 yyn += 1;
2660 YYCHK (yyresolveStates (*firstTopState (), yyn));
2662 return yyok;
2665 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2666 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2667 * semantic values. Assumes that all ambiguities in semantic values
2668 * have been previously resolved. Set *YYVALP to the resulting value,
2669 * and *YYLOCP to the computed location (if any). Return value is as
2670 * for userAction. */
2671 YYRESULTTAG
2672 yydoAction (state_set_index yyk, rule_num yyrule,
2673 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2675 const int yynrhs = yyrhsLength (yyrule);
2677 if (!yystateStack.isSplit())
2679 /* Standard special case: single stack. */
2680 YYASSERT (yyk.get() == 0);
2681 glr_stack_item* yyrhs = yystateStack.firstTop()->asItem();
2682 const YYRESULTTAG res
2683 = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[);
2684 yystateStack.pop_back(static_cast<size_t>(yynrhs));
2685 yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState());
2686 return res;
2688 else
2690 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
2691 glr_state* yys = yystateStack.topAt(yyk);
2692 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[
2693 if (yynrhs == 0)
2694 /* Set default location. */
2695 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[
2696 for (int yyi = 0; yyi < yynrhs; yyi += 1)
2698 yys = yys->pred();
2699 YYASSERT (yys != YY_NULLPTR);
2701 yystateStack.yyupdateSplit (*yys);
2702 yystateStack.setTopAt(yyk, yys);
2703 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
2704 yyk,
2705 yyvalp]b4_locations_if([, yylocp])[);
2709 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2710 * and push back on the resulting nonterminal symbol. Perform the
2711 * semantic action associated with YYRULE and store its value with the
2712 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2713 * unambiguous. Otherwise, store the deferred semantic action with
2714 * the new state. If the new state would have an identical input
2715 * position, LR state, and predecessor to an existing state on the stack,
2716 * it is identified with that existing state, eliminating stack #YYK from
2717 * *YYSTACKP. In this case, the semantic value is
2718 * added to the options for the existing state's semantic value.
2720 YYRESULTTAG
2721 yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval)
2723 size_t yyposn = topState(yyk)->yyposn;
2725 if (yyforceEval || !yystateStack.isSplit())
2727 value_type val;]b4_locations_if([[
2728 location_type loc;]])[
2730 YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[);
2731 if (yyflag == yyerr && yystateStack.isSplit())
2732 {]b4_parse_trace_if([[
2733 YYCDEBUG << "Parse on stack " << yyk.get ()
2734 << " rejected by rule " << yyrule - 1
2735 << " (line " << int (yyrline[yyrule]) << ").\n";
2736 ]])[}
2737 if (yyflag != yyok)
2738 return yyflag;
2739 yyglrShift (yyk,
2740 yyLRgotoState (topState(yyk)->yylrState,
2741 yylhsNonterm (yyrule)),
2742 yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[
2743 // FIXME: User destructors.
2744 // Value type destructor.
2745 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[
2747 else
2749 glr_state *yys = yystateStack.topAt(yyk);
2750 glr_state *yys0 = yys;
2751 for (int yyn = yyrhsLength (yyrule); 0 < yyn; yyn -= 1)
2753 yys = yys->pred();
2754 YYASSERT (yys != YY_NULLPTR);
2756 yystateStack.yyupdateSplit (*yys);
2757 state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[
2758 YYCDEBUG << "Reduced stack " << yyk.get ()
2759 << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule])
2760 << "); action deferred. Now in state " << yynewLRState
2761 << ".\n";]])[
2762 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi)
2763 if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR)
2765 const glr_state* yysplit = yystateStack.yysplitPoint;
2766 glr_state* yyp = yystateStack.topAt(yyi);
2767 while (yyp != yys && yyp != yysplit
2768 && yyp->yyposn >= yyposn)
2770 if (yyp->yylrState == yynewLRState
2771 && yyp->pred() == yys)
2773 yyaddDeferredAction (yyk, yyp, yys0, yyrule);
2774 yystateStack.yytops.yymarkStackDeleted (yyk);
2775 YYCDEBUG << "Merging stack " << yyk.get ()
2776 << " into stack " << yyi.get () << ".\n";
2777 return yyok;
2779 yyp = yyp->pred();
2782 yystateStack.setTopAt(yyk, yys);
2783 yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule);
2785 return yyok;
2788 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2789 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2790 * semantic value of YYRHS under the action for YYRULE. */
2791 void
2792 yyglrShiftDefer (state_set_index yyk, state_num yylrState,
2793 size_t yyposn, glr_state* yyrhs, rule_num yyrule)
2795 glr_state& yynewState = yystateStack.yynewGLRState (
2796 glr_state (yylrState, yyposn));
2797 yynewState.setPred (yystateStack.topAt (yyk));
2798 yystateStack.setTopAt (yyk, &yynewState);
2800 /* Invokes yyreserveStack. */
2801 yyaddDeferredAction (yyk, &yynewState, yyrhs, yyrule);
2804 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2805 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2806 * value YYVAL_ARG and source location YYLOC_ARG. */
2807 void
2808 yyglrShift (state_set_index yyk, state_num yylrState,
2809 size_t yyposn,
2810 const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[)
2812 glr_state& yynewState = yystateStack.yynewGLRState (
2813 glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[));
2814 yynewState.setPred (yystateStack.topAt(yyk));
2815 yystateStack.setTopAt (yyk, &yynewState);
2816 yyreserveGlrStack ();
2819 #if ]b4_api_PREFIX[DEBUG
2820 void
2821 yypstack (state_set_index yyk) const
2823 yystateStack.yypstates (yystateStack.topAt (yyk));
2825 #endif
2827 glr_state* topState(state_set_index i) {
2828 return yystateStack.topAt(i);
2831 glr_state* firstTopState() {
2832 return yystateStack.firstTop();
2835 private:
2837 void popall_ ()
2839 /* If the stack is well-formed, pop the stack until it is empty,
2840 destroying its entries as we go. But free the stack regardless
2841 of whether it is well-formed. */
2842 for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); k += 1)
2843 if (yystateStack.topAt(k) != YY_NULLPTR)
2845 while (yystateStack.topAt(k) != YY_NULLPTR)
2847 glr_state* state = topState(k);]b4_locations_if([[
2848 yyerror_range[1].getState().yyloc = state->yyloc;]])[
2849 if (state->pred() != YY_NULLPTR)
2850 state->destroy ("Cleanup: popping", yyparser]b4_user_args[);
2851 yystateStack.setTopAt(k, state->pred());
2852 yystateStack.pop_back();
2854 break;
2858 /** Resolve the previous YYN states starting at and including state YYS
2859 * on *YYSTACKP. If result != yyok, some states may have been left
2860 * unresolved possibly with empty semantic option chains. Regardless
2861 * of whether result = yyok, each state has been left with consistent
2862 * data so that destroy can be invoked if necessary. */
2863 YYRESULTTAG
2864 yyresolveStates (glr_state& yys, int yyn)
2866 if (0 < yyn)
2868 YYASSERT (yys.pred() != YY_NULLPTR);
2869 YYCHK (yyresolveStates (*yys.pred(), yyn-1));
2870 if (! yys.yyresolved)
2871 YYCHK (yyresolveValue (yys));
2873 return yyok;
2876 static void
2877 yyuserMerge (int yyn, value_type& yy0, value_type& yy1)
2879 YY_USE (yy0);
2880 YY_USE (yy1);
2882 switch (yyn)
2884 ]b4_mergers[
2885 default: break;
2889 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2890 * perform the indicated actions, and set the semantic value of YYS.
2891 * If result != yyok, the chain of semantic options in YYS has been
2892 * cleared instead or it has been left unmodified except that
2893 * redundant options may have been removed. Regardless of whether
2894 * result = yyok, YYS has been left with consistent data so that
2895 * destroy can be invoked if necessary. */
2896 YYRESULTTAG
2897 yyresolveValue (glr_state& yys)
2899 semantic_option* yybest = yys.firstVal();
2900 YYASSERT(yybest != YY_NULLPTR);
2901 bool yymerge = false;
2902 YYRESULTTAG yyflag;]b4_locations_if([
2903 location_type *yylocp = &yys.yyloc;])[
2905 semantic_option* yypPrev = yybest;
2906 for (semantic_option* yyp = yybest->next();
2907 yyp != YY_NULLPTR; )
2909 if (yybest->isIdenticalTo (*yyp))
2911 yybest->mergeWith (*yyp);
2912 yypPrev->setNext(yyp->next());
2913 yyp = yypPrev->next();
2915 else
2917 switch (yypreference (*yybest, *yyp))
2919 case 0:]b4_locations_if([[
2920 yyresolveLocations (yys, 1);]])[
2921 return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[);
2922 break;
2923 case 1:
2924 yymerge = true;
2925 break;
2926 case 2:
2927 break;
2928 case 3:
2929 yybest = yyp;
2930 yymerge = false;
2931 break;
2932 default:
2933 /* This cannot happen so it is not worth a YYASSERT (false),
2934 but some compilers complain if the default case is
2935 omitted. */
2936 break;
2938 yypPrev = yyp;
2939 yyp = yyp->next();
2943 value_type val;
2944 if (yymerge)
2946 int yyprec = yydprec[yybest->yyrule];
2947 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2948 if (yyflag == yyok)
2949 for (semantic_option* yyp = yybest->next();
2950 yyp != YY_NULLPTR;
2951 yyp = yyp->next())
2953 if (yyprec == yydprec[yyp->yyrule])
2955 value_type yyval_other;]b4_locations_if([
2956 location_type yydummy;])[
2957 yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[);
2958 if (yyflag != yyok)
2960 yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2961 yy_accessing_symbol (yys.yylrState),
2962 this->yyla.value]b4_locations_if([, *yylocp])[);
2963 break;
2965 yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
2966 // FIXME: User destructors.
2967 // Value type destructor.
2968 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[
2972 else
2973 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2975 if (yyflag == yyok)
2977 yys.yyresolved = true;
2978 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[
2979 new (&yys.value ()) value_type ();
2980 ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)],
2981 [yys.value ()], [copy], [val])], [[
2982 new (&yys.value ()) value_type (val);]])[
2984 YY_IGNORE_MAYBE_UNINITIALIZED_END
2986 else
2987 yys.setFirstVal(YY_NULLPTR);
2988 ]b4_variant_if([[
2989 // FIXME: User destructors.
2990 // Value type destructor.
2991 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[
2992 return yyflag;
2995 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2996 * user action, and return the semantic value and location in *YYVALP
2997 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2998 * have been destroyed (assuming the user action destroys all RHS
2999 * semantic values if invoked). */
3000 YYRESULTTAG
3001 yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
3003 glr_state* yyoptState = yyopt.state();
3004 YYASSERT(yyoptState != YY_NULLPTR);
3005 int yynrhs = yyrhsLength (yyopt.yyrule);
3006 YYRESULTTAG yyflag = yyresolveStates (*yyoptState, yynrhs);
3007 if (yyflag != yyok)
3009 for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1)
3010 yys->destroy ("Cleanup: popping", yyparser]b4_user_args[);
3011 return yyflag;
3014 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
3015 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[
3016 if (yynrhs == 0)
3017 /* Set default location. */
3018 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
3020 symbol_type yyla_current = std::move (this->yyla);
3021 this->yyla.kind_ = yyopt.yytoken;]b4_variant_if([[
3022 ]b4_symbol_variant([this->yyla.kind ()],
3023 [this->yyla.value], [move], [yyopt.yyval])], [[
3024 this->yyla.value = yyopt.yyval;]])[]b4_locations_if([
3025 this->yyla.location = yyopt.yyloc;])[
3026 yyflag = yyuserAction (yyopt.yyrule, yynrhs,
3027 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
3028 create_state_set_index (-1),
3029 yyvalp]b4_locations_if([, yylocp])[);
3031 this->yyla = std::move (yyla_current);
3033 return yyflag;
3034 }]b4_locations_if([[
3036 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
3037 * ending at YYS1. Has no effect on previously resolved states.
3038 * The first semantic option of a state is always chosen. */
3039 void
3040 yyresolveLocations (glr_state &yys1, int yyn1)
3042 if (0 < yyn1)
3044 yyresolveLocations (*yys1.pred(), yyn1 - 1);
3045 if (!yys1.yyresolved)
3047 glr_stack_item yyrhsloc[1 + YYMAXRHS];
3048 YYASSERT (yys1.firstVal() != YY_NULLPTR);
3049 semantic_option& yyoption = *yys1.firstVal();
3050 const int yynrhs = yyrhsLength (yyoption.yyrule);
3051 if (0 < yynrhs)
3053 yyresolveLocations (*yyoption.state(), yynrhs);
3054 const glr_state *yys = yyoption.state();
3055 for (int yyn = yynrhs; yyn > 0; yyn -= 1)
3057 yyrhsloc[yyn].getState().yyloc = yys->yyloc;
3058 yys = yys->pred();
3061 else
3063 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3064 in reverse rightmost order. It is only necessary to invoke
3065 yyresolveLocations on a subforest for which yyresolveAction
3066 would have been invoked next had an ambiguity not been
3067 detected. Thus the location of the previous state (but not
3068 necessarily the previous state itself) is guaranteed to be
3069 resolved already. */
3070 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3071 yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc;
3072 YY_IGNORE_NULL_DEREFERENCE_END
3074 YYLLOC_DEFAULT ((yys1.yyloc), yyrhsloc, yynrhs);
3077 }]])[
3079 /** If yytoken is empty, fetch the next token. */
3080 void
3081 yyget_token ()
3083 ]b4_parse_param_use()dnl
3084 [ if (this->yyla.empty ())
3086 YYCDEBUG << "Reading a token\n";
3087 #if YY_EXCEPTIONS
3089 #endif // YY_EXCEPTIONS
3090 {]b4_token_ctor_if([[
3091 symbol_type yylookahead (]b4_yylex[);
3092 yyla.move (yylookahead);]], [[
3093 yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[
3095 #if YY_EXCEPTIONS
3096 catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
3098 YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
3099 this->yyla.location = yyexc.location;])[
3100 yyparser.error (]b4_locations_if([this->yyla.location, ])[yyexc.what ());
3101 // Map errors caught in the scanner to the error token, so that error
3102 // handling is started.
3103 this->yyla.kind_ = ]b4_symbol(error, kind)[;
3106 #endif // YY_EXCEPTIONS
3107 if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
3108 YYCDEBUG << "Now at end of input.\n";
3109 else
3110 YY_SYMBOL_PRINT ("Next token is", this->yyla.kind (), this->yyla.value, this->yyla.location);
3114 /* Bison grammar-table manipulation. */
3116 /** The action to take in YYSTATE on seeing YYTOKEN.
3117 * Result R means
3118 * R < 0: Reduce on rule -R.
3119 * R = 0: Error.
3120 * R > 0: Shift to state R.
3121 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3122 * of conflicting reductions.
3124 static int
3125 yygetLRActions (state_num yystate, yysymbol_kind_t yytoken, const short*& yyconflicts)
3127 int yyindex = yypact[yystate] + yytoken;
3128 if (yytoken == ]b4_symbol(error, kind)[)
3130 // This is the error token.
3131 yyconflicts = yyconfl;
3132 return 0;
3134 else if (yy_is_defaulted_state (yystate)
3135 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
3137 yyconflicts = yyconfl;
3138 return -yydefact[yystate];
3140 else if (! yytable_value_is_error (yytable[yyindex]))
3142 yyconflicts = yyconfl + yyconflp[yyindex];
3143 return yytable[yyindex];
3145 else
3147 yyconflicts = yyconfl + yyconflp[yyindex];
3148 return 0;
3152 /** Compute post-reduction state.
3153 * \param yystate the current state
3154 * \param yysym the nonterminal to push on the stack
3156 static state_num
3157 yyLRgotoState (state_num yystate, yysymbol_kind_t yysym)
3159 const int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
3160 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
3161 return yytable[yyr];
3162 else
3163 return yydefgoto[yysym - YYNTOKENS];
3166 static bool
3167 yypact_value_is_default (state_num yystate)
3169 return ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf], [YYPACT_NINF])[;
3172 static bool
3173 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED)
3175 return ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[;
3178 static bool
3179 yy_is_shift_action (int yyaction)
3181 return 0 < yyaction;
3184 static bool
3185 yy_is_error_action (int yyaction)
3187 return yyaction == 0;
3190 /** Whether LR state YYSTATE has only a default reduction
3191 * (regardless of token). */
3192 static bool
3193 yy_is_defaulted_state (state_num yystate)
3195 return yypact_value_is_default (yypact[yystate]);
3198 /** The default reduction for YYSTATE, assuming it has one. */
3199 static rule_num
3200 yy_default_action (state_num yystate)
3202 return yydefact[yystate];
3205 /* GLRStacks */
3207 /** Y0 and Y1 represent two possible actions to take in a given
3208 * parsing state; return 0 if no combination is possible,
3209 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3210 static int
3211 yypreference (const semantic_option& y0, const semantic_option& y1)
3213 rule_num r0 = y0.yyrule, r1 = y1.yyrule;
3214 int p0 = yydprec[r0], p1 = yydprec[r1];
3216 if (p0 == p1)
3218 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
3219 return 0;
3220 else
3221 return 1;
3223 if (p0 == 0 || p1 == 0)
3224 return 0;
3225 if (p0 < p1)
3226 return 3;
3227 if (p1 < p0)
3228 return 2;
3229 return 0;
3232 ]b4_parse_param_vars[
3237 /* DEBUGGING ONLY */
3238 #if ]b4_api_PREFIX[DEBUG
3239 static void
3240 yypstack (const glr_stack& yystack, size_t yyk)
3242 yystack.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk)));
3244 static void yypdumpstack (const glr_stack& yystack)
3246 yystack.yypdumpstack ();
3249 #endif
3251 ]b4_namespace_open[
3252 /// Build a parser object.
3253 ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
3254 :])[
3255 #if ]b4_api_PREFIX[DEBUG
3256 ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
3257 #endif]b4_parse_param_cons[
3260 ]b4_parser_class::~b4_parser_class[ ()
3263 ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3267 ]b4_parser_class[::operator() ()
3269 return parse ();
3273 ]b4_parser_class[::parse ()
3275 glr_stack yystack(YYINITDEPTH, *this]b4_user_args[);
3276 return yystack.parse ();
3279 ]b4_parse_error_bmatch([custom\|detailed],
3280 [[ const char *
3281 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3283 static const char *const yy_sname[] =
3285 ]b4_symbol_names[
3286 };]b4_has_translations_if([[
3287 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3288 internationalizable. */
3289 static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
3291 ]b4_translatable[
3293 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
3294 ? _(yy_sname[yysymbol])
3295 : yy_sname[yysymbol]);]], [[
3296 return yy_sname[yysymbol];]])[
3299 [simple],
3300 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3301 const char *
3302 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3304 return yytname_[yysymbol];
3306 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3308 [verbose],
3309 [[ /* Return YYSTR after stripping away unnecessary quotes and
3310 backslashes, so that it's suitable for yyerror. The heuristic is
3311 that double-quoting is unnecessary unless the string contains an
3312 apostrophe, a comma, or backslash (other than backslash-backslash).
3313 YYSTR is taken from yytname. */
3314 std::string
3315 ]b4_parser_class[::yytnamerr_ (const char *yystr)
3317 if (*yystr == '"')
3319 std::string yyr;
3320 char const *yyp = yystr;
3322 for (;;)
3323 switch (*++yyp)
3325 case '\'':
3326 case ',':
3327 goto do_not_strip_quotes;
3329 case '\\':
3330 if (*++yyp != '\\')
3331 goto do_not_strip_quotes;
3332 else
3333 goto append;
3335 append:
3336 default:
3337 yyr += *yyp;
3338 break;
3340 case '"':
3341 return yyr;
3343 do_not_strip_quotes: ;
3346 return yystr;
3349 std::string
3350 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3352 return yytnamerr_ (yytname_[yysymbol]);
3354 ]])[
3356 ]b4_parse_error_bmatch([simple\|verbose],
3357 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3358 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3359 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3360 const char*
3361 const ]b4_parser_class[::yytname_[] =
3363 ]b4_tname[
3365 #endif
3366 ]])[
3368 void
3369 ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
3370 value_type& yyval]b4_locations_if([[,
3371 location_type& yyloc]])[)
3373 YY_USE (yyval);]b4_locations_if([[
3374 YY_USE (yyloc);]])[
3375 if (!yymsg)
3376 yymsg = "Deleting";
3377 ]b4_parser_class[& yyparser = *this;
3378 YY_USE (yyparser);
3379 YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc);
3381 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3382 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3383 [b4_symbol_actions([destructor])],
3384 [m4_popdef([b4_symbol_action])])[
3385 YY_IGNORE_MAYBE_UNINITIALIZED_END
3388 #if ]b4_api_PREFIX[DEBUG
3389 /*--------------------.
3390 | Print this symbol. |
3391 `--------------------*/
3393 void
3394 ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
3395 const value_type& yyval]b4_locations_if([[,
3396 const location_type& yyloc]])[) const
3397 {]b4_locations_if([[
3398 YY_USE (yyloc);]])[
3399 YY_USE (yyval);
3400 std::ostream& yyo = debug_stream ();
3401 YY_USE (yyo);
3402 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3403 [b4_symbol_actions([printer])],
3404 [m4_popdef([b4_symbol_action])])[
3407 void
3408 ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
3409 const value_type& yyval]b4_locations_if([[,
3410 const location_type& yyloc]])[) const
3412 *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
3413 << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
3414 << yyloc << ": "]])[;
3415 yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[);
3416 *yycdebug_ << ')';
3419 std::ostream&
3420 ]b4_parser_class[::debug_stream () const
3422 return *yycdebug_;
3425 void
3426 ]b4_parser_class[::set_debug_stream (std::ostream& o)
3428 yycdebug_ = &o;
3432 ]b4_parser_class[::debug_level_type
3433 ]b4_parser_class[::debug_level () const
3435 return yydebug;
3438 void
3439 ]b4_parser_class[::set_debug_level (debug_level_type l)
3441 // Actually, it is yydebug which is really used.
3442 yydebug = l;
3444 #endif // ]b4_api_PREFIX[DEBUG
3446 ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[
3448 ]b4_token_ctor_if([], [[
3449 /*---------.
3450 | symbol. |
3451 `---------*/
3452 ]b4_public_types_define([cc])])[
3453 ]b4_namespace_close[]dnl
3454 b4_epilogue[]dnl
3455 b4_output_end