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
]]),
28 [b4_token_table_if([$
1],
31 b4_bison_locations_if([
32 m4_define([b4_location_constructors
])
33 m4_include(b4_skeletonsdir
/[location
.cc
])])
34 b4_variant_if([m4_include(b4_skeletonsdir
/[variant
.hh
])])
36 m4_define([b4_parser_class
],
37 [b4_percent_define_get([[api
.parser
.class]])])
39 ]m4_define([b4_define_symbol_kind
],
40 [m4_format([#define %-15s %s],
41 b4_symbol($
][1, kind_base
),
42 b4_namespace_ref
[::]b4_parser_class
[::symbol_kind::]b4_symbol($
1, kind_base
))
45 ## ---------------- ##
47 ## ---------------- ##
50 m4_define_default([b4_stack_depth_max
], [10000])
51 m4_define_default([b4_stack_depth_init
], [200])
61 # The possible parse-params formal arguments preceded by a comma.
63 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
64 # formal argument declarations.
65 m4_define([b4_user_formals
],
66 [m4_ifset([b4_parse_param
], [, b4_formals(b4_parse_param
)])])
71 m4_define([b4_symbol_kind
],
72 [symbol_kind::b4_symbol_kind_base($@
)])
75 ## ----------------- ##
76 ## Semantic Values. ##
77 ## ----------------- ##
80 # b4_lhs_value(SYMBOL-NUM, [TYPE])
81 # --------------------------------
83 m4_define([b4_lhs_value
],
84 [b4_symbol_value([(*yyvalp
)], [$
1], [$
2])])
87 # b4_rhs_data(RULE-LENGTH, POS)
88 # -----------------------------
90 m4_define([b4_rhs_data
],
91 [(static_cast<glr_stack_item
const *>(yyvsp
))@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.getState()])
94 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
95 # --------------------------------------------------
96 # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
97 m4_define([b4_rhs_value
],
98 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value ()], [$
3], [$
4])])
109 m4_define([b4_lhs_location
],
113 # b4_rhs_location(RULE-LENGTH, NUM)
114 # ---------------------------------
115 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
117 m4_define([b4_rhs_location
],
118 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
121 # b4_symbol_action(SYMBOL-NUM, KIND)
122 # ----------------------------------
123 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
124 # Same as in C, but using references instead of pointers.
126 # Currently we need two different b4_symbol_action: once for the
127 # self-contained symbols, and another time for yy_destroy_ and
128 # yy_symbol_value_print_, which don't use genuine symbols yet.
129 m4_define([b4_symbol_action],
130 [b4_symbol_if([$1], [has_$2],
131 [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
132 b4_dollar_pushdef([yysym.value],
136 _b4_symbol_case([$1])[]dnl
137 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
138 b4_symbol([$1], [$2])
139 b4_syncline([@oline@], [@ofile@])dnl
142 m4_popdef([b4_symbol_value])[]dnl
143 b4_dollar_popdef[]dnl
147 # b4_symbol_action_for_yyval(SYMBOL-NUM, KIND)
148 # --------------------------------------------
149 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
150 # Same as in C, but using references instead of pointers.
151 m4_define([b4_symbol_action_for_yyval],
152 [b4_symbol_if([$1], [has_$2],
153 [b4_dollar_pushdef([yyval],
157 _b4_symbol_case([$1])[]dnl
158 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
159 b4_symbol([$1], [$2])
160 b4_syncline([@oline@], [@ofile@])dnl
163 b4_dollar_popdef[]dnl
167 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
168 # ---------------------------------------------------
169 m4_define([b4_call_merger],
171 [ b4_symbol_if([$3], [has_type],
172 [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());],
173 [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])],
174 [yy0 = $2 (yy0, yy1);])])])
179 m4_define([b4_yylex],
181 [b4_function_call([yylex],
182 [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
183 [b4_function_call([yylex], [int],
184 [[value_type *], [&this->yylval]][]dnl
185 b4_locations_if([, [[location_type *], [&this->yylloc]]])dnl
186 m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
189 # b4_shared_declarations(hh|cc)
190 # -----------------------------
191 # Declaration that might either go into the header (if --header, $1 = hh)
192 # or in the implementation file.
193 m4_define([b4_shared_declarations],
194 [b4_percent_code_get([[requires]])[
196 #include <cstddef> // ptrdiff_t
197 #include <cstring> // memcpy
207 ]m4_ifdef([b4_location_include],
208 [[# include ]b4_location_include])[
209 ]b4_variant_if([b4_variant_includes])[
211 // Whether we are compiled with exception support.
212 #ifndef YY_EXCEPTIONS
213 # if defined __GNUC__ && !defined __EXCEPTIONS
214 # define YY_EXCEPTIONS 0
216 # define YY_EXCEPTIONS 1
224 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
225 [b4_location_define])])[
228 class ]b4_parser_class[
231 ]b4_public_types_declare[
232 ]b4_symbol_type_define[
234 /// Build a parser object.
235 ]b4_parser_class[ (]b4_parse_param_decl[);
236 ~]b4_parser_class[ ();
238 /// Parse. An alias for parse ().
239 /// \returns 0 iff parsing succeeded.
243 /// \returns 0 iff parsing succeeded.
246 #if ]b4_api_PREFIX[DEBUG
247 /// The current debugging stream.
248 std::ostream& debug_stream () const;
249 /// Set the current debugging stream.
250 void set_debug_stream (std::ostream &);
252 /// Type for debugging levels.
253 typedef int debug_level_type;
254 /// The current debugging level.
255 debug_level_type debug_level () const;
256 /// Set the current debugging level.
257 void set_debug_level (debug_level_type l);
260 /// Report a syntax error.]b4_locations_if([[
261 /// \param loc where the syntax error is found.]])[
262 /// \param msg a description of the syntax error.
263 void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
265 ]b4_parse_error_bmatch(
267 [[ /// The user-facing name of the symbol whose (internal) number is
268 /// YYSYMBOL. No bounds checking.
269 static const char *symbol_name (symbol_kind_type yysymbol);]],
271 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
272 /// The user-facing name of the symbol whose (internal) number is
273 /// YYSYMBOL. No bounds checking.
274 static const char *symbol_name (symbol_kind_type yysymbol);
275 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
278 [[ /// The user-facing name of the symbol whose (internal) number is
279 /// YYSYMBOL. No bounds checking.
280 static std::string symbol_name (symbol_kind_type yysymbol);]])[
282 ]b4_token_constructor_define[
283 # if ]b4_api_PREFIX[DEBUG
285 /// \brief Report a symbol value on the debug stream.
286 /// \param yykind The symbol kind.
287 /// \param yyval Its semantic value.]b4_locations_if([[
288 /// \param yyloc Its location.]])[
289 void yy_symbol_value_print_ (symbol_kind_type yykind,
290 const value_type& yyval]b4_locations_if([[,
291 const location_type& yyloc]])[) const;
292 /// \brief Report a symbol on the debug stream.
293 /// \param yykind The symbol kind.
294 /// \param yyval Its semantic value.]b4_locations_if([[
295 /// \param yyloc Its location.]])[
296 void yy_symbol_print_ (symbol_kind_type yykind,
297 const value_type& yyval]b4_locations_if([[,
298 const location_type& yyloc]])[) const;
301 std::ostream* yycdebug_;
304 public: // FIXME: Private
305 /// Convert a scanner token kind \a t to a symbol kind.
306 /// In theory \a t should be a token_kind_type, but character literals
307 /// are valid, yet not members of the token_type enum.
308 static symbol_kind_type yytranslate_ (int t);
310 ]b4_parse_error_bmatch(
312 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
313 /// For a symbol, its name in clear.
314 static const char* const yytname_[];
315 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
318 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
319 static std::string yytnamerr_ (const char *yystr);
321 /// For a symbol, its name in clear.
322 static const char* const yytname_[];
325 /// \brief Reclaim the memory associated to a symbol.
326 /// \param yymsg Why this token is reclaimed.
327 /// If null, print nothing.
328 /// \param yykind The symbol kind.
329 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
330 value_type& yyval]b4_locations_if([[,
331 location_type& yyloc]])[);
333 ]b4_parse_param_vars[
336 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
337 ]b4_public_types_define([$1])])[
340 ]b4_percent_code_get([[provides]])[
354 ]b4_output_begin([b4_spec_header_file])[
355 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
356 [2002-2015, 2018-2021])[
357 // C++ GLR parser skeleton written by Valentin Tolmer.
360 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
361 ]b4_shared_declarations([hh])[
362 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
366 # --------------------- #
367 # Implementation file. #
368 # --------------------- #
370 ]b4_output_begin([b4_parser_file_name])[
371 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
372 [2002-2015, 2018-2021])[
373 // C++ GLR parser skeleton written by Valentin Tolmer.
378 ]b4_percent_code_get([[top]])[
379 ]m4_if(b4_prefix, [yy], [],
380 [[/* Substitute the variable and function names. */
381 #define yyparse ]b4_prefix[parse
382 #define yylex ]b4_prefix[lex
383 #define yyerror ]b4_prefix[error
384 #define yydebug ]b4_prefix[debug]])[
386 ]b4_user_pre_prologue[
390 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
391 [b4_shared_declarations([cc])])[
393 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
395 /* Default (constant) value used for initialization for null
396 right-hand sides. Unlike the standard yacc.c template, here we set
397 the default value of $$ to a zeroed-out value. Since the default
398 value is undefined, this behavior is technically correct. */
399 static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;]b4_locations_if([[
400 static ]b4_namespace_ref[::]b4_parser_class[::location_type yyloc_default][]b4_yyloc_default;])[
402 ]b4_user_post_prologue[
403 ]b4_percent_code_get[]dnl
409 # if defined YYENABLE_NLS && YYENABLE_NLS
411 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
412 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
416 # define YY_(Msgid) Msgid
424 # define YYMALLOC malloc
429 # define YYJMP_BUF jmp_buf
430 # define YYSETJMP(Env) setjmp (Env)
431 /* Pacify Clang and ICC. */
432 # define YYLONGJMP(Env, Val) \
434 longjmp (Env, Val); \
439 ]b4_attribute_define([noreturn])[
441 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
442 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
443 _Pragma ("GCC diagnostic push") \
444 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
445 # define YY_IGNORE_NULL_DEREFERENCE_END \
446 _Pragma ("GCC diagnostic pop")
448 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
449 # define YY_IGNORE_NULL_DEREFERENCE_END
455 // FIXME: Use the same conventions as lalr1.cc.
458 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
462 # define YYDASSERT(Condition) YYASSERT(Condition)
464 # define YYDASSERT(Condition)
467 /* YYFINAL -- State number of the termination state. */
468 #define YYFINAL ]b4_final_state_number[
469 /* YYLAST -- Last index in YYTABLE. */
470 #define YYLAST ]b4_last[
472 /* YYNTOKENS -- Number of terminals. */
473 #define YYNTOKENS ]b4_tokens_number[
474 /* YYNNTS -- Number of nonterminals. */
475 #define YYNNTS ]b4_nterms_number[
476 /* YYNRULES -- Number of rules. */
477 #define YYNRULES ]b4_rules_number[
478 /* YYNSTATES -- Number of states. */
479 #define YYNSTATES ]b4_states_number[
480 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
481 #define YYMAXRHS ]b4_r2_max[
482 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
483 accessed by $0, $-1, etc., in any rule. */
484 #define YYMAXLEFT ]b4_max_left_semantic_context[
486 #if ]b4_api_PREFIX[DEBUG
487 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
488 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
494 #define YYPACT_NINF ]b4_pact_ninf[
495 #define YYTABLE_NINF ]b4_table_ninf[
497 ]b4_parser_tables_define[
499 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
500 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
505 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
506 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
511 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
512 in the case of predicates. */
513 static const bool yyimmediate[] =
518 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
519 list of conflicting reductions corresponding to action entry for
520 state STATE-NUM in yytable. 0 means no conflicts. The list in
521 yyconfl is terminated by a rule number of 0. */
522 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
524 ]b4_conflict_list_heads[
527 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
528 0, pointed into by YYCONFLP. */
529 ]dnl Do not use b4_int_type_for here, since there are places where
530 dnl pointers onto yyconfl are taken, whose type is "short*".
531 dnl We probably ought to introduce a type for confl.
532 [static const short yyconfl[] =
534 ]b4_conflicting_rules[
537 /* Error token number */
541 ]b4_yylloc_default_define[
542 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
545 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
549 YYRESULTTAG yychk_flag = YYE; \
550 if (yychk_flag != yyok) \
554 #if ]b4_api_PREFIX[DEBUG
556 #define YYCDEBUG if (!yydebug) {} else std::cerr
558 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
562 std::cerr << Title << ' '; \
563 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
568 # define YY_REDUCE_PRINT(Args) \
571 yystateStack.yy_reduce_print Args; \
574 /* Nonzero means print parse trace. It is left uninitialized so that
575 multiple parsers can coexist. */
579 static void yypstack (const glr_stack& yystack, size_t yyk)
581 static void yypdumpstack (const glr_stack& yystack)
584 #else /* !]b4_api_PREFIX[DEBUG */
586 # define YYCDEBUG if (true) {} else std::cerr
587 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
588 # define YY_REDUCE_PRINT(Args) {}
590 #endif /* !]b4_api_PREFIX[DEBUG */
592 /* YYINITDEPTH -- initial size of the parser's stacks. */
594 # define YYINITDEPTH ]b4_stack_depth_init[
597 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
598 if the built-in stack extension method is used).
600 Do not make this value too large; the results are undefined if
601 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
602 evaluated with infinite-precision integer arithmetic. */
605 # define YYMAXDEPTH ]b4_stack_depth_max[
608 /* Minimum number of free items on the stack allowed after an
609 allocation. This is to allow allocation and initialization
610 to be completed by functions that call yyexpandGLRStack before the
611 stack is expanded, thus insuring that all necessary pointers get
612 properly redirected to new data. */
615 #ifndef YYSTACKEXPANDABLE
616 # define YYSTACKEXPANDABLE 1
619 template <typename Parameter
>
620 class strong_index_alias
623 static strong_index_alias
create (std::ptrdiff_t value
)
625 strong_index_alias result
;
626 result
.value_
= value
;
630 std::ptrdiff_t const& get () const { return value_
; }
632 size_t uget () const { return static_cast<size_t> (value_
); }
634 strong_index_alias
operator+ (std::ptrdiff_t other
) const
636 return strong_index_alias (get () + other
);
639 void operator+= (std::ptrdiff_t other
)
644 strong_index_alias
operator- (std::ptrdiff_t other
)
646 return strong_index_alias (get () - other
);
649 void operator-= (std::ptrdiff_t other
)
654 size_t operator- (strong_index_alias other
)
656 return strong_index_alias (get () - other
.get ());
659 strong_index_alias
& operator++ ()
665 bool isValid () const
667 return value_
!= INVALID_INDEX
;
672 value_
= INVALID_INDEX
;
675 bool operator== (strong_index_alias other
)
677 return get () == other
.get ();
680 bool operator!= (strong_index_alias other
)
682 return get () != other
.get ();
685 bool operator< (strong_index_alias other
)
687 return get () < other
.get ();
691 static const std::ptrdiff_t INVALID_INDEX
;
693 // WARNING: 0-initialized.
694 std::ptrdiff_t value_
;
698 const std::ptrdiff_t strong_index_alias
<T
>::INVALID_INDEX
=
699 std::numeric_limits
<std::ptrdiff_t>::max ();
701 typedef strong_index_alias
<struct glr_state_set_tag
> state_set_index
;
703 state_set_index
create_state_set_index (std::ptrdiff_t value
)
705 return state_set_index::create (value
);
708 /** State numbers, as in LALR(1) machine */
709 typedef int state_num
;
711 /** Rule numbers, as in LALR(1) machine */
712 typedef int rule_num
;
714 // Forward declarations.
716 class semantic_option
;
717 class glr_stack_item
;
720 /** Accessing symbol of state YYSTATE. */
721 static inline yysymbol_kind_t
722 yy_accessing_symbol (state_num yystate
)
724 return YY_CAST (yysymbol_kind_t
, yystos
[yystate
]);
727 /** Left-hand-side symbol for rule #YYRULE. */
728 static inline yysymbol_kind_t
729 yylhsNonterm (rule_num yyrule
)
731 return static_cast<yysymbol_kind_t
>(yyr1
[yyrule
]);
734 /** Number of symbols composing the right hand side of rule #RULE. */
736 yyrhsLength (rule_num yyrule
)
744 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
745 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type symbol_kind_type
;
746 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
747 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
754 , yyfirstVal (0)]b4_locations_if([[
755 , yyloc ()]])[]b4_parse_assert_if([[
759 /// Build with a semantic value.
760 glr_state (state_num lrState
, size_t posn
, const value_type
& val
]b4_locations_if([[, const location_type
& loc
]])[)
762 , yylrState (lrState
)
765 , yyval (]b4_variant_if([], [[val
]])[)]b4_locations_if([[
766 , yyloc (loc
)]])[]b4_parse_assert_if([[
769 ]b4_symbol_variant([yy_accessing_symbol (lrState
)],
770 [yyval
], [copy
], [val
])])[}
772 /// Build with a semantic option.
773 glr_state (state_num lrState
, size_t posn
)
775 , yylrState (lrState
)
778 , yyfirstVal (0)]b4_locations_if([[
779 , yyloc ()]])[]b4_parse_assert_if([[
783 glr_state (const glr_state
& other
)
784 : yyresolved (other
.yyresolved
)
785 , yylrState (other
.yylrState
)
786 , yyposn (other
.yyposn
)
787 , yypred (0)]b4_locations_if([[
788 , yyloc (other
.yyloc
)]])[]b4_parse_assert_if([[
791 setPred (other
.pred ());
792 if (other
.yyresolved
)]b4_variant_if([[
794 new (&yyval
) value_type ();
795 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
796 [yyval
], [copy
], [other
.value ()])[
798 new (&yyval
) value_type (other
.value ());]])[
802 setFirstVal (other
.firstVal ());
803 }]b4_parse_assert_if([[
808 {]b4_parse_assert_if([[
812 yysymbol_kind_t yykind
= yy_accessing_symbol (yylrState
);
813 // FIXME: User destructors.
814 // Value type destructor.
815 ]b4_symbol_variant([[yykind
]], [[yyval
]], [[template destroy
]])])[
816 yyval
.~value_type ();
817 }]b4_parse_assert_if([[
821 glr_state
& operator= (const glr_state
& other
)
822 {]b4_parse_assert_if([[
825 if (!yyresolved
&& other
.yyresolved
)
826 new (&yyval
) value_type
;
827 yyresolved
= other
.yyresolved
;
828 yylrState
= other
.yylrState
;
829 yyposn
= other
.yyposn
;
830 setPred (other
.pred ());
831 if (other
.yyresolved
)]b4_variant_if([[
832 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
833 [yyval
], [copy
], [other
.value ()])], [[
834 value () = other
.value ();]])[
836 setFirstVal (other
.firstVal ());]b4_locations_if([[
837 yyloc
= other
.yyloc
;]])[
841 /** Type tag for the semantic value. If true, yyval applies, otherwise
842 * yyfirstVal applies. */
844 /** Number of corresponding LALR(1) machine state. */
846 /** Source position of the last token produced by my symbol */
849 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
851 const glr_state
* pred () const;
852 void setPred (const glr_state
* state
);
854 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
856 semantic_option
* firstVal ();
857 const semantic_option
* firstVal () const;
858 void setFirstVal (const semantic_option
* option
);
861 {]b4_parse_assert_if([[
866 const value_type
& value () const
867 {]b4_parse_assert_if([[
873 destroy (char const *yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[);
876 #if ]b4_api_PREFIX[DEBUG
877 void yy_yypstack () const
878 {]b4_parse_assert_if([[
880 if (pred () != YY_NULLPTR
)
882 pred ()->yy_yypstack ();
885 std::cerr
<< yylrState
<< "@@" << yyposn
;
889 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const;
891 glr_stack_item
* asItem ()
892 {]b4_parse_assert_if([[
897 const glr_stack_item
* asItem () const
898 {]b4_parse_assert_if([[
900 return asItem (this);
904 template <typename T
>
905 static const glr_stack_item
* asItem (const T
* state
)
907 return reinterpret_cast<const glr_stack_item
*>(state
);
909 template <typename T
>
910 static glr_stack_item
* asItem (T
* state
)
912 return reinterpret_cast<glr_stack_item
*> (state
);
914 static const char *as_pointer_ (const glr_state
*state
)
916 return reinterpret_cast<const char *> (state
);
918 static char *as_pointer_ (glr_state
*state
)
920 return reinterpret_cast<char *> (state
);
922 /** Preceding state in this stack */
923 std::ptrdiff_t yypred
;
925 /** First in a chain of alternative reductions producing the
926 * nonterminal corresponding to this state, threaded through
927 * yyfirstVal. Value "0" means empty. */
928 std::ptrdiff_t yyfirstVal
;
929 /** Semantic value for this state. */
931 };]b4_locations_if([[
932 // FIXME: Why public?
934 /** Source location for this state. */
935 location_type yyloc
;]])[
937 ]b4_parse_assert_if([[
942 YY_IGNORE_NULL_DEREFERENCE_BEGIN
943 YYASSERT (this->magic_
== MAGIC
);
944 YY_IGNORE_NULL_DEREFERENCE_END
947 // A magic number to check our pointer arithmetic is sane.
948 enum { MAGIC
= 713705 };
949 unsigned int magic_
;]])[
952 /** A stack of GLRState representing the different heads during
953 * nondeterministic evaluation. */
957 /** Initialize YYSET to a singleton set containing an empty stack. */
959 : yylastDeleted (YY_NULLPTR
)
961 yystates
.push_back (YY_NULLPTR
);
962 yylookaheadNeeds
.push_back (false);
965 // Behave like a vector of states.
966 glr_state
*& operator[] (state_set_index index
)
968 return yystates
[index
.uget()];
971 glr_state
* operator[] (state_set_index index
) const
973 return yystates
[index
.uget()];
978 return yystates
.size ();
981 std::vector
<glr_state
*>::iterator
begin ()
983 return yystates
.begin ();
986 std::vector
<glr_state
*>::iterator
end ()
988 return yystates
.end ();
991 bool lookaheadNeeds (state_set_index index
) const
993 return yylookaheadNeeds
[index
.uget ()];
996 bool setLookaheadNeeds (state_set_index index
, bool value
)
998 return yylookaheadNeeds
[index
.uget ()] = value
;
1001 /** Invalidate stack #YYK. */
1003 yymarkStackDeleted (state_set_index yyk
)
1005 size_t k
= yyk
.uget ();
1006 if (yystates
[k
] != YY_NULLPTR
)
1007 yylastDeleted
= yystates
[k
];
1008 yystates
[k
] = YY_NULLPTR
;
1011 /** Undelete the last stack in *this that was marked as deleted. Can
1012 only be done once after a deletion, and only when all other stacks have
1015 yyundeleteLastStack ()
1017 if (yylastDeleted
== YY_NULLPTR
|| !yystates
.empty ())
1019 yystates
.push_back (yylastDeleted
);
1020 YYCDEBUG
<< "Restoring last deleted stack as stack #0.\n";
1021 clearLastDeleted ();
1024 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1029 size_t newsize
= yystates
.size ();
1030 /* j is the number of live stacks we have seen. */
1031 for (size_t i
= 0, j
= 0; j
< newsize
; ++i
)
1033 if (yystates
[i
] == YY_NULLPTR
)
1037 YYCDEBUG
<< "Removing dead stacks.\n";
1043 yystates
[j
] = yystates
[i
];
1044 /* In the current implementation, it's unnecessary to copy
1045 yylookaheadNeeds[i] since, after
1046 yyremoveDeletes returns, the parser immediately either enters
1047 deterministic operation or shifts a token. However, it doesn't
1048 hurt, and the code might evolve to need it. */
1049 yylookaheadNeeds
[j
] = yylookaheadNeeds
[i
];
1052 YYCDEBUG
<< "Rename stack " << i
<< " -> " << j
<< ".\n";
1057 yystates
.resize (newsize
);
1058 yylookaheadNeeds
.resize (newsize
);
1063 yysplitStack (state_set_index yyk
)
1065 const size_t k
= yyk
.uget ();
1066 yystates
.push_back (yystates
[k
]);
1067 yylookaheadNeeds
.push_back (yylookaheadNeeds
[k
]);
1068 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates
.size () - 1));
1071 void clearLastDeleted ()
1073 yylastDeleted
= YY_NULLPTR
;
1078 std::vector
<glr_state
*> yystates
;
1079 /** During nondeterministic operation, yylookaheadNeeds tracks which
1080 * stacks have actually needed the current lookahead. During deterministic
1081 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1082 * duplicate yytoken != ]b4_symbol(empty, kind)[. */
1083 std::vector
<bool> yylookaheadNeeds
;
1085 /** The last stack we invalidated. */
1086 glr_state
* yylastDeleted
;
1089 class semantic_option
1092 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
1093 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type symbol_kind_type
;
1094 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1095 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1101 , yytoken (]b4_symbol(empty
, kind
)[)
1102 , yyval ()]b4_locations_if([[
1103 , yyloc ()]])[]b4_parse_assert_if([[
1104 , magic_ (MAGIC
)]])[
1107 semantic_option (rule_num rule
, symbol_kind_type token
)
1112 , yyval ()]b4_locations_if([[
1113 , yyloc ()]])[]b4_parse_assert_if([[
1114 , magic_ (MAGIC
)]])[
1117 semantic_option (const semantic_option
& that
)
1118 : yyrule (that
.yyrule
)
1119 , yystate (that
.yystate
)
1120 , yynext (that
.yynext
)
1121 , yytoken (that
.yytoken
)
1122 , yyval (]b4_variant_if([], [[that
.yyval
]])[)]b4_locations_if([[
1123 , yyloc (that
.yyloc
)]])[]b4_parse_assert_if([[
1124 , magic_ (MAGIC
)]])[
1125 {]b4_parse_assert_if([[
1126 that
.check_ ();]])[]b4_variant_if([[
1127 ]b4_symbol_variant([yytoken
],
1128 [yyval
], [copy
], [that
.yyval
])])[
1131 // Needed for the assignment in yynewSemanticOption.
1132 semantic_option
& operator= (const semantic_option
& that
)
1133 {]b4_parse_assert_if([[
1136 yyrule
= that
.yyrule
;
1137 yystate
= that
.yystate
;
1138 yynext
= that
.yynext
;
1139 yytoken
= that
.yytoken
;]b4_variant_if([[
1140 ]b4_symbol_variant([yytoken
],
1141 [yyval
], [copy
], [that
.yyval
])], [[
1142 yyval
= that
.yyval
;]])[]b4_locations_if([[
1143 yyloc
= that
.yyloc
;]])[
1147 /// Only call state() and setState() on objects in yyitems, not temporaries.
1149 const glr_state
* state() const;
1150 void setState(const glr_state
* s
);
1152 const semantic_option
* next () const;
1153 semantic_option
* next ();
1154 void setNext (const semantic_option
* s
);
1156 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const;
1158 /** True iff YYY0 and YYY1 represent identical options at the top level.
1159 * That is, they represent the same rule applied to RHS symbols
1160 * that produce the same terminal symbols. */
1162 isIdenticalTo (const semantic_option
& yyy1
) const
1163 {]b4_parse_assert_if([[
1166 if (this->yyrule
== yyy1
.yyrule
)
1168 const glr_state
*yys0
, *yys1
;
1170 for (yys0
= this->state(),
1171 yys1
= yyy1
.state(),
1172 yyn
= yyrhsLength (this->yyrule
);
1174 yys0
= yys0
->pred(),
1175 yys1
= yys1
->pred(), yyn
-= 1)
1176 if (yys0
->yyposn
!= yys1
->yyposn
)
1184 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1185 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1187 mergeWith (semantic_option
& yyy1
)
1188 {]b4_parse_assert_if([[
1191 glr_state
*yys0
= this->state ();
1192 glr_state
*yys1
= yyy1
.state ();
1193 for (int yyn
= yyrhsLength (this->yyrule
);
1195 yyn
-= 1, yys0
= yys0
->pred (), yys1
= yys1
->pred ())
1199 else if (yys0
->yyresolved
)
1201 yys1
->yyresolved
= true;]b4_variant_if([[
1202 YYASSERT (yys1
->yylrState
== yys0
->yylrState
);
1203 ]b4_symbol_variant([yy_accessing_symbol (yys0
->yylrState
)],
1204 [yys1
->value ()], [copy
], [yys0
->value ()])], [[
1205 yys1
->value () = yys0
->value ();]])[
1207 else if (yys1
->yyresolved
)
1209 yys0
->yyresolved
= true;]b4_variant_if([[
1210 YYASSERT (yys0
->yylrState
== yys1
->yylrState
);
1211 ]b4_symbol_variant([yy_accessing_symbol (yys1
->yylrState
)],
1212 [yys0
->value ()], [copy
], [yys1
->value ()])], [[
1213 yys0
->value () = yys1
->value ();]])[
1217 semantic_option
* yyz0prev
= YY_NULLPTR
;
1218 semantic_option
* yyz0
= yys0
->firstVal();
1219 semantic_option
* yyz1
= yys1
->firstVal();
1222 if (yyz1
== yyz0
|| yyz1
== YY_NULLPTR
)
1224 else if (yyz0
== YY_NULLPTR
)
1226 if (yyz0prev
!= YY_NULLPTR
)
1227 yyz0prev
->setNext (yyz1
);
1229 yys0
->setFirstVal (yyz1
);
1232 else if (yyz0
< yyz1
)
1234 semantic_option
* yyz
= yyz0
;
1235 if (yyz0prev
!= YY_NULLPTR
)
1236 yyz0prev
->setNext(yyz1
);
1238 yys0
->setFirstVal(yyz1
);
1239 yyz1
= yyz1
->next();
1243 yyz0
= yyz0
->next();
1245 yys1
->setFirstVal(yys0
->firstVal());
1250 #if ]b4_api_PREFIX[DEBUG
1251 void yyreportTree (size_t yyindent
= 2) const
1252 {]b4_parse_assert_if([[
1254 int yynrhs
= yyrhsLength (this->yyrule
);
1255 const glr_state
* yystates
[1 + YYMAXRHS
];
1256 glr_state yyleftmost_state
;
1259 const glr_state
* yys
= this->state();
1260 for (int yyi
= yynrhs
; 0 < yyi
; yyi
-= 1)
1262 yystates
[yyi
] = yys
;
1265 if (yys
== YY_NULLPTR
)
1267 yyleftmost_state
.yyposn
= 0;
1268 yystates
[0] = &yyleftmost_state
;
1274 std::string yylhs
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yylhsNonterm (this->yyrule
));
1275 YYASSERT(this->state());
1276 if (this->state()->yyposn
< yystates
[0]->yyposn
+ 1)
1277 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1278 << this->yyrule
- 1 << ", empty>\n";
1280 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1281 << this->yyrule
- 1 << ", tokens "
1282 << yystates
[0]->yyposn
+ 1 << " .. "
1283 << this->state()->yyposn
<< ">\n";
1284 for (int yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1286 if (yystates
[yyi
]->yyresolved
)
1288 std::string yysym
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yy_accessing_symbol (yystates
[yyi
]->yylrState
));
1289 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1290 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1293 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1294 << " <tokens " << yystates
[yyi
-1]->yyposn
+ 1
1295 << " .. " << yystates
[yyi
]->yyposn
<< ">\n";
1298 yystates
[yyi
]->firstVal ()->yyreportTree (yyindent
+2);
1303 /** Rule number for this reduction */
1307 template <typename T
>
1308 static const glr_stack_item
* asItem(const T
* state
)
1310 return reinterpret_cast<const glr_stack_item
*>(state
);
1312 template <typename T
>
1313 static glr_stack_item
* asItem(T
* state
)
1315 return reinterpret_cast<glr_stack_item
*>(state
);
1317 /** The last RHS state in the list of states to be reduced. */
1318 std::ptrdiff_t yystate
;
1319 /** Next sibling in chain of options. To facilitate merging,
1320 * options are chained in decreasing order by address. */
1321 std::ptrdiff_t yynext
;
1324 /** The lookahead for this reduction. */
1325 symbol_kind_type yytoken
;
1326 value_type yyval
;]b4_locations_if([[
1327 location_type yyloc
;]])[
1329 ]b4_parse_assert_if([[
1331 // Check invariants.
1332 void check_ () const
1334 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1335 YYASSERT (this->magic_
== MAGIC
);
1336 YY_IGNORE_NULL_DEREFERENCE_END
1339 // A magic number to check our pointer arithmetic is sane.
1340 enum { MAGIC
= 0xeff1cace };
1341 unsigned int magic_
;]])[
1344 /** Type of the items in the GLR stack.
1345 * It can be either a glr_state or a semantic_option. The is_state_ field
1346 * indicates which item of the union is valid. */
1347 class glr_stack_item
1350 glr_stack_item (bool state
= true)
1351 : is_state_ (state
)]b4_parse_assert_if([[
1352 , magic_ (MAGIC
)]])[
1355 new (&raw_
) glr_state
;
1357 new (&raw_
) semantic_option
;
1360 glr_stack_item (const glr_stack_item
& other
) YY_NOEXCEPT YY_NOTHROW
1361 : is_state_ (other
.is_state_
)]b4_parse_assert_if([[
1362 , magic_ (MAGIC
)]])[
1363 {]b4_parse_assert_if([[
1364 other
.check_ ();]])[
1365 std::memcpy (raw_
, other
.raw_
, union_size
);
1368 glr_stack_item
& operator= (glr_stack_item other
)
1369 {]b4_parse_assert_if([[
1371 other
.check_ ();]])[
1372 std::swap (is_state_
, other
.is_state_
);
1373 // NB: swap on arrays is C++11.
1374 std::swap (raw_
, other
.raw_
);
1379 {]b4_parse_assert_if([[
1382 getState ().~glr_state ();
1384 getOption ().~semantic_option ();
1387 void setState (const glr_state
&state
)
1388 {]b4_parse_assert_if([[
1390 state
.check_ ();]])[
1391 if (this != state
.asItem ())
1394 getState ().~glr_state ();
1396 getOption ().~semantic_option ();
1397 new (&raw_
) glr_state (state
);
1402 glr_state
& getState ()
1403 {]b4_parse_assert_if([[
1405 YYDASSERT (is_state ());
1407 glr_state
& res
= *static_cast<glr_state
*> (yyp
);]b4_parse_assert_if([[
1412 const glr_state
& getState () const
1413 {]b4_parse_assert_if([[
1415 YYDASSERT (is_state ());
1416 const void *yyp
= raw_
;
1417 const glr_state
& res
= *static_cast<const glr_state
*> (yyp
);]b4_parse_assert_if([[
1422 semantic_option
& getOption ()
1423 {]b4_parse_assert_if([[
1425 YYDASSERT (!is_state ());
1427 return *static_cast<semantic_option
*> (yyp
);
1429 const semantic_option
& getOption () const
1430 {]b4_parse_assert_if([[
1432 YYDASSERT (!is_state ());
1433 const void *yyp
= raw_
;
1434 return *static_cast<const semantic_option
*> (yyp
);
1436 bool is_state () const
1437 {]b4_parse_assert_if([[
1443 /// The possible contents of raw_. Since they have constructors, they cannot
1444 /// be directly included in the union.
1447 char yystate
[sizeof (glr_state
)];
1448 char yyoption
[sizeof (semantic_option
)];
1450 enum { union_size
= sizeof (contents
) };
1452 /// Strongest alignment constraints.
1453 long double yyalign_me
;
1454 /// A buffer large enough to store the contents.
1455 char raw_
[union_size
];
1457 /** Type tag for the union. */
1459 ]b4_parse_assert_if([[
1461 // Check invariants.
1462 void check_ () const
1464 YYASSERT (this->magic_
== MAGIC
);
1465 YYASSERT (this->is_state_
== false || this->is_state_
== true);
1467 // A magic number to check our pointer arithmetic is sane.
1468 enum { MAGIC
= 0xDEAD1ACC }; // 3735886540.
1469 const unsigned int magic_
;]])[
1472 glr_state
* glr_state::pred ()
1473 {]b4_parse_assert_if([[
1475 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1476 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1477 YY_IGNORE_NULL_DEREFERENCE_END
1480 const glr_state
* glr_state::pred () const
1481 {]b4_parse_assert_if([[
1483 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1484 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1485 YY_IGNORE_NULL_DEREFERENCE_END
1488 void glr_state::setPred (const glr_state
* state
)
1489 {]b4_parse_assert_if([[
1492 state
->check_ ();]])[
1493 yypred
= state
? as_pointer_ (this) - as_pointer_ (state
) : 0;
1496 semantic_option
* glr_state::firstVal ()
1497 {]b4_parse_assert_if([[
1499 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1502 const semantic_option
* glr_state::firstVal () const
1503 {]b4_parse_assert_if([[
1505 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1508 void glr_state::setFirstVal (const semantic_option
* option
)
1509 {]b4_parse_assert_if([[
1511 yyfirstVal
= option
? asItem(this) - asItem(option
) : 0;
1514 std::ptrdiff_t glr_state::indexIn (const glr_stack_item
* array
) const
1515 {]b4_parse_assert_if([[
1517 return asItem(this) - array
;
1520 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item
* array
) const
1522 return asItem(this) - array
;
1525 glr_state
* semantic_option::state ()
1527 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1528 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1529 YY_IGNORE_NULL_DEREFERENCE_END
1532 const glr_state
* semantic_option::state () const
1534 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1537 void semantic_option::setState (const glr_state
* s
)
1539 yystate
= s
? asItem(this) - asItem(s
) : 0;
1542 const semantic_option
* semantic_option::next () const
1544 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1547 semantic_option
* semantic_option::next ()
1549 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1552 void semantic_option::setNext (const semantic_option
* s
)
1554 yynext
= s
? asItem(this) - asItem(s
) : 0;
1557 void glr_state::destroy (char const* yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[)
1558 {]b4_parse_assert_if([[
1561 yyparser
.yy_destroy_ (yymsg
, yy_accessing_symbol(yylrState
),
1562 value ()]b4_locations_if([, yyloc
])[);
1565 #if ]b4_api_PREFIX[DEBUG
1567 << (firstVal() ? " unresolved " : " incomplete ")
1568 << (yy_accessing_symbol (yylrState
) < YYNTOKENS
? "token" : "nterm")
1569 << ' ' << yyparser
.symbol_name (yy_accessing_symbol (yylrState
))
1570 << " ("]b4_locations_if([[
1571 << yyloc
<< ": "]])[
1574 if (firstVal() != YY_NULLPTR
)
1576 semantic_option
& yyoption
= *firstVal ();
1577 glr_state
*yyrh
= yyoption
.state ();
1578 for (int yyn
= yyrhsLength (yyoption
.yyrule
); yyn
> 0; yyn
-= 1)
1580 yyrh
->destroy (yymsg
, yyparser
]b4_user_args
[);
1581 yyrh
= yyrh
->pred();
1589 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1594 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
1595 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1596 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1598 /** Initialize to a single empty stack, with total maximum
1599 * capacity for all stacks of YYSIZE. */
1600 state_stack (size_t yysize
)
1601 : yysplitPoint (YY_NULLPTR
)
1603 yyitems
.reserve (yysize
);
1606 #if YYSTACKEXPANDABLE
1607 /** Returns false if it tried to expand but could not. */
1609 yyexpandGLRStackIfNeeded ()
1611 return YYHEADROOM
<= spaceLeft () || yyexpandGLRStack ();
1615 /** If *this is expandable, extend it. WARNING: Pointers into the
1616 stack from outside should be considered invalid after this call.
1617 We always expand when there are 1 or fewer items left AFTER an
1618 allocation, so that we can avoid having external pointers exist
1619 across an allocation. */
1623 const size_t oldsize
= yyitems
.size();
1624 if (YYMAXDEPTH
- YYHEADROOM
< oldsize
)
1626 const size_t yynewSize
= YYMAXDEPTH
< 2 * oldsize
? YYMAXDEPTH
: 2 * oldsize
;
1627 const glr_stack_item
*oldbase
= &yyitems
[0];
1629 yyitems
.reserve (yynewSize
);
1630 const glr_stack_item
*newbase
= &yyitems
[0];
1632 // Adjust the pointers. Perform raw pointer arithmetic, as there
1633 // is no reason for objects to be aligned on their size.
1634 const ptrdiff_t disp
1635 = reinterpret_cast<const char*> (newbase
) - reinterpret_cast<const char*> (oldbase
);
1637 const_cast<glr_state
*&> (yysplitPoint
)
1638 = reinterpret_cast<glr_state
*> (reinterpret_cast<char*> (const_cast<glr_state
*> (yysplitPoint
)) + disp
);
1640 for (std::vector
<glr_state
*>::iterator
1641 i
= yytops
.begin (),
1642 yyend
= yytops
.end ();
1644 if (glr_state_not_null (*i
))
1645 *i
= reinterpret_cast<glr_state
*>(reinterpret_cast<char*>(*i
) + disp
);
1652 bool yyexpandGLRStackIfNeeded ()
1654 return YYHEADROOM
<= spaceLeft ();
1657 #undef YYSTACKEXPANDABLE
1659 static bool glr_state_not_null (glr_state
* s
)
1661 return s
!= YY_NULLPTR
;
1667 typedef std::vector
<glr_state
*>::iterator iterator
;
1668 const iterator yybegin
= yytops
.begin();
1669 const iterator yyend
= yytops
.end();
1670 const iterator yyit
= std::find_if(yybegin
, yyend
, glr_state_not_null
);
1673 for (state_set_index yyk
= create_state_set_index(yyit
+ 1 - yybegin
);
1674 yyk
.uget() != numTops(); ++yyk
)
1675 yytops
.yymarkStackDeleted (yyk
);
1676 yytops
.yyremoveDeletes ();
1681 /** Called when returning to deterministic operation to clean up the extra
1686 if (yytops
.size() != 1 || !isSplit())
1689 // yyr is the state after the split point.
1690 glr_state
* yyr
= YY_NULLPTR
;
1691 for (glr_state
*yyp
= firstTop(), *yyq
= yyp
->pred();
1692 yyp
!= yysplitPoint
;
1693 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->pred())
1696 // This const_cast is okay, since anyway we have access to the mutable
1697 // yyitems into which yysplitPoint points.
1698 glr_stack_item
* nextFreeItem
1699 = const_cast<glr_state
*> (yysplitPoint
)->asItem () + 1;
1700 yysplitPoint
= YY_NULLPTR
;
1701 yytops
.clearLastDeleted ();
1703 while (yyr
!= YY_NULLPTR
)
1705 nextFreeItem
->setState (*yyr
);
1706 glr_state
& nextFreeState
= nextFreeItem
->getState();
1708 nextFreeState
.setPred(&(nextFreeItem
- 1)->getState());
1709 setFirstTop (&nextFreeState
);
1712 yyitems
.resize(static_cast<size_t>(nextFreeItem
- yyitems
.data()));
1715 bool isSplit() const {
1716 return yysplitPoint
!= YY_NULLPTR
;
1719 // Present the interface of a vector of glr_stack_item.
1720 std::vector
<glr_stack_item
>::const_iterator
begin () const
1722 return yyitems
.begin ();
1725 std::vector
<glr_stack_item
>::const_iterator
end () const
1727 return yyitems
.end ();
1732 return yyitems
.size ();
1735 glr_stack_item
& operator[] (size_t i
)
1740 glr_stack_item
& stackItemAt (size_t index
)
1742 return yyitems
[index
];
1745 size_t numTops () const
1747 return yytops
.size ();
1750 glr_state
* firstTop () const
1752 return yytops
[create_state_set_index (0)];
1755 glr_state
* topAt (state_set_index i
) const
1760 void setFirstTop (glr_state
* value
)
1762 yytops
[create_state_set_index (0)] = value
;
1765 void setTopAt (state_set_index i
, glr_state
* value
)
1772 yyitems
.pop_back ();
1775 void pop_back (size_t n
)
1777 yyitems
.resize (yyitems
.size () - n
);
1781 yysplitStack (state_set_index yyk
)
1785 YYASSERT (yyk
.get () == 0);
1786 yysplitPoint
= topAt (yyk
);
1788 return yytops
.yysplitStack (yyk
);
1791 /** Assuming that YYS is a GLRState somewhere on *this, update the
1792 * splitpoint of *this, if needed, so that it is at least as deep as
1795 yyupdateSplit (glr_state
& yys
)
1797 if (isSplit() && &yys
< yysplitPoint
)
1798 yysplitPoint
= &yys
;
1801 /** Return a fresh GLRState.
1802 * Callers should call yyreserveStack afterwards to make sure there is
1803 * sufficient headroom. */
1804 glr_state
& yynewGLRState (const glr_state
& newState
)
1806 glr_state
& state
= yyitems
[yynewGLRStackItem (true)].getState ();
1807 #if false && 201103L <= YY_CPLUSPLUS
1808 state
= std::move (newState
);
1815 /** Return a fresh SemanticOption.
1816 * Callers should call yyreserveStack afterwards to make sure there is
1817 * sufficient headroom. */
1818 semantic_option
& yynewSemanticOption (semantic_option newOption
)
1820 semantic_option
& option
= yyitems
[yynewGLRStackItem (false)].getOption ();
1821 #if 201103L <= YY_CPLUSPLUS
1822 option
= std::move (newOption
);
1829 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1830 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1831 * For convenience, always return YYLOW1. */
1833 yyfill (glr_stack_item
*yyvsp
, int &yylow
, int yylow1
, bool yynormal
)
1835 if (!yynormal
&& yylow1
< yylow
)
1837 yyfillin (yyvsp
, yylow
, yylow1
);
1843 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1844 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1845 * containing the pointer to the next state in the chain. */
1847 yyfillin (glr_stack_item
*yyvsp
, int yylow0
, int yylow1
)
1849 glr_state
* s
= yyvsp
[yylow0
].getState().pred();
1850 YYASSERT(s
!= YY_NULLPTR
);
1851 for (int i
= yylow0
-1; i
>= yylow1
; i
-= 1, s
= s
->pred())
1853 glr_state
& yys
= yyvsp
[i
].getState();
1854 #if ]b4_api_PREFIX[DEBUG
1855 yys
.yylrState
= s
->yylrState
;
1857 yys
.yyresolved
= s
->yyresolved
;
1860 new (&yys
.value ()) value_type ();
1861 ]b4_symbol_variant([yy_accessing_symbol (s
->yylrState
)],
1862 [yys
.value ()], [copy
], [s
->value ()])], [[
1863 new (&yys
.value ()) value_type (s
->value ());]])[
1866 /* The effect of using yyval or yyloc (in an immediate
1867 * rule) is undefined. */
1868 yys
.setFirstVal (YY_NULLPTR
);]b4_locations_if([[
1869 yys
.yyloc
= s
->yyloc
;]])[
1870 yys
.setPred(s
->pred());
1874 #if ]b4_api_PREFIX[DEBUG
1876 /*----------------------------------------------------------------------.
1877 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1878 `----------------------------------------------------------------------*/
1881 yy_reduce_print (bool yynormal
, glr_stack_item
* yyvsp
, state_set_index yyk
,
1882 rule_num yyrule
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
)
1884 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1887 std::cerr
<< "Reducing stack " << yyk
.get() << " by rule " << yyrule
- 1
1888 << " (line " << int (yyrline
[yyrule
]) << "):\n";
1890 yyfillin (yyvsp
, 1, -yynrhs
);
1891 /* The symbols being reduced. */
1892 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1894 std::cerr
<< " $" << yyi
+ 1 << " = ";
1895 yyparser
.yy_symbol_print_
1896 (yy_accessing_symbol (yyvsp
[yyi
- yynrhs
+ 1].getState().yylrState
),
1897 yyvsp
[yyi
- yynrhs
+ 1].getState().value ()]b4_locations_if([[,
1898 ]b4_rhs_location(yynrhs
, yyi
+ 1)])[);
1899 if (!yyvsp
[yyi
- yynrhs
+ 1].getState().yyresolved
)
1900 std::cerr
<< " (unresolved)";
1906 #define YYINDEX(YYX) \
1907 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1912 for (size_t yyi
= 0; yyi
< size(); ++yyi
)
1914 const glr_stack_item
& item
= yyitems
[yyi
];
1915 std::cerr
<< std::setw(3) << yyi
<< ". ";
1916 if (item
.is_state())
1918 std::cerr
<< "Res: " << item
.getState().yyresolved
1919 << ", LR State: " << item
.getState().yylrState
1920 << ", posn: " << item
.getState().yyposn
1921 << ", pred: " << YYINDEX(item
.getState().pred());
1922 if (! item
.getState().yyresolved
)
1923 std::cerr
<< ", firstVal: "
1924 << YYINDEX(item
.getState().firstVal());
1928 std::cerr
<< "Option. rule: " << item
.getOption().yyrule
- 1
1929 << ", state: " << YYINDEX(item
.getOption().state())
1930 << ", next: " << YYINDEX(item
.getOption().next());
1934 std::cerr
<< "Tops:";
1935 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < numTops(); ++yyi
) {
1936 std::cerr
<< yyi
.get() << ": " << YYINDEX(topAt(yyi
)) << "; ";
1945 yyreportAmbiguity (const semantic_option
& yyx0
,
1946 const semantic_option
& yyx1
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_locations_if([, const location_type
& yyloc
])[)
1951 #if ]b4_api_PREFIX[DEBUG
1952 std::cerr
<< "Ambiguity detected.\n"
1954 yyx0
.yyreportTree ();
1955 std::cerr
<< "\nOption 2,\n";
1956 yyx1
.yyreportTree ();
1960 yyparser
.error (]b4_locations_if([yyloc
, ])[YY_("syntax is ambiguous"));
1964 /* DEBUGGING ONLY */
1965 #if ]b4_api_PREFIX[DEBUG
1966 /* Print YYS (possibly NULL) and its predecessors. */
1968 yypstates (const glr_state
* yys
) const
1970 if (yys
!= YY_NULLPTR
)
1973 std::cerr
<< "<null>";
1979 size_t spaceLeft() const
1981 return yyitems
.capacity() - yyitems
.size();
1984 /** Return a fresh GLRStackItem in this. The item is an LR state
1985 * if YYIS_STATE, and otherwise a semantic option. Callers should call
1986 * yyreserveStack afterwards to make sure there is sufficient
1989 yynewGLRStackItem (bool yyis_state
)
1991 YYDASSERT(yyitems
.size() < yyitems
.capacity());
1992 yyitems
.push_back(glr_stack_item(yyis_state
));
1993 return yyitems
.size() - 1;
1999 std::vector
<glr_stack_item
> yyitems
;
2000 // Where the stack splits. Anything below this address is deterministic.
2001 const glr_state
* yysplitPoint
;
2002 glr_state_set yytops
;
2006 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2011 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
2012 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type symbol_kind_type
;
2013 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
2014 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
2016 glr_stack (size_t yysize
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser_yyarg
]m4_ifset([b4_parse_param
], [, b4_parse_param_decl
])[)
2018 , yystateStack (yysize
)
2020 , yytoken (]b4_symbol(empty
, kind
)[)
2021 , yyparser (yyparser_yyarg
)]m4_ifset([b4_parse_param
], [,b4_parse_param_cons
])[
2026 if (this->yytoken
!= ]b4_symbol(empty
, kind
)[)
2027 yyparser
.yy_destroy_ ("Cleanup: discarding lookahead",
2028 this->yytoken
, this->yylval
]b4_locations_if([, this->yylloc
])[);
2033 ]b4_locations_if([[ /* To compute the location of the error token. */
2034 glr_stack_item yyerror_range
[3];]])[
2035 state_stack yystateStack
;
2037 symbol_kind_type yytoken
;
2038 value_type yylval
;]b4_locations_if([[
2039 location_type yylloc
;]])[
2040 YYJMP_BUF yyexception_buffer
;
2041 ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
;
2043 #define YYCHK1(YYE) \
2053 goto yyuser_error; \
2065 YYCDEBUG
<< "Starting parse\n";
2067 this->yytoken
= ]b4_symbol(empty
, kind
)[;]b4_variant_if([], [[
2068 this->yylval
= yyval_default
;]])[]b4_locations_if([
2069 this->yylloc
= yyloc_default
;])[
2070 ]m4_ifdef([b4_initial_action
], [
2071 b4_dollar_pushdef([this->yylval
], [], [], [this->yylloc
])dnl
2072 b4_user_initial_action
2073 b4_dollar_popdef
])[]dnl
2075 switch (YYSETJMP (this->yyexception_buffer
))
2078 case 1: goto yyabortlab
;
2079 case 2: goto yyexhaustedlab
;
2080 default: goto yybuglab
;
2082 this->yyglrShift (create_state_set_index(0), 0, 0, this->yylval
]b4_locations_if([, this->yylloc
])[);
2087 /* For efficiency, we have two loops, the first of which is
2088 specialized to deterministic operation (single stack, no
2089 potential ambiguity). */
2093 const state_num yystate
= this->firstTopState()->yylrState
;
2094 YYCDEBUG
<< "Entering state " << yystate
<< '\n';
2095 if (yystate
== YYFINAL
)
2097 if (yy_is_defaulted_state (yystate
))
2099 const rule_num yyrule
= yy_default_action (yystate
);
2101 {]b4_locations_if([[
2102 this->yyerror_range
[1].getState().yyloc
= this->yylloc
;]])[
2103 this->yyreportSyntaxError ();
2106 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule
, true));
2111 const short* yyconflicts
;
2112 const int yyaction
= yygetLRActions (yystate
, this->yytoken
, yyconflicts
);
2113 if (*yyconflicts
!= 0)
2115 if (yy_is_shift_action (yyaction
))
2117 YY_SYMBOL_PRINT ("Shifting", this->yytoken
, this->yylval
, this->yylloc
);
2119 // FIXME: we should move yylval.
2120 this->yyglrShift (create_state_set_index(0), yyaction
, yyposn
, this->yylval
]b4_locations_if([, this->yylloc
])[);]b4_variant_if([[
2121 // FIXME: User destructors.
2122 // Value type destructor.
2123 ]b4_symbol_variant([[this->yytoken
]], [[this->yylval
]], [[template destroy
]])])[
2124 this->yytoken
= ]b4_symbol(empty
, kind
)[;
2125 if (0 < this->yyerrState
)
2126 this->yyerrState
-= 1;
2128 else if (yy_is_error_action (yyaction
))
2129 {]b4_locations_if([[
2130 this->yyerror_range
[1].getState().yyloc
= this->yylloc
;]])[
2131 /* Don't issue an error message again for exceptions
2132 thrown from the scanner. */
2133 if (this->yytoken
!= ]b4_symbol(error
, kind
)[)
2134 this->yyreportSyntaxError ();
2138 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction
, true));
2144 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < this->yystateStack
.numTops(); ++yys
)
2145 this->yystateStack
.yytops
.setLookaheadNeeds(yys
, this->yytoken
!= ]b4_symbol(empty
, kind
)[);
2147 /* yyprocessOneStack returns one of three things:
2149 - An error flag. If the caller is yyprocessOneStack, it
2150 immediately returns as well. When the caller is finally
2151 yyparse, it jumps to an error label via YYCHK1.
2153 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2154 (yys), which sets the top state of yys to NULL. Thus,
2155 yyparse's following invocation of yyremoveDeletes will remove
2158 - yyok, when ready to shift a token.
2160 Except in the first case, yyparse will invoke yyremoveDeletes and
2161 then shift the next token onto all remaining stacks. This
2162 synchronization of the shift (that is, after all preceding
2163 reductions on all stacks) helps prevent double destructor calls
2164 on yylval in the event of memory exhaustion. */
2166 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < this->yystateStack
.numTops(); ++yys
)
2167 YYCHK1 (this->yyprocessOneStack (yys
, yyposn
]b4_locations_if([, &this->yylloc
])[));
2168 this->yystateStack
.yytops
.yyremoveDeletes ();
2169 if (this->yystateStack
.yytops
.size() == 0)
2171 this->yystateStack
.yytops
.yyundeleteLastStack ();
2172 if (this->yystateStack
.yytops
.size() == 0)
2173 this->yyFail (]b4_locations_if([&this->yylloc
, ])[YY_("syntax error"));
2174 YYCHK1 (this->yyresolveStack ());
2175 YYCDEBUG
<< "Returning to deterministic operation.\n";]b4_locations_if([[
2176 this->yyerror_range
[1].getState().yyloc
= this->yylloc
;]])[
2177 this->yyreportSyntaxError ();
2181 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2182 a copy of yylval will already be on stack 0 in the event of a
2183 failure in the following loop. Thus, yytoken is set to ]b4_symbol(empty, kind)[
2184 before the loop to make sure the user destructor for yylval isn't
2186 yysymbol_kind_t yytoken_to_shift
= this->yytoken
;
2187 this->yytoken
= ]b4_symbol(empty
, kind
)[;
2189 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < this->yystateStack
.numTops(); ++yys
)
2191 const state_num yystate
= this->topState(yys
)->yylrState
;
2192 const short* yyconflicts
;
2194 = yygetLRActions (yystate
, yytoken_to_shift
, yyconflicts
);
2195 /* Note that yyconflicts were handled by yyprocessOneStack. */
2196 YYCDEBUG
<< "On stack " << yys
.get() << ", ";
2197 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, this->yylval
, this->yylloc
);
2198 this->yyglrShift (yys
, yyaction
, yyposn
, this->yylval
]b4_locations_if([, this->yylloc
])[);
2199 YYCDEBUG
<< "Stack " << yys
.get() << " now in state "
2200 << this->topState(yys
)->yylrState
<< '\n';
2203 // FIXME: User destructors.
2204 // Value type destructor.
2205 ]b4_symbol_variant([[yytoken_to_shift
]], [[this->yylval
]], [[template destroy
]])])[
2207 if (this->yystateStack
.yytops
.size() == 1)
2209 YYCHK1 (this->yyresolveStack ());
2210 YYCDEBUG
<< "Returning to deterministic operation.\n";
2211 this->yystateStack
.yycompressStack ();
2217 this->yyrecoverSyntaxError (]b4_locations_if([&this->yylloc
])[);
2218 yyposn
= this->firstTopState()->yyposn
;
2234 yyparser
.error (]b4_locations_if([this->yylloc
, ])[YY_("memory exhausted"));
2243 void yyreserveGlrStack ()
2245 if (!yystateStack
.yyexpandGLRStackIfNeeded ())
2246 yyMemoryExhausted ();
2250 yyMemoryExhausted ()
2252 YYLONGJMP (yyexception_buffer
, 2);
2256 yyFail (]b4_locations_if([location_type
* yylocp
, ])[const char* yymsg
)
2258 if (yymsg
!= YY_NULLPTR
)
2259 yyparser
.error (]b4_locations_if([*yylocp
, ])[yymsg
);
2260 YYLONGJMP (yyexception_buffer
, 1);
2266 /** Add a new semantic action that will execute the action for rule
2267 * YYRULE on the semantic values in YYRHS to the list of
2268 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2269 * stack #YYK of *this. */
2271 yyaddDeferredAction (state_set_index yyk
, glr_state
* yystate
,
2272 glr_state
* yyrhs
, rule_num yyrule
)
2274 semantic_option
& yynewOption
=
2275 yystateStack
.yynewSemanticOption(semantic_option(yyrule
, ]b4_symbol(empty
, kind
)[));
2276 yynewOption
.setState(yyrhs
);
2277 yynewOption
.setNext(yystate
->firstVal());
2278 if (yystateStack
.yytops
.lookaheadNeeds(yyk
))
2280 yynewOption
.yytoken
= this->yytoken
;]b4_variant_if([[
2281 ]b4_symbol_variant([this->yytoken
],
2282 [yynewOption
.yyval
], [copy
], [this->yylval
])], [[
2283 yynewOption
.yyval
= this->yylval
;]])[]b4_locations_if([
2284 yynewOption
.yyloc
= this->yylloc
;])[
2286 yystate
->setFirstVal(&yynewOption
);
2288 yyreserveGlrStack();
2291 #if ]b4_api_PREFIX[DEBUG
2292 void yypdumpstack () const
2294 yystateStack
.dumpStack();
2298 yyreportSyntaxError ()
2300 if (yyerrState
!= 0)
2302 ]b4_parse_error_bmatch(
2304 [[ yyparser
.error (]b4_locations_if([this->yylloc
, ])[YY_("syntax error"));]],
2306 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2307 /* Arguments of yyformat. */
2308 yysymbol_kind_t yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
]
2309 = { ]b4_symbol(empty
, kind
)[ };
2310 /* Number of reported tokens (one for the "unexpected", one per
2314 /* There are many possibilities here to consider:
2315 - If this state is a consistent state with a default action, then
2316 the only way this function was invoked is if the default action
2317 is an error action. In that case, don't check for expected
2318 tokens because there are none.
2319 - The only way there can be no lookahead present (in yytoken) is if
2320 this state is a consistent state with a default action. Thus,
2321 detecting the absence of a lookahead is sufficient to determine
2322 that there is no unexpected or expected token to report. In that
2323 case, just report a simple "syntax error".
2324 - Don't assume there isn't a lookahead just because this state is a
2325 consistent state with a default action. There might have been a
2326 previous inconsistent state, consistent state with a non-default
2327 action, or user semantic action that manipulated yytoken.
2328 - Of course, the expected token list depends on states to have
2329 correct lookahead information, and it depends on the parser not
2330 to perform extra reductions after fetching a lookahead from the
2331 scanner and before detecting a syntax error. Thus, state merging
2332 (from LALR or IELR) and default reductions corrupt the expected
2333 token list. However, the list is correct for canonical LR with
2334 one exception: it will still contain any token that will not be
2335 accepted due to an error action in a later state.
2337 if (yytoken
!= ]b4_symbol(empty
, kind
)[)
2339 const int yyn
= yypact
[firstTopState()->yylrState
];
2340 yyarg
[yycount
++] = yytoken
;
2341 if (!yypact_value_is_default (yyn
))
2343 /* Start YYX at -YYN if negative to avoid negative indexes in
2344 YYCHECK. In other words, skip the first -YYN actions for this
2345 state because they are default actions. */
2346 const int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2347 /* Stay within bounds of both yycheck and yytname. */
2348 const int yychecklim
= YYLAST
- yyn
+ 1;
2349 const int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2350 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2351 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= ]b4_symbol(error
, kind
)[
2352 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2354 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2359 yyarg
[yycount
++] = static_cast<yysymbol_kind_t
>(yyx
);
2364 /* Internationalized format string. */
2365 const char *yyformat
= YY_NULLPTR
;
2368 #define YYCASE_(N, S) \
2372 default: /* Avoid compiler warnings. */
2373 YYCASE_(0, YY_("syntax error"));
2374 YYCASE_(1, YY_("syntax error, unexpected %s"));
2375 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2376 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2377 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2378 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2384 std::ptrdiff_t yyi
= 0;
2385 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
2386 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
2388 yymsg
+= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yyarg
[yyi
++]);
2393 yyparser
.error (]b4_locations_if([[yylloc
, ]])[yymsg
);
2400 /* Recover from a syntax error on this, assuming that yytoken,
2401 yylval, and yylloc are the syntactic category, semantic value, and location
2402 of the lookahead. */
2404 yyrecoverSyntaxError (]b4_locations_if([location_type
* yylocp
])[)
2406 if (yyerrState
== 3)
2407 /* We just shifted the error token and (perhaps) took some
2408 reductions. Skip tokens until we can proceed. */
2411 if (this->yytoken
== ]b4_symbol(eof
, kind
)[)
2412 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2413 if (this->yytoken
!= ]b4_symbol(empty
, kind
)[)
2414 {]b4_locations_if([[
2415 /* We throw away the lookahead, but the error range
2416 of the shifted error token must take it into account. */
2417 glr_state
*yys
= firstTopState();
2418 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;
2419 yyerror_range
[2].getState().yyloc
= this->yylloc
;
2420 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2421 yyparser
.yy_destroy_ ("Error: discarding",
2422 this->yytoken
, this->yylval
]b4_locations_if([, this->yylloc
])[);]b4_variant_if([[
2423 // Value type destructor.
2424 ]b4_symbol_variant([[this->yytoken
]], [[this->yylval
]], [[template destroy
]])])[
2425 this->yytoken
= ]b4_symbol(empty
, kind
)[;
2428 int yyj
= yypact
[firstTopState()->yylrState
];
2429 if (yypact_value_is_default (yyj
))
2431 yyj
+= this->yytoken
;
2432 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != this->yytoken
)
2434 if (yydefact
[firstTopState()->yylrState
] != 0)
2437 else if (! yytable_value_is_error (yytable
[yyj
]))
2441 if (!yystateStack
.reduceToOneStack())
2442 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2444 /* Now pop stack until we find a state that shifts the error token. */
2446 while (firstTopState () != YY_NULLPTR
)
2448 glr_state
*yys
= firstTopState ();
2449 int yyj
= yypact
[yys
->yylrState
];
2450 if (! yypact_value_is_default (yyj
))
2453 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2454 && yy_is_shift_action (yytable
[yyj
]))
2456 /* Shift the error token. */]b4_locations_if([[
2457 /* First adjust its location.*/
2458 location_type yyerrloc
;
2459 yyerror_range
[2].getState().yyloc
= this->yylloc
;
2460 YYLLOC_DEFAULT (yyerrloc
, (yyerror_range
), 2);]])[
2461 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable
[yyj
]),
2463 yyglrShift (create_state_set_index(0), yytable
[yyj
],
2464 yys
->yyposn
, yylval
]b4_locations_if([, yyerrloc
])[);
2465 yys
= firstTopState();
2468 }]b4_locations_if([[
2469 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;]])[
2470 if (yys
->pred() != YY_NULLPTR
)
2471 yys
->destroy ("Error: popping", yyparser
]b4_user_args
[);
2472 yystateStack
.setFirstTop(yys
->pred());
2473 yystateStack
.pop_back();
2475 if (firstTopState() == YY_NULLPTR
)
2476 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2480 yyprocessOneStack (state_set_index yyk
,
2481 size_t yyposn
]b4_locations_if([, location_type
* yylocp
])[)
2483 while (yystateStack
.topAt(yyk
) != YY_NULLPTR
)
2485 const state_num yystate
= topState(yyk
)->yylrState
;
2486 YYCDEBUG
<< "Stack " << yyk
.get()
2487 << " Entering state " << yystate
<< '\n';
2489 YYASSERT (yystate
!= YYFINAL
);
2491 if (yy_is_defaulted_state (yystate
))
2493 const rule_num yyrule
= yy_default_action (yystate
);
2496 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2497 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2500 const YYRESULTTAG yyflag
2501 = yyglrReduce (yyk
, yyrule
, yyimmediate
[yyrule
]);
2502 if (yyflag
== yyerr
)
2504 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2505 " (predicate failure or explicit user error).\n";
2506 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2514 yystateStack
.yytops
.setLookaheadNeeds(yyk
, true);
2516 const short* yyconflicts
;
2517 const int yyaction
= yygetLRActions (yystate
, this->yytoken
, yyconflicts
);
2519 for (; *yyconflicts
!= 0; ++yyconflicts
)
2521 state_set_index yynewStack
= yystateStack
.yysplitStack (yyk
);
2522 YYCDEBUG
<< "Splitting off stack " << yynewStack
.get()
2523 << " from " << yyk
.get() << ".\n";
2524 YYRESULTTAG yyflag
=
2525 yyglrReduce (yynewStack
, *yyconflicts
, yyimmediate
[*yyconflicts
]);
2527 YYCHK (yyprocessOneStack (yynewStack
,
2528 yyposn
]b4_locations_if([, yylocp
])[));
2529 else if (yyflag
== yyerr
)
2531 YYCDEBUG
<< "Stack " << yynewStack
.get() << " dies.\n";
2532 yystateStack
.yytops
.yymarkStackDeleted (yynewStack
);
2538 if (yy_is_shift_action (yyaction
))
2540 else if (yy_is_error_action (yyaction
))
2542 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2543 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2549 = yyglrReduce (yyk
, -yyaction
, yyimmediate
[-yyaction
]);
2550 if (yyflag
== yyerr
)
2552 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2553 " (predicate failure or explicit user error).\n";
2554 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2557 else if (yyflag
!= yyok
)
2565 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2566 * and top stack item YYVSP. YYVALP points to place to put semantic
2567 * value ($$), and yylocp points to place for location information
2568 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2569 * yyerr for YYERROR, yyabort for YYABORT. */
2571 yyuserAction (rule_num yyrule
, int yyrhslen
, glr_stack_item
* yyvsp
, state_set_index yyk
,
2572 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2574 bool yynormal YY_ATTRIBUTE_UNUSED
= !yystateStack
.isSplit();
2576 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
2580 # define yyerrok (yyerrState = 0)
2582 # define YYACCEPT return yyaccept
2584 # define YYABORT return yyabort
2586 # define YYERROR return yyerrok, yyerr
2587 # undef YYRECOVERING
2588 # define YYRECOVERING() (yyerrState != 0)
2590 # define yytoken this->yytoken
2592 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2594 # define YYBACKUP(Token, Value) \
2595 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2599 /* Variants are always initialized to an empty instance of the
2600 correct type. The default '$$ = $1' action is NOT applied
2601 when using variants. */
2602 // However we really need to prepare yyvsp now if we want to get
2603 // correct locations, so invoke YYFILL for $1 anyway.
2604 (void) YYFILL (1-yyrhslen
);
2605 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [(*yyvalp
)], [emplace
])], [[
2607 *yyvalp
= yyval_default
;
2609 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].getState().value ();]])[]b4_locations_if([[
2610 /* Default location. */
2611 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
2612 yyerror_range
[1].getState().yyloc
= *yylocp
;
2614 /* If yyk == -1, we are running a deferred action on a temporary
2615 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2616 so pretend the stack is "normal". */
2617 YY_REDUCE_PRINT ((yynormal
|| yyk
== create_state_set_index (-1), yyvsp
, yyk
, yyrule
, yyparser
));
2619 typedef ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error syntax_error
;
2622 #endif // YY_EXCEPTIONS
2630 catch (const syntax_error
& yyexc
)
2632 YYCDEBUG
<< "Caught exception: " << yyexc
.what() << '\n';]b4_locations_if([
2633 *yylocp
= yyexc
.location
;])[
2634 yyparser
.error (]b4_locations_if([*yylocp
, ])[yyexc
.what ());
2637 #endif // YY_EXCEPTIONS
2638 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule
), *yyvalp
, *yylocp
);
2648 # undef YYRECOVERING
2654 if (yystateStack
.isSplit ())
2657 for (glr_state
* yys
= firstTopState ();
2658 yys
!= yystateStack
.yysplitPoint
;
2661 YYCHK (yyresolveStates (*firstTopState (), yyn
));
2666 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2667 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2668 * semantic values. Assumes that all ambiguities in semantic values
2669 * have been previously resolved. Set *YYVALP to the resulting value,
2670 * and *YYLOCP to the computed location (if any). Return value is as
2671 * for userAction. */
2673 yydoAction (state_set_index yyk
, rule_num yyrule
,
2674 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2676 const int yynrhs
= yyrhsLength (yyrule
);
2678 if (!yystateStack
.isSplit())
2680 /* Standard special case: single stack. */
2681 YYASSERT (yyk
.get() == 0);
2682 glr_stack_item
* yyrhs
= yystateStack
.firstTop()->asItem();
2683 const YYRESULTTAG res
2684 = yyuserAction (yyrule
, yynrhs
, yyrhs
, yyk
, yyvalp
]b4_locations_if([, yylocp
])[);
2685 yystateStack
.pop_back(static_cast<size_t>(yynrhs
));
2686 yystateStack
.setFirstTop(&yystateStack
[yystateStack
.size() - 1].getState());
2691 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2692 glr_state
* yys
= yystateStack
.topAt(yyk
);
2693 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yys
);]b4_locations_if([[
2695 /* Set default location. */
2696 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yys
->yyloc
;]])[
2697 for (int yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
2700 YYASSERT (yys
!= YY_NULLPTR
);
2702 yystateStack
.yyupdateSplit (*yys
);
2703 yystateStack
.setTopAt(yyk
, yys
);
2704 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2706 yyvalp
]b4_locations_if([, yylocp
])[);
2710 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2711 * and push back on the resulting nonterminal symbol. Perform the
2712 * semantic action associated with YYRULE and store its value with the
2713 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2714 * unambiguous. Otherwise, store the deferred semantic action with
2715 * the new state. If the new state would have an identical input
2716 * position, LR state, and predecessor to an existing state on the stack,
2717 * it is identified with that existing state, eliminating stack #YYK from
2718 * *YYSTACKP. In this case, the semantic value is
2719 * added to the options for the existing state's semantic value.
2722 yyglrReduce (state_set_index yyk
, rule_num yyrule
, bool yyforceEval
)
2724 size_t yyposn
= topState(yyk
)->yyposn
;
2726 if (yyforceEval
|| !yystateStack
.isSplit())
2728 value_type val
;]b4_locations_if([[
2729 location_type loc
;]])[
2731 YYRESULTTAG yyflag
= yydoAction (yyk
, yyrule
, &val
]b4_locations_if([, &loc
])[);
2732 if (yyflag
== yyerr
&& yystateStack
.isSplit())
2733 {]b4_parse_trace_if([[
2734 YYCDEBUG
<< "Parse on stack " << yyk
.get ()
2735 << " rejected by rule " << yyrule
- 1
2736 << " (line " << int (yyrline
[yyrule
]) << ").\n";
2741 yyLRgotoState (topState(yyk
)->yylrState
,
2742 yylhsNonterm (yyrule
)),
2743 yyposn
, val
]b4_locations_if([, loc
])[);]b4_variant_if([[
2744 // FIXME: User destructors.
2745 // Value type destructor.
2746 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [[val
]], [[template destroy
]])])[
2750 glr_state
*yys
= yystateStack
.topAt(yyk
);
2751 glr_state
*yys0
= yys
;
2752 for (int yyn
= yyrhsLength (yyrule
); 0 < yyn
; yyn
-= 1)
2755 YYASSERT (yys
!= YY_NULLPTR
);
2757 yystateStack
.yyupdateSplit (*yys
);
2758 state_num yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));]b4_parse_trace_if([[
2759 YYCDEBUG
<< "Reduced stack " << yyk
.get ()
2760 << " by rule " << yyrule
- 1 << " (line " << int (yyrline
[yyrule
])
2761 << "); action deferred. Now in state " << yynewLRState
2763 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < yystateStack
.numTops(); ++yyi
)
2764 if (yyi
!= yyk
&& yystateStack
.topAt(yyi
) != YY_NULLPTR
)
2766 const glr_state
* yysplit
= yystateStack
.yysplitPoint
;
2767 glr_state
* yyp
= yystateStack
.topAt(yyi
);
2768 while (yyp
!= yys
&& yyp
!= yysplit
2769 && yyp
->yyposn
>= yyposn
)
2771 if (yyp
->yylrState
== yynewLRState
2772 && yyp
->pred() == yys
)
2774 yyaddDeferredAction (yyk
, yyp
, yys0
, yyrule
);
2775 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2776 YYCDEBUG
<< "Merging stack " << yyk
.get ()
2777 << " into stack " << yyi
.get () << ".\n";
2783 yystateStack
.setTopAt(yyk
, yys
);
2784 yyglrShiftDefer (yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
2789 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2790 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2791 * semantic value of YYRHS under the action for YYRULE. */
2793 yyglrShiftDefer (state_set_index yyk
, state_num yylrState
,
2794 size_t yyposn
, glr_state
* yyrhs
, rule_num yyrule
)
2796 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2797 glr_state (yylrState
, yyposn
));
2798 yynewState
.setPred (yystateStack
.topAt (yyk
));
2799 yystateStack
.setTopAt (yyk
, &yynewState
);
2801 /* Invokes yyreserveStack. */
2802 yyaddDeferredAction (yyk
, &yynewState
, yyrhs
, yyrule
);
2805 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2806 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2807 * value YYVAL_ARG and source location YYLOC_ARG. */
2809 yyglrShift (state_set_index yyk
, state_num yylrState
,
2811 const value_type
& yyval_arg
]b4_locations_if([, const location_type
& yyloc_arg
])[)
2813 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2814 glr_state (yylrState
, yyposn
, yyval_arg
]b4_locations_if([, yyloc_arg
])[));
2815 yynewState
.setPred (yystateStack
.topAt(yyk
));
2816 yystateStack
.setTopAt (yyk
, &yynewState
);
2817 yyreserveGlrStack ();
2820 #if ]b4_api_PREFIX[DEBUG
2822 yypstack (state_set_index yyk
) const
2824 yystateStack
.yypstates (yystateStack
.topAt (yyk
));
2828 glr_state
* topState(state_set_index i
) {
2829 return yystateStack
.topAt(i
);
2832 glr_state
* firstTopState() {
2833 return yystateStack
.firstTop();
2840 /* If the stack is well-formed, pop the stack until it is empty,
2841 destroying its entries as we go. But free the stack regardless
2842 of whether it is well-formed. */
2843 for (state_set_index k
= create_state_set_index(0); k
.uget() < yystateStack
.numTops(); k
+= 1)
2844 if (yystateStack
.topAt(k
) != YY_NULLPTR
)
2846 while (yystateStack
.topAt(k
) != YY_NULLPTR
)
2848 glr_state
* state
= topState(k
);]b4_locations_if([[
2849 yyerror_range
[1].getState().yyloc
= state
->yyloc
;]])[
2850 if (state
->pred() != YY_NULLPTR
)
2851 state
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
2852 yystateStack
.setTopAt(k
, state
->pred());
2853 yystateStack
.pop_back();
2859 /** Resolve the previous YYN states starting at and including state YYS
2860 * on *YYSTACKP. If result != yyok, some states may have been left
2861 * unresolved possibly with empty semantic option chains. Regardless
2862 * of whether result = yyok, each state has been left with consistent
2863 * data so that destroy can be invoked if necessary. */
2865 yyresolveStates (glr_state
& yys
, int yyn
)
2869 YYASSERT (yys
.pred() != YY_NULLPTR
);
2870 YYCHK (yyresolveStates (*yys
.pred(), yyn
-1));
2871 if (! yys
.yyresolved
)
2872 YYCHK (yyresolveValue (yys
));
2878 yyuserMerge (int yyn
, value_type
& yy0
, value_type
& yy1
)
2890 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2891 * perform the indicated actions, and set the semantic value of YYS.
2892 * If result != yyok, the chain of semantic options in YYS has been
2893 * cleared instead or it has been left unmodified except that
2894 * redundant options may have been removed. Regardless of whether
2895 * result = yyok, YYS has been left with consistent data so that
2896 * destroy can be invoked if necessary. */
2898 yyresolveValue (glr_state
& yys
)
2900 semantic_option
* yybest
= yys
.firstVal();
2901 YYASSERT(yybest
!= YY_NULLPTR
);
2902 bool yymerge
= false;
2903 YYRESULTTAG yyflag
;]b4_locations_if([
2904 location_type
*yylocp
= &yys
.yyloc
;])[
2906 semantic_option
* yypPrev
= yybest
;
2907 for (semantic_option
* yyp
= yybest
->next();
2908 yyp
!= YY_NULLPTR
; )
2910 if (yybest
->isIdenticalTo (*yyp
))
2912 yybest
->mergeWith (*yyp
);
2913 yypPrev
->setNext(yyp
->next());
2914 yyp
= yypPrev
->next();
2918 switch (yypreference (*yybest
, *yyp
))
2920 case 0:]b4_locations_if([[
2921 yyresolveLocations (yys
, 1);]])[
2922 return yystateStack
.yyreportAmbiguity (*yybest
, *yyp
, yyparser
]b4_locations_if([, *yylocp
])[);
2934 /* This cannot happen so it is not worth a YYASSERT (false),
2935 but some compilers complain if the default case is
2947 int yyprec
= yydprec
[yybest
->yyrule
];
2948 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2950 for (semantic_option
* yyp
= yybest
->next();
2954 if (yyprec
== yydprec
[yyp
->yyrule
])
2956 value_type yyval_other
;]b4_locations_if([
2957 location_type yydummy
;])[
2958 yyflag
= yyresolveAction (*yyp
, &yyval_other
]b4_locations_if([, &yydummy
])[);
2961 yyparser
.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2962 yy_accessing_symbol (yys
.yylrState
),
2963 this->yylval
]b4_locations_if([, *yylocp
])[);
2966 yyuserMerge (yymerger
[yyp
->yyrule
], val
, yyval_other
);]b4_variant_if([[
2967 // FIXME: User destructors.
2968 // Value type destructor.
2969 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[yyval_other
]], [[template destroy
]])])[
2974 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2978 yys
.yyresolved
= true;
2979 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_variant_if([[
2980 new (&yys
.value ()) value_type ();
2981 ]b4_symbol_variant([yy_accessing_symbol (yys
.yylrState
)],
2982 [yys
.value ()], [copy
], [val
])], [[
2983 new (&yys
.value ()) value_type (val
);]])[
2985 YY_IGNORE_MAYBE_UNINITIALIZED_END
2988 yys
.setFirstVal(YY_NULLPTR
);
2990 // FIXME: User destructors.
2991 // Value type destructor.
2992 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[val
]], [[template destroy
]])])[
2996 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2997 * user action, and return the semantic value and location in *YYVALP
2998 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2999 * have been destroyed (assuming the user action destroys all RHS
3000 * semantic values if invoked). */
3002 yyresolveAction (semantic_option
& yyopt
, value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
3004 glr_state
* yyoptState
= yyopt
.state();
3005 YYASSERT(yyoptState
!= YY_NULLPTR
);
3006 int yynrhs
= yyrhsLength (yyopt
.yyrule
);
3007 YYRESULTTAG yyflag
= yyresolveStates (*yyoptState
, yynrhs
);
3010 for (glr_state
*yys
= yyoptState
; yynrhs
> 0; yys
= yys
->pred(), yynrhs
-= 1)
3011 yys
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
3015 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
3016 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yyopt
.state());]b4_locations_if([[
3018 /* Set default location. */
3019 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yyoptState
->yyloc
;]])[
3021 symbol_kind_type yytoken_current
= this->yytoken
;]b4_variant_if([[
3022 value_type yylval_current
;
3023 ]b4_symbol_variant([this->yytoken
],
3024 [yylval_current
], [move
], [this->yylval
])], [[
3025 value_type yylval_current
= this->yylval
;]])[]b4_locations_if([
3026 location_type yylloc_current
= this->yylloc
;])[
3028 this->yytoken
= yyopt
.yytoken
;]b4_variant_if([[
3029 ]b4_symbol_variant([this->yytoken
],
3030 [this->yylval
], [move
], [yyopt
.yyval
])], [[
3031 this->yylval
= yyopt
.yyval
;]])[]b4_locations_if([
3032 this->yylloc
= yyopt
.yyloc
;])[
3033 yyflag
= yyuserAction (yyopt
.yyrule
, yynrhs
,
3034 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
3035 create_state_set_index (-1),
3036 yyvalp
]b4_locations_if([, yylocp
])[);
3038 this->yytoken
= yytoken_current
;]b4_variant_if([[
3039 ]b4_symbol_variant([this->yytoken
],
3040 [this->yylval
], [move
], [yylval_current
])], [[
3041 this->yylval
= yylval_current
;]])[]b4_locations_if([
3042 this->yylloc
= yylloc_current
;])[
3045 }]b4_locations_if([[
3047 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
3048 * ending at YYS1. Has no effect on previously resolved states.
3049 * The first semantic option of a state is always chosen. */
3051 yyresolveLocations (glr_state
&yys1
, int yyn1
)
3055 yyresolveLocations (*yys1
.pred(), yyn1
- 1);
3056 if (!yys1
.yyresolved
)
3058 glr_stack_item yyrhsloc
[1 + YYMAXRHS
];
3059 YYASSERT (yys1
.firstVal() != YY_NULLPTR
);
3060 semantic_option
& yyoption
= *yys1
.firstVal();
3061 const int yynrhs
= yyrhsLength (yyoption
.yyrule
);
3064 yyresolveLocations (*yyoption
.state(), yynrhs
);
3065 const glr_state
*yys
= yyoption
.state();
3066 for (int yyn
= yynrhs
; yyn
> 0; yyn
-= 1)
3068 yyrhsloc
[yyn
].getState().yyloc
= yys
->yyloc
;
3074 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3075 in reverse rightmost order. It is only necessary to invoke
3076 yyresolveLocations on a subforest for which yyresolveAction
3077 would have been invoked next had an ambiguity not been
3078 detected. Thus the location of the previous state (but not
3079 necessarily the previous state itself) is guaranteed to be
3080 resolved already. */
3081 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3082 yyrhsloc
[0].getState().yyloc
= yyoption
.state()->yyloc
;
3083 YY_IGNORE_NULL_DEREFERENCE_END
3085 YYLLOC_DEFAULT ((yys1
.yyloc
), yyrhsloc
, yynrhs
);
3090 /** If yytoken is empty, fetch the next token. */
3094 ]b4_parse_param_use()dnl
3095 [ if (this->yytoken
== ]b4_symbol(empty
, kind
)[)
3097 YYCDEBUG
<< "Reading a token\n";
3102 #endif // YY_EXCEPTIONS
3103 {]b4_token_ctor_if([[
3104 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_type symbol_type
;
3105 symbol_type yylookahead
= ]b4_yylex
[;
3106 this->yytoken
= yylookahead
.kind ();]b4_variant_if([[
3107 ]b4_symbol_variant([this->yytoken
],
3108 [this->yylval
], [move
], [yylookahead
.value
])], [[
3109 this->yylval
= yylookahead
.value
;]])[]b4_locations_if([
3110 this->yylloc
= yylookahead
.location
;
3111 yylookahead
.kind_
= symbol_kind::S_YYEMPTY
;])[]], [[
3112 yychar
= ]b4_yylex
[;]])[
3116 catch (const ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error
& yyexc
)
3118 YYCDEBUG
<< "Caught exception: " << yyexc
.what () << '\n';]b4_locations_if([
3119 this->yylloc
= yyexc
.location
;])[
3120 yyparser
.error (]b4_locations_if([this->yylloc
, ])[yyexc
.what ());
3121 // Map errors caught in the scanner to the error token, so that error
3122 // handling is started.]b4_token_ctor_if([[
3123 this->yytoken
= ]b4_symbol(error
, kind
)[;]], [[
3124 yychar
= ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(error
, id
)[;]])[
3126 #endif // YY_EXCEPTIONS]b4_token_ctor_if([], [[
3128 = ]b4_namespace_ref
[::]b4_parser_class
[::yytranslate_ (yychar
);]])[
3130 if (this->yytoken
== ]b4_symbol(eof
, kind
)[)
3131 YYCDEBUG
<< "Now at end of input.\n";
3133 YY_SYMBOL_PRINT ("Next token is", this->yytoken
, this->yylval
, this->yylloc
);
3137 /* Bison grammar-table manipulation. */
3139 /** The action to take in YYSTATE on seeing YYTOKEN.
3141 * R < 0: Reduce on rule -R.
3143 * R > 0: Shift to state R.
3144 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3145 * of conflicting reductions.
3148 yygetLRActions (state_num yystate
, yysymbol_kind_t yytoken
, const short*& yyconflicts
)
3150 int yyindex
= yypact
[yystate
] + yytoken
;
3151 if (yytoken
== ]b4_symbol(error
, kind
)[)
3153 // This is the error token.
3154 yyconflicts
= yyconfl
;
3157 else if (yy_is_defaulted_state (yystate
)
3158 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
3160 yyconflicts
= yyconfl
;
3161 return -yydefact
[yystate
];
3163 else if (! yytable_value_is_error (yytable
[yyindex
]))
3165 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3166 return yytable
[yyindex
];
3170 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3175 /** Compute post-reduction state.
3176 * \param yystate the current state
3177 * \param yysym the nonterminal to push on the stack
3180 yyLRgotoState (state_num yystate
, yysymbol_kind_t yysym
)
3182 const int yyr
= yypgoto
[yysym
- YYNTOKENS
] + yystate
;
3183 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
3184 return yytable
[yyr
];
3186 return yydefgoto
[yysym
- YYNTOKENS
];
3190 yypact_value_is_default (state_num yystate
)
3192 return ]b4_table_value_equals([[pact
]], [[yystate
]], [b4_pact_ninf
], [YYPACT_NINF
])[;
3196 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED
)
3198 return ]b4_table_value_equals([[table
]], [[yytable_value
]], [b4_table_ninf
], [YYTABLE_NINF
])[;
3202 yy_is_shift_action (int yyaction
)
3204 return 0 < yyaction
;
3208 yy_is_error_action (int yyaction
)
3210 return yyaction
== 0;
3213 /** Whether LR state YYSTATE has only a default reduction
3214 * (regardless of token). */
3216 yy_is_defaulted_state (state_num yystate
)
3218 return yypact_value_is_default (yypact
[yystate
]);
3221 /** The default reduction for YYSTATE, assuming it has one. */
3223 yy_default_action (state_num yystate
)
3225 return yydefact
[yystate
];
3230 /** Y0 and Y1 represent two possible actions to take in a given
3231 * parsing state; return 0 if no combination is possible,
3232 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3234 yypreference (const semantic_option
& y0
, const semantic_option
& y1
)
3236 rule_num r0
= y0
.yyrule
, r1
= y1
.yyrule
;
3237 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
3241 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
3246 if (p0
== 0 || p1
== 0)
3255 ]b4_parse_param_vars
[
3260 /* DEBUGGING ONLY */
3261 #if ]b4_api_PREFIX[DEBUG
3263 yypstack (const glr_stack
& yystack
, size_t yyk
)
3265 yystack
.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk
)));
3267 static void yypdumpstack (const glr_stack
& yystack
)
3269 yystack
.yypdumpstack ();
3275 /// Build a parser object.
3276 ]b4_parser_class::b4_parser_class
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
3278 #if ]b4_api_PREFIX[DEBUG
3279 ]m4_ifset([b4_parse_param
], [ ], [ :])[yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
3280 #endif]b4_parse_param_cons[
3283 ]b4_parser_class::~b4_parser_class
[ ()
3286 ]b4_parser_class
[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3290 ]b4_parser_class
[::operator() ()
3296 ]b4_parser_class
[::parse ()
3298 glr_stack
yystack(YYINITDEPTH
, *this]b4_user_args
[);
3299 return yystack
.parse ();
3302 ]b4_parse_error_bmatch([custom\
|detailed
],
3304 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3306 static const char *const yy_sname
[] =
3309 };]b4_has_translations_if([[
3310 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3311 internationalizable. */
3312 static ]b4_int_type_for([b4_translatable
])[ yytranslatable
[] =
3316 return (yysymbol
< YYNTOKENS
&& yytranslatable
[yysymbol
]
3317 ? _(yy_sname
[yysymbol
])
3318 : yy_sname
[yysymbol
]);]], [[
3319 return yy_sname
[yysymbol
];]])[
3323 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3325 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3327 return yytname_
[yysymbol
];
3329 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3332 [[ /* Return YYSTR after stripping away unnecessary quotes and
3333 backslashes, so that it's suitable for yyerror. The heuristic is
3334 that double-quoting is unnecessary unless the string contains an
3335 apostrophe, a comma, or backslash (other than backslash-backslash).
3336 YYSTR is taken from yytname. */
3338 ]b4_parser_class
[::yytnamerr_ (const char *yystr
)
3343 char const *yyp
= yystr
;
3350 goto do_not_strip_quotes
;
3354 goto do_not_strip_quotes
;
3366 do_not_strip_quotes
: ;
3373 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3375 return yytnamerr_ (yytname_
[yysymbol
]);
3379 ]b4_parse_error_bmatch([simple\
|verbose
],
3380 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3381 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3382 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3384 const ]b4_parser_class
[::yytname_
[] =
3392 ]b4_parser_class
[::yy_destroy_ (const char* yymsg
, symbol_kind_type yykind
,
3393 value_type
& yyval
]b4_locations_if([[,
3394 location_type
& yyloc
]])[)
3396 YY_USE (yyval
);]b4_locations_if([[
3400 ]b4_parser_class
[& yyparser
= *this;
3402 YY_SYMBOL_PRINT (yymsg
, yykind
, yyval
, yyloc
);
3404 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3405 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3406 [b4_symbol_actions([destructor
])],
3407 [m4_popdef([b4_symbol_action
])])[
3408 YY_IGNORE_MAYBE_UNINITIALIZED_END
3411 #if ]b4_api_PREFIX[DEBUG
3412 /*--------------------.
3413 | Print this symbol. |
3414 `--------------------*/
3417 ]b4_parser_class
[::yy_symbol_value_print_ (symbol_kind_type yykind
,
3418 const value_type
& yyval
]b4_locations_if([[,
3419 const location_type
& yyloc
]])[) const
3420 {]b4_locations_if([[
3423 std::ostream
& yyo
= debug_stream ();
3425 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3426 [b4_symbol_actions([printer
])],
3427 [m4_popdef([b4_symbol_action
])])[
3431 ]b4_parser_class
[::yy_symbol_print_ (symbol_kind_type yykind
,
3432 const value_type
& yyval
]b4_locations_if([[,
3433 const location_type
& yyloc
]])[) const
3435 *yycdebug_
<< (yykind
< YYNTOKENS
? "token" : "nterm")
3436 << ' ' << symbol_name (yykind
) << " ("]b4_locations_if([[
3437 << yyloc
<< ": "]])[;
3438 yy_symbol_value_print_ (yykind
, yyval
]b4_locations_if([[, yyloc
]])[);
3443 ]b4_parser_class
[::debug_stream () const
3449 ]b4_parser_class
[::set_debug_stream (std::ostream
& o
)
3455 ]b4_parser_class
[::debug_level_type
3456 ]b4_parser_class
[::debug_level () const
3462 ]b4_parser_class
[::set_debug_level (debug_level_type l
)
3464 // Actually, it is yydebug which is really used.
3467 #endif // ]b4_api_PREFIX[DEBUG
3469 ]b4_token_ctor_if([], [b4_yytranslate_define([cc
])])[
3470 ]b4_namespace_close
[]dnl