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
))
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[[]] =
59 ## ---------------- ##
61 ## ---------------- ##
64 m4_define_default([b4_stack_depth_max
], [10000])
65 m4_define_default([b4_stack_depth_init
], [200])
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
)])])
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 # --------------------------------
97 m4_define([b4_lhs_value
],
98 [b4_symbol_value([(*yyvalp
)], [$
1], [$
2])])
101 # b4_rhs_data(RULE-LENGTH, POS)
102 # -----------------------------
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])])
123 m4_define([b4_lhs_location
],
127 # b4_rhs_location(RULE-LENGTH, NUM)
128 # ---------------------------------
129 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
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],
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
156 m4_popdef([b4_symbol_value])[]dnl
157 b4_dollar_popdef[]dnl
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],
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
177 b4_dollar_popdef[]dnl
181 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
182 # ---------------------------------------------------
183 m4_define([b4_call_merger],
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);])])])
193 m4_define([b4_yylex],
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]])[
210 #include <cstddef> // ptrdiff_t
211 #include <cstring> // memcpy
221 ]m4_ifdef([b4_location_include],
222 [[# include ]b4_location_include])[
223 ]b4_variant_if([b4_variant_includes])[
229 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
230 [b4_location_define])])[
233 class ]b4_parser_class[
236 ]b4_public_types_declare[
237 ]b4_symbol_type_define[
239 // FIXME: should be private eventually.
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.
252 /// \returns 0 iff parsing succeeded.
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);
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(
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);]],
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[
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], [[
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; }
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;
308 const symbol_type& yyla_;
311 # if ]b4_api_PREFIX[DEBUG
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;
329 std::ostream* yycdebug_;
332 ]b4_parse_error_bmatch(
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], [[
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) YY_NOEXCEPT;
353 ]b4_parse_error_bmatch(
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[
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_[];
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.
381 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
382 ]b4_public_types_define([$1])])[
385 ]b4_percent_code_get([[provides]])[
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.
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])[
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.
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[
435 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
436 [b4_shared_declarations([cc])])[
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[
454 # if defined YYENABLE_NLS && YYENABLE_NLS
456 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
457 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
461 # define YY_(Msgid) Msgid
465 // Whether we are compiled with exception support.
466 #ifndef YY_EXCEPTIONS
467 # if defined __GNUC__ && !defined __EXCEPTIONS
468 # define YY_EXCEPTIONS 0
470 # define YY_EXCEPTIONS 1
478 # define YYMALLOC malloc
483 # define YYJMP_BUF jmp_buf
484 # define YYSETJMP(Env) setjmp (Env)
485 /* Pacify Clang and ICC. */
486 # define YYLONGJMP(Env, Val) \
488 longjmp (Env, Val); \
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")
502 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
503 # define YY_IGNORE_NULL_DEREFERENCE_END
509 // FIXME: Use the same conventions as lalr1.cc.
512 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
516 # define YYDASSERT(Condition) YYASSERT(Condition)
518 # define YYDASSERT(Condition)
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[
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[] =
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[] =
561 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
562 const ]b4_int_type_for([b4_merger])[ yymerger[] =
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[] =
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[
595 /* Error token number */
599 ]b4_yylloc_default_define[
600 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
603 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
607 YYRESULTTAG yychk_flag = YYE; \
608 if (yychk_flag != yyok) \
612 #if ]b4_api_PREFIX[DEBUG
614 #define YYCDEBUG if (!yydebug) {} else std::cerr
616 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
620 std::cerr << Title << ' '; \
621 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
626 # define YY_REDUCE_PRINT(Args) \
629 yystateStack.yy_reduce_print Args; \
632 /* Nonzero means print parse trace. It is left uninitialized so that
633 multiple parsers can coexist. */
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)
643 void yypdumpstack (const glr_stack& yystack)
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. */
657 # define YYINITDEPTH ]b4_stack_depth_init[
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. */
668 # define YYMAXDEPTH ]b4_stack_depth_max[
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. */
678 #ifndef YYSTACKEXPANDABLE
679 # define YYSTACKEXPANDABLE 1
684 template <typename Parameter
>
685 class strong_index_alias
688 static strong_index_alias
create (std::ptrdiff_t value
)
690 strong_index_alias result
;
691 result
.value_
= value
;
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
)
709 strong_index_alias
operator- (std::ptrdiff_t other
)
711 return strong_index_alias (get () - other
);
714 void operator-= (std::ptrdiff_t other
)
719 size_t operator- (strong_index_alias other
)
721 return strong_index_alias (get () - other
.get ());
724 strong_index_alias
& operator++ ()
730 bool isValid () const
732 return value_
!= INVALID_INDEX
;
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 ();
756 static const std::ptrdiff_t INVALID_INDEX
;
758 // WARNING: 0-initialized.
759 std::ptrdiff_t value_
;
760 }; // class strong_index_alias
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 symbol_type
= parser_type::symbol_type
;
784 using value_type
= parser_type::value_type
;]b4_locations_if([[
785 using location_type
= parser_type::location_type
;]])[
787 // Forward declarations.
788 class glr_stack_item
;
789 class semantic_option
;
794 /** Accessing symbol of state YYSTATE. */
795 inline symbol_kind_type
796 yy_accessing_symbol (state_num yystate
)
798 return YY_CAST (symbol_kind_type
, yystos
[yystate
]);
801 /** Left-hand-side symbol for rule #YYRULE. */
802 inline symbol_kind_type
803 yylhsNonterm (rule_num yyrule
)
805 return static_cast<symbol_kind_type
>(yyr1
[yyrule
]);
808 /** Number of symbols composing the right hand side of rule #RULE. */
810 yyrhsLength (rule_num yyrule
)
816 namespace ]b4_namespace_ref
[
818 class ]b4_parser_class
[::glr_state
826 , yyfirstVal (0)]b4_locations_if([[
827 , yyloc ()]])[]b4_parse_assert_if([[
831 /// Build with a semantic value.
832 glr_state (state_num lrState
, size_t posn
, const value_type
& val
]b4_locations_if([[, const location_type
& loc
]])[)
834 , yylrState (lrState
)
837 , yyval (]b4_variant_if([], [[val
]])[)]b4_locations_if([[
838 , yyloc (loc
)]])[]b4_parse_assert_if([[
841 ]b4_symbol_variant([yy_accessing_symbol (lrState
)],
842 [yyval
], [copy
], [val
])])[}
844 /// Build with a semantic option.
845 glr_state (state_num lrState
, size_t posn
)
847 , yylrState (lrState
)
850 , yyfirstVal (0)]b4_locations_if([[
851 , yyloc ()]])[]b4_parse_assert_if([[
855 glr_state (const glr_state
& other
)
856 : yyresolved (other
.yyresolved
)
857 , yylrState (other
.yylrState
)
858 , yyposn (other
.yyposn
)
859 , yypred (0)]b4_locations_if([[
860 , yyloc (other
.yyloc
)]])[]b4_parse_assert_if([[
863 setPred (other
.pred ());
864 if (other
.yyresolved
)]b4_variant_if([[
866 new (&yyval
) value_type ();
867 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
868 [yyval
], [copy
], [other
.value ()])[
870 new (&yyval
) value_type (other
.value ());]])[
874 setFirstVal (other
.firstVal ());
875 }]b4_parse_assert_if([[
880 {]b4_parse_assert_if([[
884 symbol_kind_type yykind
= yy_accessing_symbol (yylrState
);
885 // FIXME: User destructors.
886 // Value type destructor.
887 ]b4_symbol_variant([[yykind
]], [[yyval
]], [[template destroy
]])])[
888 yyval
.~value_type ();
889 }]b4_parse_assert_if([[
893 glr_state
& operator= (const glr_state
& other
)
894 {]b4_parse_assert_if([[
897 if (!yyresolved
&& other
.yyresolved
)
898 new (&yyval
) value_type
;
899 yyresolved
= other
.yyresolved
;
900 yylrState
= other
.yylrState
;
901 yyposn
= other
.yyposn
;
902 setPred (other
.pred ());
903 if (other
.yyresolved
)]b4_variant_if([[
904 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
905 [yyval
], [copy
], [other
.value ()])], [[
906 value () = other
.value ();]])[
908 setFirstVal (other
.firstVal ());]b4_locations_if([[
909 yyloc
= other
.yyloc
;]])[
913 /** Type tag for the semantic value. If true, yyval applies, otherwise
914 * yyfirstVal applies. */
916 /** Number of corresponding LALR(1) machine state. */
918 /** Source position of the last token produced by my symbol */
921 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
923 const glr_state
* pred () const;
924 void setPred (const glr_state
* state
);
926 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
928 semantic_option
* firstVal ();
929 const semantic_option
* firstVal () const;
930 void setFirstVal (const semantic_option
* option
);
933 {]b4_parse_assert_if([[
938 const value_type
& value () const
939 {]b4_parse_assert_if([[
945 destroy (char const *yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
);
948 #if ]b4_api_PREFIX[DEBUG
949 void yy_yypstack () const
950 {]b4_parse_assert_if([[
952 if (pred () != YY_NULLPTR
)
954 pred ()->yy_yypstack ();
957 std::cerr
<< yylrState
<< "@@" << yyposn
;
961 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const YY_ATTRIBUTE_UNUSED
;
963 glr_stack_item
* asItem ()
964 {]b4_parse_assert_if([[
969 const glr_stack_item
* asItem () const
970 {]b4_parse_assert_if([[
972 return asItem (this);
976 template <typename T
>
977 static const glr_stack_item
* asItem (const T
* state
)
979 return reinterpret_cast<const glr_stack_item
*>(state
);
981 template <typename T
>
982 static glr_stack_item
* asItem (T
* state
)
984 return reinterpret_cast<glr_stack_item
*> (state
);
986 static const char *as_pointer_ (const glr_state
*state
)
988 return reinterpret_cast<const char *> (state
);
990 static char *as_pointer_ (glr_state
*state
)
992 return reinterpret_cast<char *> (state
);
994 /** Preceding state in this stack */
995 std::ptrdiff_t yypred
;
997 /** First in a chain of alternative reductions producing the
998 * nonterminal corresponding to this state, threaded through
999 * yyfirstVal. Value "0" means empty. */
1000 std::ptrdiff_t yyfirstVal
;
1001 /** Semantic value for this state. */
1003 };]b4_locations_if([[
1004 // FIXME: Why public?
1006 /** Source location for this state. */
1007 location_type yyloc
;]])[
1009 ]b4_parse_assert_if([[
1011 // Check invariants.
1012 void check_ () const
1014 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1015 YYASSERT (this->magic_
== MAGIC
);
1016 YY_IGNORE_NULL_DEREFERENCE_END
1019 // A magic number to check our pointer arithmetic is sane.
1020 enum { MAGIC
= 713705 };
1021 unsigned int magic_
;]])[
1022 }; // class ]b4_parser_class[::glr_state
1023 } // namespace ]b4_namespace_ref[
1028 /** A stack of GLRState representing the different heads during
1029 * nondeterministic evaluation. */
1033 /** Initialize YYSET to a singleton set containing an empty stack. */
1035 : yylastDeleted (YY_NULLPTR
)
1037 yystates
.push_back (YY_NULLPTR
);
1038 yylookaheadNeeds
.push_back (false);
1041 // Behave like a vector of states.
1042 glr_state
*& operator[] (state_set_index index
)
1044 return yystates
[index
.uget()];
1047 glr_state
* operator[] (state_set_index index
) const
1049 return yystates
[index
.uget()];
1052 size_t size () const
1054 return yystates
.size ();
1057 std::vector
<glr_state
*>::iterator
begin ()
1059 return yystates
.begin ();
1062 std::vector
<glr_state
*>::iterator
end ()
1064 return yystates
.end ();
1067 bool lookaheadNeeds (state_set_index index
) const
1069 return yylookaheadNeeds
[index
.uget ()];
1072 bool setLookaheadNeeds (state_set_index index
, bool value
)
1074 return yylookaheadNeeds
[index
.uget ()] = value
;
1077 /** Invalidate stack #YYK. */
1079 yymarkStackDeleted (state_set_index yyk
)
1081 size_t k
= yyk
.uget ();
1082 if (yystates
[k
] != YY_NULLPTR
)
1083 yylastDeleted
= yystates
[k
];
1084 yystates
[k
] = YY_NULLPTR
;
1087 /** Undelete the last stack in *this that was marked as deleted. Can
1088 only be done once after a deletion, and only when all other stacks have
1091 yyundeleteLastStack ()
1093 if (yylastDeleted
== YY_NULLPTR
|| !yystates
.empty ())
1095 yystates
.push_back (yylastDeleted
);
1096 YYCDEBUG
<< "Restoring last deleted stack as stack #0.\n";
1097 clearLastDeleted ();
1100 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1105 size_t newsize
= yystates
.size ();
1106 /* j is the number of live stacks we have seen. */
1107 for (size_t i
= 0, j
= 0; j
< newsize
; ++i
)
1109 if (yystates
[i
] == YY_NULLPTR
)
1113 YYCDEBUG
<< "Removing dead stacks.\n";
1119 yystates
[j
] = yystates
[i
];
1120 /* In the current implementation, it's unnecessary to copy
1121 yylookaheadNeeds[i] since, after
1122 yyremoveDeletes returns, the parser immediately either enters
1123 deterministic operation or shifts a token. However, it doesn't
1124 hurt, and the code might evolve to need it. */
1125 yylookaheadNeeds
[j
] = yylookaheadNeeds
[i
];
1128 YYCDEBUG
<< "Rename stack " << i
<< " -> " << j
<< ".\n";
1133 yystates
.resize (newsize
);
1134 yylookaheadNeeds
.resize (newsize
);
1139 yysplitStack (state_set_index yyk
)
1141 const size_t k
= yyk
.uget ();
1142 yystates
.push_back (yystates
[k
]);
1143 yylookaheadNeeds
.push_back (yylookaheadNeeds
[k
]);
1144 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates
.size () - 1));
1147 void clearLastDeleted ()
1149 yylastDeleted
= YY_NULLPTR
;
1154 std::vector
<glr_state
*> yystates
;
1155 /** During nondeterministic operation, yylookaheadNeeds tracks which
1156 * stacks have actually needed the current lookahead. During deterministic
1157 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1158 * duplicate !yyla.empty (). */
1159 std::vector
<bool> yylookaheadNeeds
;
1161 /** The last stack we invalidated. */
1162 glr_state
* yylastDeleted
;
1163 }; // class glr_state_set
1168 class semantic_option
1175 , yyla ()]b4_parse_assert_if([[
1176 , magic_ (MAGIC
)]])[
1179 semantic_option (rule_num rule
)
1183 , yyla ()]b4_parse_assert_if([[
1184 , magic_ (MAGIC
)]])[
1187 semantic_option (const semantic_option
& that
)
1188 : yyrule (that
.yyrule
)
1189 , yystate (that
.yystate
)
1190 , yynext (that
.yynext
)
1191 , yyla (that
.yyla
)]b4_parse_assert_if([[
1192 , magic_ (MAGIC
)]])[
1193 {]b4_parse_assert_if([[
1197 // Needed for the assignment in yynewSemanticOption.
1198 semantic_option
& operator= (const semantic_option
& that
)
1199 {]b4_parse_assert_if([[
1202 yyrule
= that
.yyrule
;
1203 yystate
= that
.yystate
;
1204 yynext
= that
.yynext
;
1209 /// Only call state() and setState() on objects in yyitems, not temporaries.
1211 const glr_state
* state() const;
1212 void setState(const glr_state
* s
);
1214 const semantic_option
* next () const YY_ATTRIBUTE_UNUSED
;
1215 semantic_option
* next ();
1216 void setNext (const semantic_option
* s
);
1218 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const YY_ATTRIBUTE_UNUSED
;
1220 /** True iff YYY0 and YYY1 represent identical options at the top level.
1221 * That is, they represent the same rule applied to RHS symbols
1222 * that produce the same terminal symbols. */
1224 isIdenticalTo (const semantic_option
& yyy1
) const
1225 {]b4_parse_assert_if([[
1228 if (this->yyrule
== yyy1
.yyrule
)
1230 const glr_state
*yys0
, *yys1
;
1232 for (yys0
= this->state(),
1233 yys1
= yyy1
.state(),
1234 yyn
= yyrhsLength (this->yyrule
);
1236 yys0
= yys0
->pred(),
1237 yys1
= yys1
->pred(), yyn
-= 1)
1238 if (yys0
->yyposn
!= yys1
->yyposn
)
1246 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1247 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1249 mergeWith (semantic_option
& yyy1
)
1250 {]b4_parse_assert_if([[
1253 glr_state
*yys0
= this->state ();
1254 glr_state
*yys1
= yyy1
.state ();
1255 for (int yyn
= yyrhsLength (this->yyrule
);
1257 yyn
-= 1, yys0
= yys0
->pred (), yys1
= yys1
->pred ())
1261 else if (yys0
->yyresolved
)
1263 yys1
->yyresolved
= true;]b4_variant_if([[
1264 YYASSERT (yys1
->yylrState
== yys0
->yylrState
);
1265 ]b4_symbol_variant([yy_accessing_symbol (yys0
->yylrState
)],
1266 [yys1
->value ()], [copy
], [yys0
->value ()])], [[
1267 yys1
->value () = yys0
->value ();]])[
1269 else if (yys1
->yyresolved
)
1271 yys0
->yyresolved
= true;]b4_variant_if([[
1272 YYASSERT (yys0
->yylrState
== yys1
->yylrState
);
1273 ]b4_symbol_variant([yy_accessing_symbol (yys1
->yylrState
)],
1274 [yys0
->value ()], [copy
], [yys1
->value ()])], [[
1275 yys0
->value () = yys1
->value ();]])[
1279 semantic_option
* yyz0prev
= YY_NULLPTR
;
1280 semantic_option
* yyz0
= yys0
->firstVal();
1281 semantic_option
* yyz1
= yys1
->firstVal();
1284 if (yyz1
== yyz0
|| yyz1
== YY_NULLPTR
)
1286 else if (yyz0
== YY_NULLPTR
)
1288 if (yyz0prev
!= YY_NULLPTR
)
1289 yyz0prev
->setNext (yyz1
);
1291 yys0
->setFirstVal (yyz1
);
1294 else if (yyz0
< yyz1
)
1296 semantic_option
* yyz
= yyz0
;
1297 if (yyz0prev
!= YY_NULLPTR
)
1298 yyz0prev
->setNext(yyz1
);
1300 yys0
->setFirstVal(yyz1
);
1301 yyz1
= yyz1
->next();
1305 yyz0
= yyz0
->next();
1307 yys1
->setFirstVal(yys0
->firstVal());
1312 #if ]b4_api_PREFIX[DEBUG
1313 void yyreportTree (size_t yyindent
= 2) const
1314 {]b4_parse_assert_if([[
1316 int yynrhs
= yyrhsLength (this->yyrule
);
1317 const glr_state
* yystates
[1 + YYMAXRHS
];
1318 glr_state yyleftmost_state
;
1321 const glr_state
* yys
= this->state();
1322 for (int yyi
= yynrhs
; 0 < yyi
; yyi
-= 1)
1324 yystates
[yyi
] = yys
;
1327 if (yys
== YY_NULLPTR
)
1329 yyleftmost_state
.yyposn
= 0;
1330 yystates
[0] = &yyleftmost_state
;
1336 std::string yylhs
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yylhsNonterm (this->yyrule
));
1337 YYASSERT(this->state());
1338 if (this->state()->yyposn
< yystates
[0]->yyposn
+ 1)
1339 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1340 << this->yyrule
- 1 << ", empty>\n";
1342 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1343 << this->yyrule
- 1 << ", tokens "
1344 << yystates
[0]->yyposn
+ 1 << " .. "
1345 << this->state()->yyposn
<< ">\n";
1346 for (int yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1348 if (yystates
[yyi
]->yyresolved
)
1350 std::string yysym
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yy_accessing_symbol (yystates
[yyi
]->yylrState
));
1351 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1352 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1355 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1356 << " <tokens " << yystates
[yyi
-1]->yyposn
+ 1
1357 << " .. " << yystates
[yyi
]->yyposn
<< ">\n";
1360 yystates
[yyi
]->firstVal ()->yyreportTree (yyindent
+2);
1365 /** Rule number for this reduction */
1369 template <typename T
>
1370 static const glr_stack_item
* asItem(const T
* state
)
1372 return reinterpret_cast<const glr_stack_item
*>(state
);
1374 template <typename T
>
1375 static glr_stack_item
* asItem(T
* state
)
1377 return reinterpret_cast<glr_stack_item
*>(state
);
1379 /** The last RHS state in the list of states to be reduced. */
1380 std::ptrdiff_t yystate
;
1381 /** Next sibling in chain of options. To facilitate merging,
1382 * options are chained in decreasing order by address. */
1383 std::ptrdiff_t yynext
;
1386 /** The lookahead for this reduction. */
1389 ]b4_parse_assert_if([[
1391 // Check invariants.
1392 void check_ () const
1394 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1395 YYASSERT (this->magic_
== MAGIC
);
1396 YY_IGNORE_NULL_DEREFERENCE_END
1399 // A magic number to check our pointer arithmetic is sane.
1400 enum { MAGIC
= 0xeff1cace };
1401 unsigned int magic_
;]])[
1402 }; // class semantic_option
1407 /** Type of the items in the GLR stack.
1408 * It can be either a glr_state or a semantic_option. The is_state_ field
1409 * indicates which item of the union is valid. */
1410 class glr_stack_item
1413 glr_stack_item (bool state
= true)
1414 : is_state_ (state
)]b4_parse_assert_if([[
1415 , magic_ (MAGIC
)]])[
1418 new (&raw_
) glr_state
;
1420 new (&raw_
) semantic_option
;
1423 glr_stack_item (const glr_stack_item
& other
) YY_NOEXCEPT YY_NOTHROW
1424 : is_state_ (other
.is_state_
)]b4_parse_assert_if([[
1425 , magic_ (MAGIC
)]])[
1426 {]b4_parse_assert_if([[
1427 other
.check_ ();]])[
1428 std::memcpy (raw_
, other
.raw_
, union_size
);
1431 glr_stack_item
& operator= (glr_stack_item other
)
1432 {]b4_parse_assert_if([[
1434 other
.check_ ();]])[
1435 std::swap (is_state_
, other
.is_state_
);
1436 std::swap (raw_
, other
.raw_
);
1441 {]b4_parse_assert_if([[
1444 getState ().~glr_state ();
1446 getOption ().~semantic_option ();
1449 void setState (const glr_state
&state
)
1450 {]b4_parse_assert_if([[
1452 state
.check_ ();]])[
1453 if (this != state
.asItem ())
1456 getState ().~glr_state ();
1458 getOption ().~semantic_option ();
1459 new (&raw_
) glr_state (state
);
1464 glr_state
& getState ()
1465 {]b4_parse_assert_if([[
1467 YYDASSERT (is_state ());
1469 glr_state
& res
= *static_cast<glr_state
*> (yyp
);]b4_parse_assert_if([[
1474 const glr_state
& getState () const
1475 {]b4_parse_assert_if([[
1477 YYDASSERT (is_state ());
1478 const void *yyp
= raw_
;
1479 const glr_state
& res
= *static_cast<const glr_state
*> (yyp
);]b4_parse_assert_if([[
1484 semantic_option
& getOption ()
1485 {]b4_parse_assert_if([[
1487 YYDASSERT (!is_state ());
1489 return *static_cast<semantic_option
*> (yyp
);
1491 const semantic_option
& getOption () const
1492 {]b4_parse_assert_if([[
1494 YYDASSERT (!is_state ());
1495 const void *yyp
= raw_
;
1496 return *static_cast<const semantic_option
*> (yyp
);
1498 bool is_state () const
1499 {]b4_parse_assert_if([[
1505 /// The possible contents of raw_. Since they have constructors, they cannot
1506 /// be directly included in the union.
1509 char yystate
[sizeof (glr_state
)];
1510 char yyoption
[sizeof (semantic_option
)];
1512 enum { union_size
= sizeof (contents
) };
1514 /// Strongest alignment constraints.
1515 long double yyalign_me
;
1516 /// A buffer large enough to store the contents.
1517 char raw_
[union_size
];
1519 /** Type tag for the union. */
1521 ]b4_parse_assert_if([[
1523 // Check invariants.
1524 void check_ () const
1526 YYASSERT (this->magic_
== MAGIC
);
1527 YYASSERT (this->is_state_
== false || this->is_state_
== true);
1529 // A magic number to check our pointer arithmetic is sane.
1530 enum { MAGIC
= 0xDEAD1ACC }; // 3735886540.
1531 const unsigned int magic_
;]])[
1532 }; // class glr_stack_item
1535 glr_state
* glr_state::pred ()
1536 {]b4_parse_assert_if([[
1538 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1539 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1540 YY_IGNORE_NULL_DEREFERENCE_END
1543 const glr_state
* glr_state::pred () const
1544 {]b4_parse_assert_if([[
1546 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1547 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1548 YY_IGNORE_NULL_DEREFERENCE_END
1551 void glr_state::setPred (const glr_state
* state
)
1552 {]b4_parse_assert_if([[
1555 state
->check_ ();]])[
1556 yypred
= state
? as_pointer_ (this) - as_pointer_ (state
) : 0;
1559 semantic_option
* glr_state::firstVal ()
1560 {]b4_parse_assert_if([[
1562 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1565 const semantic_option
* glr_state::firstVal () const
1566 {]b4_parse_assert_if([[
1568 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1571 void glr_state::setFirstVal (const semantic_option
* option
)
1572 {]b4_parse_assert_if([[
1574 yyfirstVal
= option
? asItem(this) - asItem(option
) : 0;
1577 std::ptrdiff_t glr_state::indexIn (const glr_stack_item
* array
) const
1578 {]b4_parse_assert_if([[
1580 return asItem(this) - array
;
1583 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item
* array
) const
1585 return asItem(this) - array
;
1588 glr_state
* semantic_option::state ()
1590 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1591 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1592 YY_IGNORE_NULL_DEREFERENCE_END
1595 const glr_state
* semantic_option::state () const
1597 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1600 void semantic_option::setState (const glr_state
* s
)
1602 yystate
= s
? asItem(this) - asItem(s
) : 0;
1605 const semantic_option
* semantic_option::next () const
1607 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1610 semantic_option
* semantic_option::next ()
1612 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1615 void semantic_option::setNext (const semantic_option
* s
)
1617 yynext
= s
? asItem(this) - asItem(s
) : 0;
1620 void glr_state::destroy (char const* yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
)
1621 {]b4_parse_assert_if([[
1624 yyparser
.yy_destroy_ (yymsg
, yy_accessing_symbol(yylrState
),
1625 value ()]b4_locations_if([, yyloc
])[);
1628 #if ]b4_api_PREFIX[DEBUG
1630 << (firstVal() ? " unresolved " : " incomplete ")
1631 << (yy_accessing_symbol (yylrState
) < YYNTOKENS
? "token" : "nterm")
1632 << ' ' << yyparser
.symbol_name (yy_accessing_symbol (yylrState
))
1633 << " ("]b4_locations_if([[
1634 << yyloc
<< ": "]])[
1637 if (firstVal() != YY_NULLPTR
)
1639 semantic_option
& yyoption
= *firstVal ();
1640 glr_state
*yyrh
= yyoption
.state ();
1641 for (int yyn
= yyrhsLength (yyoption
.yyrule
); yyn
> 0; yyn
-= 1)
1643 yyrh
->destroy (yymsg
, yyparser
);
1644 yyrh
= yyrh
->pred();
1652 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1659 using parser_type
= ]b4_namespace_ref
[::]b4_parser_class
[;
1660 using symbol_kind
= parser_type::symbol_kind
;
1661 using value_type
= parser_type::value_type
;]b4_locations_if([[
1662 using location_type
= parser_type::location_type
;]])[
1664 /** Initialize to a single empty stack, with total maximum
1665 * capacity for all stacks of YYSIZE. */
1666 state_stack (size_t yysize
)
1667 : yysplitPoint (YY_NULLPTR
)
1669 yyitems
.reserve (yysize
);
1672 #if YYSTACKEXPANDABLE
1673 /** Returns false if it tried to expand but could not. */
1675 yyexpandGLRStackIfNeeded ()
1677 return YYHEADROOM
<= spaceLeft () || yyexpandGLRStack ();
1681 /** If *this is expandable, extend it. WARNING: Pointers into the
1682 stack from outside should be considered invalid after this call.
1683 We always expand when there are 1 or fewer items left AFTER an
1684 allocation, so that we can avoid having external pointers exist
1685 across an allocation. */
1689 const size_t oldsize
= yyitems
.size();
1690 if (YYMAXDEPTH
- YYHEADROOM
< oldsize
)
1692 const size_t yynewSize
= YYMAXDEPTH
< 2 * oldsize
? YYMAXDEPTH
: 2 * oldsize
;
1693 const glr_stack_item
*oldbase
= &yyitems
[0];
1695 yyitems
.reserve (yynewSize
);
1696 const glr_stack_item
*newbase
= &yyitems
[0];
1698 // Adjust the pointers. Perform raw pointer arithmetic, as there
1699 // is no reason for objects to be aligned on their size.
1700 const ptrdiff_t disp
1701 = reinterpret_cast<const char*> (newbase
) - reinterpret_cast<const char*> (oldbase
);
1703 const_cast<glr_state
*&> (yysplitPoint
)
1704 = reinterpret_cast<glr_state
*> (reinterpret_cast<char*> (const_cast<glr_state
*> (yysplitPoint
)) + disp
);
1706 for (std::vector
<glr_state
*>::iterator
1707 i
= yytops
.begin (),
1708 yyend
= yytops
.end ();
1710 if (glr_state_not_null (*i
))
1711 *i
= reinterpret_cast<glr_state
*>(reinterpret_cast<char*>(*i
) + disp
);
1718 bool yyexpandGLRStackIfNeeded ()
1720 return YYHEADROOM
<= spaceLeft ();
1723 #undef YYSTACKEXPANDABLE
1725 static bool glr_state_not_null (glr_state
* s
)
1727 return s
!= YY_NULLPTR
;
1733 using iterator
= std::vector
<glr_state
*>::iterator
;
1734 const iterator yybegin
= yytops
.begin();
1735 const iterator yyend
= yytops
.end();
1736 const iterator yyit
= std::find_if(yybegin
, yyend
, glr_state_not_null
);
1739 for (state_set_index yyk
= create_state_set_index(yyit
+ 1 - yybegin
);
1740 yyk
.uget() != numTops(); ++yyk
)
1741 yytops
.yymarkStackDeleted (yyk
);
1742 yytops
.yyremoveDeletes ();
1747 /** Called when returning to deterministic operation to clean up the extra
1752 if (yytops
.size() != 1 || !isSplit())
1755 // yyr is the state after the split point.
1756 glr_state
* yyr
= YY_NULLPTR
;
1757 for (glr_state
*yyp
= firstTop(), *yyq
= yyp
->pred();
1758 yyp
!= yysplitPoint
;
1759 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->pred())
1762 // This const_cast is okay, since anyway we have access to the mutable
1763 // yyitems into which yysplitPoint points.
1764 glr_stack_item
* nextFreeItem
1765 = const_cast<glr_state
*> (yysplitPoint
)->asItem () + 1;
1766 yysplitPoint
= YY_NULLPTR
;
1767 yytops
.clearLastDeleted ();
1769 while (yyr
!= YY_NULLPTR
)
1771 nextFreeItem
->setState (*yyr
);
1772 glr_state
& nextFreeState
= nextFreeItem
->getState();
1774 nextFreeState
.setPred(&(nextFreeItem
- 1)->getState());
1775 setFirstTop (&nextFreeState
);
1778 yyitems
.resize(static_cast<size_t>(nextFreeItem
- yyitems
.data()));
1781 bool isSplit() const {
1782 return yysplitPoint
!= YY_NULLPTR
;
1785 // Present the interface of a vector of glr_stack_item.
1786 std::vector
<glr_stack_item
>::const_iterator
begin () const
1788 return yyitems
.begin ();
1791 std::vector
<glr_stack_item
>::const_iterator
end () const
1793 return yyitems
.end ();
1798 return yyitems
.size ();
1801 glr_stack_item
& operator[] (size_t i
)
1806 glr_stack_item
& stackItemAt (size_t index
)
1808 return yyitems
[index
];
1811 size_t numTops () const
1813 return yytops
.size ();
1816 glr_state
* firstTop () const
1818 return yytops
[create_state_set_index (0)];
1821 glr_state
* topAt (state_set_index i
) const
1826 void setFirstTop (glr_state
* value
)
1828 yytops
[create_state_set_index (0)] = value
;
1831 void setTopAt (state_set_index i
, glr_state
* value
)
1838 yyitems
.pop_back ();
1841 void pop_back (size_t n
)
1843 yyitems
.resize (yyitems
.size () - n
);
1847 yysplitStack (state_set_index yyk
)
1851 YYASSERT (yyk
.get () == 0);
1852 yysplitPoint
= topAt (yyk
);
1854 return yytops
.yysplitStack (yyk
);
1857 /** Assuming that YYS is a GLRState somewhere on *this, update the
1858 * splitpoint of *this, if needed, so that it is at least as deep as
1861 yyupdateSplit (glr_state
& yys
)
1863 if (isSplit() && &yys
< yysplitPoint
)
1864 yysplitPoint
= &yys
;
1867 /** Return a fresh GLRState.
1868 * Callers should call yyreserveStack afterwards to make sure there is
1869 * sufficient headroom. */
1870 glr_state
& yynewGLRState (const glr_state
& newState
)
1872 glr_state
& state
= yyitems
[yynewGLRStackItem (true)].getState ();
1873 #if false && 201103L <= YY_CPLUSPLUS
1874 state
= std::move (newState
);
1881 /** Return a fresh SemanticOption.
1882 * Callers should call yyreserveStack afterwards to make sure there is
1883 * sufficient headroom. */
1884 semantic_option
& yynewSemanticOption (semantic_option newOption
)
1886 semantic_option
& option
= yyitems
[yynewGLRStackItem (false)].getOption ();
1887 option
= std::move (newOption
);
1891 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1892 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1893 * For convenience, always return YYLOW1. */
1895 yyfill (glr_stack_item
*yyvsp
, int &yylow
, int yylow1
, bool yynormal
)
1897 if (!yynormal
&& yylow1
< yylow
)
1899 yyfillin (yyvsp
, yylow
, yylow1
);
1905 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1906 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1907 * containing the pointer to the next state in the chain. */
1909 yyfillin (glr_stack_item
*yyvsp
, int yylow0
, int yylow1
)
1911 glr_state
* s
= yyvsp
[yylow0
].getState().pred();
1912 YYASSERT(s
!= YY_NULLPTR
);
1913 for (int i
= yylow0
-1; i
>= yylow1
; i
-= 1, s
= s
->pred())
1915 glr_state
& yys
= yyvsp
[i
].getState();
1916 #if ]b4_api_PREFIX[DEBUG
1917 yys
.yylrState
= s
->yylrState
;
1919 yys
.yyresolved
= s
->yyresolved
;
1922 new (&yys
.value ()) value_type ();
1923 ]b4_symbol_variant([yy_accessing_symbol (s
->yylrState
)],
1924 [yys
.value ()], [copy
], [s
->value ()])], [[
1925 new (&yys
.value ()) value_type (s
->value ());]])[
1928 /* The effect of using yyval or yyloc (in an immediate
1929 * rule) is undefined. */
1930 yys
.setFirstVal (YY_NULLPTR
);]b4_locations_if([[
1931 yys
.yyloc
= s
->yyloc
;]])[
1932 yys
.setPred(s
->pred());
1936 #if ]b4_api_PREFIX[DEBUG
1938 /*----------------------------------------------------------------------.
1939 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1940 `----------------------------------------------------------------------*/
1943 yy_reduce_print (bool yynormal
, glr_stack_item
* yyvsp
, state_set_index yyk
,
1944 rule_num yyrule
, parser_type
& yyparser
)
1946 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1949 std::cerr
<< "Reducing stack " << yyk
.get() << " by rule " << yyrule
- 1
1950 << " (line " << int (yyrline
[yyrule
]) << "):\n";
1952 yyfillin (yyvsp
, 1, -yynrhs
);
1953 /* The symbols being reduced. */
1954 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1956 std::cerr
<< " $" << yyi
+ 1 << " = ";
1957 yyparser
.yy_symbol_print_
1958 (yy_accessing_symbol (yyvsp
[yyi
- yynrhs
+ 1].getState().yylrState
),
1959 yyvsp
[yyi
- yynrhs
+ 1].getState().value ()]b4_locations_if([[,
1960 ]b4_rhs_location(yynrhs
, yyi
+ 1)])[);
1961 if (!yyvsp
[yyi
- yynrhs
+ 1].getState().yyresolved
)
1962 std::cerr
<< " (unresolved)";
1968 #define YYINDEX(YYX) \
1969 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1974 for (size_t yyi
= 0; yyi
< size(); ++yyi
)
1976 const glr_stack_item
& item
= yyitems
[yyi
];
1977 std::cerr
<< std::setw(3) << yyi
<< ". ";
1978 if (item
.is_state())
1980 std::cerr
<< "Res: " << item
.getState().yyresolved
1981 << ", LR State: " << item
.getState().yylrState
1982 << ", posn: " << item
.getState().yyposn
1983 << ", pred: " << YYINDEX(item
.getState().pred());
1984 if (! item
.getState().yyresolved
)
1985 std::cerr
<< ", firstVal: "
1986 << YYINDEX(item
.getState().firstVal());
1990 std::cerr
<< "Option. rule: " << item
.getOption().yyrule
- 1
1991 << ", state: " << YYINDEX(item
.getOption().state())
1992 << ", next: " << YYINDEX(item
.getOption().next());
1996 std::cerr
<< "Tops:";
1997 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < numTops(); ++yyi
) {
1998 std::cerr
<< yyi
.get() << ": " << YYINDEX(topAt(yyi
)) << "; ";
2007 yyreportAmbiguity (const semantic_option
& yyx0
,
2008 const semantic_option
& yyx1
, parser_type
& yyparser
]b4_locations_if([, const location_type
& yyloc
])[)
2013 #if ]b4_api_PREFIX[DEBUG
2014 std::cerr
<< "Ambiguity detected.\n"
2016 yyx0
.yyreportTree ();
2017 std::cerr
<< "\nOption 2,\n";
2018 yyx1
.yyreportTree ();
2022 yyparser
.error (]b4_locations_if([yyloc
, ])[YY_("syntax is ambiguous"));
2026 #if ]b4_api_PREFIX[DEBUG
2027 /* Print YYS (possibly NULL) and its predecessors. */
2029 yypstates (const glr_state
* yys
) const
2031 if (yys
!= YY_NULLPTR
)
2034 std::cerr
<< "<null>";
2040 size_t spaceLeft() const
2042 return yyitems
.capacity() - yyitems
.size();
2045 /** Return a fresh GLRStackItem in this. The item is an LR state
2046 * if YYIS_STATE, and otherwise a semantic option. Callers should call
2047 * yyreserveStack afterwards to make sure there is sufficient
2050 yynewGLRStackItem (bool yyis_state
)
2052 YYDASSERT(yyitems
.size() < yyitems
.capacity());
2053 yyitems
.push_back(glr_stack_item(yyis_state
));
2054 return yyitems
.size() - 1;
2059 std::vector
<glr_stack_item
> yyitems
;
2060 // Where the stack splits. Anything below this address is deterministic.
2061 const glr_state
* yysplitPoint
;
2062 glr_state_set yytops
;
2063 }; // class state_stack
2067 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2069 namespace ]b4_namespace_ref
[
2071 class ]b4_parser_class
[::glr_stack
2074 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
2075 // Needs access to yypact_value_is_default, etc.
2079 glr_stack (size_t yysize
, parser_type
& yyparser_yyarg
]m4_ifset([b4_parse_param
], [, b4_parse_param_decl
])[)
2081 , yystateStack (yysize
)
2084 , yyparser (yyparser_yyarg
)]m4_ifset([b4_parse_param
], [,b4_parse_param_cons
])[
2089 if (!this->yyla
.empty ())
2090 yyparser
.yy_destroy_ ("Cleanup: discarding lookahead",
2091 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2096 ]b4_locations_if([[ /* To compute the location of the error token. */
2097 glr_stack_item yyerror_range
[3];]])[
2098 state_stack yystateStack
;
2101 YYJMP_BUF yyexception_buffer
;
2102 parser_type
& yyparser
;
2104 #define YYCHK1(YYE) \
2114 goto yyuser_error; \
2126 YYCDEBUG
<< "Starting parse\n";
2128 this->yyla
.clear ();
2129 ]m4_ifdef([b4_initial_action
], [
2130 b4_dollar_pushdef([yyla
.value
], [], [], [yyla
.location
])dnl
2131 b4_user_initial_action
2132 b4_dollar_popdef
])[]dnl
2134 switch (YYSETJMP (this->yyexception_buffer
))
2137 case 1: goto yyabortlab
;
2138 case 2: goto yyexhaustedlab
;
2139 default: goto yybuglab
;
2141 this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2146 /* For efficiency, we have two loops, the first of which is
2147 specialized to deterministic operation (single stack, no
2148 potential ambiguity). */
2152 const state_num yystate
= this->firstTopState()->yylrState
;
2153 YYCDEBUG
<< "Entering state " << yystate
<< '\n';
2154 if (yystate
== YYFINAL
)
2156 if (yy_is_defaulted_state (yystate
))
2158 const rule_num yyrule
= yy_default_action (yystate
);
2160 {]b4_locations_if([[
2161 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2162 this->yyreportSyntaxError ();
2165 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule
, true));
2170 const short* yyconflicts
;
2171 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2172 if (*yyconflicts
!= 0)
2174 if (yy_is_shift_action (yyaction
))
2176 YY_SYMBOL_PRINT ("Shifting", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
2178 // FIXME: we should move yylval.
2179 this->yyglrShift (create_state_set_index(0), yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2181 if (0 < this->yyerrState
)
2182 this->yyerrState
-= 1;
2184 else if (yy_is_error_action (yyaction
))
2185 {]b4_locations_if([[
2186 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2187 /* Don't issue an error message again for exceptions
2188 thrown from the scanner. */
2189 if (this->yyla
.kind () != ]b4_symbol(error
, kind
)[)
2190 this->yyreportSyntaxError ();
2194 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction
, true));
2200 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < this->yystateStack
.numTops(); ++yys
)
2201 this->yystateStack
.yytops
.setLookaheadNeeds(yys
, !this->yyla
.empty ());
2203 /* yyprocessOneStack returns one of three things:
2205 - An error flag. If the caller is yyprocessOneStack, it
2206 immediately returns as well. When the caller is finally
2207 yyparse, it jumps to an error label via YYCHK1.
2209 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2210 (yys), which sets the top state of yys to NULL. Thus,
2211 yyparse's following invocation of yyremoveDeletes will remove
2214 - yyok, when ready to shift a token.
2216 Except in the first case, yyparse will invoke yyremoveDeletes and
2217 then shift the next token onto all remaining stacks. This
2218 synchronization of the shift (that is, after all preceding
2219 reductions on all stacks) helps prevent double destructor calls
2220 on yylval in the event of memory exhaustion. */
2222 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2223 YYCHK1 (this->yyprocessOneStack (yys
, yyposn
]b4_locations_if([, &this->yyla
.location
])[));
2224 this->yystateStack
.yytops
.yyremoveDeletes ();
2225 if (this->yystateStack
.yytops
.size() == 0)
2227 this->yystateStack
.yytops
.yyundeleteLastStack ();
2228 if (this->yystateStack
.yytops
.size() == 0)
2229 this->yyFail (]b4_locations_if([&this->yyla
.location
, ])[YY_("syntax error"));
2230 YYCHK1 (this->yyresolveStack ());
2231 YYCDEBUG
<< "Returning to deterministic operation.\n";]b4_locations_if([[
2232 this->yyerror_range
[1].getState ().yyloc
= this->yyla
.location
;]])[
2233 this->yyreportSyntaxError ();
2237 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2238 a copy of yylval will already be on stack 0 in the event of a
2239 failure in the following loop. Thus, yyla is emptied
2240 before the loop to make sure the user destructor for yylval isn't
2242 symbol_kind_type yytoken_to_shift
= this->yyla
.kind ();
2243 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2245 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2247 const state_num yystate
= this->topState (yys
)->yylrState
;
2248 const short* yyconflicts
;
2249 const int yyaction
= yygetLRActions (yystate
, yytoken_to_shift
, yyconflicts
);
2250 /* Note that yyconflicts were handled by yyprocessOneStack. */
2251 YYCDEBUG
<< "On stack " << yys
.get() << ", ";
2252 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, this->yyla
.value
, this->yyla
.location
);
2253 this->yyglrShift (yys
, yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2254 YYCDEBUG
<< "Stack " << yys
.get() << " now in state "
2255 << this->topState(yys
)->yylrState
<< '\n';
2258 // FIXME: User destructors.
2259 // Value type destructor.
2260 ]b4_symbol_variant([[yytoken_to_shift
]], [[this->yyla
.value
]], [[template destroy
]])])[
2262 if (this->yystateStack
.yytops
.size () == 1)
2264 YYCHK1 (this->yyresolveStack ());
2265 YYCDEBUG
<< "Returning to deterministic operation.\n";
2266 this->yystateStack
.yycompressStack ();
2272 this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla
.location
])[);
2273 yyposn
= this->firstTopState()->yyposn
;
2289 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[YY_("memory exhausted"));
2298 void yyreserveGlrStack ()
2300 if (!yystateStack
.yyexpandGLRStackIfNeeded ())
2301 yyMemoryExhausted ();
2305 yyMemoryExhausted ()
2307 YYLONGJMP (yyexception_buffer
, 2);
2311 yyFail (]b4_locations_if([location_type
* yylocp
, ])[const char* yymsg
)
2313 if (yymsg
!= YY_NULLPTR
)
2314 yyparser
.error (]b4_locations_if([*yylocp
, ])[yymsg
);
2315 YYLONGJMP (yyexception_buffer
, 1);
2321 /** Add a new semantic action that will execute the action for rule
2322 * YYRULE on the semantic values in YYRHS to the list of
2323 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2324 * stack #YYK of *this. */
2326 yyaddDeferredAction (state_set_index yyk
, glr_state
* yystate
,
2327 glr_state
* yyrhs
, rule_num yyrule
)
2329 semantic_option
& yyopt
= yystateStack
.yynewSemanticOption (semantic_option (yyrule
));
2330 yyopt
.setState (yyrhs
);
2331 yyopt
.setNext (yystate
->firstVal ());
2332 if (yystateStack
.yytops
.lookaheadNeeds (yyk
))
2333 yyopt
.yyla
= this->yyla
;
2334 yystate
->setFirstVal (&yyopt
);
2336 yyreserveGlrStack ();
2339 #if ]b4_api_PREFIX[DEBUG
2340 void yypdumpstack () const
2342 yystateStack
.dumpStack();
2347 yyreportSyntaxError ()
2349 if (yyerrState
!= 0)
2351 ]b4_parse_error_case(
2353 std::string msg
= YY_("syntax error");
2354 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]],
2356 context
yyctx (*this, yyla
);
2357 yyparser
.report_syntax_error (yyctx
);]],
2359 context
yyctx (*this, yyla
);
2360 std::string msg
= yyparser
.yysyntax_error_ (yyctx
);
2361 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]])[
2365 /* Recover from a syntax error on this, assuming that yytoken,
2366 yylval, and yylloc are the syntactic category, semantic value, and location
2367 of the lookahead. */
2369 yyrecoverSyntaxError (]b4_locations_if([location_type
* yylocp
])[)
2371 if (yyerrState
== 3)
2372 /* We just shifted the error token and (perhaps) took some
2373 reductions. Skip tokens until we can proceed. */
2376 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
2377 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2378 if (this->yyla
.kind () != ]b4_symbol(empty
, kind
)[)
2379 {]b4_locations_if([[
2380 /* We throw away the lookahead, but the error range
2381 of the shifted error token must take it into account. */
2382 glr_state
*yys
= firstTopState();
2383 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;
2384 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2385 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2386 yyparser
.yy_destroy_ ("Error: discarding",
2387 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);]b4_variant_if([[
2388 // Value type destructor.
2389 ]b4_symbol_variant([[this->yyla
.kind ()]], [[this->yyla
.value
]], [[template destroy
]])])[
2390 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2393 int yyj
= yypact
[firstTopState()->yylrState
];
2394 if (yypact_value_is_default (yyj
))
2396 yyj
+= this->yyla
.kind ();
2397 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != this->yyla
.kind ())
2399 if (yydefact
[firstTopState()->yylrState
] != 0)
2402 else if (! yytable_value_is_error (yytable
[yyj
]))
2406 if (!yystateStack
.reduceToOneStack())
2407 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2409 /* Now pop stack until we find a state that shifts the error token. */
2411 while (firstTopState () != YY_NULLPTR
)
2413 glr_state
*yys
= firstTopState ();
2414 int yyj
= yypact
[yys
->yylrState
];
2415 if (! yypact_value_is_default (yyj
))
2418 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2419 && yy_is_shift_action (yytable
[yyj
]))
2421 /* Shift the error token. */]b4_locations_if([[
2422 /* First adjust its location.*/
2423 location_type yyerrloc
;
2424 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2425 YYLLOC_DEFAULT (yyerrloc
, (yyerror_range
), 2);]])[
2426 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable
[yyj
]),
2427 this->yyla
.value
, yyerrloc
);
2428 yyglrShift (create_state_set_index(0), yytable
[yyj
],
2429 yys
->yyposn
, yyla
.value
]b4_locations_if([, yyerrloc
])[);
2430 yys
= firstTopState();
2433 }]b4_locations_if([[
2434 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;]])[
2435 if (yys
->pred() != YY_NULLPTR
)
2436 yys
->destroy ("Error: popping", yyparser
);
2437 yystateStack
.setFirstTop(yys
->pred());
2438 yystateStack
.pop_back();
2440 if (firstTopState() == YY_NULLPTR
)
2441 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2445 yyprocessOneStack (state_set_index yyk
,
2446 size_t yyposn
]b4_locations_if([, location_type
* yylocp
])[)
2448 while (yystateStack
.topAt(yyk
) != YY_NULLPTR
)
2450 const state_num yystate
= topState(yyk
)->yylrState
;
2451 YYCDEBUG
<< "Stack " << yyk
.get()
2452 << " Entering state " << yystate
<< '\n';
2454 YYASSERT (yystate
!= YYFINAL
);
2456 if (yy_is_defaulted_state (yystate
))
2458 const rule_num yyrule
= yy_default_action (yystate
);
2461 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2462 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2465 const YYRESULTTAG yyflag
2466 = yyglrReduce (yyk
, yyrule
, yyimmediate
[yyrule
]);
2467 if (yyflag
== yyerr
)
2469 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2470 " (predicate failure or explicit user error).\n";
2471 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2479 yystateStack
.yytops
.setLookaheadNeeds(yyk
, true);
2481 const short* yyconflicts
;
2482 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2484 for (; *yyconflicts
!= 0; ++yyconflicts
)
2486 state_set_index yynewStack
= yystateStack
.yysplitStack (yyk
);
2487 YYCDEBUG
<< "Splitting off stack " << yynewStack
.get()
2488 << " from " << yyk
.get() << ".\n";
2489 YYRESULTTAG yyflag
=
2490 yyglrReduce (yynewStack
, *yyconflicts
, yyimmediate
[*yyconflicts
]);
2492 YYCHK (yyprocessOneStack (yynewStack
,
2493 yyposn
]b4_locations_if([, yylocp
])[));
2494 else if (yyflag
== yyerr
)
2496 YYCDEBUG
<< "Stack " << yynewStack
.get() << " dies.\n";
2497 yystateStack
.yytops
.yymarkStackDeleted (yynewStack
);
2503 if (yy_is_shift_action (yyaction
))
2505 else if (yy_is_error_action (yyaction
))
2507 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2508 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2514 = yyglrReduce (yyk
, -yyaction
, yyimmediate
[-yyaction
]);
2515 if (yyflag
== yyerr
)
2517 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2518 " (predicate failure or explicit user error).\n";
2519 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2522 else if (yyflag
!= yyok
)
2530 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2531 * and top stack item YYVSP. YYVALP points to place to put semantic
2532 * value ($$), and yylocp points to place for location information
2533 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2534 * yyerr for YYERROR, yyabort for YYABORT. */
2536 yyuserAction (rule_num yyrule
, int yyrhslen
, glr_stack_item
* yyvsp
, state_set_index yyk
,
2537 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2539 bool yynormal YY_ATTRIBUTE_UNUSED
= !yystateStack
.isSplit();
2541 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
2545 # define yyerrok (yyerrState = 0)
2547 # define YYACCEPT return yyaccept
2549 # define YYABORT return yyabort
2551 # define YYERROR return yyerrok, yyerr
2552 # undef YYRECOVERING
2553 # define YYRECOVERING() (yyerrState != 0)
2555 # define yytoken this->yyla.kind_
2557 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2559 # define YYBACKUP(Token, Value) \
2560 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2564 /* Variants are always initialized to an empty instance of the
2565 correct type. The default '$$ = $1' action is NOT applied
2566 when using variants. */
2567 // However we really need to prepare yyvsp now if we want to get
2568 // correct locations, so invoke YYFILL for $1 anyway.
2569 (void) YYFILL (1-yyrhslen
);
2570 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [(*yyvalp
)], [emplace
])], [[
2572 *yyvalp
= yyval_default
;
2574 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].getState().value ();]])[]b4_locations_if([[
2575 /* Default location. */
2576 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
2577 yyerror_range
[1].getState().yyloc
= *yylocp
;
2579 /* If yyk == -1, we are running a deferred action on a temporary
2580 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2581 so pretend the stack is "normal". */
2582 YY_REDUCE_PRINT ((yynormal
|| yyk
== create_state_set_index (-1), yyvsp
, yyk
, yyrule
, yyparser
));
2586 #endif // YY_EXCEPTIONS
2594 catch (const syntax_error
& yyexc
)
2596 YYCDEBUG
<< "Caught exception: " << yyexc
.what() << '\n';]b4_locations_if([
2597 *yylocp
= yyexc
.location
;])[
2598 yyparser
.error (]b4_locations_if([*yylocp
, ])[yyexc
.what ());
2601 #endif // YY_EXCEPTIONS
2602 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule
), *yyvalp
, *yylocp
);
2612 # undef YYRECOVERING
2618 if (yystateStack
.isSplit ())
2621 for (glr_state
* yys
= firstTopState ();
2622 yys
!= yystateStack
.yysplitPoint
;
2625 YYCHK (yyresolveStates (*firstTopState (), yyn
));
2630 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2631 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2632 * semantic values. Assumes that all ambiguities in semantic values
2633 * have been previously resolved. Set *YYVALP to the resulting value,
2634 * and *YYLOCP to the computed location (if any). Return value is as
2635 * for userAction. */
2637 yydoAction (state_set_index yyk
, rule_num yyrule
,
2638 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2640 const int yynrhs
= yyrhsLength (yyrule
);
2642 if (!yystateStack
.isSplit())
2644 /* Standard special case: single stack. */
2645 YYASSERT (yyk
.get() == 0);
2646 glr_stack_item
* yyrhs
= yystateStack
.firstTop()->asItem();
2647 const YYRESULTTAG res
2648 = yyuserAction (yyrule
, yynrhs
, yyrhs
, yyk
, yyvalp
]b4_locations_if([, yylocp
])[);
2649 yystateStack
.pop_back(static_cast<size_t>(yynrhs
));
2650 yystateStack
.setFirstTop(&yystateStack
[yystateStack
.size() - 1].getState());
2655 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2656 glr_state
* yys
= yystateStack
.topAt(yyk
);
2657 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yys
);]b4_locations_if([[
2659 /* Set default location. */
2660 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yys
->yyloc
;]])[
2661 for (int yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
2664 YYASSERT (yys
!= YY_NULLPTR
);
2666 yystateStack
.yyupdateSplit (*yys
);
2667 yystateStack
.setTopAt(yyk
, yys
);
2668 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2670 yyvalp
]b4_locations_if([, yylocp
])[);
2674 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2675 * and push back on the resulting nonterminal symbol. Perform the
2676 * semantic action associated with YYRULE and store its value with the
2677 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2678 * unambiguous. Otherwise, store the deferred semantic action with
2679 * the new state. If the new state would have an identical input
2680 * position, LR state, and predecessor to an existing state on the stack,
2681 * it is identified with that existing state, eliminating stack #YYK from
2682 * *YYSTACKP. In this case, the semantic value is
2683 * added to the options for the existing state's semantic value.
2686 yyglrReduce (state_set_index yyk
, rule_num yyrule
, bool yyforceEval
)
2688 size_t yyposn
= topState(yyk
)->yyposn
;
2690 if (yyforceEval
|| !yystateStack
.isSplit())
2692 value_type val
;]b4_locations_if([[
2693 location_type loc
;]])[
2695 YYRESULTTAG yyflag
= yydoAction (yyk
, yyrule
, &val
]b4_locations_if([, &loc
])[);
2696 if (yyflag
== yyerr
&& yystateStack
.isSplit())
2697 {]b4_parse_trace_if([[
2698 YYCDEBUG
<< "Parse on stack " << yyk
.get ()
2699 << " rejected by rule " << yyrule
- 1
2700 << " (line " << int (yyrline
[yyrule
]) << ").\n";
2705 yyLRgotoState (topState(yyk
)->yylrState
,
2706 yylhsNonterm (yyrule
)),
2707 yyposn
, val
]b4_locations_if([, loc
])[);]b4_variant_if([[
2708 // FIXME: User destructors.
2709 // Value type destructor.
2710 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [[val
]], [[template destroy
]])])[
2714 glr_state
*yys
= yystateStack
.topAt(yyk
);
2715 glr_state
*yys0
= yys
;
2716 for (int yyn
= yyrhsLength (yyrule
); 0 < yyn
; yyn
-= 1)
2719 YYASSERT (yys
!= YY_NULLPTR
);
2721 yystateStack
.yyupdateSplit (*yys
);
2722 state_num yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));]b4_parse_trace_if([[
2723 YYCDEBUG
<< "Reduced stack " << yyk
.get ()
2724 << " by rule " << yyrule
- 1 << " (line " << int (yyrline
[yyrule
])
2725 << "); action deferred. Now in state " << yynewLRState
2727 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < yystateStack
.numTops(); ++yyi
)
2728 if (yyi
!= yyk
&& yystateStack
.topAt(yyi
) != YY_NULLPTR
)
2730 const glr_state
* yysplit
= yystateStack
.yysplitPoint
;
2731 glr_state
* yyp
= yystateStack
.topAt(yyi
);
2732 while (yyp
!= yys
&& yyp
!= yysplit
2733 && yyp
->yyposn
>= yyposn
)
2735 if (yyp
->yylrState
== yynewLRState
2736 && yyp
->pred() == yys
)
2738 yyaddDeferredAction (yyk
, yyp
, yys0
, yyrule
);
2739 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2740 YYCDEBUG
<< "Merging stack " << yyk
.get ()
2741 << " into stack " << yyi
.get () << ".\n";
2747 yystateStack
.setTopAt(yyk
, yys
);
2748 yyglrShiftDefer (yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
2753 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2754 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2755 * semantic value of YYRHS under the action for YYRULE. */
2757 yyglrShiftDefer (state_set_index yyk
, state_num yylrState
,
2758 size_t yyposn
, glr_state
* yyrhs
, rule_num yyrule
)
2760 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2761 glr_state (yylrState
, yyposn
));
2762 yynewState
.setPred (yystateStack
.topAt (yyk
));
2763 yystateStack
.setTopAt (yyk
, &yynewState
);
2765 /* Invokes yyreserveStack. */
2766 yyaddDeferredAction (yyk
, &yynewState
, yyrhs
, yyrule
);
2769 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2770 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2771 * value YYVAL_ARG and source location YYLOC_ARG. */
2773 yyglrShift (state_set_index yyk
, state_num yylrState
,
2775 const value_type
& yyval_arg
]b4_locations_if([, const location_type
& yyloc_arg
])[)
2777 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2778 glr_state (yylrState
, yyposn
, yyval_arg
]b4_locations_if([, yyloc_arg
])[));
2779 yynewState
.setPred (yystateStack
.topAt(yyk
));
2780 yystateStack
.setTopAt (yyk
, &yynewState
);
2781 yyreserveGlrStack ();
2784 #if ]b4_api_PREFIX[DEBUG
2786 yypstack (state_set_index yyk
) const
2788 yystateStack
.yypstates (yystateStack
.topAt (yyk
));
2792 glr_state
* topState(state_set_index i
) {
2793 return yystateStack
.topAt(i
);
2796 glr_state
* firstTopState() {
2797 return yystateStack
.firstTop();
2804 /* If the stack is well-formed, pop the stack until it is empty,
2805 destroying its entries as we go. But free the stack regardless
2806 of whether it is well-formed. */
2807 for (state_set_index k
= create_state_set_index(0); k
.uget() < yystateStack
.numTops(); k
+= 1)
2808 if (yystateStack
.topAt(k
) != YY_NULLPTR
)
2810 while (yystateStack
.topAt(k
) != YY_NULLPTR
)
2812 glr_state
* state
= topState(k
);]b4_locations_if([[
2813 yyerror_range
[1].getState().yyloc
= state
->yyloc
;]])[
2814 if (state
->pred() != YY_NULLPTR
)
2815 state
->destroy ("Cleanup: popping", yyparser
);
2816 yystateStack
.setTopAt(k
, state
->pred());
2817 yystateStack
.pop_back();
2823 /** Resolve the previous YYN states starting at and including state YYS
2824 * on *YYSTACKP. If result != yyok, some states may have been left
2825 * unresolved possibly with empty semantic option chains. Regardless
2826 * of whether result = yyok, each state has been left with consistent
2827 * data so that destroy can be invoked if necessary. */
2829 yyresolveStates (glr_state
& yys
, int yyn
)
2833 YYASSERT (yys
.pred() != YY_NULLPTR
);
2834 YYCHK (yyresolveStates (*yys
.pred(), yyn
-1));
2835 if (! yys
.yyresolved
)
2836 YYCHK (yyresolveValue (yys
));
2842 yyuserMerge (int yyn
, value_type
& yy0
, value_type
& yy1
)
2854 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2855 * perform the indicated actions, and set the semantic value of YYS.
2856 * If result != yyok, the chain of semantic options in YYS has been
2857 * cleared instead or it has been left unmodified except that
2858 * redundant options may have been removed. Regardless of whether
2859 * result = yyok, YYS has been left with consistent data so that
2860 * destroy can be invoked if necessary. */
2862 yyresolveValue (glr_state
& yys
)
2864 semantic_option
* yybest
= yys
.firstVal();
2865 YYASSERT(yybest
!= YY_NULLPTR
);
2866 bool yymerge
= false;
2867 YYRESULTTAG yyflag
;]b4_locations_if([
2868 location_type
*yylocp
= &yys
.yyloc
;])[
2870 semantic_option
* yypPrev
= yybest
;
2871 for (semantic_option
* yyp
= yybest
->next();
2872 yyp
!= YY_NULLPTR
; )
2874 if (yybest
->isIdenticalTo (*yyp
))
2876 yybest
->mergeWith (*yyp
);
2877 yypPrev
->setNext(yyp
->next());
2878 yyp
= yypPrev
->next();
2882 switch (yypreference (*yybest
, *yyp
))
2884 case 0:]b4_locations_if([[
2885 yyresolveLocations (yys
, 1);]])[
2886 return yystateStack
.yyreportAmbiguity (*yybest
, *yyp
, yyparser
]b4_locations_if([, *yylocp
])[);
2898 /* This cannot happen so it is not worth a YYASSERT (false),
2899 but some compilers complain if the default case is
2911 int yyprec
= yydprec
[yybest
->yyrule
];
2912 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2914 for (semantic_option
* yyp
= yybest
->next();
2918 if (yyprec
== yydprec
[yyp
->yyrule
])
2920 value_type yyval_other
;]b4_locations_if([
2921 location_type yydummy
;])[
2922 yyflag
= yyresolveAction (*yyp
, &yyval_other
]b4_locations_if([, &yydummy
])[);
2925 yyparser
.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2926 yy_accessing_symbol (yys
.yylrState
),
2927 this->yyla
.value
]b4_locations_if([, *yylocp
])[);
2930 yyuserMerge (yymerger
[yyp
->yyrule
], val
, yyval_other
);]b4_variant_if([[
2931 // FIXME: User destructors.
2932 // Value type destructor.
2933 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[yyval_other
]], [[template destroy
]])])[
2938 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2942 yys
.yyresolved
= true;
2943 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_variant_if([[
2944 new (&yys
.value ()) value_type ();
2945 ]b4_symbol_variant([yy_accessing_symbol (yys
.yylrState
)],
2946 [yys
.value ()], [copy
], [val
])], [[
2947 new (&yys
.value ()) value_type (val
);]])[
2949 YY_IGNORE_MAYBE_UNINITIALIZED_END
2952 yys
.setFirstVal(YY_NULLPTR
);
2954 // FIXME: User destructors.
2955 // Value type destructor.
2956 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[val
]], [[template destroy
]])])[
2960 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2961 * user action, and return the semantic value and location in *YYVALP
2962 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2963 * have been destroyed (assuming the user action destroys all RHS
2964 * semantic values if invoked). */
2966 yyresolveAction (semantic_option
& yyopt
, value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2968 glr_state
* yyoptState
= yyopt
.state();
2969 YYASSERT(yyoptState
!= YY_NULLPTR
);
2970 int yynrhs
= yyrhsLength (yyopt
.yyrule
);
2971 YYRESULTTAG yyflag
= yyresolveStates (*yyoptState
, yynrhs
);
2974 for (glr_state
*yys
= yyoptState
; yynrhs
> 0; yys
= yys
->pred(), yynrhs
-= 1)
2975 yys
->destroy ("Cleanup: popping", yyparser
);
2979 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2980 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yyopt
.state());]b4_locations_if([[
2982 /* Set default location. */
2983 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yyoptState
->yyloc
;]])[
2985 symbol_type yyla_current
= std::move (this->yyla
);
2986 this->yyla
= std::move (yyopt
.yyla
);
2987 yyflag
= yyuserAction (yyopt
.yyrule
, yynrhs
,
2988 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2989 create_state_set_index (-1),
2990 yyvalp
]b4_locations_if([, yylocp
])[);
2991 this->yyla
= std::move (yyla_current
);
2994 }]b4_locations_if([[
2996 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
2997 * ending at YYS1. Has no effect on previously resolved states.
2998 * The first semantic option of a state is always chosen. */
3000 yyresolveLocations (glr_state
&yys1
, int yyn1
)
3004 yyresolveLocations (*yys1
.pred(), yyn1
- 1);
3005 if (!yys1
.yyresolved
)
3007 glr_stack_item yyrhsloc
[1 + YYMAXRHS
];
3008 YYASSERT (yys1
.firstVal() != YY_NULLPTR
);
3009 semantic_option
& yyoption
= *yys1
.firstVal();
3010 const int yynrhs
= yyrhsLength (yyoption
.yyrule
);
3013 yyresolveLocations (*yyoption
.state(), yynrhs
);
3014 const glr_state
*yys
= yyoption
.state();
3015 for (int yyn
= yynrhs
; yyn
> 0; yyn
-= 1)
3017 yyrhsloc
[yyn
].getState().yyloc
= yys
->yyloc
;
3023 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3024 in reverse rightmost order. It is only necessary to invoke
3025 yyresolveLocations on a subforest for which yyresolveAction
3026 would have been invoked next had an ambiguity not been
3027 detected. Thus the location of the previous state (but not
3028 necessarily the previous state itself) is guaranteed to be
3029 resolved already. */
3030 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3031 yyrhsloc
[0].getState().yyloc
= yyoption
.state()->yyloc
;
3032 YY_IGNORE_NULL_DEREFERENCE_END
3034 YYLLOC_DEFAULT ((yys1
.yyloc
), yyrhsloc
, yynrhs
);
3039 /** If yytoken is empty, fetch the next token. */
3043 ]b4_parse_param_use()dnl
3044 [ if (this->yyla
.empty ())
3046 YYCDEBUG
<< "Reading a token\n";
3049 #endif // YY_EXCEPTIONS
3050 {]b4_token_ctor_if([[
3051 symbol_type
yylookahead (]b4_yylex
[);
3052 yyla
.move (yylookahead
);]], [[
3053 yyla
.kind_
= yyparser
.yytranslate_ (]b4_yylex
[);]])[
3056 catch (const parser_type::syntax_error
& yyexc
)
3058 YYCDEBUG
<< "Caught exception: " << yyexc
.what () << '\n';]b4_locations_if([
3059 this->yyla
.location
= yyexc
.location
;])[
3060 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[yyexc
.what ());
3061 // Map errors caught in the scanner to the error token, so that error
3062 // handling is started.
3063 this->yyla
.kind_
= ]b4_symbol(error
, kind
)[;
3066 #endif // YY_EXCEPTIONS
3067 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
3068 YYCDEBUG
<< "Now at end of input.\n";
3070 YY_SYMBOL_PRINT ("Next token is", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
3074 /* Bison grammar-table manipulation. */
3076 /** The action to take in YYSTATE on seeing YYTOKEN.
3078 * R < 0: Reduce on rule -R.
3080 * R > 0: Shift to state R.
3081 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3082 * of conflicting reductions.
3085 yygetLRActions (state_num yystate
, symbol_kind_type yytoken
, const short*& yyconflicts
)
3087 int yyindex
= yypact
[yystate
] + yytoken
;
3088 if (yytoken
== ]b4_symbol(error
, kind
)[)
3090 // This is the error token.
3091 yyconflicts
= yyconfl
;
3094 else if (yy_is_defaulted_state (yystate
)
3095 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
3097 yyconflicts
= yyconfl
;
3098 return -yydefact
[yystate
];
3100 else if (! yytable_value_is_error (yytable
[yyindex
]))
3102 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3103 return yytable
[yyindex
];
3107 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3112 /** Compute post-reduction state.
3113 * \param yystate the current state
3114 * \param yysym the nonterminal to push on the stack
3117 yyLRgotoState (state_num yystate
, symbol_kind_type yysym
)
3119 const int yyr
= yypgoto
[yysym
- YYNTOKENS
] + yystate
;
3120 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
3121 return yytable
[yyr
];
3123 return yydefgoto
[yysym
- YYNTOKENS
];
3127 yypact_value_is_default (state_num yystate
)
3129 return ]b4_table_value_equals([[pact
]], [[yystate
]], [b4_pact_ninf
], [YYPACT_NINF
])[;
3133 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED
)
3135 return ]b4_table_value_equals([[table
]], [[yytable_value
]], [b4_table_ninf
], [YYTABLE_NINF
])[;
3139 yy_is_shift_action (int yyaction
) YY_NOEXCEPT
3141 return 0 < yyaction
;
3145 yy_is_error_action (int yyaction
) YY_NOEXCEPT
3147 return yyaction
== 0;
3150 /** Whether LR state YYSTATE has only a default reduction
3151 * (regardless of token). */
3153 yy_is_defaulted_state (state_num yystate
)
3155 return yypact_value_is_default (yypact
[yystate
]);
3158 /** The default reduction for YYSTATE, assuming it has one. */
3160 yy_default_action (state_num yystate
)
3162 return yydefact
[yystate
];
3167 /** Y0 and Y1 represent two possible actions to take in a given
3168 * parsing state; return 0 if no combination is possible,
3169 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3171 yypreference (const semantic_option
& y0
, const semantic_option
& y1
)
3173 const rule_num r0
= y0
.yyrule
, r1
= y1
.yyrule
;
3174 const int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
3178 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
3183 else if (p0
== 0 || p1
== 0)
3193 ]b4_parse_param_vars
[
3194 }; // class ]b4_parser_class[::glr_stack
3195 } // namespace ]b4_namespace_ref[
3198 #if ]b4_api_PREFIX[DEBUG
3202 yypstack (const glr_stack
& yystack
, size_t yyk
)
3204 yystack
.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk
)));
3208 yypdumpstack (const glr_stack
& yystack
)
3210 yystack
.yypdumpstack ();
3216 /// Build a parser object.
3217 ]b4_parser_class::b4_parser_class
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
3219 #if ]b4_api_PREFIX[DEBUG
3220 ]m4_ifset([b4_parse_param
], [ ], [ :])[yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
3221 #endif]b4_parse_param_cons[
3224 ]b4_parser_class::~b4_parser_class
[ ()
3227 ]b4_parser_class
[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3231 ]b4_parser_class
[::operator() ()
3237 ]b4_parser_class
[::parse ()
3239 glr_stack
yystack(YYINITDEPTH
, *this]b4_user_args
[);
3240 return yystack
.parse ();
3243 ]b4_parse_error_bmatch([custom\
|detailed
],
3245 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3247 static const char *const yy_sname
[] =
3250 };]b4_has_translations_if([[
3251 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3252 internationalizable. */
3253 static ]b4_int_type_for([b4_translatable
])[ yytranslatable
[] =
3257 return (yysymbol
< YYNTOKENS
&& yytranslatable
[yysymbol
]
3258 ? _(yy_sname
[yysymbol
])
3259 : yy_sname
[yysymbol
]);]], [[
3260 return yy_sname
[yysymbol
];]])[
3264 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3266 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3268 return yytname_
[yysymbol
];
3270 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3273 [[ /* Return YYSTR after stripping away unnecessary quotes and
3274 backslashes, so that it's suitable for yyerror. The heuristic is
3275 that double-quoting is unnecessary unless the string contains an
3276 apostrophe, a comma, or backslash (other than backslash-backslash).
3277 YYSTR is taken from yytname. */
3279 ]b4_parser_class
[::yytnamerr_ (const char *yystr
)
3284 char const *yyp
= yystr
;
3291 goto do_not_strip_quotes
;
3295 goto do_not_strip_quotes
;
3307 do_not_strip_quotes
: ;
3314 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3316 return yytnamerr_ (yytname_
[yysymbol
]);
3320 ]b4_parse_error_bmatch([simple\
|verbose
],
3321 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3322 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3323 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3325 const ]b4_parser_class
[::yytname_
[] =
3332 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
3333 // ]b4_parser_class[::context.
3334 ]b4_parser_class
[::context::context (glr_stack
& yystack
, const symbol_type
& yyla
)
3335 : yystack_ (yystack
)
3340 ]b4_parser_class
[::context::expected_tokens (symbol_kind_type yyarg
[], int yyargn
) const
3342 // Actual number of expected tokens
3344 const int yyn
= yypact
[yystack_
.firstTopState()->yylrState
];
3345 if (!yystack_
.yypact_value_is_default (yyn
))
3347 /* Start YYX at -YYN if negative to avoid negative indexes in
3348 YYCHECK. In other words, skip the first -YYN actions for this
3349 state because they are default actions. */
3350 const int yyxbegin
= yyn
< 0 ? -yyn
: 0;
3351 /* Stay within bounds of both yycheck and yytname. */
3352 const int yychecklim
= YYLAST
- yyn
+ 1;
3353 const int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
3354 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
3355 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= ]b4_symbol(error
, kind
)[
3356 && !yystack_
.yytable_value_is_error (yytable
[yyx
+ yyn
]))
3360 else if (yycount
== yyargn
)
3363 yyarg
[yycount
++] = YY_CAST (symbol_kind_type
, yyx
);
3366 if (yyarg
&& yycount
== 0 && 0 < yyargn
)
3367 yyarg
[0] = ]b4_symbol(empty
, kind
)[;
3373 ]b4_parse_error_bmatch([detailed\
|verbose
], [[
3375 ]b4_parser_class
[::yy_syntax_error_arguments_ (const context
& yyctx
,
3376 symbol_kind_type yyarg
[], int yyargn
) const
3378 /* There are many possibilities here to consider:
3379 - If this state is a consistent state with a default action, then
3380 the only way this function was invoked is if the default action
3381 is an error action. In that case, don't check for expected
3382 tokens because there are none.
3383 - The only way there can be no lookahead present (in yyla) is
3384 if this state is a consistent state with a default action.
3385 Thus, detecting the absence of a lookahead is sufficient to
3386 determine that there is no unexpected or expected token to
3387 report. In that case, just report a simple "syntax error".
3388 - Don't assume there isn't a lookahead just because this state is
3389 a consistent state with a default action. There might have
3390 been a previous inconsistent state, consistent state with a
3391 non-default action, or user semantic action that manipulated
3392 yyla. (However, yyla is currently not documented for users.)
3395 if (!yyctx
.lookahead ().empty ())
3398 yyarg
[0] = yyctx
.token ();
3399 int yyn
= yyctx
.expected_tokens (yyarg
? yyarg
+ 1 : yyarg
, yyargn
- 1);
3405 // Generate an error message.
3407 ]b4_parser_class
[::yysyntax_error_ (const context
& yyctx
) const
3410 enum { YYARGS_MAX
= 5 };
3411 // Arguments of yyformat.
3412 symbol_kind_type yyarg
[YYARGS_MAX
];
3413 int yycount
= yy_syntax_error_arguments_ (yyctx
, yyarg
, YYARGS_MAX
);
3415 char const* yyformat
= YY_NULLPTR
;
3418 #define YYCASE_(N, S) \
3422 default: // Avoid compiler warnings.
3423 YYCASE_ (0, YY_("syntax error"));
3424 YYCASE_ (1, YY_("syntax error, unexpected %s"));
3425 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
3426 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
3427 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
3428 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
3434 std::ptrdiff_t yyi
= 0;
3435 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
3436 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
3438 yyres
+= symbol_name (yyarg
[yyi
++]);
3447 ]b4_parser_class
[::yy_destroy_ (const char* yymsg
, symbol_kind_type yykind
,
3448 value_type
& yyval
]b4_locations_if([[,
3449 location_type
& yyloc
]])[)
3451 YY_USE (yyval
);]b4_locations_if([[
3455 ]b4_parser_class
[& yyparser
= *this;
3457 YY_SYMBOL_PRINT (yymsg
, yykind
, yyval
, yyloc
);
3459 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3460 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3461 [b4_symbol_actions([destructor
])],
3462 [m4_popdef([b4_symbol_action
])])[
3463 YY_IGNORE_MAYBE_UNINITIALIZED_END
3466 #if ]b4_api_PREFIX[DEBUG
3467 /*--------------------.
3468 | Print this symbol. |
3469 `--------------------*/
3472 ]b4_parser_class
[::yy_symbol_value_print_ (symbol_kind_type yykind
,
3473 const value_type
& yyval
]b4_locations_if([[,
3474 const location_type
& yyloc
]])[) const
3475 {]b4_locations_if([[
3478 std::ostream
& yyo
= debug_stream ();
3480 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3481 [b4_symbol_actions([printer
])],
3482 [m4_popdef([b4_symbol_action
])])[
3486 ]b4_parser_class
[::yy_symbol_print_ (symbol_kind_type yykind
,
3487 const value_type
& yyval
]b4_locations_if([[,
3488 const location_type
& yyloc
]])[) const
3490 *yycdebug_
<< (yykind
< YYNTOKENS
? "token" : "nterm")
3491 << ' ' << symbol_name (yykind
) << " ("]b4_locations_if([[
3492 << yyloc
<< ": "]])[;
3493 yy_symbol_value_print_ (yykind
, yyval
]b4_locations_if([[, yyloc
]])[);
3498 ]b4_parser_class
[::debug_stream () const
3504 ]b4_parser_class
[::set_debug_stream (std::ostream
& o
)
3510 ]b4_parser_class
[::debug_level_type
3511 ]b4_parser_class
[::debug_level () const
3517 ]b4_parser_class
[::set_debug_level (debug_level_type l
)
3519 // Actually, it is yydebug which is really used.
3522 #endif // ]b4_api_PREFIX[DEBUG
3524 ]b4_token_ctor_if([], [b4_yytranslate_define([cc
])])[
3526 ]b4_token_ctor_if([], [[
3530 ]b4_public_types_define([cc
])])[
3531 ]b4_namespace_close
[]dnl