glr2.cc: simplify semantic_option
[bison.git] / data / skeletons / glr2.cc
blobbce8db9f8f42eb3064926e45884be3c22c28b4fc
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))
46 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
47 # -------------------------------------------------------------
48 # Define "yy<TABLE-NAME>" whose contents is CONTENT. Does not use "static",
49 # should be in unnamed namespace.
50 m4_define([b4_integral_parser_table_define],
51 [m4_ifvaln([$3], [ b4_comment([$3])])dnl
52 const b4_int_type_for([$2]) yy$1[[]] =
55 };dnl
59 ## ---------------- ##
60 ## Default values. ##
61 ## ---------------- ##
63 # Stack parameters.
64 m4_define_default([b4_stack_depth_max], [10000])
65 m4_define_default([b4_stack_depth_init], [200])
69 ## ------------ ##
70 ## Interfaces. ##
71 ## ------------ ##
73 # b4_user_formals
74 # ---------------
75 # The possible parse-params formal arguments preceded by a comma.
77 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
78 # formal argument declarations.
79 m4_define([b4_user_formals],
80 [m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
83 # b4_symbol_kind(NUM)
84 # -------------------
85 m4_define([b4_symbol_kind],
86 [symbol_kind::b4_symbol_kind_base($@)])
89 ## ----------------- ##
90 ## Semantic Values. ##
91 ## ----------------- ##
94 # b4_lhs_value(SYMBOL-NUM, [TYPE])
95 # --------------------------------
96 # See README.
97 m4_define([b4_lhs_value],
98 [b4_symbol_value([(*yyvalp)], [$1], [$2])])
101 # b4_rhs_data(RULE-LENGTH, POS)
102 # -----------------------------
103 # See README.
104 m4_define([b4_rhs_data],
105 [(static_cast<glr_stack_item const *>(yyvsp))@{YYFILL (b4_subtract([$2], [$1]))@}.getState()])
108 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
109 # --------------------------------------------------
110 # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
111 m4_define([b4_rhs_value],
112 [b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])])
116 ## ----------- ##
117 ## Locations. ##
118 ## ----------- ##
120 # b4_lhs_location()
121 # -----------------
122 # Expansion of @$.
123 m4_define([b4_lhs_location],
124 [(*yylocp)])
127 # b4_rhs_location(RULE-LENGTH, NUM)
128 # ---------------------------------
129 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
130 # on RHS.
131 m4_define([b4_rhs_location],
132 [(b4_rhs_data([$1], [$2]).yyloc)])
135 # b4_symbol_action(SYMBOL-NUM, KIND)
136 # ----------------------------------
137 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
138 # Same as in C, but using references instead of pointers.
140 # Currently we need two different b4_symbol_action: once for the
141 # self-contained symbols, and another time for yy_destroy_ and
142 # yy_symbol_value_print_, which don't use genuine symbols yet.
143 m4_define([b4_symbol_action],
144 [b4_symbol_if([$1], [has_$2],
145 [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
146 b4_dollar_pushdef([yysym.value],
147 [$1],
149 [yysym.location])dnl
150 _b4_symbol_case([$1])[]dnl
151 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
152 b4_symbol([$1], [$2])
153 b4_syncline([@oline@], [@ofile@])dnl
154 break;
156 m4_popdef([b4_symbol_value])[]dnl
157 b4_dollar_popdef[]dnl
158 ])])
161 # b4_symbol_action_for_yyval(SYMBOL-NUM, KIND)
162 # --------------------------------------------
163 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
164 # Same as in C, but using references instead of pointers.
165 m4_define([b4_symbol_action_for_yyval],
166 [b4_symbol_if([$1], [has_$2],
167 [b4_dollar_pushdef([yyval],
168 [$1],
170 [yyloc])dnl
171 _b4_symbol_case([$1])[]dnl
172 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
173 b4_symbol([$1], [$2])
174 b4_syncline([@oline@], [@ofile@])dnl
175 break;
177 b4_dollar_popdef[]dnl
178 ])])
181 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
182 # ---------------------------------------------------
183 m4_define([b4_call_merger],
184 [b4_case([$1],
185 [ b4_symbol_if([$3], [has_type],
186 [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());],
187 [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])],
188 [yy0 = $2 (yy0, yy1);])])])
190 # b4_yylex
191 # --------
192 # Call yylex.
193 m4_define([b4_yylex],
194 [b4_token_ctor_if(
195 [b4_function_call([yylex],
196 [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
197 [b4_function_call([yylex], [int],
198 [[value_type *], [&this->yyla.value]][]dnl
199 b4_locations_if([, [[location_type *], [&this->yyla.location]]])dnl
200 m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
203 # b4_shared_declarations(hh|cc)
204 # -----------------------------
205 # Declaration that might either go into the header (if --header, $1 = hh)
206 # or in the implementation file.
207 m4_define([b4_shared_declarations],
208 [b4_percent_code_get([[requires]])[
209 #include <algorithm>
210 #include <cstddef> // ptrdiff_t
211 #include <cstring> // memcpy
212 #include <iostream>
213 #include <iomanip>
214 #include <limits>
215 #include <stdexcept>
216 #include <stdint.h>
217 #include <string>
218 #include <vector>
220 ]b4_cxx_portability[
221 ]m4_ifdef([b4_location_include],
222 [[# include ]b4_location_include])[
223 ]b4_variant_if([b4_variant_includes])[
225 ]b4_YYDEBUG_define[
227 ]b4_namespace_open[
229 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
230 [b4_location_define])])[
232 /// A Bison parser.
233 class ]b4_parser_class[
235 public:
236 ]b4_public_types_declare[
237 ]b4_symbol_type_define[
239 // FIXME: should be private eventually.
240 class glr_stack;
241 class glr_state;
243 /// Build a parser object.
244 ]b4_parser_class[ (]b4_parse_param_decl[);
245 ~]b4_parser_class[ ();
247 /// Parse. An alias for parse ().
248 /// \returns 0 iff parsing succeeded.
249 int operator() ();
251 /// Parse.
252 /// \returns 0 iff parsing succeeded.
253 int parse ();
255 #if ]b4_api_PREFIX[DEBUG
256 /// The current debugging stream.
257 std::ostream& debug_stream () const;
258 /// Set the current debugging stream.
259 void set_debug_stream (std::ostream &);
261 /// Type for debugging levels.
262 using debug_level_type = int;
263 /// The current debugging level.
264 debug_level_type debug_level () const;
265 /// Set the current debugging level.
266 void set_debug_level (debug_level_type l);
267 #endif
269 /// Report a syntax error.]b4_locations_if([[
270 /// \param loc where the syntax error is found.]])[
271 /// \param msg a description of the syntax error.
272 void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
274 ]b4_parse_error_bmatch(
275 [custom\|detailed],
276 [[ /// The user-facing name of the symbol whose (internal) number is
277 /// YYSYMBOL. No bounds checking.
278 static const char *symbol_name (symbol_kind_type yysymbol);]],
279 [simple],
280 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
281 /// The user-facing name of the symbol whose (internal) number is
282 /// YYSYMBOL. No bounds checking.
283 static const char *symbol_name (symbol_kind_type yysymbol);
284 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
286 [verbose],
287 [[ /// The user-facing name of the symbol whose (internal) number is
288 /// YYSYMBOL. No bounds checking.
289 static std::string symbol_name (symbol_kind_type yysymbol);]])[
291 ]b4_token_constructor_define[
292 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
293 class context
295 public:
296 context (glr_stack& yystack, const symbol_type& yyla);
297 const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; }
298 symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[
299 const location_type& location () const YY_NOEXCEPT { return yyla_.location; }
300 ]])[
301 /// Put in YYARG at most YYARGN of the expected tokens, and return the
302 /// number of tokens stored in YYARG. If YYARG is null, return the
303 /// number of expected tokens (guaranteed to be less than YYNTOKENS).
304 int expected_tokens (symbol_kind_type yyarg[], int yyargn) const;
306 private:
307 glr_stack& yystack_;
308 const symbol_type& yyla_;
310 ]])[
311 # if ]b4_api_PREFIX[DEBUG
312 public:
313 /// \brief Report a symbol value on the debug stream.
314 /// \param yykind The symbol kind.
315 /// \param yyval Its semantic value.]b4_locations_if([[
316 /// \param yyloc Its location.]])[
317 void yy_symbol_value_print_ (symbol_kind_type yykind,
318 const value_type& yyval]b4_locations_if([[,
319 const location_type& yyloc]])[) const;
320 /// \brief Report a symbol on the debug stream.
321 /// \param yykind The symbol kind.
322 /// \param yyval Its semantic value.]b4_locations_if([[
323 /// \param yyloc Its location.]])[
324 void yy_symbol_print_ (symbol_kind_type yykind,
325 const value_type& yyval]b4_locations_if([[,
326 const location_type& yyloc]])[) const;
327 private:
328 /// Debug stream.
329 std::ostream* yycdebug_;
330 #endif
332 ]b4_parse_error_bmatch(
333 [custom], [[
334 private:
335 /// Report a syntax error
336 /// \param yyctx the context in which the error occurred.
337 void report_syntax_error (const context& yyctx) const;]],
338 [detailed\|verbose], [[
339 private:
340 /// The arguments of the error message.
341 int yy_syntax_error_arguments_ (const context& yyctx,
342 symbol_kind_type yyarg[], int yyargn) const;
344 /// Generate an error message.
345 /// \param yyctx the context in which the error occurred.
346 virtual std::string yysyntax_error_ (const context& yyctx) const;]])[
348 /// Convert a scanner token kind \a t to a symbol kind.
349 /// In theory \a t should be a token_kind_type, but character literals
350 /// are valid, yet not members of the token_kind_type enum.
351 static symbol_kind_type yytranslate_ (int t);
353 ]b4_parse_error_bmatch(
354 [simple],
355 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
356 /// For a symbol, its name in clear.
357 static const char* const yytname_[];
358 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
360 [verbose],
361 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
362 static std::string yytnamerr_ (const char *yystr);
364 /// For a symbol, its name in clear.
365 static const char* const yytname_[];
366 ]])[
368 /// \brief Reclaim the memory associated to a symbol.
369 /// \param yymsg Why this token is reclaimed.
370 /// If null, print nothing.
371 /// \param yykind The symbol kind.
372 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
373 value_type& yyval]b4_locations_if([[,
374 location_type& yyloc]])[);
376 ]b4_parse_param_vars[
377 // Needs access to yy_destroy_, report_syntax_error, etc.
378 friend glr_stack;
381 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
382 ]b4_public_types_define([$1])])[
383 ]b4_namespace_close[
385 ]b4_percent_code_get([[provides]])[
386 ]])[
389 ## -------------- ##
390 ## Output files. ##
391 ## -------------- ##
394 # ------------- #
395 # Header file. #
396 # ------------- #
398 ]b4_header_if([[
399 ]b4_output_begin([b4_spec_header_file])[
400 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
401 [2002-2015, 2018-2021])[
402 // C++ GLR parser skeleton written by Valentin Tolmer.
404 ]b4_disclaimer[
405 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
406 ]b4_shared_declarations([hh])[
407 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
408 ]b4_output_end])[
411 # --------------------- #
412 # Implementation file. #
413 # --------------------- #
415 ]b4_output_begin([b4_parser_file_name])[
416 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
417 [2002-2015, 2018-2021])[
418 // C++ GLR parser skeleton written by Valentin Tolmer.
420 ]b4_disclaimer[
421 ]b4_identification[
423 ]b4_percent_code_get([[top]])[
424 ]m4_if(b4_prefix, [yy], [],
425 [[/* Substitute the variable and function names. */
426 #define yyparse ]b4_prefix[parse
427 #define yylex ]b4_prefix[lex
428 #define yyerror ]b4_prefix[error
429 #define yydebug ]b4_prefix[debug]])[
431 ]b4_user_pre_prologue[
433 ]b4_null_define[
435 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
436 [b4_shared_declarations([cc])])[
438 namespace
440 /* Default (constant) value used for initialization for null
441 right-hand sides. Unlike the standard yacc.c template, here we set
442 the default value of $$ to a zeroed-out value. Since the default
443 value is undefined, this behavior is technically correct. */
444 ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;
447 ]b4_user_post_prologue[
448 ]b4_percent_code_get[
450 #include <cstdio>
451 #include <cstdlib>
453 #ifndef YY_
454 # if defined YYENABLE_NLS && YYENABLE_NLS
455 # if ENABLE_NLS
456 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
457 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
458 # endif
459 # endif
460 # ifndef YY_
461 # define YY_(Msgid) Msgid
462 # endif
463 #endif
465 // Whether we are compiled with exception support.
466 #ifndef YY_EXCEPTIONS
467 # if defined __GNUC__ && !defined __EXCEPTIONS
468 # define YY_EXCEPTIONS 0
469 # else
470 # define YY_EXCEPTIONS 1
471 # endif
472 #endif
474 #ifndef YYFREE
475 # define YYFREE free
476 #endif
477 #ifndef YYMALLOC
478 # define YYMALLOC malloc
479 #endif
481 #ifndef YYSETJMP
482 # include <setjmp.h>
483 # define YYJMP_BUF jmp_buf
484 # define YYSETJMP(Env) setjmp (Env)
485 /* Pacify Clang and ICC. */
486 # define YYLONGJMP(Env, Val) \
487 do { \
488 longjmp (Env, Val); \
489 YYASSERT (0); \
490 } while (false)
491 #endif
493 ]b4_attribute_define([noreturn])[
495 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
496 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
497 _Pragma ("GCC diagnostic push") \
498 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
499 # define YY_IGNORE_NULL_DEREFERENCE_END \
500 _Pragma ("GCC diagnostic pop")
501 #else
502 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
503 # define YY_IGNORE_NULL_DEREFERENCE_END
504 #endif
506 ]b4_null_define[
507 ]b4_cast_define[
509 // FIXME: Use the same conventions as lalr1.cc.
510 ]b4_parse_assert_if[
511 #ifndef YYASSERT
512 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
513 #endif
515 #ifdef YYDEBUG
516 # define YYDASSERT(Condition) YYASSERT(Condition)
517 #else
518 # define YYDASSERT(Condition)
519 #endif
521 /* YYFINAL -- State number of the termination state. */
522 #define YYFINAL ]b4_final_state_number[
523 /* YYLAST -- Last index in YYTABLE. */
524 #define YYLAST ]b4_last[
526 /* YYNTOKENS -- Number of terminals. */
527 #define YYNTOKENS ]b4_tokens_number[
528 /* YYNNTS -- Number of nonterminals. */
529 #define YYNNTS ]b4_nterms_number[
530 /* YYNRULES -- Number of rules. */
531 #define YYNRULES ]b4_rules_number[
532 /* YYNSTATES -- Number of states. */
533 #define YYNSTATES ]b4_states_number[
534 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
535 #define YYMAXRHS ]b4_r2_max[
536 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
537 accessed by $0, $-1, etc., in any rule. */
538 #define YYMAXLEFT ]b4_max_left_semantic_context[
540 namespace
542 #if ]b4_api_PREFIX[DEBUG
543 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
544 const ]b4_int_type_for([b4_rline])[ yyrline[] =
546 ]b4_rline[
548 #endif
550 #define YYPACT_NINF ]b4_pact_ninf[
551 #define YYTABLE_NINF ]b4_table_ninf[
553 ]b4_parser_tables_define[
555 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
556 const ]b4_int_type_for([b4_dprec])[ yydprec[] =
558 ]b4_dprec[
561 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
562 const ]b4_int_type_for([b4_merger])[ yymerger[] =
564 ]b4_merger[
567 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
568 in the case of predicates. */
569 const bool yyimmediate[] =
571 ]b4_immediate[
574 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
575 list of conflicting reductions corresponding to action entry for
576 state STATE-NUM in yytable. 0 means no conflicts. The list in
577 yyconfl is terminated by a rule number of 0. */
578 const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
580 ]b4_conflict_list_heads[
583 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
584 0, pointed into by YYCONFLP. */
585 ]dnl Do not use b4_int_type_for here, since there are places where
586 dnl pointers onto yyconfl are taken, whose type is "short*".
587 dnl We probably ought to introduce a type for confl.
588 [const short yyconfl[] =
590 ]b4_conflicting_rules[
592 } // namespace
595 /* Error token number */
596 #define YYTERROR 1
598 ]b4_locations_if([[
599 ]b4_yylloc_default_define[
600 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
601 ]])[
603 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
605 #define YYCHK(YYE) \
606 do { \
607 YYRESULTTAG yychk_flag = YYE; \
608 if (yychk_flag != yyok) \
609 return yychk_flag; \
610 } while (false)
612 #if ]b4_api_PREFIX[DEBUG
614 #define YYCDEBUG if (!yydebug) {} else std::cerr
616 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
617 do { \
618 if (yydebug) \
620 std::cerr << Title << ' '; \
621 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
622 std::cerr << '\n'; \
624 } while (false)
626 # define YY_REDUCE_PRINT(Args) \
627 do { \
628 if (yydebug) \
629 yystateStack.yy_reduce_print Args; \
630 } while (false)
632 /* Nonzero means print parse trace. It is left uninitialized so that
633 multiple parsers can coexist. */
634 int yydebug;
636 namespace
638 using glr_stack = ]b4_namespace_ref[::]b4_parser_class[::glr_stack;
639 using glr_state = ]b4_namespace_ref[::]b4_parser_class[::glr_state;
641 void yypstack (const glr_stack& yystack, size_t yyk)
642 YY_ATTRIBUTE_UNUSED;
643 void yypdumpstack (const glr_stack& yystack)
644 YY_ATTRIBUTE_UNUSED;
647 #else /* !]b4_api_PREFIX[DEBUG */
649 # define YYCDEBUG if (true) {} else std::cerr
650 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
651 # define YY_REDUCE_PRINT(Args) {}
653 #endif /* !]b4_api_PREFIX[DEBUG */
655 /* YYINITDEPTH -- initial size of the parser's stacks. */
656 #ifndef YYINITDEPTH
657 # define YYINITDEPTH ]b4_stack_depth_init[
658 #endif
660 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
661 if the built-in stack extension method is used).
663 Do not make this value too large; the results are undefined if
664 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
665 evaluated with infinite-precision integer arithmetic. */
667 #ifndef YYMAXDEPTH
668 # define YYMAXDEPTH ]b4_stack_depth_max[
669 #endif
671 /* Minimum number of free items on the stack allowed after an
672 allocation. This is to allow allocation and initialization
673 to be completed by functions that call yyexpandGLRStack before the
674 stack is expanded, thus insuring that all necessary pointers get
675 properly redirected to new data. */
676 #define YYHEADROOM 2
678 #ifndef YYSTACKEXPANDABLE
679 # define YYSTACKEXPANDABLE 1
680 #endif
682 namespace
684 template <typename Parameter>
685 class strong_index_alias
687 public:
688 static strong_index_alias create (std::ptrdiff_t value)
690 strong_index_alias result;
691 result.value_ = value;
692 return result;
695 std::ptrdiff_t const& get () const { return value_; }
697 size_t uget () const { return static_cast<size_t> (value_); }
699 strong_index_alias operator+ (std::ptrdiff_t other) const
701 return strong_index_alias (get () + other);
704 void operator+= (std::ptrdiff_t other)
706 value_ += other;
709 strong_index_alias operator- (std::ptrdiff_t other)
711 return strong_index_alias (get () - other);
714 void operator-= (std::ptrdiff_t other)
716 value_ -= other;
719 size_t operator- (strong_index_alias other)
721 return strong_index_alias (get () - other.get ());
724 strong_index_alias& operator++ ()
726 ++value_;
727 return *this;
730 bool isValid () const
732 return value_ != INVALID_INDEX;
735 void setInvalid()
737 value_ = INVALID_INDEX;
740 bool operator== (strong_index_alias other)
742 return get () == other.get ();
745 bool operator!= (strong_index_alias other)
747 return get () != other.get ();
750 bool operator< (strong_index_alias other)
752 return get () < other.get ();
755 private:
756 static const std::ptrdiff_t INVALID_INDEX;
758 // WARNING: 0-initialized.
759 std::ptrdiff_t value_;
760 }; // class strong_index_alias
762 template<typename T>
763 const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
764 std::numeric_limits<std::ptrdiff_t>::max ();
766 using state_set_index = strong_index_alias<struct glr_state_set_tag>;
768 state_set_index create_state_set_index (std::ptrdiff_t value)
770 return state_set_index::create (value);
773 /** State numbers, as in LALR(1) machine */
774 using state_num = int;
776 /** Rule numbers, as in LALR(1) machine */
777 using rule_num = int;
779 using parser_type = ]b4_namespace_ref[::]b4_parser_class[;
780 using glr_state = parser_type::glr_state;
781 using symbol_kind = parser_type::symbol_kind;
782 using symbol_kind_type = parser_type::symbol_kind_type;
783 using value_type = parser_type::value_type;]b4_locations_if([[
784 using location_type = parser_type::location_type;]])[
786 // Forward declarations.
787 class glr_stack_item;
788 class semantic_option;
789 } // namespace
791 namespace
793 /** Accessing symbol of state YYSTATE. */
794 inline symbol_kind_type
795 yy_accessing_symbol (state_num yystate)
797 return YY_CAST (symbol_kind_type, yystos[yystate]);
800 /** Left-hand-side symbol for rule #YYRULE. */
801 inline symbol_kind_type
802 yylhsNonterm (rule_num yyrule)
804 return static_cast<symbol_kind_type>(yyr1[yyrule]);
807 /** Number of symbols composing the right hand side of rule #RULE. */
808 inline int
809 yyrhsLength (rule_num yyrule)
811 return yyr2[yyrule];
815 namespace ]b4_namespace_ref[
817 class ]b4_parser_class[::glr_state
819 public:
820 glr_state ()
821 : yyresolved (false)
822 , yylrState (0)
823 , yyposn (0)
824 , yypred (0)
825 , yyfirstVal (0)]b4_locations_if([[
826 , yyloc ()]])[]b4_parse_assert_if([[
827 , magic_ (MAGIC)]])[
830 /// Build with a semantic value.
831 glr_state (state_num lrState, size_t posn, const value_type& val]b4_locations_if([[, const location_type& loc]])[)
832 : yyresolved (true)
833 , yylrState (lrState)
834 , yyposn (posn)
835 , yypred (0)
836 , yyval (]b4_variant_if([], [[val]])[)]b4_locations_if([[
837 , yyloc (loc)]])[]b4_parse_assert_if([[
838 , magic_ (MAGIC)]])[
839 {]b4_variant_if([[
840 ]b4_symbol_variant([yy_accessing_symbol (lrState)],
841 [yyval], [copy], [val])])[}
843 /// Build with a semantic option.
844 glr_state (state_num lrState, size_t posn)
845 : yyresolved (false)
846 , yylrState (lrState)
847 , yyposn (posn)
848 , yypred (0)
849 , yyfirstVal (0)]b4_locations_if([[
850 , yyloc ()]])[]b4_parse_assert_if([[
851 , magic_ (MAGIC)]])[
854 glr_state (const glr_state& other)
855 : yyresolved (other.yyresolved)
856 , yylrState (other.yylrState)
857 , yyposn (other.yyposn)
858 , yypred (0)]b4_locations_if([[
859 , yyloc (other.yyloc)]])[]b4_parse_assert_if([[
860 , magic_ (MAGIC)]])[
862 setPred (other.pred ());
863 if (other.yyresolved)]b4_variant_if([[
865 new (&yyval) value_type ();
866 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
867 [yyval], [copy], [other.value ()])[
868 }]], [[
869 new (&yyval) value_type (other.value ());]])[
870 else
872 yyfirstVal = 0;
873 setFirstVal (other.firstVal ());
874 }]b4_parse_assert_if([[
875 check_();]])[
878 ~glr_state ()
879 {]b4_parse_assert_if([[
880 check_ ();]])[
881 if (yyresolved)
882 {]b4_variant_if([[
883 symbol_kind_type yykind = yy_accessing_symbol (yylrState);
884 // FIXME: User destructors.
885 // Value type destructor.
886 ]b4_symbol_variant([[yykind]], [[yyval]], [[template destroy]])])[
887 yyval.~value_type ();
888 }]b4_parse_assert_if([[
889 magic_ = 0;]])[
892 glr_state& operator= (const glr_state& other)
893 {]b4_parse_assert_if([[
894 check_ ();
895 other.check_ ();]])[
896 if (!yyresolved && other.yyresolved)
897 new (&yyval) value_type;
898 yyresolved = other.yyresolved;
899 yylrState = other.yylrState;
900 yyposn = other.yyposn;
901 setPred (other.pred ());
902 if (other.yyresolved)]b4_variant_if([[
903 ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)],
904 [yyval], [copy], [other.value ()])], [[
905 value () = other.value ();]])[
906 else
907 setFirstVal (other.firstVal ());]b4_locations_if([[
908 yyloc = other.yyloc;]])[
909 return *this;
912 /** Type tag for the semantic value. If true, yyval applies, otherwise
913 * yyfirstVal applies. */
914 bool yyresolved;
915 /** Number of corresponding LALR(1) machine state. */
916 state_num yylrState;
917 /** Source position of the last token produced by my symbol */
918 size_t yyposn;
920 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
921 glr_state* pred ();
922 const glr_state* pred () const;
923 void setPred (const glr_state* state);
925 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
926 /// temporaries.
927 semantic_option* firstVal ();
928 const semantic_option* firstVal () const;
929 void setFirstVal (const semantic_option* option);
931 value_type& value ()
932 {]b4_parse_assert_if([[
933 check_ ();]])[
934 return yyval;
937 const value_type& value () const
938 {]b4_parse_assert_if([[
939 check_ ();]])[
940 return yyval;
943 void
944 destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser);
946 /* DEBUGGING ONLY */
947 #if ]b4_api_PREFIX[DEBUG
948 void yy_yypstack () const
949 {]b4_parse_assert_if([[
950 check_ ();]])[
951 if (pred () != YY_NULLPTR)
953 pred ()->yy_yypstack ();
954 std::cerr << " -> ";
956 std::cerr << yylrState << "@@" << yyposn;
958 #endif
960 std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED;
962 glr_stack_item* asItem ()
963 {]b4_parse_assert_if([[
964 check_ ();]])[
965 return asItem(this);
968 const glr_stack_item* asItem () const
969 {]b4_parse_assert_if([[
970 check_ ();]])[
971 return asItem (this);
974 private:
975 template <typename T>
976 static const glr_stack_item* asItem (const T* state)
978 return reinterpret_cast<const glr_stack_item*>(state);
980 template <typename T>
981 static glr_stack_item* asItem (T* state)
983 return reinterpret_cast<glr_stack_item*> (state);
985 static const char *as_pointer_ (const glr_state *state)
987 return reinterpret_cast<const char *> (state);
989 static char *as_pointer_ (glr_state *state)
991 return reinterpret_cast<char *> (state);
993 /** Preceding state in this stack */
994 std::ptrdiff_t yypred;
995 union {
996 /** First in a chain of alternative reductions producing the
997 * nonterminal corresponding to this state, threaded through
998 * yyfirstVal. Value "0" means empty. */
999 std::ptrdiff_t yyfirstVal;
1000 /** Semantic value for this state. */
1001 value_type yyval;
1002 };]b4_locations_if([[
1003 // FIXME: Why public?
1004 public:
1005 /** Source location for this state. */
1006 location_type yyloc;]])[
1008 ]b4_parse_assert_if([[
1009 public:
1010 // Check invariants.
1011 void check_ () const
1013 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1014 YYASSERT (this->magic_ == MAGIC);
1015 YY_IGNORE_NULL_DEREFERENCE_END
1018 // A magic number to check our pointer arithmetic is sane.
1019 enum { MAGIC = 713705 };
1020 unsigned int magic_;]])[
1021 }; // class ]b4_parser_class[::glr_state
1022 } // namespace ]b4_namespace_ref[
1025 namespace
1027 /** A stack of GLRState representing the different heads during
1028 * nondeterministic evaluation. */
1029 class glr_state_set
1031 public:
1032 /** Initialize YYSET to a singleton set containing an empty stack. */
1033 glr_state_set ()
1034 : yylastDeleted (YY_NULLPTR)
1036 yystates.push_back (YY_NULLPTR);
1037 yylookaheadNeeds.push_back (false);
1040 // Behave like a vector of states.
1041 glr_state*& operator[] (state_set_index index)
1043 return yystates[index.uget()];
1046 glr_state* operator[] (state_set_index index) const
1048 return yystates[index.uget()];
1051 size_t size () const
1053 return yystates.size ();
1056 std::vector<glr_state*>::iterator begin ()
1058 return yystates.begin ();
1061 std::vector<glr_state*>::iterator end ()
1063 return yystates.end ();
1066 bool lookaheadNeeds (state_set_index index) const
1068 return yylookaheadNeeds[index.uget ()];
1071 bool setLookaheadNeeds (state_set_index index, bool value)
1073 return yylookaheadNeeds[index.uget ()] = value;
1076 /** Invalidate stack #YYK. */
1077 void
1078 yymarkStackDeleted (state_set_index yyk)
1080 size_t k = yyk.uget ();
1081 if (yystates[k] != YY_NULLPTR)
1082 yylastDeleted = yystates[k];
1083 yystates[k] = YY_NULLPTR;
1086 /** Undelete the last stack in *this that was marked as deleted. Can
1087 only be done once after a deletion, and only when all other stacks have
1088 been deleted. */
1089 void
1090 yyundeleteLastStack ()
1092 if (yylastDeleted == YY_NULLPTR || !yystates.empty ())
1093 return;
1094 yystates.push_back (yylastDeleted);
1095 YYCDEBUG << "Restoring last deleted stack as stack #0.\n";
1096 clearLastDeleted ();
1099 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1100 * ones. */
1101 void
1102 yyremoveDeletes ()
1104 size_t newsize = yystates.size ();
1105 /* j is the number of live stacks we have seen. */
1106 for (size_t i = 0, j = 0; j < newsize; ++i)
1108 if (yystates[i] == YY_NULLPTR)
1110 if (i == j)
1112 YYCDEBUG << "Removing dead stacks.\n";
1114 newsize -= 1;
1116 else
1118 yystates[j] = yystates[i];
1119 /* In the current implementation, it's unnecessary to copy
1120 yylookaheadNeeds[i] since, after
1121 yyremoveDeletes returns, the parser immediately either enters
1122 deterministic operation or shifts a token. However, it doesn't
1123 hurt, and the code might evolve to need it. */
1124 yylookaheadNeeds[j] = yylookaheadNeeds[i];
1125 if (j != i)
1127 YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n";
1129 j += 1;
1132 yystates.resize (newsize);
1133 yylookaheadNeeds.resize (newsize);
1137 state_set_index
1138 yysplitStack (state_set_index yyk)
1140 const size_t k = yyk.uget ();
1141 yystates.push_back (yystates[k]);
1142 yylookaheadNeeds.push_back (yylookaheadNeeds[k]);
1143 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates.size () - 1));
1146 void clearLastDeleted ()
1148 yylastDeleted = YY_NULLPTR;
1151 private:
1153 std::vector<glr_state*> yystates;
1154 /** During nondeterministic operation, yylookaheadNeeds tracks which
1155 * stacks have actually needed the current lookahead. During deterministic
1156 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1157 * duplicate !yyla.empty (). */
1158 std::vector<bool> yylookaheadNeeds;
1160 /** The last stack we invalidated. */
1161 glr_state* yylastDeleted;
1162 }; // class glr_state_set
1163 } // namespace
1165 namespace
1167 class semantic_option
1169 public:
1170 semantic_option ()
1171 : yyrule (0)
1172 , yystate (0)
1173 , yynext (0)
1174 , yytoken (]b4_symbol(empty, kind)[)
1175 , yyval ()]b4_locations_if([[
1176 , yyloc ()]])[]b4_parse_assert_if([[
1177 , magic_ (MAGIC)]])[
1180 semantic_option (rule_num rule)
1181 : yyrule (rule)
1182 , yystate (0)
1183 , yynext (0)
1184 , yytoken (]b4_symbol(empty, kind)[)
1185 , yyval ()]b4_locations_if([[
1186 , yyloc ()]])[]b4_parse_assert_if([[
1187 , magic_ (MAGIC)]])[
1190 semantic_option (const semantic_option& that)
1191 : yyrule (that.yyrule)
1192 , yystate (that.yystate)
1193 , yynext (that.yynext)
1194 , yytoken (that.yytoken)
1195 , yyval (]b4_variant_if([], [[that.yyval]])[)]b4_locations_if([[
1196 , yyloc (that.yyloc)]])[]b4_parse_assert_if([[
1197 , magic_ (MAGIC)]])[
1198 {]b4_parse_assert_if([[
1199 that.check_ ();]])[]b4_variant_if([[
1200 ]b4_symbol_variant([yytoken],
1201 [yyval], [copy], [that.yyval])])[
1204 // Needed for the assignment in yynewSemanticOption.
1205 semantic_option& operator= (const semantic_option& that)
1206 {]b4_parse_assert_if([[
1207 check_ ();
1208 that.check_ ();]])[
1209 yyrule = that.yyrule;
1210 yystate = that.yystate;
1211 yynext = that.yynext;
1212 yytoken = that.yytoken;]b4_variant_if([[
1213 ]b4_symbol_variant([yytoken],
1214 [yyval], [copy], [that.yyval])], [[
1215 yyval = that.yyval;]])[]b4_locations_if([[
1216 yyloc = that.yyloc;]])[
1217 return *this;
1220 /// Only call state() and setState() on objects in yyitems, not temporaries.
1221 glr_state* state();
1222 const glr_state* state() const;
1223 void setState(const glr_state* s);
1225 const semantic_option* next () const YY_ATTRIBUTE_UNUSED;
1226 semantic_option* next ();
1227 void setNext (const semantic_option* s);
1229 std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED;
1231 /** True iff YYY0 and YYY1 represent identical options at the top level.
1232 * That is, they represent the same rule applied to RHS symbols
1233 * that produce the same terminal symbols. */
1234 bool
1235 isIdenticalTo (const semantic_option& yyy1) const
1236 {]b4_parse_assert_if([[
1237 check_ ();
1238 yyy1.check_ ();]])[
1239 if (this->yyrule == yyy1.yyrule)
1241 const glr_state *yys0, *yys1;
1242 int yyn;
1243 for (yys0 = this->state(),
1244 yys1 = yyy1.state(),
1245 yyn = yyrhsLength (this->yyrule);
1246 yyn > 0;
1247 yys0 = yys0->pred(),
1248 yys1 = yys1->pred(), yyn -= 1)
1249 if (yys0->yyposn != yys1->yyposn)
1250 return false;
1251 return true;
1253 else
1254 return false;
1257 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1258 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1259 void
1260 mergeWith (semantic_option& yyy1)
1261 {]b4_parse_assert_if([[
1262 check_ ();
1263 yyy1.check_ ();]])[
1264 glr_state *yys0 = this->state ();
1265 glr_state *yys1 = yyy1.state ();
1266 for (int yyn = yyrhsLength (this->yyrule);
1267 yyn > 0;
1268 yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ())
1270 if (yys0 == yys1)
1271 break;
1272 else if (yys0->yyresolved)
1274 yys1->yyresolved = true;]b4_variant_if([[
1275 YYASSERT (yys1->yylrState == yys0->yylrState);
1276 ]b4_symbol_variant([yy_accessing_symbol (yys0->yylrState)],
1277 [yys1->value ()], [copy], [yys0->value ()])], [[
1278 yys1->value () = yys0->value ();]])[
1280 else if (yys1->yyresolved)
1282 yys0->yyresolved = true;]b4_variant_if([[
1283 YYASSERT (yys0->yylrState == yys1->yylrState);
1284 ]b4_symbol_variant([yy_accessing_symbol (yys1->yylrState)],
1285 [yys0->value ()], [copy], [yys1->value ()])], [[
1286 yys0->value () = yys1->value ();]])[
1288 else
1290 semantic_option* yyz0prev = YY_NULLPTR;
1291 semantic_option* yyz0 = yys0->firstVal();
1292 semantic_option* yyz1 = yys1->firstVal();
1293 while (true)
1295 if (yyz1 == yyz0 || yyz1 == YY_NULLPTR)
1296 break;
1297 else if (yyz0 == YY_NULLPTR)
1299 if (yyz0prev != YY_NULLPTR)
1300 yyz0prev->setNext (yyz1);
1301 else
1302 yys0->setFirstVal (yyz1);
1303 break;
1305 else if (yyz0 < yyz1)
1307 semantic_option* yyz = yyz0;
1308 if (yyz0prev != YY_NULLPTR)
1309 yyz0prev->setNext(yyz1);
1310 else
1311 yys0->setFirstVal(yyz1);
1312 yyz1 = yyz1->next();
1313 yyz0->setNext(yyz);
1315 yyz0prev = yyz0;
1316 yyz0 = yyz0->next();
1318 yys1->setFirstVal(yys0->firstVal());
1323 #if ]b4_api_PREFIX[DEBUG
1324 void yyreportTree (size_t yyindent = 2) const
1325 {]b4_parse_assert_if([[
1326 check_ ();]])[
1327 int yynrhs = yyrhsLength (this->yyrule);
1328 const glr_state* yystates[1 + YYMAXRHS];
1329 glr_state yyleftmost_state;
1332 const glr_state* yys = this->state();
1333 for (int yyi = yynrhs; 0 < yyi; yyi -= 1)
1335 yystates[yyi] = yys;
1336 yys = yys->pred();
1338 if (yys == YY_NULLPTR)
1340 yyleftmost_state.yyposn = 0;
1341 yystates[0] = &yyleftmost_state;
1343 else
1344 yystates[0] = yys;
1347 std::string yylhs = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yylhsNonterm (this->yyrule));
1348 YYASSERT(this->state());
1349 if (this->state()->yyposn < yystates[0]->yyposn + 1)
1350 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1351 << this->yyrule - 1 << ", empty>\n";
1352 else
1353 std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule "
1354 << this->yyrule - 1 << ", tokens "
1355 << yystates[0]->yyposn + 1 << " .. "
1356 << this->state()->yyposn << ">\n";
1357 for (int yyi = 1; yyi <= yynrhs; yyi += 1)
1359 if (yystates[yyi]->yyresolved)
1361 std::string yysym = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yy_accessing_symbol (yystates[yyi]->yylrState));
1362 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1363 std::cerr << std::string(yyindent + 2, ' ') << yysym
1364 << " <empty>\n";
1365 else
1366 std::cerr << std::string(yyindent + 2, ' ') << yysym
1367 << " <tokens " << yystates[yyi-1]->yyposn + 1
1368 << " .. " << yystates[yyi]->yyposn << ">\n";
1370 else
1371 yystates[yyi]->firstVal ()->yyreportTree (yyindent+2);
1374 #endif
1376 /** Rule number for this reduction */
1377 rule_num yyrule;
1379 private:
1380 template <typename T>
1381 static const glr_stack_item* asItem(const T* state)
1383 return reinterpret_cast<const glr_stack_item*>(state);
1385 template <typename T>
1386 static glr_stack_item* asItem(T* state)
1388 return reinterpret_cast<glr_stack_item*>(state);
1390 /** The last RHS state in the list of states to be reduced. */
1391 std::ptrdiff_t yystate;
1392 /** Next sibling in chain of options. To facilitate merging,
1393 * options are chained in decreasing order by address. */
1394 std::ptrdiff_t yynext;
1396 public:
1397 /** The lookahead for this reduction. */
1398 symbol_kind_type yytoken;
1399 value_type yyval;]b4_locations_if([[
1400 location_type yyloc;]])[
1402 ]b4_parse_assert_if([[
1403 public:
1404 // Check invariants.
1405 void check_ () const
1407 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1408 YYASSERT (this->magic_ == MAGIC);
1409 YY_IGNORE_NULL_DEREFERENCE_END
1412 // A magic number to check our pointer arithmetic is sane.
1413 enum { MAGIC = 0xeff1cace };
1414 unsigned int magic_;]])[
1415 }; // class semantic_option
1416 } // namespace
1418 namespace
1420 /** Type of the items in the GLR stack.
1421 * It can be either a glr_state or a semantic_option. The is_state_ field
1422 * indicates which item of the union is valid. */
1423 class glr_stack_item
1425 public:
1426 glr_stack_item (bool state = true)
1427 : is_state_ (state)]b4_parse_assert_if([[
1428 , magic_ (MAGIC)]])[
1430 if (is_state_)
1431 new (&raw_) glr_state;
1432 else
1433 new (&raw_) semantic_option;
1436 glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW
1437 : is_state_ (other.is_state_)]b4_parse_assert_if([[
1438 , magic_ (MAGIC)]])[
1439 {]b4_parse_assert_if([[
1440 other.check_ ();]])[
1441 std::memcpy (raw_, other.raw_, union_size);
1444 glr_stack_item& operator= (glr_stack_item other)
1445 {]b4_parse_assert_if([[
1446 check_ ();
1447 other.check_ ();]])[
1448 std::swap (is_state_, other.is_state_);
1449 std::swap (raw_, other.raw_);
1450 return *this;
1453 ~glr_stack_item ()
1454 {]b4_parse_assert_if([[
1455 check_ ();]])[
1456 if (is_state ())
1457 getState ().~glr_state ();
1458 else
1459 getOption ().~semantic_option ();
1462 void setState (const glr_state &state)
1463 {]b4_parse_assert_if([[
1464 check_ ();
1465 state.check_ ();]])[
1466 if (this != state.asItem ())
1468 if (is_state_)
1469 getState ().~glr_state ();
1470 else
1471 getOption ().~semantic_option ();
1472 new (&raw_) glr_state (state);
1473 is_state_ = true;
1477 glr_state& getState ()
1478 {]b4_parse_assert_if([[
1479 check_ ();]])[
1480 YYDASSERT (is_state ());
1481 void *yyp = raw_;
1482 glr_state& res = *static_cast<glr_state*> (yyp);]b4_parse_assert_if([[
1483 res.check_ ();]])[
1484 return res;
1487 const glr_state& getState () const
1488 {]b4_parse_assert_if([[
1489 check_ ();]])[
1490 YYDASSERT (is_state ());
1491 const void *yyp = raw_;
1492 const glr_state& res = *static_cast<const glr_state*> (yyp);]b4_parse_assert_if([[
1493 res.check_ ();]])[
1494 return res;
1497 semantic_option& getOption ()
1498 {]b4_parse_assert_if([[
1499 check_ ();]])[
1500 YYDASSERT (!is_state ());
1501 void *yyp = raw_;
1502 return *static_cast<semantic_option*> (yyp);
1504 const semantic_option& getOption () const
1505 {]b4_parse_assert_if([[
1506 check_ ();]])[
1507 YYDASSERT (!is_state ());
1508 const void *yyp = raw_;
1509 return *static_cast<const semantic_option*> (yyp);
1511 bool is_state () const
1512 {]b4_parse_assert_if([[
1513 check_ ();]])[
1514 return is_state_;
1517 private:
1518 /// The possible contents of raw_. Since they have constructors, they cannot
1519 /// be directly included in the union.
1520 union contents
1522 char yystate[sizeof (glr_state)];
1523 char yyoption[sizeof (semantic_option)];
1525 enum { union_size = sizeof (contents) };
1526 union {
1527 /// Strongest alignment constraints.
1528 long double yyalign_me;
1529 /// A buffer large enough to store the contents.
1530 char raw_[union_size];
1532 /** Type tag for the union. */
1533 bool is_state_;
1534 ]b4_parse_assert_if([[
1535 public:
1536 // Check invariants.
1537 void check_ () const
1539 YYASSERT (this->magic_ == MAGIC);
1540 YYASSERT (this->is_state_ == false || this->is_state_ == true);
1542 // A magic number to check our pointer arithmetic is sane.
1543 enum { MAGIC = 0xDEAD1ACC }; // 3735886540.
1544 const unsigned int magic_;]])[
1545 }; // class glr_stack_item
1546 } // namespace
1548 glr_state* glr_state::pred ()
1549 {]b4_parse_assert_if([[
1550 check_ ();]])[
1551 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1552 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1553 YY_IGNORE_NULL_DEREFERENCE_END
1556 const glr_state* glr_state::pred () const
1557 {]b4_parse_assert_if([[
1558 check_ ();]])[
1559 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1560 return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR;
1561 YY_IGNORE_NULL_DEREFERENCE_END
1564 void glr_state::setPred (const glr_state* state)
1565 {]b4_parse_assert_if([[
1566 check_ ();
1567 if (state)
1568 state->check_ ();]])[
1569 yypred = state ? as_pointer_ (this) - as_pointer_ (state) : 0;
1572 semantic_option* glr_state::firstVal ()
1573 {]b4_parse_assert_if([[
1574 check_ ();]])[
1575 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1578 const semantic_option* glr_state::firstVal () const
1579 {]b4_parse_assert_if([[
1580 check_ ();]])[
1581 return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR;
1584 void glr_state::setFirstVal (const semantic_option* option)
1585 {]b4_parse_assert_if([[
1586 check_ ();]])[
1587 yyfirstVal = option ? asItem(this) - asItem(option) : 0;
1590 std::ptrdiff_t glr_state::indexIn (const glr_stack_item* array) const
1591 {]b4_parse_assert_if([[
1592 check_ ();]])[
1593 return asItem(this) - array;
1596 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item* array) const
1598 return asItem(this) - array;
1601 glr_state* semantic_option::state ()
1603 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1604 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1605 YY_IGNORE_NULL_DEREFERENCE_END
1608 const glr_state* semantic_option::state () const
1610 return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR;
1613 void semantic_option::setState (const glr_state* s)
1615 yystate = s ? asItem(this) - asItem(s) : 0;
1618 const semantic_option* semantic_option::next () const
1620 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1623 semantic_option* semantic_option::next ()
1625 return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR;
1628 void semantic_option::setNext (const semantic_option* s)
1630 yynext = s ? asItem(this) - asItem(s) : 0;
1633 void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser)
1634 {]b4_parse_assert_if([[
1635 check_ ();]])[
1636 if (yyresolved)
1637 yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
1638 value ()]b4_locations_if([, yyloc])[);
1639 else
1641 #if ]b4_api_PREFIX[DEBUG
1642 YYCDEBUG << yymsg
1643 << (firstVal() ? " unresolved " : " incomplete ")
1644 << (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm")
1645 << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState))
1646 << " ("]b4_locations_if([[
1647 << yyloc << ": "]])[
1648 << ")\n";
1649 #endif
1650 if (firstVal() != YY_NULLPTR)
1652 semantic_option& yyoption = *firstVal ();
1653 glr_state *yyrh = yyoption.state ();
1654 for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1)
1656 yyrh->destroy (yymsg, yyparser);
1657 yyrh = yyrh->pred();
1664 #undef YYFILL
1665 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1667 namespace
1669 class state_stack
1671 public:
1672 using parser_type = ]b4_namespace_ref[::]b4_parser_class[;
1673 using symbol_kind = parser_type::symbol_kind;
1674 using value_type = parser_type::value_type;]b4_locations_if([[
1675 using location_type = parser_type::location_type;]])[
1677 /** Initialize to a single empty stack, with total maximum
1678 * capacity for all stacks of YYSIZE. */
1679 state_stack (size_t yysize)
1680 : yysplitPoint (YY_NULLPTR)
1682 yyitems.reserve (yysize);
1685 #if YYSTACKEXPANDABLE
1686 /** Returns false if it tried to expand but could not. */
1687 bool
1688 yyexpandGLRStackIfNeeded ()
1690 return YYHEADROOM <= spaceLeft () || yyexpandGLRStack ();
1693 private:
1694 /** If *this is expandable, extend it. WARNING: Pointers into the
1695 stack from outside should be considered invalid after this call.
1696 We always expand when there are 1 or fewer items left AFTER an
1697 allocation, so that we can avoid having external pointers exist
1698 across an allocation. */
1699 bool
1700 yyexpandGLRStack ()
1702 const size_t oldsize = yyitems.size();
1703 if (YYMAXDEPTH - YYHEADROOM < oldsize)
1704 return false;
1705 const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize;
1706 const glr_stack_item *oldbase = &yyitems[0];
1708 yyitems.reserve (yynewSize);
1709 const glr_stack_item *newbase = &yyitems[0];
1711 // Adjust the pointers. Perform raw pointer arithmetic, as there
1712 // is no reason for objects to be aligned on their size.
1713 const ptrdiff_t disp
1714 = reinterpret_cast<const char*> (newbase) - reinterpret_cast<const char*> (oldbase);
1715 if (yysplitPoint)
1716 const_cast<glr_state*&> (yysplitPoint)
1717 = reinterpret_cast<glr_state*> (reinterpret_cast<char*> (const_cast<glr_state*> (yysplitPoint)) + disp);
1719 for (std::vector<glr_state*>::iterator
1720 i = yytops.begin (),
1721 yyend = yytops.end ();
1722 i != yyend; ++i)
1723 if (glr_state_not_null (*i))
1724 *i = reinterpret_cast<glr_state*>(reinterpret_cast<char*>(*i) + disp);
1726 return true;
1729 public:
1730 #else
1731 bool yyexpandGLRStackIfNeeded ()
1733 return YYHEADROOM <= spaceLeft ();
1735 #endif
1736 #undef YYSTACKEXPANDABLE
1738 static bool glr_state_not_null (glr_state* s)
1740 return s != YY_NULLPTR;
1743 bool
1744 reduceToOneStack ()
1746 using iterator = std::vector<glr_state*>::iterator;
1747 const iterator yybegin = yytops.begin();
1748 const iterator yyend = yytops.end();
1749 const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null);
1750 if (yyit == yyend)
1751 return false;
1752 for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin);
1753 yyk.uget() != numTops(); ++yyk)
1754 yytops.yymarkStackDeleted (yyk);
1755 yytops.yyremoveDeletes ();
1756 yycompressStack ();
1757 return true;
1760 /** Called when returning to deterministic operation to clean up the extra
1761 * stacks. */
1762 void
1763 yycompressStack ()
1765 if (yytops.size() != 1 || !isSplit())
1766 return;
1768 // yyr is the state after the split point.
1769 glr_state* yyr = YY_NULLPTR;
1770 for (glr_state *yyp = firstTop(), *yyq = yyp->pred();
1771 yyp != yysplitPoint;
1772 yyr = yyp, yyp = yyq, yyq = yyp->pred())
1773 yyp->setPred(yyr);
1775 // This const_cast is okay, since anyway we have access to the mutable
1776 // yyitems into which yysplitPoint points.
1777 glr_stack_item* nextFreeItem
1778 = const_cast<glr_state*> (yysplitPoint)->asItem () + 1;
1779 yysplitPoint = YY_NULLPTR;
1780 yytops.clearLastDeleted ();
1782 while (yyr != YY_NULLPTR)
1784 nextFreeItem->setState (*yyr);
1785 glr_state& nextFreeState = nextFreeItem->getState();
1786 yyr = yyr->pred();
1787 nextFreeState.setPred(&(nextFreeItem - 1)->getState());
1788 setFirstTop (&nextFreeState);
1789 ++nextFreeItem;
1791 yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data()));
1794 bool isSplit() const {
1795 return yysplitPoint != YY_NULLPTR;
1798 // Present the interface of a vector of glr_stack_item.
1799 std::vector<glr_stack_item>::const_iterator begin () const
1801 return yyitems.begin ();
1804 std::vector<glr_stack_item>::const_iterator end () const
1806 return yyitems.end ();
1809 size_t size() const
1811 return yyitems.size ();
1814 glr_stack_item& operator[] (size_t i)
1816 return yyitems[i];
1819 glr_stack_item& stackItemAt (size_t index)
1821 return yyitems[index];
1824 size_t numTops () const
1826 return yytops.size ();
1829 glr_state* firstTop () const
1831 return yytops[create_state_set_index (0)];
1834 glr_state* topAt (state_set_index i) const
1836 return yytops[i];
1839 void setFirstTop (glr_state* value)
1841 yytops[create_state_set_index (0)] = value;
1844 void setTopAt (state_set_index i, glr_state* value)
1846 yytops[i] = value;
1849 void pop_back ()
1851 yyitems.pop_back ();
1854 void pop_back (size_t n)
1856 yyitems.resize (yyitems.size () - n);
1859 state_set_index
1860 yysplitStack (state_set_index yyk)
1862 if (!isSplit ())
1864 YYASSERT (yyk.get () == 0);
1865 yysplitPoint = topAt (yyk);
1867 return yytops.yysplitStack (yyk);
1870 /** Assuming that YYS is a GLRState somewhere on *this, update the
1871 * splitpoint of *this, if needed, so that it is at least as deep as
1872 * YYS. */
1873 void
1874 yyupdateSplit (glr_state& yys)
1876 if (isSplit() && &yys < yysplitPoint)
1877 yysplitPoint = &yys;
1880 /** Return a fresh GLRState.
1881 * Callers should call yyreserveStack afterwards to make sure there is
1882 * sufficient headroom. */
1883 glr_state& yynewGLRState (const glr_state& newState)
1885 glr_state& state = yyitems[yynewGLRStackItem (true)].getState ();
1886 #if false && 201103L <= YY_CPLUSPLUS
1887 state = std::move (newState);
1888 #else
1889 state = newState;
1890 #endif
1891 return state;
1894 /** Return a fresh SemanticOption.
1895 * Callers should call yyreserveStack afterwards to make sure there is
1896 * sufficient headroom. */
1897 semantic_option& yynewSemanticOption (semantic_option newOption)
1899 semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption ();
1900 option = std::move (newOption);
1901 return option;
1904 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1905 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1906 * For convenience, always return YYLOW1. */
1908 yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal)
1910 if (!yynormal && yylow1 < yylow)
1912 yyfillin (yyvsp, yylow, yylow1);
1913 yylow = yylow1;
1915 return yylow1;
1918 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1919 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1920 * containing the pointer to the next state in the chain. */
1921 void
1922 yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1)
1924 glr_state* s = yyvsp[yylow0].getState().pred();
1925 YYASSERT(s != YY_NULLPTR);
1926 for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred())
1928 glr_state& yys = yyvsp[i].getState();
1929 #if ]b4_api_PREFIX[DEBUG
1930 yys.yylrState = s->yylrState;
1931 #endif
1932 yys.yyresolved = s->yyresolved;
1933 if (s->yyresolved)
1934 {]b4_variant_if([[
1935 new (&yys.value ()) value_type ();
1936 ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)],
1937 [yys.value ()], [copy], [s->value ()])], [[
1938 new (&yys.value ()) value_type (s->value ());]])[
1940 else
1941 /* The effect of using yyval or yyloc (in an immediate
1942 * rule) is undefined. */
1943 yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[
1944 yys.yyloc = s->yyloc;]])[
1945 yys.setPred(s->pred());
1949 #if ]b4_api_PREFIX[DEBUG
1951 /*----------------------------------------------------------------------.
1952 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1953 `----------------------------------------------------------------------*/
1955 void
1956 yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk,
1957 rule_num yyrule, parser_type& yyparser)
1959 int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
1960 int yylow = 1;])[
1961 int yyi;
1962 std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1
1963 << " (line " << int (yyrline[yyrule]) << "):\n";
1964 if (! yynormal)
1965 yyfillin (yyvsp, 1, -yynrhs);
1966 /* The symbols being reduced. */
1967 for (yyi = 0; yyi < yynrhs; yyi++)
1969 std::cerr << " $" << yyi + 1 << " = ";
1970 yyparser.yy_symbol_print_
1971 (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
1972 yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
1973 ]b4_rhs_location(yynrhs, yyi + 1)])[);
1974 if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
1975 std::cerr << " (unresolved)";
1976 std::cerr << '\n';
1981 #define YYINDEX(YYX) \
1982 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1984 void
1985 dumpStack () const
1987 for (size_t yyi = 0; yyi < size(); ++yyi)
1989 const glr_stack_item& item = yyitems[yyi];
1990 std::cerr << std::setw(3) << yyi << ". ";
1991 if (item.is_state())
1993 std::cerr << "Res: " << item.getState().yyresolved
1994 << ", LR State: " << item.getState().yylrState
1995 << ", posn: " << item.getState().yyposn
1996 << ", pred: " << YYINDEX(item.getState().pred());
1997 if (! item.getState().yyresolved)
1998 std::cerr << ", firstVal: "
1999 << YYINDEX(item.getState().firstVal());
2001 else
2003 std::cerr << "Option. rule: " << item.getOption().yyrule - 1
2004 << ", state: " << YYINDEX(item.getOption().state())
2005 << ", next: " << YYINDEX(item.getOption().next());
2007 std::cerr << '\n';
2009 std::cerr << "Tops:";
2010 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) {
2011 std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; ";
2013 std::cerr << '\n';
2016 #undef YYINDEX
2017 #endif
2019 YYRESULTTAG
2020 yyreportAmbiguity (const semantic_option& yyx0,
2021 const semantic_option& yyx1, parser_type& yyparser]b4_locations_if([, const location_type& yyloc])[)
2023 YY_USE (yyx0);
2024 YY_USE (yyx1);
2026 #if ]b4_api_PREFIX[DEBUG
2027 std::cerr << "Ambiguity detected.\n"
2028 "Option 1,\n";
2029 yyx0.yyreportTree ();
2030 std::cerr << "\nOption 2,\n";
2031 yyx1.yyreportTree ();
2032 std::cerr << '\n';
2033 #endif
2035 yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous"));
2036 return yyabort;
2039 #if ]b4_api_PREFIX[DEBUG
2040 /* Print YYS (possibly NULL) and its predecessors. */
2041 void
2042 yypstates (const glr_state* yys) const
2044 if (yys != YY_NULLPTR)
2045 yys->yy_yypstack();
2046 else
2047 std::cerr << "<null>";
2048 std::cerr << '\n';
2050 #endif
2052 private:
2053 size_t spaceLeft() const
2055 return yyitems.capacity() - yyitems.size();
2058 /** Return a fresh GLRStackItem in this. The item is an LR state
2059 * if YYIS_STATE, and otherwise a semantic option. Callers should call
2060 * yyreserveStack afterwards to make sure there is sufficient
2061 * headroom. */
2062 size_t
2063 yynewGLRStackItem (bool yyis_state)
2065 YYDASSERT(yyitems.size() < yyitems.capacity());
2066 yyitems.push_back(glr_stack_item(yyis_state));
2067 return yyitems.size() - 1;
2071 public:
2072 std::vector<glr_stack_item> yyitems;
2073 // Where the stack splits. Anything below this address is deterministic.
2074 const glr_state* yysplitPoint;
2075 glr_state_set yytops;
2076 }; // class state_stack
2077 } // namespace
2079 #undef YYFILL
2080 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2082 namespace ]b4_namespace_ref[
2084 class ]b4_parser_class[::glr_stack
2086 public:
2087 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
2088 // Needs access to yypact_value_is_default, etc.
2089 friend context;
2090 ]])[
2092 glr_stack (size_t yysize, parser_type& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
2093 : yyerrState (0)
2094 , yystateStack (yysize)
2095 , yyerrcnt (0)
2096 , yyla ()
2097 , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
2100 ~glr_stack ()
2102 if (!this->yyla.empty ())
2103 yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
2104 this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);
2105 popall_ ();
2108 int yyerrState;
2109 ]b4_locations_if([[ /* To compute the location of the error token. */
2110 glr_stack_item yyerror_range[3];]])[
2111 state_stack yystateStack;
2112 int yyerrcnt;
2113 symbol_type yyla;
2114 YYJMP_BUF yyexception_buffer;
2115 parser_type& yyparser;
2117 #define YYCHK1(YYE) \
2118 do { \
2119 switch (YYE) { \
2120 case yyok: \
2121 break; \
2122 case yyabort: \
2123 goto yyabortlab; \
2124 case yyaccept: \
2125 goto yyacceptlab; \
2126 case yyerr: \
2127 goto yyuser_error; \
2128 default: \
2129 goto yybuglab; \
2131 } while (false)
2134 parse ()
2136 int yyresult;
2137 size_t yyposn;
2139 YYCDEBUG << "Starting parse\n";
2141 this->yyla.clear ();
2142 ]m4_ifdef([b4_initial_action], [
2143 b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl
2144 b4_user_initial_action
2145 b4_dollar_popdef])[]dnl
2147 switch (YYSETJMP (this->yyexception_buffer))
2149 case 0: break;
2150 case 1: goto yyabortlab;
2151 case 2: goto yyexhaustedlab;
2152 default: goto yybuglab;
2154 this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2155 yyposn = 0;
2157 while (true)
2159 /* For efficiency, we have two loops, the first of which is
2160 specialized to deterministic operation (single stack, no
2161 potential ambiguity). */
2162 /* Standard mode */
2163 while (true)
2165 const state_num yystate = this->firstTopState()->yylrState;
2166 YYCDEBUG << "Entering state " << yystate << '\n';
2167 if (yystate == YYFINAL)
2168 goto yyacceptlab;
2169 if (yy_is_defaulted_state (yystate))
2171 const rule_num yyrule = yy_default_action (yystate);
2172 if (yyrule == 0)
2173 {]b4_locations_if([[
2174 this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[
2175 this->yyreportSyntaxError ();
2176 goto yyuser_error;
2178 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule, true));
2180 else
2182 yyget_token ();
2183 const short* yyconflicts;
2184 const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
2185 if (*yyconflicts != 0)
2186 break;
2187 if (yy_is_shift_action (yyaction))
2189 YY_SYMBOL_PRINT ("Shifting", this->yyla.kind (), this->yyla.value, this->yyla.location);
2190 yyposn += 1;
2191 // FIXME: we should move yylval.
2192 this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2193 yyla.clear ();
2194 if (0 < this->yyerrState)
2195 this->yyerrState -= 1;
2197 else if (yy_is_error_action (yyaction))
2198 {]b4_locations_if([[
2199 this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[
2200 /* Don't issue an error message again for exceptions
2201 thrown from the scanner. */
2202 if (this->yyla.kind () != ]b4_symbol(error, kind)[)
2203 this->yyreportSyntaxError ();
2204 goto yyuser_error;
2206 else
2207 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction, true));
2211 while (true)
2213 for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys)
2214 this->yystateStack.yytops.setLookaheadNeeds(yys, !this->yyla.empty ());
2216 /* yyprocessOneStack returns one of three things:
2218 - An error flag. If the caller is yyprocessOneStack, it
2219 immediately returns as well. When the caller is finally
2220 yyparse, it jumps to an error label via YYCHK1.
2222 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2223 (yys), which sets the top state of yys to NULL. Thus,
2224 yyparse's following invocation of yyremoveDeletes will remove
2225 the stack.
2227 - yyok, when ready to shift a token.
2229 Except in the first case, yyparse will invoke yyremoveDeletes and
2230 then shift the next token onto all remaining stacks. This
2231 synchronization of the shift (that is, after all preceding
2232 reductions on all stacks) helps prevent double destructor calls
2233 on yylval in the event of memory exhaustion. */
2235 for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
2236 YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yyla.location])[));
2237 this->yystateStack.yytops.yyremoveDeletes ();
2238 if (this->yystateStack.yytops.size() == 0)
2240 this->yystateStack.yytops.yyundeleteLastStack ();
2241 if (this->yystateStack.yytops.size() == 0)
2242 this->yyFail (]b4_locations_if([&this->yyla.location, ])[YY_("syntax error"));
2243 YYCHK1 (this->yyresolveStack ());
2244 YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[
2245 this->yyerror_range[1].getState ().yyloc = this->yyla.location;]])[
2246 this->yyreportSyntaxError ();
2247 goto yyuser_error;
2250 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2251 a copy of yylval will already be on stack 0 in the event of a
2252 failure in the following loop. Thus, yyla is emptied
2253 before the loop to make sure the user destructor for yylval isn't
2254 called twice. */
2255 symbol_kind_type yytoken_to_shift = this->yyla.kind ();
2256 this->yyla.kind_ = ]b4_symbol(empty, kind)[;
2257 yyposn += 1;
2258 for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
2260 const state_num yystate = this->topState (yys)->yylrState;
2261 const short* yyconflicts;
2262 const int yyaction = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
2263 /* Note that yyconflicts were handled by yyprocessOneStack. */
2264 YYCDEBUG << "On stack " << yys.get() << ", ";
2265 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yyla.value, this->yyla.location);
2266 this->yyglrShift (yys, yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
2267 YYCDEBUG << "Stack " << yys.get() << " now in state "
2268 << this->topState(yys)->yylrState << '\n';
2270 ]b4_variant_if([[
2271 // FIXME: User destructors.
2272 // Value type destructor.
2273 ]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[
2275 if (this->yystateStack.yytops.size () == 1)
2277 YYCHK1 (this->yyresolveStack ());
2278 YYCDEBUG << "Returning to deterministic operation.\n";
2279 this->yystateStack.yycompressStack ();
2280 break;
2283 continue;
2284 yyuser_error:
2285 this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla.location])[);
2286 yyposn = this->firstTopState()->yyposn;
2289 yyacceptlab:
2290 yyresult = 0;
2291 goto yyreturn;
2293 yybuglab:
2294 YYASSERT (false);
2295 goto yyabortlab;
2297 yyabortlab:
2298 yyresult = 1;
2299 goto yyreturn;
2301 yyexhaustedlab:
2302 yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("memory exhausted"));
2303 yyresult = 2;
2304 goto yyreturn;
2306 yyreturn:
2307 return yyresult;
2309 #undef YYCHK1
2311 void yyreserveGlrStack ()
2313 if (!yystateStack.yyexpandGLRStackIfNeeded ())
2314 yyMemoryExhausted ();
2317 _Noreturn void
2318 yyMemoryExhausted ()
2320 YYLONGJMP (yyexception_buffer, 2);
2323 _Noreturn void
2324 yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg)
2326 if (yymsg != YY_NULLPTR)
2327 yyparser.error (]b4_locations_if([*yylocp, ])[yymsg);
2328 YYLONGJMP (yyexception_buffer, 1);
2331 /* GLRStates */
2334 /** Add a new semantic action that will execute the action for rule
2335 * YYRULE on the semantic values in YYRHS to the list of
2336 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2337 * stack #YYK of *this. */
2338 void
2339 yyaddDeferredAction (state_set_index yyk, glr_state* yystate,
2340 glr_state* yyrhs, rule_num yyrule)
2342 semantic_option& yynewOption =
2343 yystateStack.yynewSemanticOption (semantic_option (yyrule));
2344 yynewOption.setState(yyrhs);
2345 yynewOption.setNext(yystate->firstVal());
2346 if (yystateStack.yytops.lookaheadNeeds(yyk))
2348 yynewOption.yytoken = this->yyla.kind ();]b4_variant_if([[
2349 ]b4_symbol_variant([this->yyla.kind ()],
2350 [yynewOption.yyval], [copy], [this->yyla.value])], [[
2351 yynewOption.yyval = this->yyla.value;]])[]b4_locations_if([
2352 yynewOption.yyloc = this->yyla.location;])[
2354 yystate->setFirstVal (&yynewOption);
2356 yyreserveGlrStack ();
2359 #if ]b4_api_PREFIX[DEBUG
2360 void yypdumpstack () const
2362 yystateStack.dumpStack();
2364 #endif
2366 void
2367 yyreportSyntaxError ()
2369 if (yyerrState != 0)
2370 return;
2371 ]b4_parse_error_case(
2372 [simple], [[
2373 std::string msg = YY_("syntax error");
2374 yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]],
2375 [custom], [[
2376 context yyctx (*this, yyla);
2377 yyparser.report_syntax_error (yyctx);]],
2379 context yyctx (*this, yyla);
2380 std::string msg = yyparser.yysyntax_error_ (yyctx);
2381 yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[
2382 yyerrcnt += 1;
2385 /* Recover from a syntax error on this, assuming that yytoken,
2386 yylval, and yylloc are the syntactic category, semantic value, and location
2387 of the lookahead. */
2388 void
2389 yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[)
2391 if (yyerrState == 3)
2392 /* We just shifted the error token and (perhaps) took some
2393 reductions. Skip tokens until we can proceed. */
2394 while (true)
2396 if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
2397 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2398 if (this->yyla.kind () != ]b4_symbol(empty, kind)[)
2399 {]b4_locations_if([[
2400 /* We throw away the lookahead, but the error range
2401 of the shifted error token must take it into account. */
2402 glr_state *yys = firstTopState();
2403 yyerror_range[1].getState().yyloc = yys->yyloc;
2404 yyerror_range[2].getState().yyloc = this->yyla.location;
2405 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2406 yyparser.yy_destroy_ ("Error: discarding",
2407 this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);]b4_variant_if([[
2408 // Value type destructor.
2409 ]b4_symbol_variant([[this->yyla.kind ()]], [[this->yyla.value]], [[template destroy]])])[
2410 this->yyla.kind_ = ]b4_symbol(empty, kind)[;
2412 yyget_token ();
2413 int yyj = yypact[firstTopState()->yylrState];
2414 if (yypact_value_is_default (yyj))
2415 return;
2416 yyj += this->yyla.kind ();
2417 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yyla.kind ())
2419 if (yydefact[firstTopState()->yylrState] != 0)
2420 return;
2422 else if (! yytable_value_is_error (yytable[yyj]))
2423 return;
2426 if (!yystateStack.reduceToOneStack())
2427 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2429 /* Now pop stack until we find a state that shifts the error token. */
2430 yyerrState = 3;
2431 while (firstTopState () != YY_NULLPTR)
2433 glr_state *yys = firstTopState ();
2434 int yyj = yypact[yys->yylrState];
2435 if (! yypact_value_is_default (yyj))
2437 yyj += YYTERROR;
2438 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2439 && yy_is_shift_action (yytable[yyj]))
2441 /* Shift the error token. */]b4_locations_if([[
2442 /* First adjust its location.*/
2443 location_type yyerrloc;
2444 yyerror_range[2].getState().yyloc = this->yyla.location;
2445 YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
2446 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
2447 this->yyla.value, yyerrloc);
2448 yyglrShift (create_state_set_index(0), yytable[yyj],
2449 yys->yyposn, yyla.value]b4_locations_if([, yyerrloc])[);
2450 yys = firstTopState();
2451 break;
2453 }]b4_locations_if([[
2454 yyerror_range[1].getState().yyloc = yys->yyloc;]])[
2455 if (yys->pred() != YY_NULLPTR)
2456 yys->destroy ("Error: popping", yyparser);
2457 yystateStack.setFirstTop(yys->pred());
2458 yystateStack.pop_back();
2460 if (firstTopState() == YY_NULLPTR)
2461 yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
2464 YYRESULTTAG
2465 yyprocessOneStack (state_set_index yyk,
2466 size_t yyposn]b4_locations_if([, location_type* yylocp])[)
2468 while (yystateStack.topAt(yyk) != YY_NULLPTR)
2470 const state_num yystate = topState(yyk)->yylrState;
2471 YYCDEBUG << "Stack " << yyk.get()
2472 << " Entering state " << yystate << '\n';
2474 YYASSERT (yystate != YYFINAL);
2476 if (yy_is_defaulted_state (yystate))
2478 const rule_num yyrule = yy_default_action (yystate);
2479 if (yyrule == 0)
2481 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2482 yystateStack.yytops.yymarkStackDeleted (yyk);
2483 return yyok;
2485 const YYRESULTTAG yyflag
2486 = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]);
2487 if (yyflag == yyerr)
2489 YYCDEBUG << "Stack " << yyk.get() << " dies"
2490 " (predicate failure or explicit user error).\n";
2491 yystateStack.yytops.yymarkStackDeleted (yyk);
2492 return yyok;
2494 if (yyflag != yyok)
2495 return yyflag;
2497 else
2499 yystateStack.yytops.setLookaheadNeeds(yyk, true);
2500 yyget_token ();
2501 const short* yyconflicts;
2502 const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
2504 for (; *yyconflicts != 0; ++yyconflicts)
2506 state_set_index yynewStack = yystateStack.yysplitStack (yyk);
2507 YYCDEBUG << "Splitting off stack " << yynewStack.get()
2508 << " from " << yyk.get() << ".\n";
2509 YYRESULTTAG yyflag =
2510 yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]);
2511 if (yyflag == yyok)
2512 YYCHK (yyprocessOneStack (yynewStack,
2513 yyposn]b4_locations_if([, yylocp])[));
2514 else if (yyflag == yyerr)
2516 YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n";
2517 yystateStack.yytops.yymarkStackDeleted (yynewStack);
2519 else
2520 return yyflag;
2523 if (yy_is_shift_action (yyaction))
2524 break;
2525 else if (yy_is_error_action (yyaction))
2527 YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
2528 yystateStack.yytops.yymarkStackDeleted (yyk);
2529 break;
2531 else
2533 YYRESULTTAG yyflag
2534 = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]);
2535 if (yyflag == yyerr)
2537 YYCDEBUG << "Stack " << yyk.get() << " dies"
2538 " (predicate failure or explicit user error).\n";
2539 yystateStack.yytops.yymarkStackDeleted (yyk);
2540 break;
2542 else if (yyflag != yyok)
2543 return yyflag;
2547 return yyok;
2550 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2551 * and top stack item YYVSP. YYVALP points to place to put semantic
2552 * value ($$), and yylocp points to place for location information
2553 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2554 * yyerr for YYERROR, yyabort for YYABORT. */
2555 YYRESULTTAG
2556 yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk,
2557 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2559 bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit();
2560 int yylow = 1;
2561 ]b4_parse_param_use([yyvalp], [yylocp])dnl
2562 [ YY_USE (yyk);
2563 YY_USE (yyrhslen);
2564 # undef yyerrok
2565 # define yyerrok (yyerrState = 0)
2566 # undef YYACCEPT
2567 # define YYACCEPT return yyaccept
2568 # undef YYABORT
2569 # define YYABORT return yyabort
2570 # undef YYERROR
2571 # define YYERROR return yyerrok, yyerr
2572 # undef YYRECOVERING
2573 # define YYRECOVERING() (yyerrState != 0)
2574 # undef yytoken
2575 # define yytoken this->yyla.kind_
2576 # undef yyclearin
2577 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2578 # undef YYBACKUP
2579 # define YYBACKUP(Token, Value) \
2580 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2581 yyerrok, yyerr
2583 ]b4_variant_if([[
2584 /* Variants are always initialized to an empty instance of the
2585 correct type. The default '$$ = $1' action is NOT applied
2586 when using variants. */
2587 // However we really need to prepare yyvsp now if we want to get
2588 // correct locations, so invoke YYFILL for $1 anyway.
2589 (void) YYFILL (1-yyrhslen);
2590 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[
2591 if (yyrhslen == 0)
2592 *yyvalp = yyval_default;
2593 else
2594 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[
2595 /* Default location. */
2596 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
2597 yyerror_range[1].getState().yyloc = *yylocp;
2598 ]])[
2599 /* If yyk == -1, we are running a deferred action on a temporary
2600 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2601 so pretend the stack is "normal". */
2602 YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser));
2603 #if YY_EXCEPTIONS
2606 #endif // YY_EXCEPTIONS
2607 switch (yyrule)
2609 ]b4_user_actions[
2610 default: break;
2612 #if YY_EXCEPTIONS
2614 catch (const syntax_error& yyexc)
2616 YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([
2617 *yylocp = yyexc.location;])[
2618 yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ());
2619 YYERROR;
2621 #endif // YY_EXCEPTIONS
2622 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp);
2624 return yyok;
2625 # undef yyerrok
2626 # undef YYABORT
2627 # undef YYACCEPT
2628 # undef YYERROR
2629 # undef YYBACKUP
2630 # undef yytoken
2631 # undef yyclearin
2632 # undef YYRECOVERING
2635 YYRESULTTAG
2636 yyresolveStack ()
2638 if (yystateStack.isSplit ())
2640 int yyn = 0;
2641 for (glr_state* yys = firstTopState ();
2642 yys != yystateStack.yysplitPoint;
2643 yys = yys->pred ())
2644 yyn += 1;
2645 YYCHK (yyresolveStates (*firstTopState (), yyn));
2647 return yyok;
2650 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2651 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2652 * semantic values. Assumes that all ambiguities in semantic values
2653 * have been previously resolved. Set *YYVALP to the resulting value,
2654 * and *YYLOCP to the computed location (if any). Return value is as
2655 * for userAction. */
2656 YYRESULTTAG
2657 yydoAction (state_set_index yyk, rule_num yyrule,
2658 value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2660 const int yynrhs = yyrhsLength (yyrule);
2662 if (!yystateStack.isSplit())
2664 /* Standard special case: single stack. */
2665 YYASSERT (yyk.get() == 0);
2666 glr_stack_item* yyrhs = yystateStack.firstTop()->asItem();
2667 const YYRESULTTAG res
2668 = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[);
2669 yystateStack.pop_back(static_cast<size_t>(yynrhs));
2670 yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState());
2671 return res;
2673 else
2675 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
2676 glr_state* yys = yystateStack.topAt(yyk);
2677 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[
2678 if (yynrhs == 0)
2679 /* Set default location. */
2680 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[
2681 for (int yyi = 0; yyi < yynrhs; yyi += 1)
2683 yys = yys->pred();
2684 YYASSERT (yys != YY_NULLPTR);
2686 yystateStack.yyupdateSplit (*yys);
2687 yystateStack.setTopAt(yyk, yys);
2688 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
2689 yyk,
2690 yyvalp]b4_locations_if([, yylocp])[);
2694 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2695 * and push back on the resulting nonterminal symbol. Perform the
2696 * semantic action associated with YYRULE and store its value with the
2697 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2698 * unambiguous. Otherwise, store the deferred semantic action with
2699 * the new state. If the new state would have an identical input
2700 * position, LR state, and predecessor to an existing state on the stack,
2701 * it is identified with that existing state, eliminating stack #YYK from
2702 * *YYSTACKP. In this case, the semantic value is
2703 * added to the options for the existing state's semantic value.
2705 YYRESULTTAG
2706 yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval)
2708 size_t yyposn = topState(yyk)->yyposn;
2710 if (yyforceEval || !yystateStack.isSplit())
2712 value_type val;]b4_locations_if([[
2713 location_type loc;]])[
2715 YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[);
2716 if (yyflag == yyerr && yystateStack.isSplit())
2717 {]b4_parse_trace_if([[
2718 YYCDEBUG << "Parse on stack " << yyk.get ()
2719 << " rejected by rule " << yyrule - 1
2720 << " (line " << int (yyrline[yyrule]) << ").\n";
2721 ]])[}
2722 if (yyflag != yyok)
2723 return yyflag;
2724 yyglrShift (yyk,
2725 yyLRgotoState (topState(yyk)->yylrState,
2726 yylhsNonterm (yyrule)),
2727 yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[
2728 // FIXME: User destructors.
2729 // Value type destructor.
2730 ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[
2732 else
2734 glr_state *yys = yystateStack.topAt(yyk);
2735 glr_state *yys0 = yys;
2736 for (int yyn = yyrhsLength (yyrule); 0 < yyn; yyn -= 1)
2738 yys = yys->pred();
2739 YYASSERT (yys != YY_NULLPTR);
2741 yystateStack.yyupdateSplit (*yys);
2742 state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[
2743 YYCDEBUG << "Reduced stack " << yyk.get ()
2744 << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule])
2745 << "); action deferred. Now in state " << yynewLRState
2746 << ".\n";]])[
2747 for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi)
2748 if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR)
2750 const glr_state* yysplit = yystateStack.yysplitPoint;
2751 glr_state* yyp = yystateStack.topAt(yyi);
2752 while (yyp != yys && yyp != yysplit
2753 && yyp->yyposn >= yyposn)
2755 if (yyp->yylrState == yynewLRState
2756 && yyp->pred() == yys)
2758 yyaddDeferredAction (yyk, yyp, yys0, yyrule);
2759 yystateStack.yytops.yymarkStackDeleted (yyk);
2760 YYCDEBUG << "Merging stack " << yyk.get ()
2761 << " into stack " << yyi.get () << ".\n";
2762 return yyok;
2764 yyp = yyp->pred();
2767 yystateStack.setTopAt(yyk, yys);
2768 yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule);
2770 return yyok;
2773 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2774 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2775 * semantic value of YYRHS under the action for YYRULE. */
2776 void
2777 yyglrShiftDefer (state_set_index yyk, state_num yylrState,
2778 size_t yyposn, glr_state* yyrhs, rule_num yyrule)
2780 glr_state& yynewState = yystateStack.yynewGLRState (
2781 glr_state (yylrState, yyposn));
2782 yynewState.setPred (yystateStack.topAt (yyk));
2783 yystateStack.setTopAt (yyk, &yynewState);
2785 /* Invokes yyreserveStack. */
2786 yyaddDeferredAction (yyk, &yynewState, yyrhs, yyrule);
2789 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2790 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2791 * value YYVAL_ARG and source location YYLOC_ARG. */
2792 void
2793 yyglrShift (state_set_index yyk, state_num yylrState,
2794 size_t yyposn,
2795 const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[)
2797 glr_state& yynewState = yystateStack.yynewGLRState (
2798 glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[));
2799 yynewState.setPred (yystateStack.topAt(yyk));
2800 yystateStack.setTopAt (yyk, &yynewState);
2801 yyreserveGlrStack ();
2804 #if ]b4_api_PREFIX[DEBUG
2805 void
2806 yypstack (state_set_index yyk) const
2808 yystateStack.yypstates (yystateStack.topAt (yyk));
2810 #endif
2812 glr_state* topState(state_set_index i) {
2813 return yystateStack.topAt(i);
2816 glr_state* firstTopState() {
2817 return yystateStack.firstTop();
2820 private:
2822 void popall_ ()
2824 /* If the stack is well-formed, pop the stack until it is empty,
2825 destroying its entries as we go. But free the stack regardless
2826 of whether it is well-formed. */
2827 for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); k += 1)
2828 if (yystateStack.topAt(k) != YY_NULLPTR)
2830 while (yystateStack.topAt(k) != YY_NULLPTR)
2832 glr_state* state = topState(k);]b4_locations_if([[
2833 yyerror_range[1].getState().yyloc = state->yyloc;]])[
2834 if (state->pred() != YY_NULLPTR)
2835 state->destroy ("Cleanup: popping", yyparser);
2836 yystateStack.setTopAt(k, state->pred());
2837 yystateStack.pop_back();
2839 break;
2843 /** Resolve the previous YYN states starting at and including state YYS
2844 * on *YYSTACKP. If result != yyok, some states may have been left
2845 * unresolved possibly with empty semantic option chains. Regardless
2846 * of whether result = yyok, each state has been left with consistent
2847 * data so that destroy can be invoked if necessary. */
2848 YYRESULTTAG
2849 yyresolveStates (glr_state& yys, int yyn)
2851 if (0 < yyn)
2853 YYASSERT (yys.pred() != YY_NULLPTR);
2854 YYCHK (yyresolveStates (*yys.pred(), yyn-1));
2855 if (! yys.yyresolved)
2856 YYCHK (yyresolveValue (yys));
2858 return yyok;
2861 static void
2862 yyuserMerge (int yyn, value_type& yy0, value_type& yy1)
2864 YY_USE (yy0);
2865 YY_USE (yy1);
2867 switch (yyn)
2869 ]b4_mergers[
2870 default: break;
2874 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2875 * perform the indicated actions, and set the semantic value of YYS.
2876 * If result != yyok, the chain of semantic options in YYS has been
2877 * cleared instead or it has been left unmodified except that
2878 * redundant options may have been removed. Regardless of whether
2879 * result = yyok, YYS has been left with consistent data so that
2880 * destroy can be invoked if necessary. */
2881 YYRESULTTAG
2882 yyresolveValue (glr_state& yys)
2884 semantic_option* yybest = yys.firstVal();
2885 YYASSERT(yybest != YY_NULLPTR);
2886 bool yymerge = false;
2887 YYRESULTTAG yyflag;]b4_locations_if([
2888 location_type *yylocp = &yys.yyloc;])[
2890 semantic_option* yypPrev = yybest;
2891 for (semantic_option* yyp = yybest->next();
2892 yyp != YY_NULLPTR; )
2894 if (yybest->isIdenticalTo (*yyp))
2896 yybest->mergeWith (*yyp);
2897 yypPrev->setNext(yyp->next());
2898 yyp = yypPrev->next();
2900 else
2902 switch (yypreference (*yybest, *yyp))
2904 case 0:]b4_locations_if([[
2905 yyresolveLocations (yys, 1);]])[
2906 return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[);
2907 break;
2908 case 1:
2909 yymerge = true;
2910 break;
2911 case 2:
2912 break;
2913 case 3:
2914 yybest = yyp;
2915 yymerge = false;
2916 break;
2917 default:
2918 /* This cannot happen so it is not worth a YYASSERT (false),
2919 but some compilers complain if the default case is
2920 omitted. */
2921 break;
2923 yypPrev = yyp;
2924 yyp = yyp->next();
2928 value_type val;
2929 if (yymerge)
2931 int yyprec = yydprec[yybest->yyrule];
2932 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2933 if (yyflag == yyok)
2934 for (semantic_option* yyp = yybest->next();
2935 yyp != YY_NULLPTR;
2936 yyp = yyp->next())
2938 if (yyprec == yydprec[yyp->yyrule])
2940 value_type yyval_other;]b4_locations_if([
2941 location_type yydummy;])[
2942 yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[);
2943 if (yyflag != yyok)
2945 yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2946 yy_accessing_symbol (yys.yylrState),
2947 this->yyla.value]b4_locations_if([, *yylocp])[);
2948 break;
2950 yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
2951 // FIXME: User destructors.
2952 // Value type destructor.
2953 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[
2957 else
2958 yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[);
2960 if (yyflag == yyok)
2962 yys.yyresolved = true;
2963 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[
2964 new (&yys.value ()) value_type ();
2965 ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)],
2966 [yys.value ()], [copy], [val])], [[
2967 new (&yys.value ()) value_type (val);]])[
2969 YY_IGNORE_MAYBE_UNINITIALIZED_END
2971 else
2972 yys.setFirstVal(YY_NULLPTR);
2973 ]b4_variant_if([[
2974 // FIXME: User destructors.
2975 // Value type destructor.
2976 ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[
2977 return yyflag;
2980 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2981 * user action, and return the semantic value and location in *YYVALP
2982 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2983 * have been destroyed (assuming the user action destroys all RHS
2984 * semantic values if invoked). */
2985 YYRESULTTAG
2986 yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
2988 glr_state* yyoptState = yyopt.state();
2989 YYASSERT(yyoptState != YY_NULLPTR);
2990 int yynrhs = yyrhsLength (yyopt.yyrule);
2991 YYRESULTTAG yyflag = yyresolveStates (*yyoptState, yynrhs);
2992 if (yyflag != yyok)
2994 for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1)
2995 yys->destroy ("Cleanup: popping", yyparser);
2996 return yyflag;
2999 glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
3000 yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[
3001 if (yynrhs == 0)
3002 /* Set default location. */
3003 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
3005 symbol_type yyla_current = std::move (this->yyla);
3006 this->yyla.kind_ = yyopt.yytoken;]b4_variant_if([[
3007 ]b4_symbol_variant([this->yyla.kind ()],
3008 [this->yyla.value], [move], [yyopt.yyval])], [[
3009 this->yyla.value = yyopt.yyval;]])[]b4_locations_if([
3010 this->yyla.location = yyopt.yyloc;])[
3011 yyflag = yyuserAction (yyopt.yyrule, yynrhs,
3012 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
3013 create_state_set_index (-1),
3014 yyvalp]b4_locations_if([, yylocp])[);
3016 this->yyla = std::move (yyla_current);
3018 return yyflag;
3019 }]b4_locations_if([[
3021 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
3022 * ending at YYS1. Has no effect on previously resolved states.
3023 * The first semantic option of a state is always chosen. */
3024 void
3025 yyresolveLocations (glr_state &yys1, int yyn1)
3027 if (0 < yyn1)
3029 yyresolveLocations (*yys1.pred(), yyn1 - 1);
3030 if (!yys1.yyresolved)
3032 glr_stack_item yyrhsloc[1 + YYMAXRHS];
3033 YYASSERT (yys1.firstVal() != YY_NULLPTR);
3034 semantic_option& yyoption = *yys1.firstVal();
3035 const int yynrhs = yyrhsLength (yyoption.yyrule);
3036 if (0 < yynrhs)
3038 yyresolveLocations (*yyoption.state(), yynrhs);
3039 const glr_state *yys = yyoption.state();
3040 for (int yyn = yynrhs; yyn > 0; yyn -= 1)
3042 yyrhsloc[yyn].getState().yyloc = yys->yyloc;
3043 yys = yys->pred();
3046 else
3048 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3049 in reverse rightmost order. It is only necessary to invoke
3050 yyresolveLocations on a subforest for which yyresolveAction
3051 would have been invoked next had an ambiguity not been
3052 detected. Thus the location of the previous state (but not
3053 necessarily the previous state itself) is guaranteed to be
3054 resolved already. */
3055 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3056 yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc;
3057 YY_IGNORE_NULL_DEREFERENCE_END
3059 YYLLOC_DEFAULT ((yys1.yyloc), yyrhsloc, yynrhs);
3062 }]])[
3064 /** If yytoken is empty, fetch the next token. */
3065 void
3066 yyget_token ()
3068 ]b4_parse_param_use()dnl
3069 [ if (this->yyla.empty ())
3071 YYCDEBUG << "Reading a token\n";
3072 #if YY_EXCEPTIONS
3074 #endif // YY_EXCEPTIONS
3075 {]b4_token_ctor_if([[
3076 symbol_type yylookahead (]b4_yylex[);
3077 yyla.move (yylookahead);]], [[
3078 yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[
3080 #if YY_EXCEPTIONS
3081 catch (const parser_type::syntax_error& yyexc)
3083 YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
3084 this->yyla.location = yyexc.location;])[
3085 yyparser.error (]b4_locations_if([this->yyla.location, ])[yyexc.what ());
3086 // Map errors caught in the scanner to the error token, so that error
3087 // handling is started.
3088 this->yyla.kind_ = ]b4_symbol(error, kind)[;
3091 #endif // YY_EXCEPTIONS
3092 if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
3093 YYCDEBUG << "Now at end of input.\n";
3094 else
3095 YY_SYMBOL_PRINT ("Next token is", this->yyla.kind (), this->yyla.value, this->yyla.location);
3099 /* Bison grammar-table manipulation. */
3101 /** The action to take in YYSTATE on seeing YYTOKEN.
3102 * Result R means
3103 * R < 0: Reduce on rule -R.
3104 * R = 0: Error.
3105 * R > 0: Shift to state R.
3106 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3107 * of conflicting reductions.
3109 static int
3110 yygetLRActions (state_num yystate, symbol_kind_type yytoken, const short*& yyconflicts)
3112 int yyindex = yypact[yystate] + yytoken;
3113 if (yytoken == ]b4_symbol(error, kind)[)
3115 // This is the error token.
3116 yyconflicts = yyconfl;
3117 return 0;
3119 else if (yy_is_defaulted_state (yystate)
3120 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
3122 yyconflicts = yyconfl;
3123 return -yydefact[yystate];
3125 else if (! yytable_value_is_error (yytable[yyindex]))
3127 yyconflicts = yyconfl + yyconflp[yyindex];
3128 return yytable[yyindex];
3130 else
3132 yyconflicts = yyconfl + yyconflp[yyindex];
3133 return 0;
3137 /** Compute post-reduction state.
3138 * \param yystate the current state
3139 * \param yysym the nonterminal to push on the stack
3141 static state_num
3142 yyLRgotoState (state_num yystate, symbol_kind_type yysym)
3144 const int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
3145 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
3146 return yytable[yyr];
3147 else
3148 return yydefgoto[yysym - YYNTOKENS];
3151 static bool
3152 yypact_value_is_default (state_num yystate)
3154 return ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf], [YYPACT_NINF])[;
3157 static bool
3158 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED)
3160 return ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[;
3163 static bool
3164 yy_is_shift_action (int yyaction)
3166 return 0 < yyaction;
3169 static bool
3170 yy_is_error_action (int yyaction)
3172 return yyaction == 0;
3175 /** Whether LR state YYSTATE has only a default reduction
3176 * (regardless of token). */
3177 static bool
3178 yy_is_defaulted_state (state_num yystate)
3180 return yypact_value_is_default (yypact[yystate]);
3183 /** The default reduction for YYSTATE, assuming it has one. */
3184 static rule_num
3185 yy_default_action (state_num yystate)
3187 return yydefact[yystate];
3190 /* GLRStacks */
3192 /** Y0 and Y1 represent two possible actions to take in a given
3193 * parsing state; return 0 if no combination is possible,
3194 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3195 static int
3196 yypreference (const semantic_option& y0, const semantic_option& y1)
3198 const rule_num r0 = y0.yyrule, r1 = y1.yyrule;
3199 const int p0 = yydprec[r0], p1 = yydprec[r1];
3201 if (p0 == p1)
3203 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
3204 return 0;
3205 else
3206 return 1;
3208 else if (p0 == 0 || p1 == 0)
3209 return 0;
3210 else if (p0 < p1)
3211 return 3;
3212 else if (p1 < p0)
3213 return 2;
3214 else
3215 return 0;
3218 ]b4_parse_param_vars[
3219 }; // class ]b4_parser_class[::glr_stack
3220 } // namespace ]b4_namespace_ref[
3223 #if ]b4_api_PREFIX[DEBUG
3224 namespace
3226 void
3227 yypstack (const glr_stack& yystack, size_t yyk)
3229 yystack.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk)));
3232 void
3233 yypdumpstack (const glr_stack& yystack)
3235 yystack.yypdumpstack ();
3238 #endif
3240 ]b4_namespace_open[
3241 /// Build a parser object.
3242 ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
3243 :])[
3244 #if ]b4_api_PREFIX[DEBUG
3245 ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
3246 #endif]b4_parse_param_cons[
3249 ]b4_parser_class::~b4_parser_class[ ()
3252 ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3256 ]b4_parser_class[::operator() ()
3258 return parse ();
3262 ]b4_parser_class[::parse ()
3264 glr_stack yystack(YYINITDEPTH, *this]b4_user_args[);
3265 return yystack.parse ();
3268 ]b4_parse_error_bmatch([custom\|detailed],
3269 [[ const char *
3270 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3272 static const char *const yy_sname[] =
3274 ]b4_symbol_names[
3275 };]b4_has_translations_if([[
3276 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3277 internationalizable. */
3278 static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
3280 ]b4_translatable[
3282 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
3283 ? _(yy_sname[yysymbol])
3284 : yy_sname[yysymbol]);]], [[
3285 return yy_sname[yysymbol];]])[
3288 [simple],
3289 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3290 const char *
3291 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3293 return yytname_[yysymbol];
3295 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3297 [verbose],
3298 [[ /* Return YYSTR after stripping away unnecessary quotes and
3299 backslashes, so that it's suitable for yyerror. The heuristic is
3300 that double-quoting is unnecessary unless the string contains an
3301 apostrophe, a comma, or backslash (other than backslash-backslash).
3302 YYSTR is taken from yytname. */
3303 std::string
3304 ]b4_parser_class[::yytnamerr_ (const char *yystr)
3306 if (*yystr == '"')
3308 std::string yyr;
3309 char const *yyp = yystr;
3311 for (;;)
3312 switch (*++yyp)
3314 case '\'':
3315 case ',':
3316 goto do_not_strip_quotes;
3318 case '\\':
3319 if (*++yyp != '\\')
3320 goto do_not_strip_quotes;
3321 else
3322 goto append;
3324 append:
3325 default:
3326 yyr += *yyp;
3327 break;
3329 case '"':
3330 return yyr;
3332 do_not_strip_quotes: ;
3335 return yystr;
3338 std::string
3339 ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
3341 return yytnamerr_ (yytname_[yysymbol]);
3343 ]])[
3345 ]b4_parse_error_bmatch([simple\|verbose],
3346 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3347 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3348 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3349 const char*
3350 const ]b4_parser_class[::yytname_[] =
3352 ]b4_tname[
3354 #endif
3355 ]])[
3357 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
3358 // ]b4_parser_class[::context.
3359 ]b4_parser_class[::context::context (glr_stack& yystack, const symbol_type& yyla)
3360 : yystack_ (yystack)
3361 , yyla_ (yyla)
3365 ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const
3367 // Actual number of expected tokens
3368 int yycount = 0;
3369 const int yyn = yypact[yystack_.firstTopState()->yylrState];
3370 if (!yystack_.yypact_value_is_default (yyn))
3372 /* Start YYX at -YYN if negative to avoid negative indexes in
3373 YYCHECK. In other words, skip the first -YYN actions for this
3374 state because they are default actions. */
3375 const int yyxbegin = yyn < 0 ? -yyn : 0;
3376 /* Stay within bounds of both yycheck and yytname. */
3377 const int yychecklim = YYLAST - yyn + 1;
3378 const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
3379 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
3380 if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
3381 && !yystack_.yytable_value_is_error (yytable[yyx + yyn]))
3383 if (!yyarg)
3384 ++yycount;
3385 else if (yycount == yyargn)
3386 return 0;
3387 else
3388 yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx);
3391 if (yyarg && yycount == 0 && 0 < yyargn)
3392 yyarg[0] = ]b4_symbol(empty, kind)[;
3393 return yycount;
3396 ]])[
3398 ]b4_parse_error_bmatch([detailed\|verbose], [[
3400 ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx,
3401 symbol_kind_type yyarg[], int yyargn) const
3403 /* There are many possibilities here to consider:
3404 - If this state is a consistent state with a default action, then
3405 the only way this function was invoked is if the default action
3406 is an error action. In that case, don't check for expected
3407 tokens because there are none.
3408 - The only way there can be no lookahead present (in yyla) is
3409 if this state is a consistent state with a default action.
3410 Thus, detecting the absence of a lookahead is sufficient to
3411 determine that there is no unexpected or expected token to
3412 report. In that case, just report a simple "syntax error".
3413 - Don't assume there isn't a lookahead just because this state is
3414 a consistent state with a default action. There might have
3415 been a previous inconsistent state, consistent state with a
3416 non-default action, or user semantic action that manipulated
3417 yyla. (However, yyla is currently not documented for users.)
3420 if (!yyctx.lookahead ().empty ())
3422 if (yyarg)
3423 yyarg[0] = yyctx.token ();
3424 int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1);
3425 return yyn + 1;
3427 return 0;
3430 // Generate an error message.
3431 std::string
3432 ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const
3434 // Its maximum.
3435 enum { YYARGS_MAX = 5 };
3436 // Arguments of yyformat.
3437 symbol_kind_type yyarg[YYARGS_MAX];
3438 int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX);
3440 char const* yyformat = YY_NULLPTR;
3441 switch (yycount)
3443 #define YYCASE_(N, S) \
3444 case N: \
3445 yyformat = S; \
3446 break
3447 default: // Avoid compiler warnings.
3448 YYCASE_ (0, YY_("syntax error"));
3449 YYCASE_ (1, YY_("syntax error, unexpected %s"));
3450 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
3451 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
3452 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
3453 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
3454 #undef YYCASE_
3457 std::string yyres;
3458 // Argument number.
3459 std::ptrdiff_t yyi = 0;
3460 for (char const* yyp = yyformat; *yyp; ++yyp)
3461 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
3463 yyres += symbol_name (yyarg[yyi++]);
3464 ++yyp;
3466 else
3467 yyres += *yyp;
3468 return yyres;
3469 }]])[
3471 void
3472 ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
3473 value_type& yyval]b4_locations_if([[,
3474 location_type& yyloc]])[)
3476 YY_USE (yyval);]b4_locations_if([[
3477 YY_USE (yyloc);]])[
3478 if (!yymsg)
3479 yymsg = "Deleting";
3480 ]b4_parser_class[& yyparser = *this;
3481 YY_USE (yyparser);
3482 YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc);
3484 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3485 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3486 [b4_symbol_actions([destructor])],
3487 [m4_popdef([b4_symbol_action])])[
3488 YY_IGNORE_MAYBE_UNINITIALIZED_END
3491 #if ]b4_api_PREFIX[DEBUG
3492 /*--------------------.
3493 | Print this symbol. |
3494 `--------------------*/
3496 void
3497 ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
3498 const value_type& yyval]b4_locations_if([[,
3499 const location_type& yyloc]])[) const
3500 {]b4_locations_if([[
3501 YY_USE (yyloc);]])[
3502 YY_USE (yyval);
3503 std::ostream& yyo = debug_stream ();
3504 YY_USE (yyo);
3505 ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))],
3506 [b4_symbol_actions([printer])],
3507 [m4_popdef([b4_symbol_action])])[
3510 void
3511 ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
3512 const value_type& yyval]b4_locations_if([[,
3513 const location_type& yyloc]])[) const
3515 *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
3516 << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
3517 << yyloc << ": "]])[;
3518 yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[);
3519 *yycdebug_ << ')';
3522 std::ostream&
3523 ]b4_parser_class[::debug_stream () const
3525 return *yycdebug_;
3528 void
3529 ]b4_parser_class[::set_debug_stream (std::ostream& o)
3531 yycdebug_ = &o;
3535 ]b4_parser_class[::debug_level_type
3536 ]b4_parser_class[::debug_level () const
3538 return yydebug;
3541 void
3542 ]b4_parser_class[::set_debug_level (debug_level_type l)
3544 // Actually, it is yydebug which is really used.
3545 yydebug = l;
3547 #endif // ]b4_api_PREFIX[DEBUG
3549 ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[
3551 ]b4_token_ctor_if([], [[
3552 /*---------.
3553 | symbol. |
3554 `---------*/
3555 ]b4_public_types_define([cc])])[
3556 ]b4_namespace_close[]dnl
3557 b4_epilogue[]dnl
3558 b4_output_end