1 # C++ GLR skeleton for Bison
3 # Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 m4_include(b4_skeletonsdir
/[c
++.m4
])
20 # api.value.type=variant is valid.
21 m4_define([b4_value_type_setup_variant
])
23 # b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED)
24 # -------------------------------------------
25 m4_define([b4_tname_if
],
26 [m4_case(b4_percent_define_get([[parse
.error
]]),
28 [b4_token_table_if([$
1],
31 b4_bison_locations_if([
32 m4_define([b4_location_constructors
])
33 m4_include(b4_skeletonsdir
/[location
.cc
])])
34 b4_variant_if([m4_include(b4_skeletonsdir
/[variant
.hh
])])
36 m4_define([b4_parser_class
],
37 [b4_percent_define_get([[api
.parser
.class]])])
39 ]m4_define([b4_define_symbol_kind
],
40 [m4_format([#define %-15s %s],
41 b4_symbol($
][1, kind_base
),
42 b4_namespace_ref
[::]b4_parser_class
[::symbol_kind::]b4_symbol($
1, kind_base
))
45 ## ---------------- ##
47 ## ---------------- ##
50 m4_define_default([b4_stack_depth_max
], [10000])
51 m4_define_default([b4_stack_depth_init
], [200])
61 # The possible parse-params formal arguments preceded by a comma.
63 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
64 # formal argument declarations.
65 m4_define([b4_user_formals
],
66 [m4_ifset([b4_parse_param
], [, b4_formals(b4_parse_param
)])])
71 m4_define([b4_symbol_kind
],
72 [symbol_kind::b4_symbol_kind_base($@
)])
75 ## ----------------- ##
76 ## Semantic Values. ##
77 ## ----------------- ##
80 # b4_lhs_value(SYMBOL-NUM, [TYPE])
81 # --------------------------------
83 m4_define([b4_lhs_value
],
84 [b4_symbol_value([(*yyvalp
)], [$
1], [$
2])])
87 # b4_rhs_data(RULE-LENGTH, POS)
88 # -----------------------------
90 m4_define([b4_rhs_data
],
91 [(static_cast<glr_stack_item
const *>(yyvsp
))@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.getState()])
94 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
95 # --------------------------------------------------
96 # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
97 m4_define([b4_rhs_value
],
98 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value ()], [$
3], [$
4])])
109 m4_define([b4_lhs_location
],
113 # b4_rhs_location(RULE-LENGTH, NUM)
114 # ---------------------------------
115 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
117 m4_define([b4_rhs_location
],
118 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
121 # b4_symbol_action(SYMBOL-NUM, KIND)
122 # ----------------------------------
123 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
124 # Same as in C, but using references instead of pointers.
126 # Currently we need two different b4_symbol_action: once for the
127 # self-contained symbols, and another time for yy_destroy_ and
128 # yy_symbol_value_print_, which don't use genuine symbols yet.
129 m4_define([b4_symbol_action],
130 [b4_symbol_if([$1], [has_$2],
131 [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
132 b4_dollar_pushdef([yysym.value],
136 _b4_symbol_case([$1])[]dnl
137 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
138 b4_symbol([$1], [$2])
139 b4_syncline([@oline@], [@ofile@])dnl
142 m4_popdef([b4_symbol_value])[]dnl
143 b4_dollar_popdef[]dnl
147 # b4_symbol_action_for_yyval(SYMBOL-NUM, KIND)
148 # --------------------------------------------
149 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
150 # Same as in C, but using references instead of pointers.
151 m4_define([b4_symbol_action_for_yyval],
152 [b4_symbol_if([$1], [has_$2],
153 [b4_dollar_pushdef([yyval],
157 _b4_symbol_case([$1])[]dnl
158 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
159 b4_symbol([$1], [$2])
160 b4_syncline([@oline@], [@ofile@])dnl
163 b4_dollar_popdef[]dnl
167 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
168 # ---------------------------------------------------
169 m4_define([b4_call_merger],
171 [ b4_symbol_if([$3], [has_type],
172 [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());],
173 [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])],
174 [yy0 = $2 (yy0, yy1);])])])
179 m4_define([b4_yylex],
181 [b4_function_call([yylex],
182 [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
183 [b4_function_call([yylex], [int],
184 [[value_type *], [&this->yyla.value]][]dnl
185 b4_locations_if([, [[location_type *], [&this->yyla.location]]])dnl
186 m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
189 # b4_shared_declarations(hh|cc)
190 # -----------------------------
191 # Declaration that might either go into the header (if --header, $1 = hh)
192 # or in the implementation file.
193 m4_define([b4_shared_declarations],
194 [b4_percent_code_get([[requires]])[
196 #include <cstddef> // ptrdiff_t
197 #include <cstring> // memcpy
207 ]m4_ifdef([b4_location_include],
208 [[# include ]b4_location_include])[
209 ]b4_variant_if([b4_variant_includes])[
211 // Whether we are compiled with exception support.
212 #ifndef YY_EXCEPTIONS
213 # if defined __GNUC__ && !defined __EXCEPTIONS
214 # define YY_EXCEPTIONS 0
216 # define YY_EXCEPTIONS 1
227 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
228 [b4_location_define])])[
231 class ]b4_parser_class[
234 ]b4_public_types_declare[
235 ]b4_symbol_type_define[
237 /// Build a parser object.
238 ]b4_parser_class[ (]b4_parse_param_decl[);
239 ~]b4_parser_class[ ();
241 /// Parse. An alias for parse ().
242 /// \returns 0 iff parsing succeeded.
246 /// \returns 0 iff parsing succeeded.
249 #if ]b4_api_PREFIX[DEBUG
250 /// The current debugging stream.
251 std::ostream& debug_stream () const;
252 /// Set the current debugging stream.
253 void set_debug_stream (std::ostream &);
255 /// Type for debugging levels.
256 typedef int debug_level_type;
257 /// The current debugging level.
258 debug_level_type debug_level () const;
259 /// Set the current debugging level.
260 void set_debug_level (debug_level_type l);
263 /// Report a syntax error.]b4_locations_if([[
264 /// \param loc where the syntax error is found.]])[
265 /// \param msg a description of the syntax error.
266 void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
268 ]b4_parse_error_bmatch(
270 [[ /// The user-facing name of the symbol whose (internal) number is
271 /// YYSYMBOL. No bounds checking.
272 static const char *symbol_name (symbol_kind_type yysymbol);]],
274 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
275 /// The user-facing name of the symbol whose (internal) number is
276 /// YYSYMBOL. No bounds checking.
277 static const char *symbol_name (symbol_kind_type yysymbol);
278 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
281 [[ /// The user-facing name of the symbol whose (internal) number is
282 /// YYSYMBOL. No bounds checking.
283 static std::string symbol_name (symbol_kind_type yysymbol);]])[
285 ]b4_token_constructor_define[
286 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
290 context (glr_stack& yystack, const symbol_type& yyla);
291 const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; }
292 symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[
293 const location_type& location () const YY_NOEXCEPT { return yyla_.location; }
295 /// Put in YYARG at most YYARGN of the expected tokens, and return the
296 /// number of tokens stored in YYARG. If YYARG is null, return the
297 /// number of expected tokens (guaranteed to be less than YYNTOKENS).
298 int expected_tokens (symbol_kind_type yyarg[], int yyargn) const;
302 const symbol_type& yyla_;
305 # if ]b4_api_PREFIX[DEBUG
307 /// \brief Report a symbol value on the debug stream.
308 /// \param yykind The symbol kind.
309 /// \param yyval Its semantic value.]b4_locations_if([[
310 /// \param yyloc Its location.]])[
311 void yy_symbol_value_print_ (symbol_kind_type yykind,
312 const value_type& yyval]b4_locations_if([[,
313 const location_type& yyloc]])[) const;
314 /// \brief Report a symbol on the debug stream.
315 /// \param yykind The symbol kind.
316 /// \param yyval Its semantic value.]b4_locations_if([[
317 /// \param yyloc Its location.]])[
318 void yy_symbol_print_ (symbol_kind_type yykind,
319 const value_type& yyval]b4_locations_if([[,
320 const location_type& yyloc]])[) const;
323 std::ostream* yycdebug_;
326 ]b4_parse_error_bmatch(
329 /// Report a syntax error
330 /// \param yyctx the context in which the error occurred.
331 void report_syntax_error (const context& yyctx) const;]],
332 [detailed\|verbose], [[
334 /// The arguments of the error message.
335 int yy_syntax_error_arguments_ (const context& yyctx,
336 symbol_kind_type yyarg[], int yyargn) const;
338 /// Generate an error message.
339 /// \param yyctx the context in which the error occurred.
340 virtual std::string yysyntax_error_ (const context& yyctx) const;]])[
342 /// Convert a scanner token kind \a t to a symbol kind.
343 /// In theory \a t should be a token_kind_type, but character literals
344 /// are valid, yet not members of the token_kind_type enum.
345 static symbol_kind_type yytranslate_ (int t);
347 ]b4_parse_error_bmatch(
349 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
350 /// For a symbol, its name in clear.
351 static const char* const yytname_[];
352 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
355 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
356 static std::string yytnamerr_ (const char *yystr);
358 /// For a symbol, its name in clear.
359 static const char* const yytname_[];
362 /// \brief Reclaim the memory associated to a symbol.
363 /// \param yymsg Why this token is reclaimed.
364 /// If null, print nothing.
365 /// \param yykind The symbol kind.
366 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
367 value_type& yyval]b4_locations_if([[,
368 location_type& yyloc]])[);
370 ]b4_parse_param_vars[
371 // Needs access to report_syntax_error, etc.
373 // Needs access to yy_destroy_.
377 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
378 ]b4_public_types_define([$1])])[
381 ]b4_percent_code_get([[provides]])[
395 ]b4_output_begin([b4_spec_header_file])[
396 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
397 [2002-2015, 2018-2021])[
398 // C++ GLR parser skeleton written by Valentin Tolmer.
401 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
402 ]b4_shared_declarations([hh])[
403 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
407 # --------------------- #
408 # Implementation file. #
409 # --------------------- #
411 ]b4_output_begin([b4_parser_file_name])[
412 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
413 [2002-2015, 2018-2021])[
414 // C++ GLR parser skeleton written by Valentin Tolmer.
419 ]b4_percent_code_get([[top]])[
420 ]m4_if(b4_prefix, [yy], [],
421 [[/* Substitute the variable and function names. */
422 #define yyparse ]b4_prefix[parse
423 #define yylex ]b4_prefix[lex
424 #define yyerror ]b4_prefix[error
425 #define yydebug ]b4_prefix[debug]])[
427 ]b4_user_pre_prologue[
431 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
432 [b4_shared_declarations([cc])])[
434 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
436 /* Default (constant) value used for initialization for null
437 right-hand sides. Unlike the standard yacc.c template, here we set
438 the default value of $$ to a zeroed-out value. Since the default
439 value is undefined, this behavior is technically correct. */
440 static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;
442 ]b4_user_post_prologue[
443 ]b4_percent_code_get[]dnl
449 # if defined YYENABLE_NLS && YYENABLE_NLS
451 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
452 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
456 # define YY_(Msgid) Msgid
464 # define YYMALLOC malloc
469 # define YYJMP_BUF jmp_buf
470 # define YYSETJMP(Env) setjmp (Env)
471 /* Pacify Clang and ICC. */
472 # define YYLONGJMP(Env, Val) \
474 longjmp (Env, Val); \
479 ]b4_attribute_define([noreturn])[
481 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
482 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
483 _Pragma ("GCC diagnostic push") \
484 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
485 # define YY_IGNORE_NULL_DEREFERENCE_END \
486 _Pragma ("GCC diagnostic pop")
488 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
489 # define YY_IGNORE_NULL_DEREFERENCE_END
495 // FIXME: Use the same conventions as lalr1.cc.
498 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
502 # define YYDASSERT(Condition) YYASSERT(Condition)
504 # define YYDASSERT(Condition)
507 /* YYFINAL -- State number of the termination state. */
508 #define YYFINAL ]b4_final_state_number[
509 /* YYLAST -- Last index in YYTABLE. */
510 #define YYLAST ]b4_last[
512 /* YYNTOKENS -- Number of terminals. */
513 #define YYNTOKENS ]b4_tokens_number[
514 /* YYNNTS -- Number of nonterminals. */
515 #define YYNNTS ]b4_nterms_number[
516 /* YYNRULES -- Number of rules. */
517 #define YYNRULES ]b4_rules_number[
518 /* YYNSTATES -- Number of states. */
519 #define YYNSTATES ]b4_states_number[
520 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
521 #define YYMAXRHS ]b4_r2_max[
522 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
523 accessed by $0, $-1, etc., in any rule. */
524 #define YYMAXLEFT ]b4_max_left_semantic_context[
526 #if ]b4_api_PREFIX[DEBUG
527 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
528 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
534 #define YYPACT_NINF ]b4_pact_ninf[
535 #define YYTABLE_NINF ]b4_table_ninf[
537 ]b4_parser_tables_define[
539 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
540 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
545 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
546 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
551 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
552 in the case of predicates. */
553 static const bool yyimmediate[] =
558 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
559 list of conflicting reductions corresponding to action entry for
560 state STATE-NUM in yytable. 0 means no conflicts. The list in
561 yyconfl is terminated by a rule number of 0. */
562 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
564 ]b4_conflict_list_heads[
567 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
568 0, pointed into by YYCONFLP. */
569 ]dnl Do not use b4_int_type_for here, since there are places where
570 dnl pointers onto yyconfl are taken, whose type is "short*".
571 dnl We probably ought to introduce a type for confl.
572 [static const short yyconfl[] =
574 ]b4_conflicting_rules[
577 /* Error token number */
581 ]b4_yylloc_default_define[
582 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
585 enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
589 YYRESULTTAG yychk_flag = YYE; \
590 if (yychk_flag != yyok) \
594 #if ]b4_api_PREFIX[DEBUG
596 #define YYCDEBUG if (!yydebug) {} else std::cerr
598 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
602 std::cerr << Title << ' '; \
603 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
608 # define YY_REDUCE_PRINT(Args) \
611 yystateStack.yy_reduce_print Args; \
614 /* Nonzero means print parse trace. It is left uninitialized so that
615 multiple parsers can coexist. */
619 static void yypstack (const glr_stack& yystack, size_t yyk)
621 static void yypdumpstack (const glr_stack& yystack)
624 #else /* !]b4_api_PREFIX[DEBUG */
626 # define YYCDEBUG if (true) {} else std::cerr
627 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
628 # define YY_REDUCE_PRINT(Args) {}
630 #endif /* !]b4_api_PREFIX[DEBUG */
632 /* YYINITDEPTH -- initial size of the parser's stacks. */
634 # define YYINITDEPTH ]b4_stack_depth_init[
637 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
638 if the built-in stack extension method is used).
640 Do not make this value too large; the results are undefined if
641 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
642 evaluated with infinite-precision integer arithmetic. */
645 # define YYMAXDEPTH ]b4_stack_depth_max[
648 /* Minimum number of free items on the stack allowed after an
649 allocation. This is to allow allocation and initialization
650 to be completed by functions that call yyexpandGLRStack before the
651 stack is expanded, thus insuring that all necessary pointers get
652 properly redirected to new data. */
655 #ifndef YYSTACKEXPANDABLE
656 # define YYSTACKEXPANDABLE 1
659 template <typename Parameter
>
660 class strong_index_alias
663 static strong_index_alias
create (std::ptrdiff_t value
)
665 strong_index_alias result
;
666 result
.value_
= value
;
670 std::ptrdiff_t const& get () const { return value_
; }
672 size_t uget () const { return static_cast<size_t> (value_
); }
674 strong_index_alias
operator+ (std::ptrdiff_t other
) const
676 return strong_index_alias (get () + other
);
679 void operator+= (std::ptrdiff_t other
)
684 strong_index_alias
operator- (std::ptrdiff_t other
)
686 return strong_index_alias (get () - other
);
689 void operator-= (std::ptrdiff_t other
)
694 size_t operator- (strong_index_alias other
)
696 return strong_index_alias (get () - other
.get ());
699 strong_index_alias
& operator++ ()
705 bool isValid () const
707 return value_
!= INVALID_INDEX
;
712 value_
= INVALID_INDEX
;
715 bool operator== (strong_index_alias other
)
717 return get () == other
.get ();
720 bool operator!= (strong_index_alias other
)
722 return get () != other
.get ();
725 bool operator< (strong_index_alias other
)
727 return get () < other
.get ();
731 static const std::ptrdiff_t INVALID_INDEX
;
733 // WARNING: 0-initialized.
734 std::ptrdiff_t value_
;
738 const std::ptrdiff_t strong_index_alias
<T
>::INVALID_INDEX
=
739 std::numeric_limits
<std::ptrdiff_t>::max ();
741 typedef strong_index_alias
<struct glr_state_set_tag
> state_set_index
;
743 state_set_index
create_state_set_index (std::ptrdiff_t value
)
745 return state_set_index::create (value
);
748 /** State numbers, as in LALR(1) machine */
749 typedef int state_num
;
751 /** Rule numbers, as in LALR(1) machine */
752 typedef int rule_num
;
754 // Forward declarations.
756 class semantic_option
;
757 class glr_stack_item
;
760 /** Accessing symbol of state YYSTATE. */
761 static inline yysymbol_kind_t
762 yy_accessing_symbol (state_num yystate
)
764 return YY_CAST (yysymbol_kind_t
, yystos
[yystate
]);
767 /** Left-hand-side symbol for rule #YYRULE. */
768 static inline yysymbol_kind_t
769 yylhsNonterm (rule_num yyrule
)
771 return static_cast<yysymbol_kind_t
>(yyr1
[yyrule
]);
774 /** Number of symbols composing the right hand side of rule #RULE. */
776 yyrhsLength (rule_num yyrule
)
784 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
785 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type symbol_kind_type
;
786 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
787 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
794 , yyfirstVal (0)]b4_locations_if([[
795 , yyloc ()]])[]b4_parse_assert_if([[
799 /// Build with a semantic value.
800 glr_state (state_num lrState
, size_t posn
, const value_type
& val
]b4_locations_if([[, const location_type
& loc
]])[)
802 , yylrState (lrState
)
805 , yyval (]b4_variant_if([], [[val
]])[)]b4_locations_if([[
806 , yyloc (loc
)]])[]b4_parse_assert_if([[
809 ]b4_symbol_variant([yy_accessing_symbol (lrState
)],
810 [yyval
], [copy
], [val
])])[}
812 /// Build with a semantic option.
813 glr_state (state_num lrState
, size_t posn
)
815 , yylrState (lrState
)
818 , yyfirstVal (0)]b4_locations_if([[
819 , yyloc ()]])[]b4_parse_assert_if([[
823 glr_state (const glr_state
& other
)
824 : yyresolved (other
.yyresolved
)
825 , yylrState (other
.yylrState
)
826 , yyposn (other
.yyposn
)
827 , yypred (0)]b4_locations_if([[
828 , yyloc (other
.yyloc
)]])[]b4_parse_assert_if([[
831 setPred (other
.pred ());
832 if (other
.yyresolved
)]b4_variant_if([[
834 new (&yyval
) value_type ();
835 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
836 [yyval
], [copy
], [other
.value ()])[
838 new (&yyval
) value_type (other
.value ());]])[
842 setFirstVal (other
.firstVal ());
843 }]b4_parse_assert_if([[
848 {]b4_parse_assert_if([[
852 yysymbol_kind_t yykind
= yy_accessing_symbol (yylrState
);
853 // FIXME: User destructors.
854 // Value type destructor.
855 ]b4_symbol_variant([[yykind
]], [[yyval
]], [[template destroy
]])])[
856 yyval
.~value_type ();
857 }]b4_parse_assert_if([[
861 glr_state
& operator= (const glr_state
& other
)
862 {]b4_parse_assert_if([[
865 if (!yyresolved
&& other
.yyresolved
)
866 new (&yyval
) value_type
;
867 yyresolved
= other
.yyresolved
;
868 yylrState
= other
.yylrState
;
869 yyposn
= other
.yyposn
;
870 setPred (other
.pred ());
871 if (other
.yyresolved
)]b4_variant_if([[
872 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
873 [yyval
], [copy
], [other
.value ()])], [[
874 value () = other
.value ();]])[
876 setFirstVal (other
.firstVal ());]b4_locations_if([[
877 yyloc
= other
.yyloc
;]])[
881 /** Type tag for the semantic value. If true, yyval applies, otherwise
882 * yyfirstVal applies. */
884 /** Number of corresponding LALR(1) machine state. */
886 /** Source position of the last token produced by my symbol */
889 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
891 const glr_state
* pred () const;
892 void setPred (const glr_state
* state
);
894 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
896 semantic_option
* firstVal ();
897 const semantic_option
* firstVal () const;
898 void setFirstVal (const semantic_option
* option
);
901 {]b4_parse_assert_if([[
906 const value_type
& value () const
907 {]b4_parse_assert_if([[
913 destroy (char const *yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[);
916 #if ]b4_api_PREFIX[DEBUG
917 void yy_yypstack () const
918 {]b4_parse_assert_if([[
920 if (pred () != YY_NULLPTR
)
922 pred ()->yy_yypstack ();
925 std::cerr
<< yylrState
<< "@@" << yyposn
;
929 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const;
931 glr_stack_item
* asItem ()
932 {]b4_parse_assert_if([[
937 const glr_stack_item
* asItem () const
938 {]b4_parse_assert_if([[
940 return asItem (this);
944 template <typename T
>
945 static const glr_stack_item
* asItem (const T
* state
)
947 return reinterpret_cast<const glr_stack_item
*>(state
);
949 template <typename T
>
950 static glr_stack_item
* asItem (T
* state
)
952 return reinterpret_cast<glr_stack_item
*> (state
);
954 static const char *as_pointer_ (const glr_state
*state
)
956 return reinterpret_cast<const char *> (state
);
958 static char *as_pointer_ (glr_state
*state
)
960 return reinterpret_cast<char *> (state
);
962 /** Preceding state in this stack */
963 std::ptrdiff_t yypred
;
965 /** First in a chain of alternative reductions producing the
966 * nonterminal corresponding to this state, threaded through
967 * yyfirstVal. Value "0" means empty. */
968 std::ptrdiff_t yyfirstVal
;
969 /** Semantic value for this state. */
971 };]b4_locations_if([[
972 // FIXME: Why public?
974 /** Source location for this state. */
975 location_type yyloc
;]])[
977 ]b4_parse_assert_if([[
982 YY_IGNORE_NULL_DEREFERENCE_BEGIN
983 YYASSERT (this->magic_
== MAGIC
);
984 YY_IGNORE_NULL_DEREFERENCE_END
987 // A magic number to check our pointer arithmetic is sane.
988 enum { MAGIC
= 713705 };
989 unsigned int magic_
;]])[
992 /** A stack of GLRState representing the different heads during
993 * nondeterministic evaluation. */
997 /** Initialize YYSET to a singleton set containing an empty stack. */
999 : yylastDeleted (YY_NULLPTR
)
1001 yystates
.push_back (YY_NULLPTR
);
1002 yylookaheadNeeds
.push_back (false);
1005 // Behave like a vector of states.
1006 glr_state
*& operator[] (state_set_index index
)
1008 return yystates
[index
.uget()];
1011 glr_state
* operator[] (state_set_index index
) const
1013 return yystates
[index
.uget()];
1016 size_t size () const
1018 return yystates
.size ();
1021 std::vector
<glr_state
*>::iterator
begin ()
1023 return yystates
.begin ();
1026 std::vector
<glr_state
*>::iterator
end ()
1028 return yystates
.end ();
1031 bool lookaheadNeeds (state_set_index index
) const
1033 return yylookaheadNeeds
[index
.uget ()];
1036 bool setLookaheadNeeds (state_set_index index
, bool value
)
1038 return yylookaheadNeeds
[index
.uget ()] = value
;
1041 /** Invalidate stack #YYK. */
1043 yymarkStackDeleted (state_set_index yyk
)
1045 size_t k
= yyk
.uget ();
1046 if (yystates
[k
] != YY_NULLPTR
)
1047 yylastDeleted
= yystates
[k
];
1048 yystates
[k
] = YY_NULLPTR
;
1051 /** Undelete the last stack in *this that was marked as deleted. Can
1052 only be done once after a deletion, and only when all other stacks have
1055 yyundeleteLastStack ()
1057 if (yylastDeleted
== YY_NULLPTR
|| !yystates
.empty ())
1059 yystates
.push_back (yylastDeleted
);
1060 YYCDEBUG
<< "Restoring last deleted stack as stack #0.\n";
1061 clearLastDeleted ();
1064 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1069 size_t newsize
= yystates
.size ();
1070 /* j is the number of live stacks we have seen. */
1071 for (size_t i
= 0, j
= 0; j
< newsize
; ++i
)
1073 if (yystates
[i
] == YY_NULLPTR
)
1077 YYCDEBUG
<< "Removing dead stacks.\n";
1083 yystates
[j
] = yystates
[i
];
1084 /* In the current implementation, it's unnecessary to copy
1085 yylookaheadNeeds[i] since, after
1086 yyremoveDeletes returns, the parser immediately either enters
1087 deterministic operation or shifts a token. However, it doesn't
1088 hurt, and the code might evolve to need it. */
1089 yylookaheadNeeds
[j
] = yylookaheadNeeds
[i
];
1092 YYCDEBUG
<< "Rename stack " << i
<< " -> " << j
<< ".\n";
1097 yystates
.resize (newsize
);
1098 yylookaheadNeeds
.resize (newsize
);
1103 yysplitStack (state_set_index yyk
)
1105 const size_t k
= yyk
.uget ();
1106 yystates
.push_back (yystates
[k
]);
1107 yylookaheadNeeds
.push_back (yylookaheadNeeds
[k
]);
1108 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates
.size () - 1));
1111 void clearLastDeleted ()
1113 yylastDeleted
= YY_NULLPTR
;
1118 std::vector
<glr_state
*> yystates
;
1119 /** During nondeterministic operation, yylookaheadNeeds tracks which
1120 * stacks have actually needed the current lookahead. During deterministic
1121 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1122 * duplicate !yyla.empty (). */
1123 std::vector
<bool> yylookaheadNeeds
;
1125 /** The last stack we invalidated. */
1126 glr_state
* yylastDeleted
;
1129 class semantic_option
1132 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
1133 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type symbol_kind_type
;
1134 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1135 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1141 , yytoken (]b4_symbol(empty
, kind
)[)
1142 , yyval ()]b4_locations_if([[
1143 , yyloc ()]])[]b4_parse_assert_if([[
1144 , magic_ (MAGIC
)]])[
1147 semantic_option (rule_num rule
, symbol_kind_type token
)
1152 , yyval ()]b4_locations_if([[
1153 , yyloc ()]])[]b4_parse_assert_if([[
1154 , magic_ (MAGIC
)]])[
1157 semantic_option (const semantic_option
& that
)
1158 : yyrule (that
.yyrule
)
1159 , yystate (that
.yystate
)
1160 , yynext (that
.yynext
)
1161 , yytoken (that
.yytoken
)
1162 , yyval (]b4_variant_if([], [[that
.yyval
]])[)]b4_locations_if([[
1163 , yyloc (that
.yyloc
)]])[]b4_parse_assert_if([[
1164 , magic_ (MAGIC
)]])[
1165 {]b4_parse_assert_if([[
1166 that
.check_ ();]])[]b4_variant_if([[
1167 ]b4_symbol_variant([yytoken
],
1168 [yyval
], [copy
], [that
.yyval
])])[
1171 // Needed for the assignment in yynewSemanticOption.
1172 semantic_option
& operator= (const semantic_option
& that
)
1173 {]b4_parse_assert_if([[
1176 yyrule
= that
.yyrule
;
1177 yystate
= that
.yystate
;
1178 yynext
= that
.yynext
;
1179 yytoken
= that
.yytoken
;]b4_variant_if([[
1180 ]b4_symbol_variant([yytoken
],
1181 [yyval
], [copy
], [that
.yyval
])], [[
1182 yyval
= that
.yyval
;]])[]b4_locations_if([[
1183 yyloc
= that
.yyloc
;]])[
1187 /// Only call state() and setState() on objects in yyitems, not temporaries.
1189 const glr_state
* state() const;
1190 void setState(const glr_state
* s
);
1192 const semantic_option
* next () const;
1193 semantic_option
* next ();
1194 void setNext (const semantic_option
* s
);
1196 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const;
1198 /** True iff YYY0 and YYY1 represent identical options at the top level.
1199 * That is, they represent the same rule applied to RHS symbols
1200 * that produce the same terminal symbols. */
1202 isIdenticalTo (const semantic_option
& yyy1
) const
1203 {]b4_parse_assert_if([[
1206 if (this->yyrule
== yyy1
.yyrule
)
1208 const glr_state
*yys0
, *yys1
;
1210 for (yys0
= this->state(),
1211 yys1
= yyy1
.state(),
1212 yyn
= yyrhsLength (this->yyrule
);
1214 yys0
= yys0
->pred(),
1215 yys1
= yys1
->pred(), yyn
-= 1)
1216 if (yys0
->yyposn
!= yys1
->yyposn
)
1224 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1225 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1227 mergeWith (semantic_option
& yyy1
)
1228 {]b4_parse_assert_if([[
1231 glr_state
*yys0
= this->state ();
1232 glr_state
*yys1
= yyy1
.state ();
1233 for (int yyn
= yyrhsLength (this->yyrule
);
1235 yyn
-= 1, yys0
= yys0
->pred (), yys1
= yys1
->pred ())
1239 else if (yys0
->yyresolved
)
1241 yys1
->yyresolved
= true;]b4_variant_if([[
1242 YYASSERT (yys1
->yylrState
== yys0
->yylrState
);
1243 ]b4_symbol_variant([yy_accessing_symbol (yys0
->yylrState
)],
1244 [yys1
->value ()], [copy
], [yys0
->value ()])], [[
1245 yys1
->value () = yys0
->value ();]])[
1247 else if (yys1
->yyresolved
)
1249 yys0
->yyresolved
= true;]b4_variant_if([[
1250 YYASSERT (yys0
->yylrState
== yys1
->yylrState
);
1251 ]b4_symbol_variant([yy_accessing_symbol (yys1
->yylrState
)],
1252 [yys0
->value ()], [copy
], [yys1
->value ()])], [[
1253 yys0
->value () = yys1
->value ();]])[
1257 semantic_option
* yyz0prev
= YY_NULLPTR
;
1258 semantic_option
* yyz0
= yys0
->firstVal();
1259 semantic_option
* yyz1
= yys1
->firstVal();
1262 if (yyz1
== yyz0
|| yyz1
== YY_NULLPTR
)
1264 else if (yyz0
== YY_NULLPTR
)
1266 if (yyz0prev
!= YY_NULLPTR
)
1267 yyz0prev
->setNext (yyz1
);
1269 yys0
->setFirstVal (yyz1
);
1272 else if (yyz0
< yyz1
)
1274 semantic_option
* yyz
= yyz0
;
1275 if (yyz0prev
!= YY_NULLPTR
)
1276 yyz0prev
->setNext(yyz1
);
1278 yys0
->setFirstVal(yyz1
);
1279 yyz1
= yyz1
->next();
1283 yyz0
= yyz0
->next();
1285 yys1
->setFirstVal(yys0
->firstVal());
1290 #if ]b4_api_PREFIX[DEBUG
1291 void yyreportTree (size_t yyindent
= 2) const
1292 {]b4_parse_assert_if([[
1294 int yynrhs
= yyrhsLength (this->yyrule
);
1295 const glr_state
* yystates
[1 + YYMAXRHS
];
1296 glr_state yyleftmost_state
;
1299 const glr_state
* yys
= this->state();
1300 for (int yyi
= yynrhs
; 0 < yyi
; yyi
-= 1)
1302 yystates
[yyi
] = yys
;
1305 if (yys
== YY_NULLPTR
)
1307 yyleftmost_state
.yyposn
= 0;
1308 yystates
[0] = &yyleftmost_state
;
1314 std::string yylhs
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yylhsNonterm (this->yyrule
));
1315 YYASSERT(this->state());
1316 if (this->state()->yyposn
< yystates
[0]->yyposn
+ 1)
1317 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1318 << this->yyrule
- 1 << ", empty>\n";
1320 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1321 << this->yyrule
- 1 << ", tokens "
1322 << yystates
[0]->yyposn
+ 1 << " .. "
1323 << this->state()->yyposn
<< ">\n";
1324 for (int yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1326 if (yystates
[yyi
]->yyresolved
)
1328 std::string yysym
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yy_accessing_symbol (yystates
[yyi
]->yylrState
));
1329 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1330 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1333 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1334 << " <tokens " << yystates
[yyi
-1]->yyposn
+ 1
1335 << " .. " << yystates
[yyi
]->yyposn
<< ">\n";
1338 yystates
[yyi
]->firstVal ()->yyreportTree (yyindent
+2);
1343 /** Rule number for this reduction */
1347 template <typename T
>
1348 static const glr_stack_item
* asItem(const T
* state
)
1350 return reinterpret_cast<const glr_stack_item
*>(state
);
1352 template <typename T
>
1353 static glr_stack_item
* asItem(T
* state
)
1355 return reinterpret_cast<glr_stack_item
*>(state
);
1357 /** The last RHS state in the list of states to be reduced. */
1358 std::ptrdiff_t yystate
;
1359 /** Next sibling in chain of options. To facilitate merging,
1360 * options are chained in decreasing order by address. */
1361 std::ptrdiff_t yynext
;
1364 /** The lookahead for this reduction. */
1365 symbol_kind_type yytoken
;
1366 value_type yyval
;]b4_locations_if([[
1367 location_type yyloc
;]])[
1369 ]b4_parse_assert_if([[
1371 // Check invariants.
1372 void check_ () const
1374 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1375 YYASSERT (this->magic_
== MAGIC
);
1376 YY_IGNORE_NULL_DEREFERENCE_END
1379 // A magic number to check our pointer arithmetic is sane.
1380 enum { MAGIC
= 0xeff1cace };
1381 unsigned int magic_
;]])[
1384 /** Type of the items in the GLR stack.
1385 * It can be either a glr_state or a semantic_option. The is_state_ field
1386 * indicates which item of the union is valid. */
1387 class glr_stack_item
1390 glr_stack_item (bool state
= true)
1391 : is_state_ (state
)]b4_parse_assert_if([[
1392 , magic_ (MAGIC
)]])[
1395 new (&raw_
) glr_state
;
1397 new (&raw_
) semantic_option
;
1400 glr_stack_item (const glr_stack_item
& other
) YY_NOEXCEPT YY_NOTHROW
1401 : is_state_ (other
.is_state_
)]b4_parse_assert_if([[
1402 , magic_ (MAGIC
)]])[
1403 {]b4_parse_assert_if([[
1404 other
.check_ ();]])[
1405 std::memcpy (raw_
, other
.raw_
, union_size
);
1408 glr_stack_item
& operator= (glr_stack_item other
)
1409 {]b4_parse_assert_if([[
1411 other
.check_ ();]])[
1412 std::swap (is_state_
, other
.is_state_
);
1413 std::swap (raw_
, other
.raw_
);
1418 {]b4_parse_assert_if([[
1421 getState ().~glr_state ();
1423 getOption ().~semantic_option ();
1426 void setState (const glr_state
&state
)
1427 {]b4_parse_assert_if([[
1429 state
.check_ ();]])[
1430 if (this != state
.asItem ())
1433 getState ().~glr_state ();
1435 getOption ().~semantic_option ();
1436 new (&raw_
) glr_state (state
);
1441 glr_state
& getState ()
1442 {]b4_parse_assert_if([[
1444 YYDASSERT (is_state ());
1446 glr_state
& res
= *static_cast<glr_state
*> (yyp
);]b4_parse_assert_if([[
1451 const glr_state
& getState () const
1452 {]b4_parse_assert_if([[
1454 YYDASSERT (is_state ());
1455 const void *yyp
= raw_
;
1456 const glr_state
& res
= *static_cast<const glr_state
*> (yyp
);]b4_parse_assert_if([[
1461 semantic_option
& getOption ()
1462 {]b4_parse_assert_if([[
1464 YYDASSERT (!is_state ());
1466 return *static_cast<semantic_option
*> (yyp
);
1468 const semantic_option
& getOption () const
1469 {]b4_parse_assert_if([[
1471 YYDASSERT (!is_state ());
1472 const void *yyp
= raw_
;
1473 return *static_cast<const semantic_option
*> (yyp
);
1475 bool is_state () const
1476 {]b4_parse_assert_if([[
1482 /// The possible contents of raw_. Since they have constructors, they cannot
1483 /// be directly included in the union.
1486 char yystate
[sizeof (glr_state
)];
1487 char yyoption
[sizeof (semantic_option
)];
1489 enum { union_size
= sizeof (contents
) };
1491 /// Strongest alignment constraints.
1492 long double yyalign_me
;
1493 /// A buffer large enough to store the contents.
1494 char raw_
[union_size
];
1496 /** Type tag for the union. */
1498 ]b4_parse_assert_if([[
1500 // Check invariants.
1501 void check_ () const
1503 YYASSERT (this->magic_
== MAGIC
);
1504 YYASSERT (this->is_state_
== false || this->is_state_
== true);
1506 // A magic number to check our pointer arithmetic is sane.
1507 enum { MAGIC
= 0xDEAD1ACC }; // 3735886540.
1508 const unsigned int magic_
;]])[
1511 glr_state
* glr_state::pred ()
1512 {]b4_parse_assert_if([[
1514 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1515 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1516 YY_IGNORE_NULL_DEREFERENCE_END
1519 const glr_state
* glr_state::pred () const
1520 {]b4_parse_assert_if([[
1522 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1523 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1524 YY_IGNORE_NULL_DEREFERENCE_END
1527 void glr_state::setPred (const glr_state
* state
)
1528 {]b4_parse_assert_if([[
1531 state
->check_ ();]])[
1532 yypred
= state
? as_pointer_ (this) - as_pointer_ (state
) : 0;
1535 semantic_option
* glr_state::firstVal ()
1536 {]b4_parse_assert_if([[
1538 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1541 const semantic_option
* glr_state::firstVal () const
1542 {]b4_parse_assert_if([[
1544 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1547 void glr_state::setFirstVal (const semantic_option
* option
)
1548 {]b4_parse_assert_if([[
1550 yyfirstVal
= option
? asItem(this) - asItem(option
) : 0;
1553 std::ptrdiff_t glr_state::indexIn (const glr_stack_item
* array
) const
1554 {]b4_parse_assert_if([[
1556 return asItem(this) - array
;
1559 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item
* array
) const
1561 return asItem(this) - array
;
1564 glr_state
* semantic_option::state ()
1566 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1567 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1568 YY_IGNORE_NULL_DEREFERENCE_END
1571 const glr_state
* semantic_option::state () const
1573 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1576 void semantic_option::setState (const glr_state
* s
)
1578 yystate
= s
? asItem(this) - asItem(s
) : 0;
1581 const semantic_option
* semantic_option::next () const
1583 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1586 semantic_option
* semantic_option::next ()
1588 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1591 void semantic_option::setNext (const semantic_option
* s
)
1593 yynext
= s
? asItem(this) - asItem(s
) : 0;
1596 void glr_state::destroy (char const* yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[)
1597 {]b4_parse_assert_if([[
1600 yyparser
.yy_destroy_ (yymsg
, yy_accessing_symbol(yylrState
),
1601 value ()]b4_locations_if([, yyloc
])[);
1604 #if ]b4_api_PREFIX[DEBUG
1606 << (firstVal() ? " unresolved " : " incomplete ")
1607 << (yy_accessing_symbol (yylrState
) < YYNTOKENS
? "token" : "nterm")
1608 << ' ' << yyparser
.symbol_name (yy_accessing_symbol (yylrState
))
1609 << " ("]b4_locations_if([[
1610 << yyloc
<< ": "]])[
1613 if (firstVal() != YY_NULLPTR
)
1615 semantic_option
& yyoption
= *firstVal ();
1616 glr_state
*yyrh
= yyoption
.state ();
1617 for (int yyn
= yyrhsLength (yyoption
.yyrule
); yyn
> 0; yyn
-= 1)
1619 yyrh
->destroy (yymsg
, yyparser
]b4_user_args
[);
1620 yyrh
= yyrh
->pred();
1628 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1633 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
1634 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1635 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1637 /** Initialize to a single empty stack, with total maximum
1638 * capacity for all stacks of YYSIZE. */
1639 state_stack (size_t yysize
)
1640 : yysplitPoint (YY_NULLPTR
)
1642 yyitems
.reserve (yysize
);
1645 #if YYSTACKEXPANDABLE
1646 /** Returns false if it tried to expand but could not. */
1648 yyexpandGLRStackIfNeeded ()
1650 return YYHEADROOM
<= spaceLeft () || yyexpandGLRStack ();
1654 /** If *this is expandable, extend it. WARNING: Pointers into the
1655 stack from outside should be considered invalid after this call.
1656 We always expand when there are 1 or fewer items left AFTER an
1657 allocation, so that we can avoid having external pointers exist
1658 across an allocation. */
1662 const size_t oldsize
= yyitems
.size();
1663 if (YYMAXDEPTH
- YYHEADROOM
< oldsize
)
1665 const size_t yynewSize
= YYMAXDEPTH
< 2 * oldsize
? YYMAXDEPTH
: 2 * oldsize
;
1666 const glr_stack_item
*oldbase
= &yyitems
[0];
1668 yyitems
.reserve (yynewSize
);
1669 const glr_stack_item
*newbase
= &yyitems
[0];
1671 // Adjust the pointers. Perform raw pointer arithmetic, as there
1672 // is no reason for objects to be aligned on their size.
1673 const ptrdiff_t disp
1674 = reinterpret_cast<const char*> (newbase
) - reinterpret_cast<const char*> (oldbase
);
1676 const_cast<glr_state
*&> (yysplitPoint
)
1677 = reinterpret_cast<glr_state
*> (reinterpret_cast<char*> (const_cast<glr_state
*> (yysplitPoint
)) + disp
);
1679 for (std::vector
<glr_state
*>::iterator
1680 i
= yytops
.begin (),
1681 yyend
= yytops
.end ();
1683 if (glr_state_not_null (*i
))
1684 *i
= reinterpret_cast<glr_state
*>(reinterpret_cast<char*>(*i
) + disp
);
1691 bool yyexpandGLRStackIfNeeded ()
1693 return YYHEADROOM
<= spaceLeft ();
1696 #undef YYSTACKEXPANDABLE
1698 static bool glr_state_not_null (glr_state
* s
)
1700 return s
!= YY_NULLPTR
;
1706 typedef std::vector
<glr_state
*>::iterator iterator
;
1707 const iterator yybegin
= yytops
.begin();
1708 const iterator yyend
= yytops
.end();
1709 const iterator yyit
= std::find_if(yybegin
, yyend
, glr_state_not_null
);
1712 for (state_set_index yyk
= create_state_set_index(yyit
+ 1 - yybegin
);
1713 yyk
.uget() != numTops(); ++yyk
)
1714 yytops
.yymarkStackDeleted (yyk
);
1715 yytops
.yyremoveDeletes ();
1720 /** Called when returning to deterministic operation to clean up the extra
1725 if (yytops
.size() != 1 || !isSplit())
1728 // yyr is the state after the split point.
1729 glr_state
* yyr
= YY_NULLPTR
;
1730 for (glr_state
*yyp
= firstTop(), *yyq
= yyp
->pred();
1731 yyp
!= yysplitPoint
;
1732 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->pred())
1735 // This const_cast is okay, since anyway we have access to the mutable
1736 // yyitems into which yysplitPoint points.
1737 glr_stack_item
* nextFreeItem
1738 = const_cast<glr_state
*> (yysplitPoint
)->asItem () + 1;
1739 yysplitPoint
= YY_NULLPTR
;
1740 yytops
.clearLastDeleted ();
1742 while (yyr
!= YY_NULLPTR
)
1744 nextFreeItem
->setState (*yyr
);
1745 glr_state
& nextFreeState
= nextFreeItem
->getState();
1747 nextFreeState
.setPred(&(nextFreeItem
- 1)->getState());
1748 setFirstTop (&nextFreeState
);
1751 yyitems
.resize(static_cast<size_t>(nextFreeItem
- yyitems
.data()));
1754 bool isSplit() const {
1755 return yysplitPoint
!= YY_NULLPTR
;
1758 // Present the interface of a vector of glr_stack_item.
1759 std::vector
<glr_stack_item
>::const_iterator
begin () const
1761 return yyitems
.begin ();
1764 std::vector
<glr_stack_item
>::const_iterator
end () const
1766 return yyitems
.end ();
1771 return yyitems
.size ();
1774 glr_stack_item
& operator[] (size_t i
)
1779 glr_stack_item
& stackItemAt (size_t index
)
1781 return yyitems
[index
];
1784 size_t numTops () const
1786 return yytops
.size ();
1789 glr_state
* firstTop () const
1791 return yytops
[create_state_set_index (0)];
1794 glr_state
* topAt (state_set_index i
) const
1799 void setFirstTop (glr_state
* value
)
1801 yytops
[create_state_set_index (0)] = value
;
1804 void setTopAt (state_set_index i
, glr_state
* value
)
1811 yyitems
.pop_back ();
1814 void pop_back (size_t n
)
1816 yyitems
.resize (yyitems
.size () - n
);
1820 yysplitStack (state_set_index yyk
)
1824 YYASSERT (yyk
.get () == 0);
1825 yysplitPoint
= topAt (yyk
);
1827 return yytops
.yysplitStack (yyk
);
1830 /** Assuming that YYS is a GLRState somewhere on *this, update the
1831 * splitpoint of *this, if needed, so that it is at least as deep as
1834 yyupdateSplit (glr_state
& yys
)
1836 if (isSplit() && &yys
< yysplitPoint
)
1837 yysplitPoint
= &yys
;
1840 /** Return a fresh GLRState.
1841 * Callers should call yyreserveStack afterwards to make sure there is
1842 * sufficient headroom. */
1843 glr_state
& yynewGLRState (const glr_state
& newState
)
1845 glr_state
& state
= yyitems
[yynewGLRStackItem (true)].getState ();
1846 #if false && 201103L <= YY_CPLUSPLUS
1847 state
= std::move (newState
);
1854 /** Return a fresh SemanticOption.
1855 * Callers should call yyreserveStack afterwards to make sure there is
1856 * sufficient headroom. */
1857 semantic_option
& yynewSemanticOption (semantic_option newOption
)
1859 semantic_option
& option
= yyitems
[yynewGLRStackItem (false)].getOption ();
1860 #if 201103L <= YY_CPLUSPLUS
1861 option
= std::move (newOption
);
1868 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1869 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1870 * For convenience, always return YYLOW1. */
1872 yyfill (glr_stack_item
*yyvsp
, int &yylow
, int yylow1
, bool yynormal
)
1874 if (!yynormal
&& yylow1
< yylow
)
1876 yyfillin (yyvsp
, yylow
, yylow1
);
1882 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1883 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1884 * containing the pointer to the next state in the chain. */
1886 yyfillin (glr_stack_item
*yyvsp
, int yylow0
, int yylow1
)
1888 glr_state
* s
= yyvsp
[yylow0
].getState().pred();
1889 YYASSERT(s
!= YY_NULLPTR
);
1890 for (int i
= yylow0
-1; i
>= yylow1
; i
-= 1, s
= s
->pred())
1892 glr_state
& yys
= yyvsp
[i
].getState();
1893 #if ]b4_api_PREFIX[DEBUG
1894 yys
.yylrState
= s
->yylrState
;
1896 yys
.yyresolved
= s
->yyresolved
;
1899 new (&yys
.value ()) value_type ();
1900 ]b4_symbol_variant([yy_accessing_symbol (s
->yylrState
)],
1901 [yys
.value ()], [copy
], [s
->value ()])], [[
1902 new (&yys
.value ()) value_type (s
->value ());]])[
1905 /* The effect of using yyval or yyloc (in an immediate
1906 * rule) is undefined. */
1907 yys
.setFirstVal (YY_NULLPTR
);]b4_locations_if([[
1908 yys
.yyloc
= s
->yyloc
;]])[
1909 yys
.setPred(s
->pred());
1913 #if ]b4_api_PREFIX[DEBUG
1915 /*----------------------------------------------------------------------.
1916 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1917 `----------------------------------------------------------------------*/
1920 yy_reduce_print (bool yynormal
, glr_stack_item
* yyvsp
, state_set_index yyk
,
1921 rule_num yyrule
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
)
1923 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1926 std::cerr
<< "Reducing stack " << yyk
.get() << " by rule " << yyrule
- 1
1927 << " (line " << int (yyrline
[yyrule
]) << "):\n";
1929 yyfillin (yyvsp
, 1, -yynrhs
);
1930 /* The symbols being reduced. */
1931 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1933 std::cerr
<< " $" << yyi
+ 1 << " = ";
1934 yyparser
.yy_symbol_print_
1935 (yy_accessing_symbol (yyvsp
[yyi
- yynrhs
+ 1].getState().yylrState
),
1936 yyvsp
[yyi
- yynrhs
+ 1].getState().value ()]b4_locations_if([[,
1937 ]b4_rhs_location(yynrhs
, yyi
+ 1)])[);
1938 if (!yyvsp
[yyi
- yynrhs
+ 1].getState().yyresolved
)
1939 std::cerr
<< " (unresolved)";
1945 #define YYINDEX(YYX) \
1946 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1951 for (size_t yyi
= 0; yyi
< size(); ++yyi
)
1953 const glr_stack_item
& item
= yyitems
[yyi
];
1954 std::cerr
<< std::setw(3) << yyi
<< ". ";
1955 if (item
.is_state())
1957 std::cerr
<< "Res: " << item
.getState().yyresolved
1958 << ", LR State: " << item
.getState().yylrState
1959 << ", posn: " << item
.getState().yyposn
1960 << ", pred: " << YYINDEX(item
.getState().pred());
1961 if (! item
.getState().yyresolved
)
1962 std::cerr
<< ", firstVal: "
1963 << YYINDEX(item
.getState().firstVal());
1967 std::cerr
<< "Option. rule: " << item
.getOption().yyrule
- 1
1968 << ", state: " << YYINDEX(item
.getOption().state())
1969 << ", next: " << YYINDEX(item
.getOption().next());
1973 std::cerr
<< "Tops:";
1974 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < numTops(); ++yyi
) {
1975 std::cerr
<< yyi
.get() << ": " << YYINDEX(topAt(yyi
)) << "; ";
1984 yyreportAmbiguity (const semantic_option
& yyx0
,
1985 const semantic_option
& yyx1
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_locations_if([, const location_type
& yyloc
])[)
1990 #if ]b4_api_PREFIX[DEBUG
1991 std::cerr
<< "Ambiguity detected.\n"
1993 yyx0
.yyreportTree ();
1994 std::cerr
<< "\nOption 2,\n";
1995 yyx1
.yyreportTree ();
1999 yyparser
.error (]b4_locations_if([yyloc
, ])[YY_("syntax is ambiguous"));
2003 /* DEBUGGING ONLY */
2004 #if ]b4_api_PREFIX[DEBUG
2005 /* Print YYS (possibly NULL) and its predecessors. */
2007 yypstates (const glr_state
* yys
) const
2009 if (yys
!= YY_NULLPTR
)
2012 std::cerr
<< "<null>";
2018 size_t spaceLeft() const
2020 return yyitems
.capacity() - yyitems
.size();
2023 /** Return a fresh GLRStackItem in this. The item is an LR state
2024 * if YYIS_STATE, and otherwise a semantic option. Callers should call
2025 * yyreserveStack afterwards to make sure there is sufficient
2028 yynewGLRStackItem (bool yyis_state
)
2030 YYDASSERT(yyitems
.size() < yyitems
.capacity());
2031 yyitems
.push_back(glr_stack_item(yyis_state
));
2032 return yyitems
.size() - 1;
2038 std::vector
<glr_stack_item
> yyitems
;
2039 // Where the stack splits. Anything below this address is deterministic.
2040 const glr_state
* yysplitPoint
;
2041 glr_state_set yytops
;
2045 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2050 typedef ]b4_namespace_ref
[::]b4_parser_class
[ parser_type
;
2051 typedef parser_type::symbol_kind symbol_kind
;
2052 typedef parser_type::symbol_kind_type symbol_kind_type
;
2053 typedef parser_type::symbol_type symbol_type
;
2054 typedef parser_type::value_type value_type
;]b4_locations_if([[
2055 typedef parser_type::location_type location_type
;]])[
2057 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
2058 typedef parser_type::context context
;
2059 // Needs access to yypact_value_is_default, etc.
2063 glr_stack (size_t yysize
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser_yyarg
]m4_ifset([b4_parse_param
], [, b4_parse_param_decl
])[)
2065 , yystateStack (yysize
)
2068 , yyparser (yyparser_yyarg
)]m4_ifset([b4_parse_param
], [,b4_parse_param_cons
])[
2073 if (!this->yyla
.empty ())
2074 yyparser
.yy_destroy_ ("Cleanup: discarding lookahead",
2075 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2080 ]b4_locations_if([[ /* To compute the location of the error token. */
2081 glr_stack_item yyerror_range
[3];]])[
2082 state_stack yystateStack
;
2085 YYJMP_BUF yyexception_buffer
;
2086 ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
;
2088 #define YYCHK1(YYE) \
2098 goto yyuser_error; \
2110 YYCDEBUG
<< "Starting parse\n";
2112 this->yyla
.clear ();
2113 ]m4_ifdef([b4_initial_action
], [
2114 b4_dollar_pushdef([yyla
.value
], [], [], [yyla
.location
])dnl
2115 b4_user_initial_action
2116 b4_dollar_popdef
])[]dnl
2118 switch (YYSETJMP (this->yyexception_buffer
))
2121 case 1: goto yyabortlab
;
2122 case 2: goto yyexhaustedlab
;
2123 default: goto yybuglab
;
2125 this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2130 /* For efficiency, we have two loops, the first of which is
2131 specialized to deterministic operation (single stack, no
2132 potential ambiguity). */
2136 const state_num yystate
= this->firstTopState()->yylrState
;
2137 YYCDEBUG
<< "Entering state " << yystate
<< '\n';
2138 if (yystate
== YYFINAL
)
2140 if (yy_is_defaulted_state (yystate
))
2142 const rule_num yyrule
= yy_default_action (yystate
);
2144 {]b4_locations_if([[
2145 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2146 this->yyreportSyntaxError ();
2149 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule
, true));
2154 const short* yyconflicts
;
2155 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2156 if (*yyconflicts
!= 0)
2158 if (yy_is_shift_action (yyaction
))
2160 YY_SYMBOL_PRINT ("Shifting", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
2162 // FIXME: we should move yylval.
2163 this->yyglrShift (create_state_set_index(0), yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2165 if (0 < this->yyerrState
)
2166 this->yyerrState
-= 1;
2168 else if (yy_is_error_action (yyaction
))
2169 {]b4_locations_if([[
2170 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2171 /* Don't issue an error message again for exceptions
2172 thrown from the scanner. */
2173 if (this->yyla
.kind () != ]b4_symbol(error
, kind
)[)
2174 this->yyreportSyntaxError ();
2178 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction
, true));
2184 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < this->yystateStack
.numTops(); ++yys
)
2185 this->yystateStack
.yytops
.setLookaheadNeeds(yys
, !this->yyla
.empty ());
2187 /* yyprocessOneStack returns one of three things:
2189 - An error flag. If the caller is yyprocessOneStack, it
2190 immediately returns as well. When the caller is finally
2191 yyparse, it jumps to an error label via YYCHK1.
2193 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2194 (yys), which sets the top state of yys to NULL. Thus,
2195 yyparse's following invocation of yyremoveDeletes will remove
2198 - yyok, when ready to shift a token.
2200 Except in the first case, yyparse will invoke yyremoveDeletes and
2201 then shift the next token onto all remaining stacks. This
2202 synchronization of the shift (that is, after all preceding
2203 reductions on all stacks) helps prevent double destructor calls
2204 on yylval in the event of memory exhaustion. */
2206 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2207 YYCHK1 (this->yyprocessOneStack (yys
, yyposn
]b4_locations_if([, &this->yyla
.location
])[));
2208 this->yystateStack
.yytops
.yyremoveDeletes ();
2209 if (this->yystateStack
.yytops
.size() == 0)
2211 this->yystateStack
.yytops
.yyundeleteLastStack ();
2212 if (this->yystateStack
.yytops
.size() == 0)
2213 this->yyFail (]b4_locations_if([&this->yyla
.location
, ])[YY_("syntax error"));
2214 YYCHK1 (this->yyresolveStack ());
2215 YYCDEBUG
<< "Returning to deterministic operation.\n";]b4_locations_if([[
2216 this->yyerror_range
[1].getState ().yyloc
= this->yyla
.location
;]])[
2217 this->yyreportSyntaxError ();
2221 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2222 a copy of yylval will already be on stack 0 in the event of a
2223 failure in the following loop. Thus, yyla is emptied
2224 before the loop to make sure the user destructor for yylval isn't
2226 yysymbol_kind_t yytoken_to_shift
= this->yyla
.kind ();
2227 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2229 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2231 const state_num yystate
= this->topState (yys
)->yylrState
;
2232 const short* yyconflicts
;
2233 const int yyaction
= yygetLRActions (yystate
, yytoken_to_shift
, yyconflicts
);
2234 /* Note that yyconflicts were handled by yyprocessOneStack. */
2235 YYCDEBUG
<< "On stack " << yys
.get() << ", ";
2236 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, this->yyla
.value
, this->yyla
.location
);
2237 this->yyglrShift (yys
, yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2238 YYCDEBUG
<< "Stack " << yys
.get() << " now in state "
2239 << this->topState(yys
)->yylrState
<< '\n';
2242 // FIXME: User destructors.
2243 // Value type destructor.
2244 ]b4_symbol_variant([[yytoken_to_shift
]], [[this->yyla
.value
]], [[template destroy
]])])[
2246 if (this->yystateStack
.yytops
.size () == 1)
2248 YYCHK1 (this->yyresolveStack ());
2249 YYCDEBUG
<< "Returning to deterministic operation.\n";
2250 this->yystateStack
.yycompressStack ();
2256 this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla
.location
])[);
2257 yyposn
= this->firstTopState()->yyposn
;
2273 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[YY_("memory exhausted"));
2282 void yyreserveGlrStack ()
2284 if (!yystateStack
.yyexpandGLRStackIfNeeded ())
2285 yyMemoryExhausted ();
2289 yyMemoryExhausted ()
2291 YYLONGJMP (yyexception_buffer
, 2);
2295 yyFail (]b4_locations_if([location_type
* yylocp
, ])[const char* yymsg
)
2297 if (yymsg
!= YY_NULLPTR
)
2298 yyparser
.error (]b4_locations_if([*yylocp
, ])[yymsg
);
2299 YYLONGJMP (yyexception_buffer
, 1);
2305 /** Add a new semantic action that will execute the action for rule
2306 * YYRULE on the semantic values in YYRHS to the list of
2307 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2308 * stack #YYK of *this. */
2310 yyaddDeferredAction (state_set_index yyk
, glr_state
* yystate
,
2311 glr_state
* yyrhs
, rule_num yyrule
)
2313 semantic_option
& yynewOption
=
2314 yystateStack
.yynewSemanticOption(semantic_option(yyrule
, ]b4_symbol(empty
, kind
)[));
2315 yynewOption
.setState(yyrhs
);
2316 yynewOption
.setNext(yystate
->firstVal());
2317 if (yystateStack
.yytops
.lookaheadNeeds(yyk
))
2319 yynewOption
.yytoken
= this->yyla
.kind ();]b4_variant_if([[
2320 ]b4_symbol_variant([this->yyla
.kind ()],
2321 [yynewOption
.yyval
], [copy
], [this->yyla
.value
])], [[
2322 yynewOption
.yyval
= this->yyla
.value
;]])[]b4_locations_if([
2323 yynewOption
.yyloc
= this->yyla
.location
;])[
2325 yystate
->setFirstVal (&yynewOption
);
2327 yyreserveGlrStack ();
2330 #if ]b4_api_PREFIX[DEBUG
2331 void yypdumpstack () const
2333 yystateStack
.dumpStack();
2338 yyreportSyntaxError ()
2340 if (yyerrState
!= 0)
2342 ]b4_parse_error_case(
2344 std::string msg
= YY_("syntax error");
2345 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]],
2347 context
yyctx (*this, yyla
);
2348 yyparser
.report_syntax_error (yyctx
);]],
2350 context
yyctx (*this, yyla
);
2351 std::string msg
= yyparser
.yysyntax_error_ (yyctx
);
2352 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]])[
2356 /* Recover from a syntax error on this, assuming that yytoken,
2357 yylval, and yylloc are the syntactic category, semantic value, and location
2358 of the lookahead. */
2360 yyrecoverSyntaxError (]b4_locations_if([location_type
* yylocp
])[)
2362 if (yyerrState
== 3)
2363 /* We just shifted the error token and (perhaps) took some
2364 reductions. Skip tokens until we can proceed. */
2367 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
2368 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2369 if (this->yyla
.kind () != ]b4_symbol(empty
, kind
)[)
2370 {]b4_locations_if([[
2371 /* We throw away the lookahead, but the error range
2372 of the shifted error token must take it into account. */
2373 glr_state
*yys
= firstTopState();
2374 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;
2375 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2376 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2377 yyparser
.yy_destroy_ ("Error: discarding",
2378 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);]b4_variant_if([[
2379 // Value type destructor.
2380 ]b4_symbol_variant([[this->yyla
.kind ()]], [[this->yyla
.value
]], [[template destroy
]])])[
2381 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2384 int yyj
= yypact
[firstTopState()->yylrState
];
2385 if (yypact_value_is_default (yyj
))
2387 yyj
+= this->yyla
.kind ();
2388 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != this->yyla
.kind ())
2390 if (yydefact
[firstTopState()->yylrState
] != 0)
2393 else if (! yytable_value_is_error (yytable
[yyj
]))
2397 if (!yystateStack
.reduceToOneStack())
2398 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2400 /* Now pop stack until we find a state that shifts the error token. */
2402 while (firstTopState () != YY_NULLPTR
)
2404 glr_state
*yys
= firstTopState ();
2405 int yyj
= yypact
[yys
->yylrState
];
2406 if (! yypact_value_is_default (yyj
))
2409 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2410 && yy_is_shift_action (yytable
[yyj
]))
2412 /* Shift the error token. */]b4_locations_if([[
2413 /* First adjust its location.*/
2414 location_type yyerrloc
;
2415 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2416 YYLLOC_DEFAULT (yyerrloc
, (yyerror_range
), 2);]])[
2417 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable
[yyj
]),
2418 this->yyla
.value
, yyerrloc
);
2419 yyglrShift (create_state_set_index(0), yytable
[yyj
],
2420 yys
->yyposn
, yyla
.value
]b4_locations_if([, yyerrloc
])[);
2421 yys
= firstTopState();
2424 }]b4_locations_if([[
2425 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;]])[
2426 if (yys
->pred() != YY_NULLPTR
)
2427 yys
->destroy ("Error: popping", yyparser
]b4_user_args
[);
2428 yystateStack
.setFirstTop(yys
->pred());
2429 yystateStack
.pop_back();
2431 if (firstTopState() == YY_NULLPTR
)
2432 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2436 yyprocessOneStack (state_set_index yyk
,
2437 size_t yyposn
]b4_locations_if([, location_type
* yylocp
])[)
2439 while (yystateStack
.topAt(yyk
) != YY_NULLPTR
)
2441 const state_num yystate
= topState(yyk
)->yylrState
;
2442 YYCDEBUG
<< "Stack " << yyk
.get()
2443 << " Entering state " << yystate
<< '\n';
2445 YYASSERT (yystate
!= YYFINAL
);
2447 if (yy_is_defaulted_state (yystate
))
2449 const rule_num yyrule
= yy_default_action (yystate
);
2452 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2453 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2456 const YYRESULTTAG yyflag
2457 = yyglrReduce (yyk
, yyrule
, yyimmediate
[yyrule
]);
2458 if (yyflag
== yyerr
)
2460 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2461 " (predicate failure or explicit user error).\n";
2462 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2470 yystateStack
.yytops
.setLookaheadNeeds(yyk
, true);
2472 const short* yyconflicts
;
2473 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2475 for (; *yyconflicts
!= 0; ++yyconflicts
)
2477 state_set_index yynewStack
= yystateStack
.yysplitStack (yyk
);
2478 YYCDEBUG
<< "Splitting off stack " << yynewStack
.get()
2479 << " from " << yyk
.get() << ".\n";
2480 YYRESULTTAG yyflag
=
2481 yyglrReduce (yynewStack
, *yyconflicts
, yyimmediate
[*yyconflicts
]);
2483 YYCHK (yyprocessOneStack (yynewStack
,
2484 yyposn
]b4_locations_if([, yylocp
])[));
2485 else if (yyflag
== yyerr
)
2487 YYCDEBUG
<< "Stack " << yynewStack
.get() << " dies.\n";
2488 yystateStack
.yytops
.yymarkStackDeleted (yynewStack
);
2494 if (yy_is_shift_action (yyaction
))
2496 else if (yy_is_error_action (yyaction
))
2498 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2499 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2505 = yyglrReduce (yyk
, -yyaction
, yyimmediate
[-yyaction
]);
2506 if (yyflag
== yyerr
)
2508 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2509 " (predicate failure or explicit user error).\n";
2510 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2513 else if (yyflag
!= yyok
)
2521 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2522 * and top stack item YYVSP. YYVALP points to place to put semantic
2523 * value ($$), and yylocp points to place for location information
2524 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2525 * yyerr for YYERROR, yyabort for YYABORT. */
2527 yyuserAction (rule_num yyrule
, int yyrhslen
, glr_stack_item
* yyvsp
, state_set_index yyk
,
2528 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2530 bool yynormal YY_ATTRIBUTE_UNUSED
= !yystateStack
.isSplit();
2532 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
2536 # define yyerrok (yyerrState = 0)
2538 # define YYACCEPT return yyaccept
2540 # define YYABORT return yyabort
2542 # define YYERROR return yyerrok, yyerr
2543 # undef YYRECOVERING
2544 # define YYRECOVERING() (yyerrState != 0)
2546 # define yytoken this->yyla.kind_
2548 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2550 # define YYBACKUP(Token, Value) \
2551 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2555 /* Variants are always initialized to an empty instance of the
2556 correct type. The default '$$ = $1' action is NOT applied
2557 when using variants. */
2558 // However we really need to prepare yyvsp now if we want to get
2559 // correct locations, so invoke YYFILL for $1 anyway.
2560 (void) YYFILL (1-yyrhslen
);
2561 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [(*yyvalp
)], [emplace
])], [[
2563 *yyvalp
= yyval_default
;
2565 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].getState().value ();]])[]b4_locations_if([[
2566 /* Default location. */
2567 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
2568 yyerror_range
[1].getState().yyloc
= *yylocp
;
2570 /* If yyk == -1, we are running a deferred action on a temporary
2571 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2572 so pretend the stack is "normal". */
2573 YY_REDUCE_PRINT ((yynormal
|| yyk
== create_state_set_index (-1), yyvsp
, yyk
, yyrule
, yyparser
));
2575 typedef ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error syntax_error
;
2578 #endif // YY_EXCEPTIONS
2586 catch (const syntax_error
& yyexc
)
2588 YYCDEBUG
<< "Caught exception: " << yyexc
.what() << '\n';]b4_locations_if([
2589 *yylocp
= yyexc
.location
;])[
2590 yyparser
.error (]b4_locations_if([*yylocp
, ])[yyexc
.what ());
2593 #endif // YY_EXCEPTIONS
2594 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule
), *yyvalp
, *yylocp
);
2604 # undef YYRECOVERING
2610 if (yystateStack
.isSplit ())
2613 for (glr_state
* yys
= firstTopState ();
2614 yys
!= yystateStack
.yysplitPoint
;
2617 YYCHK (yyresolveStates (*firstTopState (), yyn
));
2622 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2623 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2624 * semantic values. Assumes that all ambiguities in semantic values
2625 * have been previously resolved. Set *YYVALP to the resulting value,
2626 * and *YYLOCP to the computed location (if any). Return value is as
2627 * for userAction. */
2629 yydoAction (state_set_index yyk
, rule_num yyrule
,
2630 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2632 const int yynrhs
= yyrhsLength (yyrule
);
2634 if (!yystateStack
.isSplit())
2636 /* Standard special case: single stack. */
2637 YYASSERT (yyk
.get() == 0);
2638 glr_stack_item
* yyrhs
= yystateStack
.firstTop()->asItem();
2639 const YYRESULTTAG res
2640 = yyuserAction (yyrule
, yynrhs
, yyrhs
, yyk
, yyvalp
]b4_locations_if([, yylocp
])[);
2641 yystateStack
.pop_back(static_cast<size_t>(yynrhs
));
2642 yystateStack
.setFirstTop(&yystateStack
[yystateStack
.size() - 1].getState());
2647 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2648 glr_state
* yys
= yystateStack
.topAt(yyk
);
2649 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yys
);]b4_locations_if([[
2651 /* Set default location. */
2652 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yys
->yyloc
;]])[
2653 for (int yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
2656 YYASSERT (yys
!= YY_NULLPTR
);
2658 yystateStack
.yyupdateSplit (*yys
);
2659 yystateStack
.setTopAt(yyk
, yys
);
2660 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2662 yyvalp
]b4_locations_if([, yylocp
])[);
2666 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2667 * and push back on the resulting nonterminal symbol. Perform the
2668 * semantic action associated with YYRULE and store its value with the
2669 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2670 * unambiguous. Otherwise, store the deferred semantic action with
2671 * the new state. If the new state would have an identical input
2672 * position, LR state, and predecessor to an existing state on the stack,
2673 * it is identified with that existing state, eliminating stack #YYK from
2674 * *YYSTACKP. In this case, the semantic value is
2675 * added to the options for the existing state's semantic value.
2678 yyglrReduce (state_set_index yyk
, rule_num yyrule
, bool yyforceEval
)
2680 size_t yyposn
= topState(yyk
)->yyposn
;
2682 if (yyforceEval
|| !yystateStack
.isSplit())
2684 value_type val
;]b4_locations_if([[
2685 location_type loc
;]])[
2687 YYRESULTTAG yyflag
= yydoAction (yyk
, yyrule
, &val
]b4_locations_if([, &loc
])[);
2688 if (yyflag
== yyerr
&& yystateStack
.isSplit())
2689 {]b4_parse_trace_if([[
2690 YYCDEBUG
<< "Parse on stack " << yyk
.get ()
2691 << " rejected by rule " << yyrule
- 1
2692 << " (line " << int (yyrline
[yyrule
]) << ").\n";
2697 yyLRgotoState (topState(yyk
)->yylrState
,
2698 yylhsNonterm (yyrule
)),
2699 yyposn
, val
]b4_locations_if([, loc
])[);]b4_variant_if([[
2700 // FIXME: User destructors.
2701 // Value type destructor.
2702 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [[val
]], [[template destroy
]])])[
2706 glr_state
*yys
= yystateStack
.topAt(yyk
);
2707 glr_state
*yys0
= yys
;
2708 for (int yyn
= yyrhsLength (yyrule
); 0 < yyn
; yyn
-= 1)
2711 YYASSERT (yys
!= YY_NULLPTR
);
2713 yystateStack
.yyupdateSplit (*yys
);
2714 state_num yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));]b4_parse_trace_if([[
2715 YYCDEBUG
<< "Reduced stack " << yyk
.get ()
2716 << " by rule " << yyrule
- 1 << " (line " << int (yyrline
[yyrule
])
2717 << "); action deferred. Now in state " << yynewLRState
2719 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < yystateStack
.numTops(); ++yyi
)
2720 if (yyi
!= yyk
&& yystateStack
.topAt(yyi
) != YY_NULLPTR
)
2722 const glr_state
* yysplit
= yystateStack
.yysplitPoint
;
2723 glr_state
* yyp
= yystateStack
.topAt(yyi
);
2724 while (yyp
!= yys
&& yyp
!= yysplit
2725 && yyp
->yyposn
>= yyposn
)
2727 if (yyp
->yylrState
== yynewLRState
2728 && yyp
->pred() == yys
)
2730 yyaddDeferredAction (yyk
, yyp
, yys0
, yyrule
);
2731 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2732 YYCDEBUG
<< "Merging stack " << yyk
.get ()
2733 << " into stack " << yyi
.get () << ".\n";
2739 yystateStack
.setTopAt(yyk
, yys
);
2740 yyglrShiftDefer (yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
2745 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2746 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2747 * semantic value of YYRHS under the action for YYRULE. */
2749 yyglrShiftDefer (state_set_index yyk
, state_num yylrState
,
2750 size_t yyposn
, glr_state
* yyrhs
, rule_num yyrule
)
2752 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2753 glr_state (yylrState
, yyposn
));
2754 yynewState
.setPred (yystateStack
.topAt (yyk
));
2755 yystateStack
.setTopAt (yyk
, &yynewState
);
2757 /* Invokes yyreserveStack. */
2758 yyaddDeferredAction (yyk
, &yynewState
, yyrhs
, yyrule
);
2761 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2762 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2763 * value YYVAL_ARG and source location YYLOC_ARG. */
2765 yyglrShift (state_set_index yyk
, state_num yylrState
,
2767 const value_type
& yyval_arg
]b4_locations_if([, const location_type
& yyloc_arg
])[)
2769 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2770 glr_state (yylrState
, yyposn
, yyval_arg
]b4_locations_if([, yyloc_arg
])[));
2771 yynewState
.setPred (yystateStack
.topAt(yyk
));
2772 yystateStack
.setTopAt (yyk
, &yynewState
);
2773 yyreserveGlrStack ();
2776 #if ]b4_api_PREFIX[DEBUG
2778 yypstack (state_set_index yyk
) const
2780 yystateStack
.yypstates (yystateStack
.topAt (yyk
));
2784 glr_state
* topState(state_set_index i
) {
2785 return yystateStack
.topAt(i
);
2788 glr_state
* firstTopState() {
2789 return yystateStack
.firstTop();
2796 /* If the stack is well-formed, pop the stack until it is empty,
2797 destroying its entries as we go. But free the stack regardless
2798 of whether it is well-formed. */
2799 for (state_set_index k
= create_state_set_index(0); k
.uget() < yystateStack
.numTops(); k
+= 1)
2800 if (yystateStack
.topAt(k
) != YY_NULLPTR
)
2802 while (yystateStack
.topAt(k
) != YY_NULLPTR
)
2804 glr_state
* state
= topState(k
);]b4_locations_if([[
2805 yyerror_range
[1].getState().yyloc
= state
->yyloc
;]])[
2806 if (state
->pred() != YY_NULLPTR
)
2807 state
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
2808 yystateStack
.setTopAt(k
, state
->pred());
2809 yystateStack
.pop_back();
2815 /** Resolve the previous YYN states starting at and including state YYS
2816 * on *YYSTACKP. If result != yyok, some states may have been left
2817 * unresolved possibly with empty semantic option chains. Regardless
2818 * of whether result = yyok, each state has been left with consistent
2819 * data so that destroy can be invoked if necessary. */
2821 yyresolveStates (glr_state
& yys
, int yyn
)
2825 YYASSERT (yys
.pred() != YY_NULLPTR
);
2826 YYCHK (yyresolveStates (*yys
.pred(), yyn
-1));
2827 if (! yys
.yyresolved
)
2828 YYCHK (yyresolveValue (yys
));
2834 yyuserMerge (int yyn
, value_type
& yy0
, value_type
& yy1
)
2846 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2847 * perform the indicated actions, and set the semantic value of YYS.
2848 * If result != yyok, the chain of semantic options in YYS has been
2849 * cleared instead or it has been left unmodified except that
2850 * redundant options may have been removed. Regardless of whether
2851 * result = yyok, YYS has been left with consistent data so that
2852 * destroy can be invoked if necessary. */
2854 yyresolveValue (glr_state
& yys
)
2856 semantic_option
* yybest
= yys
.firstVal();
2857 YYASSERT(yybest
!= YY_NULLPTR
);
2858 bool yymerge
= false;
2859 YYRESULTTAG yyflag
;]b4_locations_if([
2860 location_type
*yylocp
= &yys
.yyloc
;])[
2862 semantic_option
* yypPrev
= yybest
;
2863 for (semantic_option
* yyp
= yybest
->next();
2864 yyp
!= YY_NULLPTR
; )
2866 if (yybest
->isIdenticalTo (*yyp
))
2868 yybest
->mergeWith (*yyp
);
2869 yypPrev
->setNext(yyp
->next());
2870 yyp
= yypPrev
->next();
2874 switch (yypreference (*yybest
, *yyp
))
2876 case 0:]b4_locations_if([[
2877 yyresolveLocations (yys
, 1);]])[
2878 return yystateStack
.yyreportAmbiguity (*yybest
, *yyp
, yyparser
]b4_locations_if([, *yylocp
])[);
2890 /* This cannot happen so it is not worth a YYASSERT (false),
2891 but some compilers complain if the default case is
2903 int yyprec
= yydprec
[yybest
->yyrule
];
2904 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2906 for (semantic_option
* yyp
= yybest
->next();
2910 if (yyprec
== yydprec
[yyp
->yyrule
])
2912 value_type yyval_other
;]b4_locations_if([
2913 location_type yydummy
;])[
2914 yyflag
= yyresolveAction (*yyp
, &yyval_other
]b4_locations_if([, &yydummy
])[);
2917 yyparser
.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2918 yy_accessing_symbol (yys
.yylrState
),
2919 this->yyla
.value
]b4_locations_if([, *yylocp
])[);
2922 yyuserMerge (yymerger
[yyp
->yyrule
], val
, yyval_other
);]b4_variant_if([[
2923 // FIXME: User destructors.
2924 // Value type destructor.
2925 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[yyval_other
]], [[template destroy
]])])[
2930 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2934 yys
.yyresolved
= true;
2935 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_variant_if([[
2936 new (&yys
.value ()) value_type ();
2937 ]b4_symbol_variant([yy_accessing_symbol (yys
.yylrState
)],
2938 [yys
.value ()], [copy
], [val
])], [[
2939 new (&yys
.value ()) value_type (val
);]])[
2941 YY_IGNORE_MAYBE_UNINITIALIZED_END
2944 yys
.setFirstVal(YY_NULLPTR
);
2946 // FIXME: User destructors.
2947 // Value type destructor.
2948 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[val
]], [[template destroy
]])])[
2952 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2953 * user action, and return the semantic value and location in *YYVALP
2954 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2955 * have been destroyed (assuming the user action destroys all RHS
2956 * semantic values if invoked). */
2958 yyresolveAction (semantic_option
& yyopt
, value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2960 glr_state
* yyoptState
= yyopt
.state();
2961 YYASSERT(yyoptState
!= YY_NULLPTR
);
2962 int yynrhs
= yyrhsLength (yyopt
.yyrule
);
2963 YYRESULTTAG yyflag
= yyresolveStates (*yyoptState
, yynrhs
);
2966 for (glr_state
*yys
= yyoptState
; yynrhs
> 0; yys
= yys
->pred(), yynrhs
-= 1)
2967 yys
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
2971 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2972 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yyopt
.state());]b4_locations_if([[
2974 /* Set default location. */
2975 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yyoptState
->yyloc
;]])[
2977 symbol_type yyla_current
= std::move (this->yyla
);
2978 this->yyla
.kind_
= yyopt
.yytoken
;]b4_variant_if([[
2979 ]b4_symbol_variant([this->yyla
.kind ()],
2980 [this->yyla
.value
], [move
], [yyopt
.yyval
])], [[
2981 this->yyla
.value
= yyopt
.yyval
;]])[]b4_locations_if([
2982 this->yyla
.location
= yyopt
.yyloc
;])[
2983 yyflag
= yyuserAction (yyopt
.yyrule
, yynrhs
,
2984 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2985 create_state_set_index (-1),
2986 yyvalp
]b4_locations_if([, yylocp
])[);
2988 this->yyla
= std::move (yyla_current
);
2991 }]b4_locations_if([[
2993 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
2994 * ending at YYS1. Has no effect on previously resolved states.
2995 * The first semantic option of a state is always chosen. */
2997 yyresolveLocations (glr_state
&yys1
, int yyn1
)
3001 yyresolveLocations (*yys1
.pred(), yyn1
- 1);
3002 if (!yys1
.yyresolved
)
3004 glr_stack_item yyrhsloc
[1 + YYMAXRHS
];
3005 YYASSERT (yys1
.firstVal() != YY_NULLPTR
);
3006 semantic_option
& yyoption
= *yys1
.firstVal();
3007 const int yynrhs
= yyrhsLength (yyoption
.yyrule
);
3010 yyresolveLocations (*yyoption
.state(), yynrhs
);
3011 const glr_state
*yys
= yyoption
.state();
3012 for (int yyn
= yynrhs
; yyn
> 0; yyn
-= 1)
3014 yyrhsloc
[yyn
].getState().yyloc
= yys
->yyloc
;
3020 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3021 in reverse rightmost order. It is only necessary to invoke
3022 yyresolveLocations on a subforest for which yyresolveAction
3023 would have been invoked next had an ambiguity not been
3024 detected. Thus the location of the previous state (but not
3025 necessarily the previous state itself) is guaranteed to be
3026 resolved already. */
3027 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3028 yyrhsloc
[0].getState().yyloc
= yyoption
.state()->yyloc
;
3029 YY_IGNORE_NULL_DEREFERENCE_END
3031 YYLLOC_DEFAULT ((yys1
.yyloc
), yyrhsloc
, yynrhs
);
3036 /** If yytoken is empty, fetch the next token. */
3040 ]b4_parse_param_use()dnl
3041 [ if (this->yyla
.empty ())
3043 YYCDEBUG
<< "Reading a token\n";
3046 #endif // YY_EXCEPTIONS
3047 {]b4_token_ctor_if([[
3048 symbol_type
yylookahead (]b4_yylex
[);
3049 yyla
.move (yylookahead
);]], [[
3050 yyla
.kind_
= yyparser
.yytranslate_ (]b4_yylex
[);]])[
3053 catch (const ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error
& yyexc
)
3055 YYCDEBUG
<< "Caught exception: " << yyexc
.what () << '\n';]b4_locations_if([
3056 this->yyla
.location
= yyexc
.location
;])[
3057 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[yyexc
.what ());
3058 // Map errors caught in the scanner to the error token, so that error
3059 // handling is started.
3060 this->yyla
.kind_
= ]b4_symbol(error
, kind
)[;
3063 #endif // YY_EXCEPTIONS
3064 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
3065 YYCDEBUG
<< "Now at end of input.\n";
3067 YY_SYMBOL_PRINT ("Next token is", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
3071 /* Bison grammar-table manipulation. */
3073 /** The action to take in YYSTATE on seeing YYTOKEN.
3075 * R < 0: Reduce on rule -R.
3077 * R > 0: Shift to state R.
3078 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3079 * of conflicting reductions.
3082 yygetLRActions (state_num yystate
, yysymbol_kind_t yytoken
, const short*& yyconflicts
)
3084 int yyindex
= yypact
[yystate
] + yytoken
;
3085 if (yytoken
== ]b4_symbol(error
, kind
)[)
3087 // This is the error token.
3088 yyconflicts
= yyconfl
;
3091 else if (yy_is_defaulted_state (yystate
)
3092 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
3094 yyconflicts
= yyconfl
;
3095 return -yydefact
[yystate
];
3097 else if (! yytable_value_is_error (yytable
[yyindex
]))
3099 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3100 return yytable
[yyindex
];
3104 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3109 /** Compute post-reduction state.
3110 * \param yystate the current state
3111 * \param yysym the nonterminal to push on the stack
3114 yyLRgotoState (state_num yystate
, yysymbol_kind_t yysym
)
3116 const int yyr
= yypgoto
[yysym
- YYNTOKENS
] + yystate
;
3117 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
3118 return yytable
[yyr
];
3120 return yydefgoto
[yysym
- YYNTOKENS
];
3124 yypact_value_is_default (state_num yystate
)
3126 return ]b4_table_value_equals([[pact
]], [[yystate
]], [b4_pact_ninf
], [YYPACT_NINF
])[;
3130 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED
)
3132 return ]b4_table_value_equals([[table
]], [[yytable_value
]], [b4_table_ninf
], [YYTABLE_NINF
])[;
3136 yy_is_shift_action (int yyaction
)
3138 return 0 < yyaction
;
3142 yy_is_error_action (int yyaction
)
3144 return yyaction
== 0;
3147 /** Whether LR state YYSTATE has only a default reduction
3148 * (regardless of token). */
3150 yy_is_defaulted_state (state_num yystate
)
3152 return yypact_value_is_default (yypact
[yystate
]);
3155 /** The default reduction for YYSTATE, assuming it has one. */
3157 yy_default_action (state_num yystate
)
3159 return yydefact
[yystate
];
3164 /** Y0 and Y1 represent two possible actions to take in a given
3165 * parsing state; return 0 if no combination is possible,
3166 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3168 yypreference (const semantic_option
& y0
, const semantic_option
& y1
)
3170 rule_num r0
= y0
.yyrule
, r1
= y1
.yyrule
;
3171 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
3175 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
3180 if (p0
== 0 || p1
== 0)
3189 ]b4_parse_param_vars
[
3194 /* DEBUGGING ONLY */
3195 #if ]b4_api_PREFIX[DEBUG
3197 yypstack (const glr_stack
& yystack
, size_t yyk
)
3199 yystack
.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk
)));
3201 static void yypdumpstack (const glr_stack
& yystack
)
3203 yystack
.yypdumpstack ();
3209 /// Build a parser object.
3210 ]b4_parser_class::b4_parser_class
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
3212 #if ]b4_api_PREFIX[DEBUG
3213 ]m4_ifset([b4_parse_param
], [ ], [ :])[yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
3214 #endif]b4_parse_param_cons[
3217 ]b4_parser_class::~b4_parser_class
[ ()
3220 ]b4_parser_class
[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3224 ]b4_parser_class
[::operator() ()
3230 ]b4_parser_class
[::parse ()
3232 glr_stack
yystack(YYINITDEPTH
, *this]b4_user_args
[);
3233 return yystack
.parse ();
3236 ]b4_parse_error_bmatch([custom\
|detailed
],
3238 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3240 static const char *const yy_sname
[] =
3243 };]b4_has_translations_if([[
3244 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3245 internationalizable. */
3246 static ]b4_int_type_for([b4_translatable
])[ yytranslatable
[] =
3250 return (yysymbol
< YYNTOKENS
&& yytranslatable
[yysymbol
]
3251 ? _(yy_sname
[yysymbol
])
3252 : yy_sname
[yysymbol
]);]], [[
3253 return yy_sname
[yysymbol
];]])[
3257 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3259 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3261 return yytname_
[yysymbol
];
3263 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3266 [[ /* Return YYSTR after stripping away unnecessary quotes and
3267 backslashes, so that it's suitable for yyerror. The heuristic is
3268 that double-quoting is unnecessary unless the string contains an
3269 apostrophe, a comma, or backslash (other than backslash-backslash).
3270 YYSTR is taken from yytname. */
3272 ]b4_parser_class
[::yytnamerr_ (const char *yystr
)
3277 char const *yyp
= yystr
;
3284 goto do_not_strip_quotes
;
3288 goto do_not_strip_quotes
;
3300 do_not_strip_quotes
: ;
3307 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3309 return yytnamerr_ (yytname_
[yysymbol
]);
3313 ]b4_parse_error_bmatch([simple\
|verbose
],
3314 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3315 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3316 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3318 const ]b4_parser_class
[::yytname_
[] =
3325 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
3326 // ]b4_parser_class[::context.
3327 ]b4_parser_class
[::context::context (glr_stack
& yystack
, const symbol_type
& yyla
)
3328 : yystack_ (yystack
)
3333 ]b4_parser_class
[::context::expected_tokens (symbol_kind_type yyarg
[], int yyargn
) const
3335 // Actual number of expected tokens
3337 const int yyn
= yypact
[yystack_
.firstTopState()->yylrState
];
3338 if (!yystack_
.yypact_value_is_default (yyn
))
3340 /* Start YYX at -YYN if negative to avoid negative indexes in
3341 YYCHECK. In other words, skip the first -YYN actions for this
3342 state because they are default actions. */
3343 const int yyxbegin
= yyn
< 0 ? -yyn
: 0;
3344 /* Stay within bounds of both yycheck and yytname. */
3345 const int yychecklim
= YYLAST
- yyn
+ 1;
3346 const int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
3347 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
3348 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= ]b4_symbol(error
, kind
)[
3349 && !yystack_
.yytable_value_is_error (yytable
[yyx
+ yyn
]))
3353 else if (yycount
== yyargn
)
3356 yyarg
[yycount
++] = YY_CAST (symbol_kind_type
, yyx
);
3359 if (yyarg
&& yycount
== 0 && 0 < yyargn
)
3360 yyarg
[0] = ]b4_symbol(empty
, kind
)[;
3366 ]b4_parse_error_bmatch([detailed\
|verbose
], [[
3368 ]b4_parser_class
[::yy_syntax_error_arguments_ (const context
& yyctx
,
3369 symbol_kind_type yyarg
[], int yyargn
) const
3371 /* There are many possibilities here to consider:
3372 - If this state is a consistent state with a default action, then
3373 the only way this function was invoked is if the default action
3374 is an error action. In that case, don't check for expected
3375 tokens because there are none.
3376 - The only way there can be no lookahead present (in yyla) is
3377 if this state is a consistent state with a default action.
3378 Thus, detecting the absence of a lookahead is sufficient to
3379 determine that there is no unexpected or expected token to
3380 report. In that case, just report a simple "syntax error".
3381 - Don't assume there isn't a lookahead just because this state is
3382 a consistent state with a default action. There might have
3383 been a previous inconsistent state, consistent state with a
3384 non-default action, or user semantic action that manipulated
3385 yyla. (However, yyla is currently not documented for users.)
3388 if (!yyctx
.lookahead ().empty ())
3391 yyarg
[0] = yyctx
.token ();
3392 int yyn
= yyctx
.expected_tokens (yyarg
? yyarg
+ 1 : yyarg
, yyargn
- 1);
3398 // Generate an error message.
3400 ]b4_parser_class
[::yysyntax_error_ (const context
& yyctx
) const
3403 enum { YYARGS_MAX
= 5 };
3404 // Arguments of yyformat.
3405 symbol_kind_type yyarg
[YYARGS_MAX
];
3406 int yycount
= yy_syntax_error_arguments_ (yyctx
, yyarg
, YYARGS_MAX
);
3408 char const* yyformat
= YY_NULLPTR
;
3411 #define YYCASE_(N, S) \
3415 default: // Avoid compiler warnings.
3416 YYCASE_ (0, YY_("syntax error"));
3417 YYCASE_ (1, YY_("syntax error, unexpected %s"));
3418 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
3419 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
3420 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
3421 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
3427 std::ptrdiff_t yyi
= 0;
3428 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
3429 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
3431 yyres
+= symbol_name (yyarg
[yyi
++]);
3440 ]b4_parser_class
[::yy_destroy_ (const char* yymsg
, symbol_kind_type yykind
,
3441 value_type
& yyval
]b4_locations_if([[,
3442 location_type
& yyloc
]])[)
3444 YY_USE (yyval
);]b4_locations_if([[
3448 ]b4_parser_class
[& yyparser
= *this;
3450 YY_SYMBOL_PRINT (yymsg
, yykind
, yyval
, yyloc
);
3452 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3453 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3454 [b4_symbol_actions([destructor
])],
3455 [m4_popdef([b4_symbol_action
])])[
3456 YY_IGNORE_MAYBE_UNINITIALIZED_END
3459 #if ]b4_api_PREFIX[DEBUG
3460 /*--------------------.
3461 | Print this symbol. |
3462 `--------------------*/
3465 ]b4_parser_class
[::yy_symbol_value_print_ (symbol_kind_type yykind
,
3466 const value_type
& yyval
]b4_locations_if([[,
3467 const location_type
& yyloc
]])[) const
3468 {]b4_locations_if([[
3471 std::ostream
& yyo
= debug_stream ();
3473 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3474 [b4_symbol_actions([printer
])],
3475 [m4_popdef([b4_symbol_action
])])[
3479 ]b4_parser_class
[::yy_symbol_print_ (symbol_kind_type yykind
,
3480 const value_type
& yyval
]b4_locations_if([[,
3481 const location_type
& yyloc
]])[) const
3483 *yycdebug_
<< (yykind
< YYNTOKENS
? "token" : "nterm")
3484 << ' ' << symbol_name (yykind
) << " ("]b4_locations_if([[
3485 << yyloc
<< ": "]])[;
3486 yy_symbol_value_print_ (yykind
, yyval
]b4_locations_if([[, yyloc
]])[);
3491 ]b4_parser_class
[::debug_stream () const
3497 ]b4_parser_class
[::set_debug_stream (std::ostream
& o
)
3503 ]b4_parser_class
[::debug_level_type
3504 ]b4_parser_class
[::debug_level () const
3510 ]b4_parser_class
[::set_debug_level (debug_level_type l
)
3512 // Actually, it is yydebug which is really used.
3515 #endif // ]b4_api_PREFIX[DEBUG
3517 ]b4_token_ctor_if([], [b4_yytranslate_define([cc
])])[
3519 ]b4_token_ctor_if([], [[
3523 ]b4_public_types_define([cc
])])[
3524 ]b4_namespace_close
[]dnl