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);
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 value_type
= parser_type::value_type
;]b4_locations_if([[
784 using location_type
= parser_type::location_type
;]])[
786 // Forward declarations.
787 class glr_stack_item
;
788 class semantic_option
;
793 /** Accessing symbol of state YYSTATE. */
794 inline symbol_kind_type
795 yy_accessing_symbol (state_num yystate
)
797 return YY_CAST (symbol_kind_type
, yystos
[yystate
]);
800 /** Left-hand-side symbol for rule #YYRULE. */
801 inline symbol_kind_type
802 yylhsNonterm (rule_num yyrule
)
804 return static_cast<symbol_kind_type
>(yyr1
[yyrule
]);
807 /** Number of symbols composing the right hand side of rule #RULE. */
809 yyrhsLength (rule_num yyrule
)
815 namespace ]b4_namespace_ref
[
817 class ]b4_parser_class
[::glr_state
825 , yyfirstVal (0)]b4_locations_if([[
826 , yyloc ()]])[]b4_parse_assert_if([[
830 /// Build with a semantic value.
831 glr_state (state_num lrState
, size_t posn
, const value_type
& val
]b4_locations_if([[, const location_type
& loc
]])[)
833 , yylrState (lrState
)
836 , yyval (]b4_variant_if([], [[val
]])[)]b4_locations_if([[
837 , yyloc (loc
)]])[]b4_parse_assert_if([[
840 ]b4_symbol_variant([yy_accessing_symbol (lrState
)],
841 [yyval
], [copy
], [val
])])[}
843 /// Build with a semantic option.
844 glr_state (state_num lrState
, size_t posn
)
846 , yylrState (lrState
)
849 , yyfirstVal (0)]b4_locations_if([[
850 , yyloc ()]])[]b4_parse_assert_if([[
854 glr_state (const glr_state
& other
)
855 : yyresolved (other
.yyresolved
)
856 , yylrState (other
.yylrState
)
857 , yyposn (other
.yyposn
)
858 , yypred (0)]b4_locations_if([[
859 , yyloc (other
.yyloc
)]])[]b4_parse_assert_if([[
862 setPred (other
.pred ());
863 if (other
.yyresolved
)]b4_variant_if([[
865 new (&yyval
) value_type ();
866 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
867 [yyval
], [copy
], [other
.value ()])[
869 new (&yyval
) value_type (other
.value ());]])[
873 setFirstVal (other
.firstVal ());
874 }]b4_parse_assert_if([[
879 {]b4_parse_assert_if([[
883 symbol_kind_type yykind
= yy_accessing_symbol (yylrState
);
884 // FIXME: User destructors.
885 // Value type destructor.
886 ]b4_symbol_variant([[yykind
]], [[yyval
]], [[template destroy
]])])[
887 yyval
.~value_type ();
888 }]b4_parse_assert_if([[
892 glr_state
& operator= (const glr_state
& other
)
893 {]b4_parse_assert_if([[
896 if (!yyresolved
&& other
.yyresolved
)
897 new (&yyval
) value_type
;
898 yyresolved
= other
.yyresolved
;
899 yylrState
= other
.yylrState
;
900 yyposn
= other
.yyposn
;
901 setPred (other
.pred ());
902 if (other
.yyresolved
)]b4_variant_if([[
903 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
904 [yyval
], [copy
], [other
.value ()])], [[
905 value () = other
.value ();]])[
907 setFirstVal (other
.firstVal ());]b4_locations_if([[
908 yyloc
= other
.yyloc
;]])[
912 /** Type tag for the semantic value. If true, yyval applies, otherwise
913 * yyfirstVal applies. */
915 /** Number of corresponding LALR(1) machine state. */
917 /** Source position of the last token produced by my symbol */
920 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
922 const glr_state
* pred () const;
923 void setPred (const glr_state
* state
);
925 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
927 semantic_option
* firstVal ();
928 const semantic_option
* firstVal () const;
929 void setFirstVal (const semantic_option
* option
);
932 {]b4_parse_assert_if([[
937 const value_type
& value () const
938 {]b4_parse_assert_if([[
944 destroy (char const *yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
);
947 #if ]b4_api_PREFIX[DEBUG
948 void yy_yypstack () const
949 {]b4_parse_assert_if([[
951 if (pred () != YY_NULLPTR
)
953 pred ()->yy_yypstack ();
956 std::cerr
<< yylrState
<< "@@" << yyposn
;
960 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const YY_ATTRIBUTE_UNUSED
;
962 glr_stack_item
* asItem ()
963 {]b4_parse_assert_if([[
968 const glr_stack_item
* asItem () const
969 {]b4_parse_assert_if([[
971 return asItem (this);
975 template <typename T
>
976 static const glr_stack_item
* asItem (const T
* state
)
978 return reinterpret_cast<const glr_stack_item
*>(state
);
980 template <typename T
>
981 static glr_stack_item
* asItem (T
* state
)
983 return reinterpret_cast<glr_stack_item
*> (state
);
985 static const char *as_pointer_ (const glr_state
*state
)
987 return reinterpret_cast<const char *> (state
);
989 static char *as_pointer_ (glr_state
*state
)
991 return reinterpret_cast<char *> (state
);
993 /** Preceding state in this stack */
994 std::ptrdiff_t yypred
;
996 /** First in a chain of alternative reductions producing the
997 * nonterminal corresponding to this state, threaded through
998 * yyfirstVal. Value "0" means empty. */
999 std::ptrdiff_t yyfirstVal
;
1000 /** Semantic value for this state. */
1002 };]b4_locations_if([[
1003 // FIXME: Why public?
1005 /** Source location for this state. */
1006 location_type yyloc
;]])[
1008 ]b4_parse_assert_if([[
1010 // Check invariants.
1011 void check_ () const
1013 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1014 YYASSERT (this->magic_
== MAGIC
);
1015 YY_IGNORE_NULL_DEREFERENCE_END
1018 // A magic number to check our pointer arithmetic is sane.
1019 enum { MAGIC
= 713705 };
1020 unsigned int magic_
;]])[
1021 }; // class ]b4_parser_class[::glr_state
1022 } // namespace ]b4_namespace_ref[
1027 /** A stack of GLRState representing the different heads during
1028 * nondeterministic evaluation. */
1032 /** Initialize YYSET to a singleton set containing an empty stack. */
1034 : yylastDeleted (YY_NULLPTR
)
1036 yystates
.push_back (YY_NULLPTR
);
1037 yylookaheadNeeds
.push_back (false);
1040 // Behave like a vector of states.
1041 glr_state
*& operator[] (state_set_index index
)
1043 return yystates
[index
.uget()];
1046 glr_state
* operator[] (state_set_index index
) const
1048 return yystates
[index
.uget()];
1051 size_t size () const
1053 return yystates
.size ();
1056 std::vector
<glr_state
*>::iterator
begin ()
1058 return yystates
.begin ();
1061 std::vector
<glr_state
*>::iterator
end ()
1063 return yystates
.end ();
1066 bool lookaheadNeeds (state_set_index index
) const
1068 return yylookaheadNeeds
[index
.uget ()];
1071 bool setLookaheadNeeds (state_set_index index
, bool value
)
1073 return yylookaheadNeeds
[index
.uget ()] = value
;
1076 /** Invalidate stack #YYK. */
1078 yymarkStackDeleted (state_set_index yyk
)
1080 size_t k
= yyk
.uget ();
1081 if (yystates
[k
] != YY_NULLPTR
)
1082 yylastDeleted
= yystates
[k
];
1083 yystates
[k
] = YY_NULLPTR
;
1086 /** Undelete the last stack in *this that was marked as deleted. Can
1087 only be done once after a deletion, and only when all other stacks have
1090 yyundeleteLastStack ()
1092 if (yylastDeleted
== YY_NULLPTR
|| !yystates
.empty ())
1094 yystates
.push_back (yylastDeleted
);
1095 YYCDEBUG
<< "Restoring last deleted stack as stack #0.\n";
1096 clearLastDeleted ();
1099 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1104 size_t newsize
= yystates
.size ();
1105 /* j is the number of live stacks we have seen. */
1106 for (size_t i
= 0, j
= 0; j
< newsize
; ++i
)
1108 if (yystates
[i
] == YY_NULLPTR
)
1112 YYCDEBUG
<< "Removing dead stacks.\n";
1118 yystates
[j
] = yystates
[i
];
1119 /* In the current implementation, it's unnecessary to copy
1120 yylookaheadNeeds[i] since, after
1121 yyremoveDeletes returns, the parser immediately either enters
1122 deterministic operation or shifts a token. However, it doesn't
1123 hurt, and the code might evolve to need it. */
1124 yylookaheadNeeds
[j
] = yylookaheadNeeds
[i
];
1127 YYCDEBUG
<< "Rename stack " << i
<< " -> " << j
<< ".\n";
1132 yystates
.resize (newsize
);
1133 yylookaheadNeeds
.resize (newsize
);
1138 yysplitStack (state_set_index yyk
)
1140 const size_t k
= yyk
.uget ();
1141 yystates
.push_back (yystates
[k
]);
1142 yylookaheadNeeds
.push_back (yylookaheadNeeds
[k
]);
1143 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates
.size () - 1));
1146 void clearLastDeleted ()
1148 yylastDeleted
= YY_NULLPTR
;
1153 std::vector
<glr_state
*> yystates
;
1154 /** During nondeterministic operation, yylookaheadNeeds tracks which
1155 * stacks have actually needed the current lookahead. During deterministic
1156 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1157 * duplicate !yyla.empty (). */
1158 std::vector
<bool> yylookaheadNeeds
;
1160 /** The last stack we invalidated. */
1161 glr_state
* yylastDeleted
;
1162 }; // class glr_state_set
1167 class semantic_option
1174 , yytoken (]b4_symbol(empty
, kind
)[)
1175 , yyval ()]b4_locations_if([[
1176 , yyloc ()]])[]b4_parse_assert_if([[
1177 , magic_ (MAGIC
)]])[
1180 semantic_option (rule_num rule
)
1184 , yytoken (]b4_symbol(empty
, kind
)[)
1185 , yyval ()]b4_locations_if([[
1186 , yyloc ()]])[]b4_parse_assert_if([[
1187 , magic_ (MAGIC
)]])[
1190 semantic_option (const semantic_option
& that
)
1191 : yyrule (that
.yyrule
)
1192 , yystate (that
.yystate
)
1193 , yynext (that
.yynext
)
1194 , yytoken (that
.yytoken
)
1195 , yyval (]b4_variant_if([], [[that
.yyval
]])[)]b4_locations_if([[
1196 , yyloc (that
.yyloc
)]])[]b4_parse_assert_if([[
1197 , magic_ (MAGIC
)]])[
1198 {]b4_parse_assert_if([[
1199 that
.check_ ();]])[]b4_variant_if([[
1200 ]b4_symbol_variant([yytoken
],
1201 [yyval
], [copy
], [that
.yyval
])])[
1204 // Needed for the assignment in yynewSemanticOption.
1205 semantic_option
& operator= (const semantic_option
& that
)
1206 {]b4_parse_assert_if([[
1209 yyrule
= that
.yyrule
;
1210 yystate
= that
.yystate
;
1211 yynext
= that
.yynext
;
1212 yytoken
= that
.yytoken
;]b4_variant_if([[
1213 ]b4_symbol_variant([yytoken
],
1214 [yyval
], [copy
], [that
.yyval
])], [[
1215 yyval
= that
.yyval
;]])[]b4_locations_if([[
1216 yyloc
= that
.yyloc
;]])[
1220 /// Only call state() and setState() on objects in yyitems, not temporaries.
1222 const glr_state
* state() const;
1223 void setState(const glr_state
* s
);
1225 const semantic_option
* next () const YY_ATTRIBUTE_UNUSED
;
1226 semantic_option
* next ();
1227 void setNext (const semantic_option
* s
);
1229 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const YY_ATTRIBUTE_UNUSED
;
1231 /** True iff YYY0 and YYY1 represent identical options at the top level.
1232 * That is, they represent the same rule applied to RHS symbols
1233 * that produce the same terminal symbols. */
1235 isIdenticalTo (const semantic_option
& yyy1
) const
1236 {]b4_parse_assert_if([[
1239 if (this->yyrule
== yyy1
.yyrule
)
1241 const glr_state
*yys0
, *yys1
;
1243 for (yys0
= this->state(),
1244 yys1
= yyy1
.state(),
1245 yyn
= yyrhsLength (this->yyrule
);
1247 yys0
= yys0
->pred(),
1248 yys1
= yys1
->pred(), yyn
-= 1)
1249 if (yys0
->yyposn
!= yys1
->yyposn
)
1257 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1258 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1260 mergeWith (semantic_option
& yyy1
)
1261 {]b4_parse_assert_if([[
1264 glr_state
*yys0
= this->state ();
1265 glr_state
*yys1
= yyy1
.state ();
1266 for (int yyn
= yyrhsLength (this->yyrule
);
1268 yyn
-= 1, yys0
= yys0
->pred (), yys1
= yys1
->pred ())
1272 else if (yys0
->yyresolved
)
1274 yys1
->yyresolved
= true;]b4_variant_if([[
1275 YYASSERT (yys1
->yylrState
== yys0
->yylrState
);
1276 ]b4_symbol_variant([yy_accessing_symbol (yys0
->yylrState
)],
1277 [yys1
->value ()], [copy
], [yys0
->value ()])], [[
1278 yys1
->value () = yys0
->value ();]])[
1280 else if (yys1
->yyresolved
)
1282 yys0
->yyresolved
= true;]b4_variant_if([[
1283 YYASSERT (yys0
->yylrState
== yys1
->yylrState
);
1284 ]b4_symbol_variant([yy_accessing_symbol (yys1
->yylrState
)],
1285 [yys0
->value ()], [copy
], [yys1
->value ()])], [[
1286 yys0
->value () = yys1
->value ();]])[
1290 semantic_option
* yyz0prev
= YY_NULLPTR
;
1291 semantic_option
* yyz0
= yys0
->firstVal();
1292 semantic_option
* yyz1
= yys1
->firstVal();
1295 if (yyz1
== yyz0
|| yyz1
== YY_NULLPTR
)
1297 else if (yyz0
== YY_NULLPTR
)
1299 if (yyz0prev
!= YY_NULLPTR
)
1300 yyz0prev
->setNext (yyz1
);
1302 yys0
->setFirstVal (yyz1
);
1305 else if (yyz0
< yyz1
)
1307 semantic_option
* yyz
= yyz0
;
1308 if (yyz0prev
!= YY_NULLPTR
)
1309 yyz0prev
->setNext(yyz1
);
1311 yys0
->setFirstVal(yyz1
);
1312 yyz1
= yyz1
->next();
1316 yyz0
= yyz0
->next();
1318 yys1
->setFirstVal(yys0
->firstVal());
1323 #if ]b4_api_PREFIX[DEBUG
1324 void yyreportTree (size_t yyindent
= 2) const
1325 {]b4_parse_assert_if([[
1327 int yynrhs
= yyrhsLength (this->yyrule
);
1328 const glr_state
* yystates
[1 + YYMAXRHS
];
1329 glr_state yyleftmost_state
;
1332 const glr_state
* yys
= this->state();
1333 for (int yyi
= yynrhs
; 0 < yyi
; yyi
-= 1)
1335 yystates
[yyi
] = yys
;
1338 if (yys
== YY_NULLPTR
)
1340 yyleftmost_state
.yyposn
= 0;
1341 yystates
[0] = &yyleftmost_state
;
1347 std::string yylhs
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yylhsNonterm (this->yyrule
));
1348 YYASSERT(this->state());
1349 if (this->state()->yyposn
< yystates
[0]->yyposn
+ 1)
1350 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1351 << this->yyrule
- 1 << ", empty>\n";
1353 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1354 << this->yyrule
- 1 << ", tokens "
1355 << yystates
[0]->yyposn
+ 1 << " .. "
1356 << this->state()->yyposn
<< ">\n";
1357 for (int yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1359 if (yystates
[yyi
]->yyresolved
)
1361 std::string yysym
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yy_accessing_symbol (yystates
[yyi
]->yylrState
));
1362 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1363 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1366 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1367 << " <tokens " << yystates
[yyi
-1]->yyposn
+ 1
1368 << " .. " << yystates
[yyi
]->yyposn
<< ">\n";
1371 yystates
[yyi
]->firstVal ()->yyreportTree (yyindent
+2);
1376 /** Rule number for this reduction */
1380 template <typename T
>
1381 static const glr_stack_item
* asItem(const T
* state
)
1383 return reinterpret_cast<const glr_stack_item
*>(state
);
1385 template <typename T
>
1386 static glr_stack_item
* asItem(T
* state
)
1388 return reinterpret_cast<glr_stack_item
*>(state
);
1390 /** The last RHS state in the list of states to be reduced. */
1391 std::ptrdiff_t yystate
;
1392 /** Next sibling in chain of options. To facilitate merging,
1393 * options are chained in decreasing order by address. */
1394 std::ptrdiff_t yynext
;
1397 /** The lookahead for this reduction. */
1398 symbol_kind_type yytoken
;
1399 value_type yyval
;]b4_locations_if([[
1400 location_type yyloc
;]])[
1402 ]b4_parse_assert_if([[
1404 // Check invariants.
1405 void check_ () const
1407 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1408 YYASSERT (this->magic_
== MAGIC
);
1409 YY_IGNORE_NULL_DEREFERENCE_END
1412 // A magic number to check our pointer arithmetic is sane.
1413 enum { MAGIC
= 0xeff1cace };
1414 unsigned int magic_
;]])[
1415 }; // class semantic_option
1420 /** Type of the items in the GLR stack.
1421 * It can be either a glr_state or a semantic_option. The is_state_ field
1422 * indicates which item of the union is valid. */
1423 class glr_stack_item
1426 glr_stack_item (bool state
= true)
1427 : is_state_ (state
)]b4_parse_assert_if([[
1428 , magic_ (MAGIC
)]])[
1431 new (&raw_
) glr_state
;
1433 new (&raw_
) semantic_option
;
1436 glr_stack_item (const glr_stack_item
& other
) YY_NOEXCEPT YY_NOTHROW
1437 : is_state_ (other
.is_state_
)]b4_parse_assert_if([[
1438 , magic_ (MAGIC
)]])[
1439 {]b4_parse_assert_if([[
1440 other
.check_ ();]])[
1441 std::memcpy (raw_
, other
.raw_
, union_size
);
1444 glr_stack_item
& operator= (glr_stack_item other
)
1445 {]b4_parse_assert_if([[
1447 other
.check_ ();]])[
1448 std::swap (is_state_
, other
.is_state_
);
1449 std::swap (raw_
, other
.raw_
);
1454 {]b4_parse_assert_if([[
1457 getState ().~glr_state ();
1459 getOption ().~semantic_option ();
1462 void setState (const glr_state
&state
)
1463 {]b4_parse_assert_if([[
1465 state
.check_ ();]])[
1466 if (this != state
.asItem ())
1469 getState ().~glr_state ();
1471 getOption ().~semantic_option ();
1472 new (&raw_
) glr_state (state
);
1477 glr_state
& getState ()
1478 {]b4_parse_assert_if([[
1480 YYDASSERT (is_state ());
1482 glr_state
& res
= *static_cast<glr_state
*> (yyp
);]b4_parse_assert_if([[
1487 const glr_state
& getState () const
1488 {]b4_parse_assert_if([[
1490 YYDASSERT (is_state ());
1491 const void *yyp
= raw_
;
1492 const glr_state
& res
= *static_cast<const glr_state
*> (yyp
);]b4_parse_assert_if([[
1497 semantic_option
& getOption ()
1498 {]b4_parse_assert_if([[
1500 YYDASSERT (!is_state ());
1502 return *static_cast<semantic_option
*> (yyp
);
1504 const semantic_option
& getOption () const
1505 {]b4_parse_assert_if([[
1507 YYDASSERT (!is_state ());
1508 const void *yyp
= raw_
;
1509 return *static_cast<const semantic_option
*> (yyp
);
1511 bool is_state () const
1512 {]b4_parse_assert_if([[
1518 /// The possible contents of raw_. Since they have constructors, they cannot
1519 /// be directly included in the union.
1522 char yystate
[sizeof (glr_state
)];
1523 char yyoption
[sizeof (semantic_option
)];
1525 enum { union_size
= sizeof (contents
) };
1527 /// Strongest alignment constraints.
1528 long double yyalign_me
;
1529 /// A buffer large enough to store the contents.
1530 char raw_
[union_size
];
1532 /** Type tag for the union. */
1534 ]b4_parse_assert_if([[
1536 // Check invariants.
1537 void check_ () const
1539 YYASSERT (this->magic_
== MAGIC
);
1540 YYASSERT (this->is_state_
== false || this->is_state_
== true);
1542 // A magic number to check our pointer arithmetic is sane.
1543 enum { MAGIC
= 0xDEAD1ACC }; // 3735886540.
1544 const unsigned int magic_
;]])[
1545 }; // class glr_stack_item
1548 glr_state
* glr_state::pred ()
1549 {]b4_parse_assert_if([[
1551 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1552 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1553 YY_IGNORE_NULL_DEREFERENCE_END
1556 const glr_state
* glr_state::pred () const
1557 {]b4_parse_assert_if([[
1559 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1560 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1561 YY_IGNORE_NULL_DEREFERENCE_END
1564 void glr_state::setPred (const glr_state
* state
)
1565 {]b4_parse_assert_if([[
1568 state
->check_ ();]])[
1569 yypred
= state
? as_pointer_ (this) - as_pointer_ (state
) : 0;
1572 semantic_option
* glr_state::firstVal ()
1573 {]b4_parse_assert_if([[
1575 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1578 const semantic_option
* glr_state::firstVal () const
1579 {]b4_parse_assert_if([[
1581 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1584 void glr_state::setFirstVal (const semantic_option
* option
)
1585 {]b4_parse_assert_if([[
1587 yyfirstVal
= option
? asItem(this) - asItem(option
) : 0;
1590 std::ptrdiff_t glr_state::indexIn (const glr_stack_item
* array
) const
1591 {]b4_parse_assert_if([[
1593 return asItem(this) - array
;
1596 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item
* array
) const
1598 return asItem(this) - array
;
1601 glr_state
* semantic_option::state ()
1603 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1604 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1605 YY_IGNORE_NULL_DEREFERENCE_END
1608 const glr_state
* semantic_option::state () const
1610 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1613 void semantic_option::setState (const glr_state
* s
)
1615 yystate
= s
? asItem(this) - asItem(s
) : 0;
1618 const semantic_option
* semantic_option::next () const
1620 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1623 semantic_option
* semantic_option::next ()
1625 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1628 void semantic_option::setNext (const semantic_option
* s
)
1630 yynext
= s
? asItem(this) - asItem(s
) : 0;
1633 void glr_state::destroy (char const* yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
)
1634 {]b4_parse_assert_if([[
1637 yyparser
.yy_destroy_ (yymsg
, yy_accessing_symbol(yylrState
),
1638 value ()]b4_locations_if([, yyloc
])[);
1641 #if ]b4_api_PREFIX[DEBUG
1643 << (firstVal() ? " unresolved " : " incomplete ")
1644 << (yy_accessing_symbol (yylrState
) < YYNTOKENS
? "token" : "nterm")
1645 << ' ' << yyparser
.symbol_name (yy_accessing_symbol (yylrState
))
1646 << " ("]b4_locations_if([[
1647 << yyloc
<< ": "]])[
1650 if (firstVal() != YY_NULLPTR
)
1652 semantic_option
& yyoption
= *firstVal ();
1653 glr_state
*yyrh
= yyoption
.state ();
1654 for (int yyn
= yyrhsLength (yyoption
.yyrule
); yyn
> 0; yyn
-= 1)
1656 yyrh
->destroy (yymsg
, yyparser
);
1657 yyrh
= yyrh
->pred();
1665 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1672 using parser_type
= ]b4_namespace_ref
[::]b4_parser_class
[;
1673 using symbol_kind
= parser_type::symbol_kind
;
1674 using value_type
= parser_type::value_type
;]b4_locations_if([[
1675 using location_type
= parser_type::location_type
;]])[
1677 /** Initialize to a single empty stack, with total maximum
1678 * capacity for all stacks of YYSIZE. */
1679 state_stack (size_t yysize
)
1680 : yysplitPoint (YY_NULLPTR
)
1682 yyitems
.reserve (yysize
);
1685 #if YYSTACKEXPANDABLE
1686 /** Returns false if it tried to expand but could not. */
1688 yyexpandGLRStackIfNeeded ()
1690 return YYHEADROOM
<= spaceLeft () || yyexpandGLRStack ();
1694 /** If *this is expandable, extend it. WARNING: Pointers into the
1695 stack from outside should be considered invalid after this call.
1696 We always expand when there are 1 or fewer items left AFTER an
1697 allocation, so that we can avoid having external pointers exist
1698 across an allocation. */
1702 const size_t oldsize
= yyitems
.size();
1703 if (YYMAXDEPTH
- YYHEADROOM
< oldsize
)
1705 const size_t yynewSize
= YYMAXDEPTH
< 2 * oldsize
? YYMAXDEPTH
: 2 * oldsize
;
1706 const glr_stack_item
*oldbase
= &yyitems
[0];
1708 yyitems
.reserve (yynewSize
);
1709 const glr_stack_item
*newbase
= &yyitems
[0];
1711 // Adjust the pointers. Perform raw pointer arithmetic, as there
1712 // is no reason for objects to be aligned on their size.
1713 const ptrdiff_t disp
1714 = reinterpret_cast<const char*> (newbase
) - reinterpret_cast<const char*> (oldbase
);
1716 const_cast<glr_state
*&> (yysplitPoint
)
1717 = reinterpret_cast<glr_state
*> (reinterpret_cast<char*> (const_cast<glr_state
*> (yysplitPoint
)) + disp
);
1719 for (std::vector
<glr_state
*>::iterator
1720 i
= yytops
.begin (),
1721 yyend
= yytops
.end ();
1723 if (glr_state_not_null (*i
))
1724 *i
= reinterpret_cast<glr_state
*>(reinterpret_cast<char*>(*i
) + disp
);
1731 bool yyexpandGLRStackIfNeeded ()
1733 return YYHEADROOM
<= spaceLeft ();
1736 #undef YYSTACKEXPANDABLE
1738 static bool glr_state_not_null (glr_state
* s
)
1740 return s
!= YY_NULLPTR
;
1746 using iterator
= std::vector
<glr_state
*>::iterator
;
1747 const iterator yybegin
= yytops
.begin();
1748 const iterator yyend
= yytops
.end();
1749 const iterator yyit
= std::find_if(yybegin
, yyend
, glr_state_not_null
);
1752 for (state_set_index yyk
= create_state_set_index(yyit
+ 1 - yybegin
);
1753 yyk
.uget() != numTops(); ++yyk
)
1754 yytops
.yymarkStackDeleted (yyk
);
1755 yytops
.yyremoveDeletes ();
1760 /** Called when returning to deterministic operation to clean up the extra
1765 if (yytops
.size() != 1 || !isSplit())
1768 // yyr is the state after the split point.
1769 glr_state
* yyr
= YY_NULLPTR
;
1770 for (glr_state
*yyp
= firstTop(), *yyq
= yyp
->pred();
1771 yyp
!= yysplitPoint
;
1772 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->pred())
1775 // This const_cast is okay, since anyway we have access to the mutable
1776 // yyitems into which yysplitPoint points.
1777 glr_stack_item
* nextFreeItem
1778 = const_cast<glr_state
*> (yysplitPoint
)->asItem () + 1;
1779 yysplitPoint
= YY_NULLPTR
;
1780 yytops
.clearLastDeleted ();
1782 while (yyr
!= YY_NULLPTR
)
1784 nextFreeItem
->setState (*yyr
);
1785 glr_state
& nextFreeState
= nextFreeItem
->getState();
1787 nextFreeState
.setPred(&(nextFreeItem
- 1)->getState());
1788 setFirstTop (&nextFreeState
);
1791 yyitems
.resize(static_cast<size_t>(nextFreeItem
- yyitems
.data()));
1794 bool isSplit() const {
1795 return yysplitPoint
!= YY_NULLPTR
;
1798 // Present the interface of a vector of glr_stack_item.
1799 std::vector
<glr_stack_item
>::const_iterator
begin () const
1801 return yyitems
.begin ();
1804 std::vector
<glr_stack_item
>::const_iterator
end () const
1806 return yyitems
.end ();
1811 return yyitems
.size ();
1814 glr_stack_item
& operator[] (size_t i
)
1819 glr_stack_item
& stackItemAt (size_t index
)
1821 return yyitems
[index
];
1824 size_t numTops () const
1826 return yytops
.size ();
1829 glr_state
* firstTop () const
1831 return yytops
[create_state_set_index (0)];
1834 glr_state
* topAt (state_set_index i
) const
1839 void setFirstTop (glr_state
* value
)
1841 yytops
[create_state_set_index (0)] = value
;
1844 void setTopAt (state_set_index i
, glr_state
* value
)
1851 yyitems
.pop_back ();
1854 void pop_back (size_t n
)
1856 yyitems
.resize (yyitems
.size () - n
);
1860 yysplitStack (state_set_index yyk
)
1864 YYASSERT (yyk
.get () == 0);
1865 yysplitPoint
= topAt (yyk
);
1867 return yytops
.yysplitStack (yyk
);
1870 /** Assuming that YYS is a GLRState somewhere on *this, update the
1871 * splitpoint of *this, if needed, so that it is at least as deep as
1874 yyupdateSplit (glr_state
& yys
)
1876 if (isSplit() && &yys
< yysplitPoint
)
1877 yysplitPoint
= &yys
;
1880 /** Return a fresh GLRState.
1881 * Callers should call yyreserveStack afterwards to make sure there is
1882 * sufficient headroom. */
1883 glr_state
& yynewGLRState (const glr_state
& newState
)
1885 glr_state
& state
= yyitems
[yynewGLRStackItem (true)].getState ();
1886 #if false && 201103L <= YY_CPLUSPLUS
1887 state
= std::move (newState
);
1894 /** Return a fresh SemanticOption.
1895 * Callers should call yyreserveStack afterwards to make sure there is
1896 * sufficient headroom. */
1897 semantic_option
& yynewSemanticOption (semantic_option newOption
)
1899 semantic_option
& option
= yyitems
[yynewGLRStackItem (false)].getOption ();
1900 option
= std::move (newOption
);
1904 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1905 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1906 * For convenience, always return YYLOW1. */
1908 yyfill (glr_stack_item
*yyvsp
, int &yylow
, int yylow1
, bool yynormal
)
1910 if (!yynormal
&& yylow1
< yylow
)
1912 yyfillin (yyvsp
, yylow
, yylow1
);
1918 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1919 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1920 * containing the pointer to the next state in the chain. */
1922 yyfillin (glr_stack_item
*yyvsp
, int yylow0
, int yylow1
)
1924 glr_state
* s
= yyvsp
[yylow0
].getState().pred();
1925 YYASSERT(s
!= YY_NULLPTR
);
1926 for (int i
= yylow0
-1; i
>= yylow1
; i
-= 1, s
= s
->pred())
1928 glr_state
& yys
= yyvsp
[i
].getState();
1929 #if ]b4_api_PREFIX[DEBUG
1930 yys
.yylrState
= s
->yylrState
;
1932 yys
.yyresolved
= s
->yyresolved
;
1935 new (&yys
.value ()) value_type ();
1936 ]b4_symbol_variant([yy_accessing_symbol (s
->yylrState
)],
1937 [yys
.value ()], [copy
], [s
->value ()])], [[
1938 new (&yys
.value ()) value_type (s
->value ());]])[
1941 /* The effect of using yyval or yyloc (in an immediate
1942 * rule) is undefined. */
1943 yys
.setFirstVal (YY_NULLPTR
);]b4_locations_if([[
1944 yys
.yyloc
= s
->yyloc
;]])[
1945 yys
.setPred(s
->pred());
1949 #if ]b4_api_PREFIX[DEBUG
1951 /*----------------------------------------------------------------------.
1952 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1953 `----------------------------------------------------------------------*/
1956 yy_reduce_print (bool yynormal
, glr_stack_item
* yyvsp
, state_set_index yyk
,
1957 rule_num yyrule
, parser_type
& yyparser
)
1959 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1962 std::cerr
<< "Reducing stack " << yyk
.get() << " by rule " << yyrule
- 1
1963 << " (line " << int (yyrline
[yyrule
]) << "):\n";
1965 yyfillin (yyvsp
, 1, -yynrhs
);
1966 /* The symbols being reduced. */
1967 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1969 std::cerr
<< " $" << yyi
+ 1 << " = ";
1970 yyparser
.yy_symbol_print_
1971 (yy_accessing_symbol (yyvsp
[yyi
- yynrhs
+ 1].getState().yylrState
),
1972 yyvsp
[yyi
- yynrhs
+ 1].getState().value ()]b4_locations_if([[,
1973 ]b4_rhs_location(yynrhs
, yyi
+ 1)])[);
1974 if (!yyvsp
[yyi
- yynrhs
+ 1].getState().yyresolved
)
1975 std::cerr
<< " (unresolved)";
1981 #define YYINDEX(YYX) \
1982 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1987 for (size_t yyi
= 0; yyi
< size(); ++yyi
)
1989 const glr_stack_item
& item
= yyitems
[yyi
];
1990 std::cerr
<< std::setw(3) << yyi
<< ". ";
1991 if (item
.is_state())
1993 std::cerr
<< "Res: " << item
.getState().yyresolved
1994 << ", LR State: " << item
.getState().yylrState
1995 << ", posn: " << item
.getState().yyposn
1996 << ", pred: " << YYINDEX(item
.getState().pred());
1997 if (! item
.getState().yyresolved
)
1998 std::cerr
<< ", firstVal: "
1999 << YYINDEX(item
.getState().firstVal());
2003 std::cerr
<< "Option. rule: " << item
.getOption().yyrule
- 1
2004 << ", state: " << YYINDEX(item
.getOption().state())
2005 << ", next: " << YYINDEX(item
.getOption().next());
2009 std::cerr
<< "Tops:";
2010 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < numTops(); ++yyi
) {
2011 std::cerr
<< yyi
.get() << ": " << YYINDEX(topAt(yyi
)) << "; ";
2020 yyreportAmbiguity (const semantic_option
& yyx0
,
2021 const semantic_option
& yyx1
, parser_type
& yyparser
]b4_locations_if([, const location_type
& yyloc
])[)
2026 #if ]b4_api_PREFIX[DEBUG
2027 std::cerr
<< "Ambiguity detected.\n"
2029 yyx0
.yyreportTree ();
2030 std::cerr
<< "\nOption 2,\n";
2031 yyx1
.yyreportTree ();
2035 yyparser
.error (]b4_locations_if([yyloc
, ])[YY_("syntax is ambiguous"));
2039 #if ]b4_api_PREFIX[DEBUG
2040 /* Print YYS (possibly NULL) and its predecessors. */
2042 yypstates (const glr_state
* yys
) const
2044 if (yys
!= YY_NULLPTR
)
2047 std::cerr
<< "<null>";
2053 size_t spaceLeft() const
2055 return yyitems
.capacity() - yyitems
.size();
2058 /** Return a fresh GLRStackItem in this. The item is an LR state
2059 * if YYIS_STATE, and otherwise a semantic option. Callers should call
2060 * yyreserveStack afterwards to make sure there is sufficient
2063 yynewGLRStackItem (bool yyis_state
)
2065 YYDASSERT(yyitems
.size() < yyitems
.capacity());
2066 yyitems
.push_back(glr_stack_item(yyis_state
));
2067 return yyitems
.size() - 1;
2072 std::vector
<glr_stack_item
> yyitems
;
2073 // Where the stack splits. Anything below this address is deterministic.
2074 const glr_state
* yysplitPoint
;
2075 glr_state_set yytops
;
2076 }; // class state_stack
2080 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2082 namespace ]b4_namespace_ref
[
2084 class ]b4_parser_class
[::glr_stack
2087 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
2088 // Needs access to yypact_value_is_default, etc.
2092 glr_stack (size_t yysize
, parser_type
& yyparser_yyarg
]m4_ifset([b4_parse_param
], [, b4_parse_param_decl
])[)
2094 , yystateStack (yysize
)
2097 , yyparser (yyparser_yyarg
)]m4_ifset([b4_parse_param
], [,b4_parse_param_cons
])[
2102 if (!this->yyla
.empty ())
2103 yyparser
.yy_destroy_ ("Cleanup: discarding lookahead",
2104 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2109 ]b4_locations_if([[ /* To compute the location of the error token. */
2110 glr_stack_item yyerror_range
[3];]])[
2111 state_stack yystateStack
;
2114 YYJMP_BUF yyexception_buffer
;
2115 parser_type
& yyparser
;
2117 #define YYCHK1(YYE) \
2127 goto yyuser_error; \
2139 YYCDEBUG
<< "Starting parse\n";
2141 this->yyla
.clear ();
2142 ]m4_ifdef([b4_initial_action
], [
2143 b4_dollar_pushdef([yyla
.value
], [], [], [yyla
.location
])dnl
2144 b4_user_initial_action
2145 b4_dollar_popdef
])[]dnl
2147 switch (YYSETJMP (this->yyexception_buffer
))
2150 case 1: goto yyabortlab
;
2151 case 2: goto yyexhaustedlab
;
2152 default: goto yybuglab
;
2154 this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2159 /* For efficiency, we have two loops, the first of which is
2160 specialized to deterministic operation (single stack, no
2161 potential ambiguity). */
2165 const state_num yystate
= this->firstTopState()->yylrState
;
2166 YYCDEBUG
<< "Entering state " << yystate
<< '\n';
2167 if (yystate
== YYFINAL
)
2169 if (yy_is_defaulted_state (yystate
))
2171 const rule_num yyrule
= yy_default_action (yystate
);
2173 {]b4_locations_if([[
2174 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2175 this->yyreportSyntaxError ();
2178 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule
, true));
2183 const short* yyconflicts
;
2184 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2185 if (*yyconflicts
!= 0)
2187 if (yy_is_shift_action (yyaction
))
2189 YY_SYMBOL_PRINT ("Shifting", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
2191 // FIXME: we should move yylval.
2192 this->yyglrShift (create_state_set_index(0), yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2194 if (0 < this->yyerrState
)
2195 this->yyerrState
-= 1;
2197 else if (yy_is_error_action (yyaction
))
2198 {]b4_locations_if([[
2199 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2200 /* Don't issue an error message again for exceptions
2201 thrown from the scanner. */
2202 if (this->yyla
.kind () != ]b4_symbol(error
, kind
)[)
2203 this->yyreportSyntaxError ();
2207 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction
, true));
2213 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < this->yystateStack
.numTops(); ++yys
)
2214 this->yystateStack
.yytops
.setLookaheadNeeds(yys
, !this->yyla
.empty ());
2216 /* yyprocessOneStack returns one of three things:
2218 - An error flag. If the caller is yyprocessOneStack, it
2219 immediately returns as well. When the caller is finally
2220 yyparse, it jumps to an error label via YYCHK1.
2222 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2223 (yys), which sets the top state of yys to NULL. Thus,
2224 yyparse's following invocation of yyremoveDeletes will remove
2227 - yyok, when ready to shift a token.
2229 Except in the first case, yyparse will invoke yyremoveDeletes and
2230 then shift the next token onto all remaining stacks. This
2231 synchronization of the shift (that is, after all preceding
2232 reductions on all stacks) helps prevent double destructor calls
2233 on yylval in the event of memory exhaustion. */
2235 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2236 YYCHK1 (this->yyprocessOneStack (yys
, yyposn
]b4_locations_if([, &this->yyla
.location
])[));
2237 this->yystateStack
.yytops
.yyremoveDeletes ();
2238 if (this->yystateStack
.yytops
.size() == 0)
2240 this->yystateStack
.yytops
.yyundeleteLastStack ();
2241 if (this->yystateStack
.yytops
.size() == 0)
2242 this->yyFail (]b4_locations_if([&this->yyla
.location
, ])[YY_("syntax error"));
2243 YYCHK1 (this->yyresolveStack ());
2244 YYCDEBUG
<< "Returning to deterministic operation.\n";]b4_locations_if([[
2245 this->yyerror_range
[1].getState ().yyloc
= this->yyla
.location
;]])[
2246 this->yyreportSyntaxError ();
2250 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2251 a copy of yylval will already be on stack 0 in the event of a
2252 failure in the following loop. Thus, yyla is emptied
2253 before the loop to make sure the user destructor for yylval isn't
2255 symbol_kind_type yytoken_to_shift
= this->yyla
.kind ();
2256 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2258 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2260 const state_num yystate
= this->topState (yys
)->yylrState
;
2261 const short* yyconflicts
;
2262 const int yyaction
= yygetLRActions (yystate
, yytoken_to_shift
, yyconflicts
);
2263 /* Note that yyconflicts were handled by yyprocessOneStack. */
2264 YYCDEBUG
<< "On stack " << yys
.get() << ", ";
2265 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, this->yyla
.value
, this->yyla
.location
);
2266 this->yyglrShift (yys
, yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2267 YYCDEBUG
<< "Stack " << yys
.get() << " now in state "
2268 << this->topState(yys
)->yylrState
<< '\n';
2271 // FIXME: User destructors.
2272 // Value type destructor.
2273 ]b4_symbol_variant([[yytoken_to_shift
]], [[this->yyla
.value
]], [[template destroy
]])])[
2275 if (this->yystateStack
.yytops
.size () == 1)
2277 YYCHK1 (this->yyresolveStack ());
2278 YYCDEBUG
<< "Returning to deterministic operation.\n";
2279 this->yystateStack
.yycompressStack ();
2285 this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla
.location
])[);
2286 yyposn
= this->firstTopState()->yyposn
;
2302 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[YY_("memory exhausted"));
2311 void yyreserveGlrStack ()
2313 if (!yystateStack
.yyexpandGLRStackIfNeeded ())
2314 yyMemoryExhausted ();
2318 yyMemoryExhausted ()
2320 YYLONGJMP (yyexception_buffer
, 2);
2324 yyFail (]b4_locations_if([location_type
* yylocp
, ])[const char* yymsg
)
2326 if (yymsg
!= YY_NULLPTR
)
2327 yyparser
.error (]b4_locations_if([*yylocp
, ])[yymsg
);
2328 YYLONGJMP (yyexception_buffer
, 1);
2334 /** Add a new semantic action that will execute the action for rule
2335 * YYRULE on the semantic values in YYRHS to the list of
2336 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2337 * stack #YYK of *this. */
2339 yyaddDeferredAction (state_set_index yyk
, glr_state
* yystate
,
2340 glr_state
* yyrhs
, rule_num yyrule
)
2342 semantic_option
& yynewOption
=
2343 yystateStack
.yynewSemanticOption (semantic_option (yyrule
));
2344 yynewOption
.setState(yyrhs
);
2345 yynewOption
.setNext(yystate
->firstVal());
2346 if (yystateStack
.yytops
.lookaheadNeeds(yyk
))
2348 yynewOption
.yytoken
= this->yyla
.kind ();]b4_variant_if([[
2349 ]b4_symbol_variant([this->yyla
.kind ()],
2350 [yynewOption
.yyval
], [copy
], [this->yyla
.value
])], [[
2351 yynewOption
.yyval
= this->yyla
.value
;]])[]b4_locations_if([
2352 yynewOption
.yyloc
= this->yyla
.location
;])[
2354 yystate
->setFirstVal (&yynewOption
);
2356 yyreserveGlrStack ();
2359 #if ]b4_api_PREFIX[DEBUG
2360 void yypdumpstack () const
2362 yystateStack
.dumpStack();
2367 yyreportSyntaxError ()
2369 if (yyerrState
!= 0)
2371 ]b4_parse_error_case(
2373 std::string msg
= YY_("syntax error");
2374 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]],
2376 context
yyctx (*this, yyla
);
2377 yyparser
.report_syntax_error (yyctx
);]],
2379 context
yyctx (*this, yyla
);
2380 std::string msg
= yyparser
.yysyntax_error_ (yyctx
);
2381 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]])[
2385 /* Recover from a syntax error on this, assuming that yytoken,
2386 yylval, and yylloc are the syntactic category, semantic value, and location
2387 of the lookahead. */
2389 yyrecoverSyntaxError (]b4_locations_if([location_type
* yylocp
])[)
2391 if (yyerrState
== 3)
2392 /* We just shifted the error token and (perhaps) took some
2393 reductions. Skip tokens until we can proceed. */
2396 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
2397 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2398 if (this->yyla
.kind () != ]b4_symbol(empty
, kind
)[)
2399 {]b4_locations_if([[
2400 /* We throw away the lookahead, but the error range
2401 of the shifted error token must take it into account. */
2402 glr_state
*yys
= firstTopState();
2403 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;
2404 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2405 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2406 yyparser
.yy_destroy_ ("Error: discarding",
2407 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);]b4_variant_if([[
2408 // Value type destructor.
2409 ]b4_symbol_variant([[this->yyla
.kind ()]], [[this->yyla
.value
]], [[template destroy
]])])[
2410 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2413 int yyj
= yypact
[firstTopState()->yylrState
];
2414 if (yypact_value_is_default (yyj
))
2416 yyj
+= this->yyla
.kind ();
2417 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != this->yyla
.kind ())
2419 if (yydefact
[firstTopState()->yylrState
] != 0)
2422 else if (! yytable_value_is_error (yytable
[yyj
]))
2426 if (!yystateStack
.reduceToOneStack())
2427 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2429 /* Now pop stack until we find a state that shifts the error token. */
2431 while (firstTopState () != YY_NULLPTR
)
2433 glr_state
*yys
= firstTopState ();
2434 int yyj
= yypact
[yys
->yylrState
];
2435 if (! yypact_value_is_default (yyj
))
2438 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2439 && yy_is_shift_action (yytable
[yyj
]))
2441 /* Shift the error token. */]b4_locations_if([[
2442 /* First adjust its location.*/
2443 location_type yyerrloc
;
2444 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2445 YYLLOC_DEFAULT (yyerrloc
, (yyerror_range
), 2);]])[
2446 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable
[yyj
]),
2447 this->yyla
.value
, yyerrloc
);
2448 yyglrShift (create_state_set_index(0), yytable
[yyj
],
2449 yys
->yyposn
, yyla
.value
]b4_locations_if([, yyerrloc
])[);
2450 yys
= firstTopState();
2453 }]b4_locations_if([[
2454 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;]])[
2455 if (yys
->pred() != YY_NULLPTR
)
2456 yys
->destroy ("Error: popping", yyparser
);
2457 yystateStack
.setFirstTop(yys
->pred());
2458 yystateStack
.pop_back();
2460 if (firstTopState() == YY_NULLPTR
)
2461 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2465 yyprocessOneStack (state_set_index yyk
,
2466 size_t yyposn
]b4_locations_if([, location_type
* yylocp
])[)
2468 while (yystateStack
.topAt(yyk
) != YY_NULLPTR
)
2470 const state_num yystate
= topState(yyk
)->yylrState
;
2471 YYCDEBUG
<< "Stack " << yyk
.get()
2472 << " Entering state " << yystate
<< '\n';
2474 YYASSERT (yystate
!= YYFINAL
);
2476 if (yy_is_defaulted_state (yystate
))
2478 const rule_num yyrule
= yy_default_action (yystate
);
2481 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2482 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2485 const YYRESULTTAG yyflag
2486 = yyglrReduce (yyk
, yyrule
, yyimmediate
[yyrule
]);
2487 if (yyflag
== yyerr
)
2489 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2490 " (predicate failure or explicit user error).\n";
2491 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2499 yystateStack
.yytops
.setLookaheadNeeds(yyk
, true);
2501 const short* yyconflicts
;
2502 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2504 for (; *yyconflicts
!= 0; ++yyconflicts
)
2506 state_set_index yynewStack
= yystateStack
.yysplitStack (yyk
);
2507 YYCDEBUG
<< "Splitting off stack " << yynewStack
.get()
2508 << " from " << yyk
.get() << ".\n";
2509 YYRESULTTAG yyflag
=
2510 yyglrReduce (yynewStack
, *yyconflicts
, yyimmediate
[*yyconflicts
]);
2512 YYCHK (yyprocessOneStack (yynewStack
,
2513 yyposn
]b4_locations_if([, yylocp
])[));
2514 else if (yyflag
== yyerr
)
2516 YYCDEBUG
<< "Stack " << yynewStack
.get() << " dies.\n";
2517 yystateStack
.yytops
.yymarkStackDeleted (yynewStack
);
2523 if (yy_is_shift_action (yyaction
))
2525 else if (yy_is_error_action (yyaction
))
2527 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2528 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2534 = yyglrReduce (yyk
, -yyaction
, yyimmediate
[-yyaction
]);
2535 if (yyflag
== yyerr
)
2537 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2538 " (predicate failure or explicit user error).\n";
2539 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2542 else if (yyflag
!= yyok
)
2550 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2551 * and top stack item YYVSP. YYVALP points to place to put semantic
2552 * value ($$), and yylocp points to place for location information
2553 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2554 * yyerr for YYERROR, yyabort for YYABORT. */
2556 yyuserAction (rule_num yyrule
, int yyrhslen
, glr_stack_item
* yyvsp
, state_set_index yyk
,
2557 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2559 bool yynormal YY_ATTRIBUTE_UNUSED
= !yystateStack
.isSplit();
2561 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
2565 # define yyerrok (yyerrState = 0)
2567 # define YYACCEPT return yyaccept
2569 # define YYABORT return yyabort
2571 # define YYERROR return yyerrok, yyerr
2572 # undef YYRECOVERING
2573 # define YYRECOVERING() (yyerrState != 0)
2575 # define yytoken this->yyla.kind_
2577 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2579 # define YYBACKUP(Token, Value) \
2580 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2584 /* Variants are always initialized to an empty instance of the
2585 correct type. The default '$$ = $1' action is NOT applied
2586 when using variants. */
2587 // However we really need to prepare yyvsp now if we want to get
2588 // correct locations, so invoke YYFILL for $1 anyway.
2589 (void) YYFILL (1-yyrhslen
);
2590 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [(*yyvalp
)], [emplace
])], [[
2592 *yyvalp
= yyval_default
;
2594 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].getState().value ();]])[]b4_locations_if([[
2595 /* Default location. */
2596 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
2597 yyerror_range
[1].getState().yyloc
= *yylocp
;
2599 /* If yyk == -1, we are running a deferred action on a temporary
2600 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2601 so pretend the stack is "normal". */
2602 YY_REDUCE_PRINT ((yynormal
|| yyk
== create_state_set_index (-1), yyvsp
, yyk
, yyrule
, yyparser
));
2606 #endif // YY_EXCEPTIONS
2614 catch (const syntax_error
& yyexc
)
2616 YYCDEBUG
<< "Caught exception: " << yyexc
.what() << '\n';]b4_locations_if([
2617 *yylocp
= yyexc
.location
;])[
2618 yyparser
.error (]b4_locations_if([*yylocp
, ])[yyexc
.what ());
2621 #endif // YY_EXCEPTIONS
2622 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule
), *yyvalp
, *yylocp
);
2632 # undef YYRECOVERING
2638 if (yystateStack
.isSplit ())
2641 for (glr_state
* yys
= firstTopState ();
2642 yys
!= yystateStack
.yysplitPoint
;
2645 YYCHK (yyresolveStates (*firstTopState (), yyn
));
2650 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2651 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2652 * semantic values. Assumes that all ambiguities in semantic values
2653 * have been previously resolved. Set *YYVALP to the resulting value,
2654 * and *YYLOCP to the computed location (if any). Return value is as
2655 * for userAction. */
2657 yydoAction (state_set_index yyk
, rule_num yyrule
,
2658 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2660 const int yynrhs
= yyrhsLength (yyrule
);
2662 if (!yystateStack
.isSplit())
2664 /* Standard special case: single stack. */
2665 YYASSERT (yyk
.get() == 0);
2666 glr_stack_item
* yyrhs
= yystateStack
.firstTop()->asItem();
2667 const YYRESULTTAG res
2668 = yyuserAction (yyrule
, yynrhs
, yyrhs
, yyk
, yyvalp
]b4_locations_if([, yylocp
])[);
2669 yystateStack
.pop_back(static_cast<size_t>(yynrhs
));
2670 yystateStack
.setFirstTop(&yystateStack
[yystateStack
.size() - 1].getState());
2675 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2676 glr_state
* yys
= yystateStack
.topAt(yyk
);
2677 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yys
);]b4_locations_if([[
2679 /* Set default location. */
2680 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yys
->yyloc
;]])[
2681 for (int yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
2684 YYASSERT (yys
!= YY_NULLPTR
);
2686 yystateStack
.yyupdateSplit (*yys
);
2687 yystateStack
.setTopAt(yyk
, yys
);
2688 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2690 yyvalp
]b4_locations_if([, yylocp
])[);
2694 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2695 * and push back on the resulting nonterminal symbol. Perform the
2696 * semantic action associated with YYRULE and store its value with the
2697 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2698 * unambiguous. Otherwise, store the deferred semantic action with
2699 * the new state. If the new state would have an identical input
2700 * position, LR state, and predecessor to an existing state on the stack,
2701 * it is identified with that existing state, eliminating stack #YYK from
2702 * *YYSTACKP. In this case, the semantic value is
2703 * added to the options for the existing state's semantic value.
2706 yyglrReduce (state_set_index yyk
, rule_num yyrule
, bool yyforceEval
)
2708 size_t yyposn
= topState(yyk
)->yyposn
;
2710 if (yyforceEval
|| !yystateStack
.isSplit())
2712 value_type val
;]b4_locations_if([[
2713 location_type loc
;]])[
2715 YYRESULTTAG yyflag
= yydoAction (yyk
, yyrule
, &val
]b4_locations_if([, &loc
])[);
2716 if (yyflag
== yyerr
&& yystateStack
.isSplit())
2717 {]b4_parse_trace_if([[
2718 YYCDEBUG
<< "Parse on stack " << yyk
.get ()
2719 << " rejected by rule " << yyrule
- 1
2720 << " (line " << int (yyrline
[yyrule
]) << ").\n";
2725 yyLRgotoState (topState(yyk
)->yylrState
,
2726 yylhsNonterm (yyrule
)),
2727 yyposn
, val
]b4_locations_if([, loc
])[);]b4_variant_if([[
2728 // FIXME: User destructors.
2729 // Value type destructor.
2730 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [[val
]], [[template destroy
]])])[
2734 glr_state
*yys
= yystateStack
.topAt(yyk
);
2735 glr_state
*yys0
= yys
;
2736 for (int yyn
= yyrhsLength (yyrule
); 0 < yyn
; yyn
-= 1)
2739 YYASSERT (yys
!= YY_NULLPTR
);
2741 yystateStack
.yyupdateSplit (*yys
);
2742 state_num yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));]b4_parse_trace_if([[
2743 YYCDEBUG
<< "Reduced stack " << yyk
.get ()
2744 << " by rule " << yyrule
- 1 << " (line " << int (yyrline
[yyrule
])
2745 << "); action deferred. Now in state " << yynewLRState
2747 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < yystateStack
.numTops(); ++yyi
)
2748 if (yyi
!= yyk
&& yystateStack
.topAt(yyi
) != YY_NULLPTR
)
2750 const glr_state
* yysplit
= yystateStack
.yysplitPoint
;
2751 glr_state
* yyp
= yystateStack
.topAt(yyi
);
2752 while (yyp
!= yys
&& yyp
!= yysplit
2753 && yyp
->yyposn
>= yyposn
)
2755 if (yyp
->yylrState
== yynewLRState
2756 && yyp
->pred() == yys
)
2758 yyaddDeferredAction (yyk
, yyp
, yys0
, yyrule
);
2759 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2760 YYCDEBUG
<< "Merging stack " << yyk
.get ()
2761 << " into stack " << yyi
.get () << ".\n";
2767 yystateStack
.setTopAt(yyk
, yys
);
2768 yyglrShiftDefer (yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
2773 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2774 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2775 * semantic value of YYRHS under the action for YYRULE. */
2777 yyglrShiftDefer (state_set_index yyk
, state_num yylrState
,
2778 size_t yyposn
, glr_state
* yyrhs
, rule_num yyrule
)
2780 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2781 glr_state (yylrState
, yyposn
));
2782 yynewState
.setPred (yystateStack
.topAt (yyk
));
2783 yystateStack
.setTopAt (yyk
, &yynewState
);
2785 /* Invokes yyreserveStack. */
2786 yyaddDeferredAction (yyk
, &yynewState
, yyrhs
, yyrule
);
2789 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2790 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2791 * value YYVAL_ARG and source location YYLOC_ARG. */
2793 yyglrShift (state_set_index yyk
, state_num yylrState
,
2795 const value_type
& yyval_arg
]b4_locations_if([, const location_type
& yyloc_arg
])[)
2797 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2798 glr_state (yylrState
, yyposn
, yyval_arg
]b4_locations_if([, yyloc_arg
])[));
2799 yynewState
.setPred (yystateStack
.topAt(yyk
));
2800 yystateStack
.setTopAt (yyk
, &yynewState
);
2801 yyreserveGlrStack ();
2804 #if ]b4_api_PREFIX[DEBUG
2806 yypstack (state_set_index yyk
) const
2808 yystateStack
.yypstates (yystateStack
.topAt (yyk
));
2812 glr_state
* topState(state_set_index i
) {
2813 return yystateStack
.topAt(i
);
2816 glr_state
* firstTopState() {
2817 return yystateStack
.firstTop();
2824 /* If the stack is well-formed, pop the stack until it is empty,
2825 destroying its entries as we go. But free the stack regardless
2826 of whether it is well-formed. */
2827 for (state_set_index k
= create_state_set_index(0); k
.uget() < yystateStack
.numTops(); k
+= 1)
2828 if (yystateStack
.topAt(k
) != YY_NULLPTR
)
2830 while (yystateStack
.topAt(k
) != YY_NULLPTR
)
2832 glr_state
* state
= topState(k
);]b4_locations_if([[
2833 yyerror_range
[1].getState().yyloc
= state
->yyloc
;]])[
2834 if (state
->pred() != YY_NULLPTR
)
2835 state
->destroy ("Cleanup: popping", yyparser
);
2836 yystateStack
.setTopAt(k
, state
->pred());
2837 yystateStack
.pop_back();
2843 /** Resolve the previous YYN states starting at and including state YYS
2844 * on *YYSTACKP. If result != yyok, some states may have been left
2845 * unresolved possibly with empty semantic option chains. Regardless
2846 * of whether result = yyok, each state has been left with consistent
2847 * data so that destroy can be invoked if necessary. */
2849 yyresolveStates (glr_state
& yys
, int yyn
)
2853 YYASSERT (yys
.pred() != YY_NULLPTR
);
2854 YYCHK (yyresolveStates (*yys
.pred(), yyn
-1));
2855 if (! yys
.yyresolved
)
2856 YYCHK (yyresolveValue (yys
));
2862 yyuserMerge (int yyn
, value_type
& yy0
, value_type
& yy1
)
2874 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2875 * perform the indicated actions, and set the semantic value of YYS.
2876 * If result != yyok, the chain of semantic options in YYS has been
2877 * cleared instead or it has been left unmodified except that
2878 * redundant options may have been removed. Regardless of whether
2879 * result = yyok, YYS has been left with consistent data so that
2880 * destroy can be invoked if necessary. */
2882 yyresolveValue (glr_state
& yys
)
2884 semantic_option
* yybest
= yys
.firstVal();
2885 YYASSERT(yybest
!= YY_NULLPTR
);
2886 bool yymerge
= false;
2887 YYRESULTTAG yyflag
;]b4_locations_if([
2888 location_type
*yylocp
= &yys
.yyloc
;])[
2890 semantic_option
* yypPrev
= yybest
;
2891 for (semantic_option
* yyp
= yybest
->next();
2892 yyp
!= YY_NULLPTR
; )
2894 if (yybest
->isIdenticalTo (*yyp
))
2896 yybest
->mergeWith (*yyp
);
2897 yypPrev
->setNext(yyp
->next());
2898 yyp
= yypPrev
->next();
2902 switch (yypreference (*yybest
, *yyp
))
2904 case 0:]b4_locations_if([[
2905 yyresolveLocations (yys
, 1);]])[
2906 return yystateStack
.yyreportAmbiguity (*yybest
, *yyp
, yyparser
]b4_locations_if([, *yylocp
])[);
2918 /* This cannot happen so it is not worth a YYASSERT (false),
2919 but some compilers complain if the default case is
2931 int yyprec
= yydprec
[yybest
->yyrule
];
2932 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2934 for (semantic_option
* yyp
= yybest
->next();
2938 if (yyprec
== yydprec
[yyp
->yyrule
])
2940 value_type yyval_other
;]b4_locations_if([
2941 location_type yydummy
;])[
2942 yyflag
= yyresolveAction (*yyp
, &yyval_other
]b4_locations_if([, &yydummy
])[);
2945 yyparser
.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2946 yy_accessing_symbol (yys
.yylrState
),
2947 this->yyla
.value
]b4_locations_if([, *yylocp
])[);
2950 yyuserMerge (yymerger
[yyp
->yyrule
], val
, yyval_other
);]b4_variant_if([[
2951 // FIXME: User destructors.
2952 // Value type destructor.
2953 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[yyval_other
]], [[template destroy
]])])[
2958 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2962 yys
.yyresolved
= true;
2963 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_variant_if([[
2964 new (&yys
.value ()) value_type ();
2965 ]b4_symbol_variant([yy_accessing_symbol (yys
.yylrState
)],
2966 [yys
.value ()], [copy
], [val
])], [[
2967 new (&yys
.value ()) value_type (val
);]])[
2969 YY_IGNORE_MAYBE_UNINITIALIZED_END
2972 yys
.setFirstVal(YY_NULLPTR
);
2974 // FIXME: User destructors.
2975 // Value type destructor.
2976 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[val
]], [[template destroy
]])])[
2980 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2981 * user action, and return the semantic value and location in *YYVALP
2982 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2983 * have been destroyed (assuming the user action destroys all RHS
2984 * semantic values if invoked). */
2986 yyresolveAction (semantic_option
& yyopt
, value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2988 glr_state
* yyoptState
= yyopt
.state();
2989 YYASSERT(yyoptState
!= YY_NULLPTR
);
2990 int yynrhs
= yyrhsLength (yyopt
.yyrule
);
2991 YYRESULTTAG yyflag
= yyresolveStates (*yyoptState
, yynrhs
);
2994 for (glr_state
*yys
= yyoptState
; yynrhs
> 0; yys
= yys
->pred(), yynrhs
-= 1)
2995 yys
->destroy ("Cleanup: popping", yyparser
);
2999 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
3000 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yyopt
.state());]b4_locations_if([[
3002 /* Set default location. */
3003 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yyoptState
->yyloc
;]])[
3005 symbol_type yyla_current
= std::move (this->yyla
);
3006 this->yyla
.kind_
= yyopt
.yytoken
;]b4_variant_if([[
3007 ]b4_symbol_variant([this->yyla
.kind ()],
3008 [this->yyla
.value
], [move
], [yyopt
.yyval
])], [[
3009 this->yyla
.value
= yyopt
.yyval
;]])[]b4_locations_if([
3010 this->yyla
.location
= yyopt
.yyloc
;])[
3011 yyflag
= yyuserAction (yyopt
.yyrule
, yynrhs
,
3012 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
3013 create_state_set_index (-1),
3014 yyvalp
]b4_locations_if([, yylocp
])[);
3016 this->yyla
= std::move (yyla_current
);
3019 }]b4_locations_if([[
3021 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
3022 * ending at YYS1. Has no effect on previously resolved states.
3023 * The first semantic option of a state is always chosen. */
3025 yyresolveLocations (glr_state
&yys1
, int yyn1
)
3029 yyresolveLocations (*yys1
.pred(), yyn1
- 1);
3030 if (!yys1
.yyresolved
)
3032 glr_stack_item yyrhsloc
[1 + YYMAXRHS
];
3033 YYASSERT (yys1
.firstVal() != YY_NULLPTR
);
3034 semantic_option
& yyoption
= *yys1
.firstVal();
3035 const int yynrhs
= yyrhsLength (yyoption
.yyrule
);
3038 yyresolveLocations (*yyoption
.state(), yynrhs
);
3039 const glr_state
*yys
= yyoption
.state();
3040 for (int yyn
= yynrhs
; yyn
> 0; yyn
-= 1)
3042 yyrhsloc
[yyn
].getState().yyloc
= yys
->yyloc
;
3048 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3049 in reverse rightmost order. It is only necessary to invoke
3050 yyresolveLocations on a subforest for which yyresolveAction
3051 would have been invoked next had an ambiguity not been
3052 detected. Thus the location of the previous state (but not
3053 necessarily the previous state itself) is guaranteed to be
3054 resolved already. */
3055 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3056 yyrhsloc
[0].getState().yyloc
= yyoption
.state()->yyloc
;
3057 YY_IGNORE_NULL_DEREFERENCE_END
3059 YYLLOC_DEFAULT ((yys1
.yyloc
), yyrhsloc
, yynrhs
);
3064 /** If yytoken is empty, fetch the next token. */
3068 ]b4_parse_param_use()dnl
3069 [ if (this->yyla
.empty ())
3071 YYCDEBUG
<< "Reading a token\n";
3074 #endif // YY_EXCEPTIONS
3075 {]b4_token_ctor_if([[
3076 symbol_type
yylookahead (]b4_yylex
[);
3077 yyla
.move (yylookahead
);]], [[
3078 yyla
.kind_
= yyparser
.yytranslate_ (]b4_yylex
[);]])[
3081 catch (const parser_type::syntax_error
& yyexc
)
3083 YYCDEBUG
<< "Caught exception: " << yyexc
.what () << '\n';]b4_locations_if([
3084 this->yyla
.location
= yyexc
.location
;])[
3085 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[yyexc
.what ());
3086 // Map errors caught in the scanner to the error token, so that error
3087 // handling is started.
3088 this->yyla
.kind_
= ]b4_symbol(error
, kind
)[;
3091 #endif // YY_EXCEPTIONS
3092 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
3093 YYCDEBUG
<< "Now at end of input.\n";
3095 YY_SYMBOL_PRINT ("Next token is", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
3099 /* Bison grammar-table manipulation. */
3101 /** The action to take in YYSTATE on seeing YYTOKEN.
3103 * R < 0: Reduce on rule -R.
3105 * R > 0: Shift to state R.
3106 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3107 * of conflicting reductions.
3110 yygetLRActions (state_num yystate
, symbol_kind_type yytoken
, const short*& yyconflicts
)
3112 int yyindex
= yypact
[yystate
] + yytoken
;
3113 if (yytoken
== ]b4_symbol(error
, kind
)[)
3115 // This is the error token.
3116 yyconflicts
= yyconfl
;
3119 else if (yy_is_defaulted_state (yystate
)
3120 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
3122 yyconflicts
= yyconfl
;
3123 return -yydefact
[yystate
];
3125 else if (! yytable_value_is_error (yytable
[yyindex
]))
3127 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3128 return yytable
[yyindex
];
3132 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3137 /** Compute post-reduction state.
3138 * \param yystate the current state
3139 * \param yysym the nonterminal to push on the stack
3142 yyLRgotoState (state_num yystate
, symbol_kind_type yysym
)
3144 const int yyr
= yypgoto
[yysym
- YYNTOKENS
] + yystate
;
3145 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
3146 return yytable
[yyr
];
3148 return yydefgoto
[yysym
- YYNTOKENS
];
3152 yypact_value_is_default (state_num yystate
)
3154 return ]b4_table_value_equals([[pact
]], [[yystate
]], [b4_pact_ninf
], [YYPACT_NINF
])[;
3158 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED
)
3160 return ]b4_table_value_equals([[table
]], [[yytable_value
]], [b4_table_ninf
], [YYTABLE_NINF
])[;
3164 yy_is_shift_action (int yyaction
)
3166 return 0 < yyaction
;
3170 yy_is_error_action (int yyaction
)
3172 return yyaction
== 0;
3175 /** Whether LR state YYSTATE has only a default reduction
3176 * (regardless of token). */
3178 yy_is_defaulted_state (state_num yystate
)
3180 return yypact_value_is_default (yypact
[yystate
]);
3183 /** The default reduction for YYSTATE, assuming it has one. */
3185 yy_default_action (state_num yystate
)
3187 return yydefact
[yystate
];
3192 /** Y0 and Y1 represent two possible actions to take in a given
3193 * parsing state; return 0 if no combination is possible,
3194 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3196 yypreference (const semantic_option
& y0
, const semantic_option
& y1
)
3198 const rule_num r0
= y0
.yyrule
, r1
= y1
.yyrule
;
3199 const int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
3203 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
3208 else if (p0
== 0 || p1
== 0)
3218 ]b4_parse_param_vars
[
3219 }; // class ]b4_parser_class[::glr_stack
3220 } // namespace ]b4_namespace_ref[
3223 #if ]b4_api_PREFIX[DEBUG
3227 yypstack (const glr_stack
& yystack
, size_t yyk
)
3229 yystack
.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk
)));
3233 yypdumpstack (const glr_stack
& yystack
)
3235 yystack
.yypdumpstack ();
3241 /// Build a parser object.
3242 ]b4_parser_class::b4_parser_class
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
3244 #if ]b4_api_PREFIX[DEBUG
3245 ]m4_ifset([b4_parse_param
], [ ], [ :])[yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
3246 #endif]b4_parse_param_cons[
3249 ]b4_parser_class::~b4_parser_class
[ ()
3252 ]b4_parser_class
[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3256 ]b4_parser_class
[::operator() ()
3262 ]b4_parser_class
[::parse ()
3264 glr_stack
yystack(YYINITDEPTH
, *this]b4_user_args
[);
3265 return yystack
.parse ();
3268 ]b4_parse_error_bmatch([custom\
|detailed
],
3270 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3272 static const char *const yy_sname
[] =
3275 };]b4_has_translations_if([[
3276 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3277 internationalizable. */
3278 static ]b4_int_type_for([b4_translatable
])[ yytranslatable
[] =
3282 return (yysymbol
< YYNTOKENS
&& yytranslatable
[yysymbol
]
3283 ? _(yy_sname
[yysymbol
])
3284 : yy_sname
[yysymbol
]);]], [[
3285 return yy_sname
[yysymbol
];]])[
3289 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3291 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3293 return yytname_
[yysymbol
];
3295 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3298 [[ /* Return YYSTR after stripping away unnecessary quotes and
3299 backslashes, so that it's suitable for yyerror. The heuristic is
3300 that double-quoting is unnecessary unless the string contains an
3301 apostrophe, a comma, or backslash (other than backslash-backslash).
3302 YYSTR is taken from yytname. */
3304 ]b4_parser_class
[::yytnamerr_ (const char *yystr
)
3309 char const *yyp
= yystr
;
3316 goto do_not_strip_quotes
;
3320 goto do_not_strip_quotes
;
3332 do_not_strip_quotes
: ;
3339 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3341 return yytnamerr_ (yytname_
[yysymbol
]);
3345 ]b4_parse_error_bmatch([simple\
|verbose
],
3346 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3347 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3348 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3350 const ]b4_parser_class
[::yytname_
[] =
3357 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
3358 // ]b4_parser_class[::context.
3359 ]b4_parser_class
[::context::context (glr_stack
& yystack
, const symbol_type
& yyla
)
3360 : yystack_ (yystack
)
3365 ]b4_parser_class
[::context::expected_tokens (symbol_kind_type yyarg
[], int yyargn
) const
3367 // Actual number of expected tokens
3369 const int yyn
= yypact
[yystack_
.firstTopState()->yylrState
];
3370 if (!yystack_
.yypact_value_is_default (yyn
))
3372 /* Start YYX at -YYN if negative to avoid negative indexes in
3373 YYCHECK. In other words, skip the first -YYN actions for this
3374 state because they are default actions. */
3375 const int yyxbegin
= yyn
< 0 ? -yyn
: 0;
3376 /* Stay within bounds of both yycheck and yytname. */
3377 const int yychecklim
= YYLAST
- yyn
+ 1;
3378 const int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
3379 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
3380 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= ]b4_symbol(error
, kind
)[
3381 && !yystack_
.yytable_value_is_error (yytable
[yyx
+ yyn
]))
3385 else if (yycount
== yyargn
)
3388 yyarg
[yycount
++] = YY_CAST (symbol_kind_type
, yyx
);
3391 if (yyarg
&& yycount
== 0 && 0 < yyargn
)
3392 yyarg
[0] = ]b4_symbol(empty
, kind
)[;
3398 ]b4_parse_error_bmatch([detailed\
|verbose
], [[
3400 ]b4_parser_class
[::yy_syntax_error_arguments_ (const context
& yyctx
,
3401 symbol_kind_type yyarg
[], int yyargn
) const
3403 /* There are many possibilities here to consider:
3404 - If this state is a consistent state with a default action, then
3405 the only way this function was invoked is if the default action
3406 is an error action. In that case, don't check for expected
3407 tokens because there are none.
3408 - The only way there can be no lookahead present (in yyla) is
3409 if this state is a consistent state with a default action.
3410 Thus, detecting the absence of a lookahead is sufficient to
3411 determine that there is no unexpected or expected token to
3412 report. In that case, just report a simple "syntax error".
3413 - Don't assume there isn't a lookahead just because this state is
3414 a consistent state with a default action. There might have
3415 been a previous inconsistent state, consistent state with a
3416 non-default action, or user semantic action that manipulated
3417 yyla. (However, yyla is currently not documented for users.)
3420 if (!yyctx
.lookahead ().empty ())
3423 yyarg
[0] = yyctx
.token ();
3424 int yyn
= yyctx
.expected_tokens (yyarg
? yyarg
+ 1 : yyarg
, yyargn
- 1);
3430 // Generate an error message.
3432 ]b4_parser_class
[::yysyntax_error_ (const context
& yyctx
) const
3435 enum { YYARGS_MAX
= 5 };
3436 // Arguments of yyformat.
3437 symbol_kind_type yyarg
[YYARGS_MAX
];
3438 int yycount
= yy_syntax_error_arguments_ (yyctx
, yyarg
, YYARGS_MAX
);
3440 char const* yyformat
= YY_NULLPTR
;
3443 #define YYCASE_(N, S) \
3447 default: // Avoid compiler warnings.
3448 YYCASE_ (0, YY_("syntax error"));
3449 YYCASE_ (1, YY_("syntax error, unexpected %s"));
3450 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
3451 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
3452 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
3453 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
3459 std::ptrdiff_t yyi
= 0;
3460 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
3461 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
3463 yyres
+= symbol_name (yyarg
[yyi
++]);
3472 ]b4_parser_class
[::yy_destroy_ (const char* yymsg
, symbol_kind_type yykind
,
3473 value_type
& yyval
]b4_locations_if([[,
3474 location_type
& yyloc
]])[)
3476 YY_USE (yyval
);]b4_locations_if([[
3480 ]b4_parser_class
[& yyparser
= *this;
3482 YY_SYMBOL_PRINT (yymsg
, yykind
, yyval
, yyloc
);
3484 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3485 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3486 [b4_symbol_actions([destructor
])],
3487 [m4_popdef([b4_symbol_action
])])[
3488 YY_IGNORE_MAYBE_UNINITIALIZED_END
3491 #if ]b4_api_PREFIX[DEBUG
3492 /*--------------------.
3493 | Print this symbol. |
3494 `--------------------*/
3497 ]b4_parser_class
[::yy_symbol_value_print_ (symbol_kind_type yykind
,
3498 const value_type
& yyval
]b4_locations_if([[,
3499 const location_type
& yyloc
]])[) const
3500 {]b4_locations_if([[
3503 std::ostream
& yyo
= debug_stream ();
3505 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3506 [b4_symbol_actions([printer
])],
3507 [m4_popdef([b4_symbol_action
])])[
3511 ]b4_parser_class
[::yy_symbol_print_ (symbol_kind_type yykind
,
3512 const value_type
& yyval
]b4_locations_if([[,
3513 const location_type
& yyloc
]])[) const
3515 *yycdebug_
<< (yykind
< YYNTOKENS
? "token" : "nterm")
3516 << ' ' << symbol_name (yykind
) << " ("]b4_locations_if([[
3517 << yyloc
<< ": "]])[;
3518 yy_symbol_value_print_ (yykind
, yyval
]b4_locations_if([[, yyloc
]])[);
3523 ]b4_parser_class
[::debug_stream () const
3529 ]b4_parser_class
[::set_debug_stream (std::ostream
& o
)
3535 ]b4_parser_class
[::debug_level_type
3536 ]b4_parser_class
[::debug_level () const
3542 ]b4_parser_class
[::set_debug_level (debug_level_type l
)
3544 // Actually, it is yydebug which is really used.
3547 #endif // ]b4_api_PREFIX[DEBUG
3549 ]b4_token_ctor_if([], [b4_yytranslate_define([cc
])])[
3551 ]b4_token_ctor_if([], [[
3555 ]b4_public_types_define([cc
])])[
3556 ]b4_namespace_close
[]dnl