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])[
232 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
233 [b4_location_define])])[
236 class ]b4_parser_class[
239 ]b4_public_types_declare[
240 ]b4_symbol_type_define[
242 /// Build a parser object.
243 ]b4_parser_class[ (]b4_parse_param_decl[);
244 ~]b4_parser_class[ ();
246 /// Parse. An alias for parse ().
247 /// \returns 0 iff parsing succeeded.
251 /// \returns 0 iff parsing succeeded.
254 #if ]b4_api_PREFIX[DEBUG
255 /// The current debugging stream.
256 std::ostream& debug_stream () const;
257 /// Set the current debugging stream.
258 void set_debug_stream (std::ostream &);
260 /// Type for debugging levels.
261 typedef int debug_level_type;
262 /// The current debugging level.
263 debug_level_type debug_level () const;
264 /// Set the current debugging level.
265 void set_debug_level (debug_level_type l);
268 /// Report a syntax error.]b4_locations_if([[
269 /// \param loc where the syntax error is found.]])[
270 /// \param msg a description of the syntax error.
271 void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
273 ]b4_parse_error_bmatch(
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);]],
279 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
280 /// The user-facing name of the symbol whose (internal) number is
281 /// YYSYMBOL. No bounds checking.
282 static const char *symbol_name (symbol_kind_type yysymbol);
283 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
286 [[ /// The user-facing name of the symbol whose (internal) number is
287 /// YYSYMBOL. No bounds checking.
288 static std::string symbol_name (symbol_kind_type yysymbol);]])[
290 ]b4_token_constructor_define[
291 ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
295 context (glr_stack& yystack, const symbol_type& yyla);
296 const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; }
297 symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[
298 const location_type& location () const YY_NOEXCEPT { return yyla_.location; }
300 /// Put in YYARG at most YYARGN of the expected tokens, and return the
301 /// number of tokens stored in YYARG. If YYARG is null, return the
302 /// number of expected tokens (guaranteed to be less than YYNTOKENS).
303 int expected_tokens (symbol_kind_type yyarg[], int yyargn) const;
307 const symbol_type& yyla_;
310 # if ]b4_api_PREFIX[DEBUG
312 /// \brief Report a symbol value on the debug stream.
313 /// \param yykind The symbol kind.
314 /// \param yyval Its semantic value.]b4_locations_if([[
315 /// \param yyloc Its location.]])[
316 void yy_symbol_value_print_ (symbol_kind_type yykind,
317 const value_type& yyval]b4_locations_if([[,
318 const location_type& yyloc]])[) const;
319 /// \brief Report a symbol on the debug stream.
320 /// \param yykind The symbol kind.
321 /// \param yyval Its semantic value.]b4_locations_if([[
322 /// \param yyloc Its location.]])[
323 void yy_symbol_print_ (symbol_kind_type yykind,
324 const value_type& yyval]b4_locations_if([[,
325 const location_type& yyloc]])[) const;
328 std::ostream* yycdebug_;
331 ]b4_parse_error_bmatch(
334 /// Report a syntax error
335 /// \param yyctx the context in which the error occurred.
336 void report_syntax_error (const context& yyctx) const;]],
337 [detailed\|verbose], [[
339 /// The arguments of the error message.
340 int yy_syntax_error_arguments_ (const context& yyctx,
341 symbol_kind_type yyarg[], int yyargn) const;
343 /// Generate an error message.
344 /// \param yyctx the context in which the error occurred.
345 virtual std::string yysyntax_error_ (const context& yyctx) const;]])[
347 /// Convert a scanner token kind \a t to a symbol kind.
348 /// In theory \a t should be a token_kind_type, but character literals
349 /// are valid, yet not members of the token_kind_type enum.
350 static symbol_kind_type yytranslate_ (int t);
352 ]b4_parse_error_bmatch(
354 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
355 /// For a symbol, its name in clear.
356 static const char* const yytname_[];
357 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
360 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
361 static std::string yytnamerr_ (const char *yystr);
363 /// For a symbol, its name in clear.
364 static const char* const yytname_[];
367 /// \brief Reclaim the memory associated to a symbol.
368 /// \param yymsg Why this token is reclaimed.
369 /// If null, print nothing.
370 /// \param yykind The symbol kind.
371 void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
372 value_type& yyval]b4_locations_if([[,
373 location_type& yyloc]])[);
375 ]b4_parse_param_vars[
376 // Needs access to report_syntax_error, etc.
378 // Needs access to yy_destroy_.
382 ]b4_token_ctor_if([b4_yytranslate_define([$1])[
383 ]b4_public_types_define([$1])])[
386 ]b4_percent_code_get([[provides]])[
400 ]b4_output_begin([b4_spec_header_file])[
401 ]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
402 [2002-2015, 2018-2021])[
403 // C++ GLR parser skeleton written by Valentin Tolmer.
406 ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
407 ]b4_shared_declarations([hh])[
408 ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
412 # --------------------- #
413 # Implementation file. #
414 # --------------------- #
416 ]b4_output_begin([b4_parser_file_name])[
417 ]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
418 [2002-2015, 2018-2021])[
419 // C++ GLR parser skeleton written by Valentin Tolmer.
424 ]b4_percent_code_get([[top]])[
425 ]m4_if(b4_prefix, [yy], [],
426 [[/* Substitute the variable and function names. */
427 #define yyparse ]b4_prefix[parse
428 #define yylex ]b4_prefix[lex
429 #define yyerror ]b4_prefix[error
430 #define yydebug ]b4_prefix[debug]])[
432 ]b4_user_pre_prologue[
436 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
437 [b4_shared_declarations([cc])])[
439 typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
441 /* Default (constant) value used for initialization for null
442 right-hand sides. Unlike the standard yacc.c template, here we set
443 the default value of $$ to a zeroed-out value. Since the default
444 value is undefined, this behavior is technically correct. */
445 static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;
447 ]b4_user_post_prologue[
448 ]b4_percent_code_get[]dnl
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 void yypstack (const glr_stack& yystack, size_t yyk)
640 void yypdumpstack (const glr_stack& yystack)
644 #else /* !]b4_api_PREFIX[DEBUG */
646 # define YYCDEBUG if (true) {} else std::cerr
647 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {}
648 # define YY_REDUCE_PRINT(Args) {}
650 #endif /* !]b4_api_PREFIX[DEBUG */
652 /* YYINITDEPTH -- initial size of the parser's stacks. */
654 # define YYINITDEPTH ]b4_stack_depth_init[
657 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
658 if the built-in stack extension method is used).
660 Do not make this value too large; the results are undefined if
661 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
662 evaluated with infinite-precision integer arithmetic. */
665 # define YYMAXDEPTH ]b4_stack_depth_max[
668 /* Minimum number of free items on the stack allowed after an
669 allocation. This is to allow allocation and initialization
670 to be completed by functions that call yyexpandGLRStack before the
671 stack is expanded, thus insuring that all necessary pointers get
672 properly redirected to new data. */
675 #ifndef YYSTACKEXPANDABLE
676 # define YYSTACKEXPANDABLE 1
679 template <typename Parameter
>
680 class strong_index_alias
683 static strong_index_alias
create (std::ptrdiff_t value
)
685 strong_index_alias result
;
686 result
.value_
= value
;
690 std::ptrdiff_t const& get () const { return value_
; }
692 size_t uget () const { return static_cast<size_t> (value_
); }
694 strong_index_alias
operator+ (std::ptrdiff_t other
) const
696 return strong_index_alias (get () + other
);
699 void operator+= (std::ptrdiff_t other
)
704 strong_index_alias
operator- (std::ptrdiff_t other
)
706 return strong_index_alias (get () - other
);
709 void operator-= (std::ptrdiff_t other
)
714 size_t operator- (strong_index_alias other
)
716 return strong_index_alias (get () - other
.get ());
719 strong_index_alias
& operator++ ()
725 bool isValid () const
727 return value_
!= INVALID_INDEX
;
732 value_
= INVALID_INDEX
;
735 bool operator== (strong_index_alias other
)
737 return get () == other
.get ();
740 bool operator!= (strong_index_alias other
)
742 return get () != other
.get ();
745 bool operator< (strong_index_alias other
)
747 return get () < other
.get ();
751 static const std::ptrdiff_t INVALID_INDEX
;
753 // WARNING: 0-initialized.
754 std::ptrdiff_t value_
;
758 const std::ptrdiff_t strong_index_alias
<T
>::INVALID_INDEX
=
759 std::numeric_limits
<std::ptrdiff_t>::max ();
761 typedef strong_index_alias
<struct glr_state_set_tag
> state_set_index
;
763 state_set_index
create_state_set_index (std::ptrdiff_t value
)
765 return state_set_index::create (value
);
768 /** State numbers, as in LALR(1) machine */
769 typedef int state_num
;
771 /** Rule numbers, as in LALR(1) machine */
772 typedef int rule_num
;
774 // Forward declarations.
778 class semantic_option
;
780 class glr_stack_item
;
783 /** Accessing symbol of state YYSTATE. */
784 static inline yysymbol_kind_t
785 yy_accessing_symbol (state_num yystate
)
787 return YY_CAST (yysymbol_kind_t
, yystos
[yystate
]);
790 /** Left-hand-side symbol for rule #YYRULE. */
791 static inline yysymbol_kind_t
792 yylhsNonterm (rule_num yyrule
)
794 return static_cast<yysymbol_kind_t
>(yyr1
[yyrule
]);
797 /** Number of symbols composing the right hand side of rule #RULE. */
799 yyrhsLength (rule_num yyrule
)
807 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
808 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type symbol_kind_type
;
809 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
810 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
817 , yyfirstVal (0)]b4_locations_if([[
818 , yyloc ()]])[]b4_parse_assert_if([[
822 /// Build with a semantic value.
823 glr_state (state_num lrState
, size_t posn
, const value_type
& val
]b4_locations_if([[, const location_type
& loc
]])[)
825 , yylrState (lrState
)
828 , yyval (]b4_variant_if([], [[val
]])[)]b4_locations_if([[
829 , yyloc (loc
)]])[]b4_parse_assert_if([[
832 ]b4_symbol_variant([yy_accessing_symbol (lrState
)],
833 [yyval
], [copy
], [val
])])[}
835 /// Build with a semantic option.
836 glr_state (state_num lrState
, size_t posn
)
838 , yylrState (lrState
)
841 , yyfirstVal (0)]b4_locations_if([[
842 , yyloc ()]])[]b4_parse_assert_if([[
846 glr_state (const glr_state
& other
)
847 : yyresolved (other
.yyresolved
)
848 , yylrState (other
.yylrState
)
849 , yyposn (other
.yyposn
)
850 , yypred (0)]b4_locations_if([[
851 , yyloc (other
.yyloc
)]])[]b4_parse_assert_if([[
854 setPred (other
.pred ());
855 if (other
.yyresolved
)]b4_variant_if([[
857 new (&yyval
) value_type ();
858 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
859 [yyval
], [copy
], [other
.value ()])[
861 new (&yyval
) value_type (other
.value ());]])[
865 setFirstVal (other
.firstVal ());
866 }]b4_parse_assert_if([[
871 {]b4_parse_assert_if([[
875 yysymbol_kind_t yykind
= yy_accessing_symbol (yylrState
);
876 // FIXME: User destructors.
877 // Value type destructor.
878 ]b4_symbol_variant([[yykind
]], [[yyval
]], [[template destroy
]])])[
879 yyval
.~value_type ();
880 }]b4_parse_assert_if([[
884 glr_state
& operator= (const glr_state
& other
)
885 {]b4_parse_assert_if([[
888 if (!yyresolved
&& other
.yyresolved
)
889 new (&yyval
) value_type
;
890 yyresolved
= other
.yyresolved
;
891 yylrState
= other
.yylrState
;
892 yyposn
= other
.yyposn
;
893 setPred (other
.pred ());
894 if (other
.yyresolved
)]b4_variant_if([[
895 ]b4_symbol_variant([yy_accessing_symbol (other
.yylrState
)],
896 [yyval
], [copy
], [other
.value ()])], [[
897 value () = other
.value ();]])[
899 setFirstVal (other
.firstVal ());]b4_locations_if([[
900 yyloc
= other
.yyloc
;]])[
904 /** Type tag for the semantic value. If true, yyval applies, otherwise
905 * yyfirstVal applies. */
907 /** Number of corresponding LALR(1) machine state. */
909 /** Source position of the last token produced by my symbol */
912 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
914 const glr_state
* pred () const;
915 void setPred (const glr_state
* state
);
917 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
919 semantic_option
* firstVal ();
920 const semantic_option
* firstVal () const;
921 void setFirstVal (const semantic_option
* option
);
924 {]b4_parse_assert_if([[
929 const value_type
& value () const
930 {]b4_parse_assert_if([[
936 destroy (char const *yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[);
939 #if ]b4_api_PREFIX[DEBUG
940 void yy_yypstack () const
941 {]b4_parse_assert_if([[
943 if (pred () != YY_NULLPTR
)
945 pred ()->yy_yypstack ();
948 std::cerr
<< yylrState
<< "@@" << yyposn
;
952 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const;
954 glr_stack_item
* asItem ()
955 {]b4_parse_assert_if([[
960 const glr_stack_item
* asItem () const
961 {]b4_parse_assert_if([[
963 return asItem (this);
967 template <typename T
>
968 static const glr_stack_item
* asItem (const T
* state
)
970 return reinterpret_cast<const glr_stack_item
*>(state
);
972 template <typename T
>
973 static glr_stack_item
* asItem (T
* state
)
975 return reinterpret_cast<glr_stack_item
*> (state
);
977 static const char *as_pointer_ (const glr_state
*state
)
979 return reinterpret_cast<const char *> (state
);
981 static char *as_pointer_ (glr_state
*state
)
983 return reinterpret_cast<char *> (state
);
985 /** Preceding state in this stack */
986 std::ptrdiff_t yypred
;
988 /** First in a chain of alternative reductions producing the
989 * nonterminal corresponding to this state, threaded through
990 * yyfirstVal. Value "0" means empty. */
991 std::ptrdiff_t yyfirstVal
;
992 /** Semantic value for this state. */
994 };]b4_locations_if([[
995 // FIXME: Why public?
997 /** Source location for this state. */
998 location_type yyloc
;]])[
1000 ]b4_parse_assert_if([[
1002 // Check invariants.
1003 void check_ () const
1005 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1006 YYASSERT (this->magic_
== MAGIC
);
1007 YY_IGNORE_NULL_DEREFERENCE_END
1010 // A magic number to check our pointer arithmetic is sane.
1011 enum { MAGIC
= 713705 };
1012 unsigned int magic_
;]])[
1015 /** A stack of GLRState representing the different heads during
1016 * nondeterministic evaluation. */
1020 /** Initialize YYSET to a singleton set containing an empty stack. */
1022 : yylastDeleted (YY_NULLPTR
)
1024 yystates
.push_back (YY_NULLPTR
);
1025 yylookaheadNeeds
.push_back (false);
1028 // Behave like a vector of states.
1029 glr_state
*& operator[] (state_set_index index
)
1031 return yystates
[index
.uget()];
1034 glr_state
* operator[] (state_set_index index
) const
1036 return yystates
[index
.uget()];
1039 size_t size () const
1041 return yystates
.size ();
1044 std::vector
<glr_state
*>::iterator
begin ()
1046 return yystates
.begin ();
1049 std::vector
<glr_state
*>::iterator
end ()
1051 return yystates
.end ();
1054 bool lookaheadNeeds (state_set_index index
) const
1056 return yylookaheadNeeds
[index
.uget ()];
1059 bool setLookaheadNeeds (state_set_index index
, bool value
)
1061 return yylookaheadNeeds
[index
.uget ()] = value
;
1064 /** Invalidate stack #YYK. */
1066 yymarkStackDeleted (state_set_index yyk
)
1068 size_t k
= yyk
.uget ();
1069 if (yystates
[k
] != YY_NULLPTR
)
1070 yylastDeleted
= yystates
[k
];
1071 yystates
[k
] = YY_NULLPTR
;
1074 /** Undelete the last stack in *this that was marked as deleted. Can
1075 only be done once after a deletion, and only when all other stacks have
1078 yyundeleteLastStack ()
1080 if (yylastDeleted
== YY_NULLPTR
|| !yystates
.empty ())
1082 yystates
.push_back (yylastDeleted
);
1083 YYCDEBUG
<< "Restoring last deleted stack as stack #0.\n";
1084 clearLastDeleted ();
1087 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1092 size_t newsize
= yystates
.size ();
1093 /* j is the number of live stacks we have seen. */
1094 for (size_t i
= 0, j
= 0; j
< newsize
; ++i
)
1096 if (yystates
[i
] == YY_NULLPTR
)
1100 YYCDEBUG
<< "Removing dead stacks.\n";
1106 yystates
[j
] = yystates
[i
];
1107 /* In the current implementation, it's unnecessary to copy
1108 yylookaheadNeeds[i] since, after
1109 yyremoveDeletes returns, the parser immediately either enters
1110 deterministic operation or shifts a token. However, it doesn't
1111 hurt, and the code might evolve to need it. */
1112 yylookaheadNeeds
[j
] = yylookaheadNeeds
[i
];
1115 YYCDEBUG
<< "Rename stack " << i
<< " -> " << j
<< ".\n";
1120 yystates
.resize (newsize
);
1121 yylookaheadNeeds
.resize (newsize
);
1126 yysplitStack (state_set_index yyk
)
1128 const size_t k
= yyk
.uget ();
1129 yystates
.push_back (yystates
[k
]);
1130 yylookaheadNeeds
.push_back (yylookaheadNeeds
[k
]);
1131 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates
.size () - 1));
1134 void clearLastDeleted ()
1136 yylastDeleted
= YY_NULLPTR
;
1141 std::vector
<glr_state
*> yystates
;
1142 /** During nondeterministic operation, yylookaheadNeeds tracks which
1143 * stacks have actually needed the current lookahead. During deterministic
1144 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1145 * duplicate !yyla.empty (). */
1146 std::vector
<bool> yylookaheadNeeds
;
1148 /** The last stack we invalidated. */
1149 glr_state
* yylastDeleted
;
1154 class semantic_option
1157 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
1158 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type symbol_kind_type
;
1159 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1160 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1166 , yytoken (]b4_symbol(empty
, kind
)[)
1167 , yyval ()]b4_locations_if([[
1168 , yyloc ()]])[]b4_parse_assert_if([[
1169 , magic_ (MAGIC
)]])[
1172 semantic_option (rule_num rule
, symbol_kind_type token
)
1177 , yyval ()]b4_locations_if([[
1178 , yyloc ()]])[]b4_parse_assert_if([[
1179 , magic_ (MAGIC
)]])[
1182 semantic_option (const semantic_option
& that
)
1183 : yyrule (that
.yyrule
)
1184 , yystate (that
.yystate
)
1185 , yynext (that
.yynext
)
1186 , yytoken (that
.yytoken
)
1187 , yyval (]b4_variant_if([], [[that
.yyval
]])[)]b4_locations_if([[
1188 , yyloc (that
.yyloc
)]])[]b4_parse_assert_if([[
1189 , magic_ (MAGIC
)]])[
1190 {]b4_parse_assert_if([[
1191 that
.check_ ();]])[]b4_variant_if([[
1192 ]b4_symbol_variant([yytoken
],
1193 [yyval
], [copy
], [that
.yyval
])])[
1196 // Needed for the assignment in yynewSemanticOption.
1197 semantic_option
& operator= (const semantic_option
& that
)
1198 {]b4_parse_assert_if([[
1201 yyrule
= that
.yyrule
;
1202 yystate
= that
.yystate
;
1203 yynext
= that
.yynext
;
1204 yytoken
= that
.yytoken
;]b4_variant_if([[
1205 ]b4_symbol_variant([yytoken
],
1206 [yyval
], [copy
], [that
.yyval
])], [[
1207 yyval
= that
.yyval
;]])[]b4_locations_if([[
1208 yyloc
= that
.yyloc
;]])[
1212 /// Only call state() and setState() on objects in yyitems, not temporaries.
1214 const glr_state
* state() const;
1215 void setState(const glr_state
* s
);
1217 const semantic_option
* next () const YY_ATTRIBUTE_UNUSED
;
1218 semantic_option
* next ();
1219 void setNext (const semantic_option
* s
);
1221 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const YY_ATTRIBUTE_UNUSED
;
1223 /** True iff YYY0 and YYY1 represent identical options at the top level.
1224 * That is, they represent the same rule applied to RHS symbols
1225 * that produce the same terminal symbols. */
1227 isIdenticalTo (const semantic_option
& yyy1
) const
1228 {]b4_parse_assert_if([[
1231 if (this->yyrule
== yyy1
.yyrule
)
1233 const glr_state
*yys0
, *yys1
;
1235 for (yys0
= this->state(),
1236 yys1
= yyy1
.state(),
1237 yyn
= yyrhsLength (this->yyrule
);
1239 yys0
= yys0
->pred(),
1240 yys1
= yys1
->pred(), yyn
-= 1)
1241 if (yys0
->yyposn
!= yys1
->yyposn
)
1249 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1250 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1252 mergeWith (semantic_option
& yyy1
)
1253 {]b4_parse_assert_if([[
1256 glr_state
*yys0
= this->state ();
1257 glr_state
*yys1
= yyy1
.state ();
1258 for (int yyn
= yyrhsLength (this->yyrule
);
1260 yyn
-= 1, yys0
= yys0
->pred (), yys1
= yys1
->pred ())
1264 else if (yys0
->yyresolved
)
1266 yys1
->yyresolved
= true;]b4_variant_if([[
1267 YYASSERT (yys1
->yylrState
== yys0
->yylrState
);
1268 ]b4_symbol_variant([yy_accessing_symbol (yys0
->yylrState
)],
1269 [yys1
->value ()], [copy
], [yys0
->value ()])], [[
1270 yys1
->value () = yys0
->value ();]])[
1272 else if (yys1
->yyresolved
)
1274 yys0
->yyresolved
= true;]b4_variant_if([[
1275 YYASSERT (yys0
->yylrState
== yys1
->yylrState
);
1276 ]b4_symbol_variant([yy_accessing_symbol (yys1
->yylrState
)],
1277 [yys0
->value ()], [copy
], [yys1
->value ()])], [[
1278 yys0
->value () = yys1
->value ();]])[
1282 semantic_option
* yyz0prev
= YY_NULLPTR
;
1283 semantic_option
* yyz0
= yys0
->firstVal();
1284 semantic_option
* yyz1
= yys1
->firstVal();
1287 if (yyz1
== yyz0
|| yyz1
== YY_NULLPTR
)
1289 else if (yyz0
== YY_NULLPTR
)
1291 if (yyz0prev
!= YY_NULLPTR
)
1292 yyz0prev
->setNext (yyz1
);
1294 yys0
->setFirstVal (yyz1
);
1297 else if (yyz0
< yyz1
)
1299 semantic_option
* yyz
= yyz0
;
1300 if (yyz0prev
!= YY_NULLPTR
)
1301 yyz0prev
->setNext(yyz1
);
1303 yys0
->setFirstVal(yyz1
);
1304 yyz1
= yyz1
->next();
1308 yyz0
= yyz0
->next();
1310 yys1
->setFirstVal(yys0
->firstVal());
1315 #if ]b4_api_PREFIX[DEBUG
1316 void yyreportTree (size_t yyindent
= 2) const
1317 {]b4_parse_assert_if([[
1319 int yynrhs
= yyrhsLength (this->yyrule
);
1320 const glr_state
* yystates
[1 + YYMAXRHS
];
1321 glr_state yyleftmost_state
;
1324 const glr_state
* yys
= this->state();
1325 for (int yyi
= yynrhs
; 0 < yyi
; yyi
-= 1)
1327 yystates
[yyi
] = yys
;
1330 if (yys
== YY_NULLPTR
)
1332 yyleftmost_state
.yyposn
= 0;
1333 yystates
[0] = &yyleftmost_state
;
1339 std::string yylhs
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yylhsNonterm (this->yyrule
));
1340 YYASSERT(this->state());
1341 if (this->state()->yyposn
< yystates
[0]->yyposn
+ 1)
1342 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1343 << this->yyrule
- 1 << ", empty>\n";
1345 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1346 << this->yyrule
- 1 << ", tokens "
1347 << yystates
[0]->yyposn
+ 1 << " .. "
1348 << this->state()->yyposn
<< ">\n";
1349 for (int yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1351 if (yystates
[yyi
]->yyresolved
)
1353 std::string yysym
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yy_accessing_symbol (yystates
[yyi
]->yylrState
));
1354 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1355 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1358 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1359 << " <tokens " << yystates
[yyi
-1]->yyposn
+ 1
1360 << " .. " << yystates
[yyi
]->yyposn
<< ">\n";
1363 yystates
[yyi
]->firstVal ()->yyreportTree (yyindent
+2);
1368 /** Rule number for this reduction */
1372 template <typename T
>
1373 static const glr_stack_item
* asItem(const T
* state
)
1375 return reinterpret_cast<const glr_stack_item
*>(state
);
1377 template <typename T
>
1378 static glr_stack_item
* asItem(T
* state
)
1380 return reinterpret_cast<glr_stack_item
*>(state
);
1382 /** The last RHS state in the list of states to be reduced. */
1383 std::ptrdiff_t yystate
;
1384 /** Next sibling in chain of options. To facilitate merging,
1385 * options are chained in decreasing order by address. */
1386 std::ptrdiff_t yynext
;
1389 /** The lookahead for this reduction. */
1390 symbol_kind_type yytoken
;
1391 value_type yyval
;]b4_locations_if([[
1392 location_type yyloc
;]])[
1394 ]b4_parse_assert_if([[
1396 // Check invariants.
1397 void check_ () const
1399 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1400 YYASSERT (this->magic_
== MAGIC
);
1401 YY_IGNORE_NULL_DEREFERENCE_END
1404 // A magic number to check our pointer arithmetic is sane.
1405 enum { MAGIC
= 0xeff1cace };
1406 unsigned int magic_
;]])[
1410 /** Type of the items in the GLR stack.
1411 * It can be either a glr_state or a semantic_option. The is_state_ field
1412 * indicates which item of the union is valid. */
1413 class glr_stack_item
1416 glr_stack_item (bool state
= true)
1417 : is_state_ (state
)]b4_parse_assert_if([[
1418 , magic_ (MAGIC
)]])[
1421 new (&raw_
) glr_state
;
1423 new (&raw_
) semantic_option
;
1426 glr_stack_item (const glr_stack_item
& other
) YY_NOEXCEPT YY_NOTHROW
1427 : is_state_ (other
.is_state_
)]b4_parse_assert_if([[
1428 , magic_ (MAGIC
)]])[
1429 {]b4_parse_assert_if([[
1430 other
.check_ ();]])[
1431 std::memcpy (raw_
, other
.raw_
, union_size
);
1434 glr_stack_item
& operator= (glr_stack_item other
)
1435 {]b4_parse_assert_if([[
1437 other
.check_ ();]])[
1438 std::swap (is_state_
, other
.is_state_
);
1439 std::swap (raw_
, other
.raw_
);
1444 {]b4_parse_assert_if([[
1447 getState ().~glr_state ();
1449 getOption ().~semantic_option ();
1452 void setState (const glr_state
&state
)
1453 {]b4_parse_assert_if([[
1455 state
.check_ ();]])[
1456 if (this != state
.asItem ())
1459 getState ().~glr_state ();
1461 getOption ().~semantic_option ();
1462 new (&raw_
) glr_state (state
);
1467 glr_state
& getState ()
1468 {]b4_parse_assert_if([[
1470 YYDASSERT (is_state ());
1472 glr_state
& res
= *static_cast<glr_state
*> (yyp
);]b4_parse_assert_if([[
1477 const glr_state
& getState () const
1478 {]b4_parse_assert_if([[
1480 YYDASSERT (is_state ());
1481 const void *yyp
= raw_
;
1482 const glr_state
& res
= *static_cast<const glr_state
*> (yyp
);]b4_parse_assert_if([[
1487 semantic_option
& getOption ()
1488 {]b4_parse_assert_if([[
1490 YYDASSERT (!is_state ());
1492 return *static_cast<semantic_option
*> (yyp
);
1494 const semantic_option
& getOption () const
1495 {]b4_parse_assert_if([[
1497 YYDASSERT (!is_state ());
1498 const void *yyp
= raw_
;
1499 return *static_cast<const semantic_option
*> (yyp
);
1501 bool is_state () const
1502 {]b4_parse_assert_if([[
1508 /// The possible contents of raw_. Since they have constructors, they cannot
1509 /// be directly included in the union.
1512 char yystate
[sizeof (glr_state
)];
1513 char yyoption
[sizeof (semantic_option
)];
1515 enum { union_size
= sizeof (contents
) };
1517 /// Strongest alignment constraints.
1518 long double yyalign_me
;
1519 /// A buffer large enough to store the contents.
1520 char raw_
[union_size
];
1522 /** Type tag for the union. */
1524 ]b4_parse_assert_if([[
1526 // Check invariants.
1527 void check_ () const
1529 YYASSERT (this->magic_
== MAGIC
);
1530 YYASSERT (this->is_state_
== false || this->is_state_
== true);
1532 // A magic number to check our pointer arithmetic is sane.
1533 enum { MAGIC
= 0xDEAD1ACC }; // 3735886540.
1534 const unsigned int magic_
;]])[
1537 glr_state
* glr_state::pred ()
1538 {]b4_parse_assert_if([[
1540 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1541 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1542 YY_IGNORE_NULL_DEREFERENCE_END
1545 const glr_state
* glr_state::pred () const
1546 {]b4_parse_assert_if([[
1548 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1549 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1550 YY_IGNORE_NULL_DEREFERENCE_END
1553 void glr_state::setPred (const glr_state
* state
)
1554 {]b4_parse_assert_if([[
1557 state
->check_ ();]])[
1558 yypred
= state
? as_pointer_ (this) - as_pointer_ (state
) : 0;
1561 semantic_option
* glr_state::firstVal ()
1562 {]b4_parse_assert_if([[
1564 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1567 const semantic_option
* glr_state::firstVal () const
1568 {]b4_parse_assert_if([[
1570 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1573 void glr_state::setFirstVal (const semantic_option
* option
)
1574 {]b4_parse_assert_if([[
1576 yyfirstVal
= option
? asItem(this) - asItem(option
) : 0;
1579 std::ptrdiff_t glr_state::indexIn (const glr_stack_item
* array
) const
1580 {]b4_parse_assert_if([[
1582 return asItem(this) - array
;
1585 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item
* array
) const
1587 return asItem(this) - array
;
1590 glr_state
* semantic_option::state ()
1592 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1593 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1594 YY_IGNORE_NULL_DEREFERENCE_END
1597 const glr_state
* semantic_option::state () const
1599 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1602 void semantic_option::setState (const glr_state
* s
)
1604 yystate
= s
? asItem(this) - asItem(s
) : 0;
1607 const semantic_option
* semantic_option::next () const
1609 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1612 semantic_option
* semantic_option::next ()
1614 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1617 void semantic_option::setNext (const semantic_option
* s
)
1619 yynext
= s
? asItem(this) - asItem(s
) : 0;
1622 void glr_state::destroy (char const* yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[)
1623 {]b4_parse_assert_if([[
1626 yyparser
.yy_destroy_ (yymsg
, yy_accessing_symbol(yylrState
),
1627 value ()]b4_locations_if([, yyloc
])[);
1630 #if ]b4_api_PREFIX[DEBUG
1632 << (firstVal() ? " unresolved " : " incomplete ")
1633 << (yy_accessing_symbol (yylrState
) < YYNTOKENS
? "token" : "nterm")
1634 << ' ' << yyparser
.symbol_name (yy_accessing_symbol (yylrState
))
1635 << " ("]b4_locations_if([[
1636 << yyloc
<< ": "]])[
1639 if (firstVal() != YY_NULLPTR
)
1641 semantic_option
& yyoption
= *firstVal ();
1642 glr_state
*yyrh
= yyoption
.state ();
1643 for (int yyn
= yyrhsLength (yyoption
.yyrule
); yyn
> 0; yyn
-= 1)
1645 yyrh
->destroy (yymsg
, yyparser
]b4_user_args
[);
1646 yyrh
= yyrh
->pred();
1654 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1659 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind symbol_kind
;
1660 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1661 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1663 /** Initialize to a single empty stack, with total maximum
1664 * capacity for all stacks of YYSIZE. */
1665 state_stack (size_t yysize
)
1666 : yysplitPoint (YY_NULLPTR
)
1668 yyitems
.reserve (yysize
);
1671 #if YYSTACKEXPANDABLE
1672 /** Returns false if it tried to expand but could not. */
1674 yyexpandGLRStackIfNeeded ()
1676 return YYHEADROOM
<= spaceLeft () || yyexpandGLRStack ();
1680 /** If *this is expandable, extend it. WARNING: Pointers into the
1681 stack from outside should be considered invalid after this call.
1682 We always expand when there are 1 or fewer items left AFTER an
1683 allocation, so that we can avoid having external pointers exist
1684 across an allocation. */
1688 const size_t oldsize
= yyitems
.size();
1689 if (YYMAXDEPTH
- YYHEADROOM
< oldsize
)
1691 const size_t yynewSize
= YYMAXDEPTH
< 2 * oldsize
? YYMAXDEPTH
: 2 * oldsize
;
1692 const glr_stack_item
*oldbase
= &yyitems
[0];
1694 yyitems
.reserve (yynewSize
);
1695 const glr_stack_item
*newbase
= &yyitems
[0];
1697 // Adjust the pointers. Perform raw pointer arithmetic, as there
1698 // is no reason for objects to be aligned on their size.
1699 const ptrdiff_t disp
1700 = reinterpret_cast<const char*> (newbase
) - reinterpret_cast<const char*> (oldbase
);
1702 const_cast<glr_state
*&> (yysplitPoint
)
1703 = reinterpret_cast<glr_state
*> (reinterpret_cast<char*> (const_cast<glr_state
*> (yysplitPoint
)) + disp
);
1705 for (std::vector
<glr_state
*>::iterator
1706 i
= yytops
.begin (),
1707 yyend
= yytops
.end ();
1709 if (glr_state_not_null (*i
))
1710 *i
= reinterpret_cast<glr_state
*>(reinterpret_cast<char*>(*i
) + disp
);
1717 bool yyexpandGLRStackIfNeeded ()
1719 return YYHEADROOM
<= spaceLeft ();
1722 #undef YYSTACKEXPANDABLE
1724 static bool glr_state_not_null (glr_state
* s
)
1726 return s
!= YY_NULLPTR
;
1732 typedef std::vector
<glr_state
*>::iterator iterator
;
1733 const iterator yybegin
= yytops
.begin();
1734 const iterator yyend
= yytops
.end();
1735 const iterator yyit
= std::find_if(yybegin
, yyend
, glr_state_not_null
);
1738 for (state_set_index yyk
= create_state_set_index(yyit
+ 1 - yybegin
);
1739 yyk
.uget() != numTops(); ++yyk
)
1740 yytops
.yymarkStackDeleted (yyk
);
1741 yytops
.yyremoveDeletes ();
1746 /** Called when returning to deterministic operation to clean up the extra
1751 if (yytops
.size() != 1 || !isSplit())
1754 // yyr is the state after the split point.
1755 glr_state
* yyr
= YY_NULLPTR
;
1756 for (glr_state
*yyp
= firstTop(), *yyq
= yyp
->pred();
1757 yyp
!= yysplitPoint
;
1758 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->pred())
1761 // This const_cast is okay, since anyway we have access to the mutable
1762 // yyitems into which yysplitPoint points.
1763 glr_stack_item
* nextFreeItem
1764 = const_cast<glr_state
*> (yysplitPoint
)->asItem () + 1;
1765 yysplitPoint
= YY_NULLPTR
;
1766 yytops
.clearLastDeleted ();
1768 while (yyr
!= YY_NULLPTR
)
1770 nextFreeItem
->setState (*yyr
);
1771 glr_state
& nextFreeState
= nextFreeItem
->getState();
1773 nextFreeState
.setPred(&(nextFreeItem
- 1)->getState());
1774 setFirstTop (&nextFreeState
);
1777 yyitems
.resize(static_cast<size_t>(nextFreeItem
- yyitems
.data()));
1780 bool isSplit() const {
1781 return yysplitPoint
!= YY_NULLPTR
;
1784 // Present the interface of a vector of glr_stack_item.
1785 std::vector
<glr_stack_item
>::const_iterator
begin () const
1787 return yyitems
.begin ();
1790 std::vector
<glr_stack_item
>::const_iterator
end () const
1792 return yyitems
.end ();
1797 return yyitems
.size ();
1800 glr_stack_item
& operator[] (size_t i
)
1805 glr_stack_item
& stackItemAt (size_t index
)
1807 return yyitems
[index
];
1810 size_t numTops () const
1812 return yytops
.size ();
1815 glr_state
* firstTop () const
1817 return yytops
[create_state_set_index (0)];
1820 glr_state
* topAt (state_set_index i
) const
1825 void setFirstTop (glr_state
* value
)
1827 yytops
[create_state_set_index (0)] = value
;
1830 void setTopAt (state_set_index i
, glr_state
* value
)
1837 yyitems
.pop_back ();
1840 void pop_back (size_t n
)
1842 yyitems
.resize (yyitems
.size () - n
);
1846 yysplitStack (state_set_index yyk
)
1850 YYASSERT (yyk
.get () == 0);
1851 yysplitPoint
= topAt (yyk
);
1853 return yytops
.yysplitStack (yyk
);
1856 /** Assuming that YYS is a GLRState somewhere on *this, update the
1857 * splitpoint of *this, if needed, so that it is at least as deep as
1860 yyupdateSplit (glr_state
& yys
)
1862 if (isSplit() && &yys
< yysplitPoint
)
1863 yysplitPoint
= &yys
;
1866 /** Return a fresh GLRState.
1867 * Callers should call yyreserveStack afterwards to make sure there is
1868 * sufficient headroom. */
1869 glr_state
& yynewGLRState (const glr_state
& newState
)
1871 glr_state
& state
= yyitems
[yynewGLRStackItem (true)].getState ();
1872 #if false && 201103L <= YY_CPLUSPLUS
1873 state
= std::move (newState
);
1880 /** Return a fresh SemanticOption.
1881 * Callers should call yyreserveStack afterwards to make sure there is
1882 * sufficient headroom. */
1883 semantic_option
& yynewSemanticOption (semantic_option newOption
)
1885 semantic_option
& option
= yyitems
[yynewGLRStackItem (false)].getOption ();
1886 #if 201103L <= YY_CPLUSPLUS
1887 option
= std::move (newOption
);
1894 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1895 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1896 * For convenience, always return YYLOW1. */
1898 yyfill (glr_stack_item
*yyvsp
, int &yylow
, int yylow1
, bool yynormal
)
1900 if (!yynormal
&& yylow1
< yylow
)
1902 yyfillin (yyvsp
, yylow
, yylow1
);
1908 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1909 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1910 * containing the pointer to the next state in the chain. */
1912 yyfillin (glr_stack_item
*yyvsp
, int yylow0
, int yylow1
)
1914 glr_state
* s
= yyvsp
[yylow0
].getState().pred();
1915 YYASSERT(s
!= YY_NULLPTR
);
1916 for (int i
= yylow0
-1; i
>= yylow1
; i
-= 1, s
= s
->pred())
1918 glr_state
& yys
= yyvsp
[i
].getState();
1919 #if ]b4_api_PREFIX[DEBUG
1920 yys
.yylrState
= s
->yylrState
;
1922 yys
.yyresolved
= s
->yyresolved
;
1925 new (&yys
.value ()) value_type ();
1926 ]b4_symbol_variant([yy_accessing_symbol (s
->yylrState
)],
1927 [yys
.value ()], [copy
], [s
->value ()])], [[
1928 new (&yys
.value ()) value_type (s
->value ());]])[
1931 /* The effect of using yyval or yyloc (in an immediate
1932 * rule) is undefined. */
1933 yys
.setFirstVal (YY_NULLPTR
);]b4_locations_if([[
1934 yys
.yyloc
= s
->yyloc
;]])[
1935 yys
.setPred(s
->pred());
1939 #if ]b4_api_PREFIX[DEBUG
1941 /*----------------------------------------------------------------------.
1942 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1943 `----------------------------------------------------------------------*/
1946 yy_reduce_print (bool yynormal
, glr_stack_item
* yyvsp
, state_set_index yyk
,
1947 rule_num yyrule
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
)
1949 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1952 std::cerr
<< "Reducing stack " << yyk
.get() << " by rule " << yyrule
- 1
1953 << " (line " << int (yyrline
[yyrule
]) << "):\n";
1955 yyfillin (yyvsp
, 1, -yynrhs
);
1956 /* The symbols being reduced. */
1957 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1959 std::cerr
<< " $" << yyi
+ 1 << " = ";
1960 yyparser
.yy_symbol_print_
1961 (yy_accessing_symbol (yyvsp
[yyi
- yynrhs
+ 1].getState().yylrState
),
1962 yyvsp
[yyi
- yynrhs
+ 1].getState().value ()]b4_locations_if([[,
1963 ]b4_rhs_location(yynrhs
, yyi
+ 1)])[);
1964 if (!yyvsp
[yyi
- yynrhs
+ 1].getState().yyresolved
)
1965 std::cerr
<< " (unresolved)";
1971 #define YYINDEX(YYX) \
1972 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1977 for (size_t yyi
= 0; yyi
< size(); ++yyi
)
1979 const glr_stack_item
& item
= yyitems
[yyi
];
1980 std::cerr
<< std::setw(3) << yyi
<< ". ";
1981 if (item
.is_state())
1983 std::cerr
<< "Res: " << item
.getState().yyresolved
1984 << ", LR State: " << item
.getState().yylrState
1985 << ", posn: " << item
.getState().yyposn
1986 << ", pred: " << YYINDEX(item
.getState().pred());
1987 if (! item
.getState().yyresolved
)
1988 std::cerr
<< ", firstVal: "
1989 << YYINDEX(item
.getState().firstVal());
1993 std::cerr
<< "Option. rule: " << item
.getOption().yyrule
- 1
1994 << ", state: " << YYINDEX(item
.getOption().state())
1995 << ", next: " << YYINDEX(item
.getOption().next());
1999 std::cerr
<< "Tops:";
2000 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < numTops(); ++yyi
) {
2001 std::cerr
<< yyi
.get() << ": " << YYINDEX(topAt(yyi
)) << "; ";
2010 yyreportAmbiguity (const semantic_option
& yyx0
,
2011 const semantic_option
& yyx1
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_locations_if([, const location_type
& yyloc
])[)
2016 #if ]b4_api_PREFIX[DEBUG
2017 std::cerr
<< "Ambiguity detected.\n"
2019 yyx0
.yyreportTree ();
2020 std::cerr
<< "\nOption 2,\n";
2021 yyx1
.yyreportTree ();
2025 yyparser
.error (]b4_locations_if([yyloc
, ])[YY_("syntax is ambiguous"));
2029 /* DEBUGGING ONLY */
2030 #if ]b4_api_PREFIX[DEBUG
2031 /* Print YYS (possibly NULL) and its predecessors. */
2033 yypstates (const glr_state
* yys
) const
2035 if (yys
!= YY_NULLPTR
)
2038 std::cerr
<< "<null>";
2044 size_t spaceLeft() const
2046 return yyitems
.capacity() - yyitems
.size();
2049 /** Return a fresh GLRStackItem in this. The item is an LR state
2050 * if YYIS_STATE, and otherwise a semantic option. Callers should call
2051 * yyreserveStack afterwards to make sure there is sufficient
2054 yynewGLRStackItem (bool yyis_state
)
2056 YYDASSERT(yyitems
.size() < yyitems
.capacity());
2057 yyitems
.push_back(glr_stack_item(yyis_state
));
2058 return yyitems
.size() - 1;
2064 std::vector
<glr_stack_item
> yyitems
;
2065 // Where the stack splits. Anything below this address is deterministic.
2066 const glr_state
* yysplitPoint
;
2067 glr_state_set yytops
;
2071 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
2076 typedef ]b4_namespace_ref
[::]b4_parser_class
[ parser_type
;
2077 typedef parser_type::symbol_kind symbol_kind
;
2078 typedef parser_type::symbol_kind_type symbol_kind_type
;
2079 typedef parser_type::symbol_type symbol_type
;
2080 typedef parser_type::value_type value_type
;]b4_locations_if([[
2081 typedef parser_type::location_type location_type
;]])[
2083 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
2084 typedef parser_type::context context
;
2085 // Needs access to yypact_value_is_default, etc.
2089 glr_stack (size_t yysize
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser_yyarg
]m4_ifset([b4_parse_param
], [, b4_parse_param_decl
])[)
2091 , yystateStack (yysize
)
2094 , yyparser (yyparser_yyarg
)]m4_ifset([b4_parse_param
], [,b4_parse_param_cons
])[
2099 if (!this->yyla
.empty ())
2100 yyparser
.yy_destroy_ ("Cleanup: discarding lookahead",
2101 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2106 ]b4_locations_if([[ /* To compute the location of the error token. */
2107 glr_stack_item yyerror_range
[3];]])[
2108 state_stack yystateStack
;
2111 YYJMP_BUF yyexception_buffer
;
2112 ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
;
2114 #define YYCHK1(YYE) \
2124 goto yyuser_error; \
2136 YYCDEBUG
<< "Starting parse\n";
2138 this->yyla
.clear ();
2139 ]m4_ifdef([b4_initial_action
], [
2140 b4_dollar_pushdef([yyla
.value
], [], [], [yyla
.location
])dnl
2141 b4_user_initial_action
2142 b4_dollar_popdef
])[]dnl
2144 switch (YYSETJMP (this->yyexception_buffer
))
2147 case 1: goto yyabortlab
;
2148 case 2: goto yyexhaustedlab
;
2149 default: goto yybuglab
;
2151 this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2156 /* For efficiency, we have two loops, the first of which is
2157 specialized to deterministic operation (single stack, no
2158 potential ambiguity). */
2162 const state_num yystate
= this->firstTopState()->yylrState
;
2163 YYCDEBUG
<< "Entering state " << yystate
<< '\n';
2164 if (yystate
== YYFINAL
)
2166 if (yy_is_defaulted_state (yystate
))
2168 const rule_num yyrule
= yy_default_action (yystate
);
2170 {]b4_locations_if([[
2171 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2172 this->yyreportSyntaxError ();
2175 YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule
, true));
2180 const short* yyconflicts
;
2181 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2182 if (*yyconflicts
!= 0)
2184 if (yy_is_shift_action (yyaction
))
2186 YY_SYMBOL_PRINT ("Shifting", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
2188 // FIXME: we should move yylval.
2189 this->yyglrShift (create_state_set_index(0), yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2191 if (0 < this->yyerrState
)
2192 this->yyerrState
-= 1;
2194 else if (yy_is_error_action (yyaction
))
2195 {]b4_locations_if([[
2196 this->yyerror_range
[1].getState().yyloc
= this->yyla
.location
;]])[
2197 /* Don't issue an error message again for exceptions
2198 thrown from the scanner. */
2199 if (this->yyla
.kind () != ]b4_symbol(error
, kind
)[)
2200 this->yyreportSyntaxError ();
2204 YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction
, true));
2210 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < this->yystateStack
.numTops(); ++yys
)
2211 this->yystateStack
.yytops
.setLookaheadNeeds(yys
, !this->yyla
.empty ());
2213 /* yyprocessOneStack returns one of three things:
2215 - An error flag. If the caller is yyprocessOneStack, it
2216 immediately returns as well. When the caller is finally
2217 yyparse, it jumps to an error label via YYCHK1.
2219 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2220 (yys), which sets the top state of yys to NULL. Thus,
2221 yyparse's following invocation of yyremoveDeletes will remove
2224 - yyok, when ready to shift a token.
2226 Except in the first case, yyparse will invoke yyremoveDeletes and
2227 then shift the next token onto all remaining stacks. This
2228 synchronization of the shift (that is, after all preceding
2229 reductions on all stacks) helps prevent double destructor calls
2230 on yylval in the event of memory exhaustion. */
2232 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2233 YYCHK1 (this->yyprocessOneStack (yys
, yyposn
]b4_locations_if([, &this->yyla
.location
])[));
2234 this->yystateStack
.yytops
.yyremoveDeletes ();
2235 if (this->yystateStack
.yytops
.size() == 0)
2237 this->yystateStack
.yytops
.yyundeleteLastStack ();
2238 if (this->yystateStack
.yytops
.size() == 0)
2239 this->yyFail (]b4_locations_if([&this->yyla
.location
, ])[YY_("syntax error"));
2240 YYCHK1 (this->yyresolveStack ());
2241 YYCDEBUG
<< "Returning to deterministic operation.\n";]b4_locations_if([[
2242 this->yyerror_range
[1].getState ().yyloc
= this->yyla
.location
;]])[
2243 this->yyreportSyntaxError ();
2247 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2248 a copy of yylval will already be on stack 0 in the event of a
2249 failure in the following loop. Thus, yyla is emptied
2250 before the loop to make sure the user destructor for yylval isn't
2252 yysymbol_kind_t yytoken_to_shift
= this->yyla
.kind ();
2253 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2255 for (state_set_index yys
= create_state_set_index (0); yys
.uget () < this->yystateStack
.numTops (); ++yys
)
2257 const state_num yystate
= this->topState (yys
)->yylrState
;
2258 const short* yyconflicts
;
2259 const int yyaction
= yygetLRActions (yystate
, yytoken_to_shift
, yyconflicts
);
2260 /* Note that yyconflicts were handled by yyprocessOneStack. */
2261 YYCDEBUG
<< "On stack " << yys
.get() << ", ";
2262 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, this->yyla
.value
, this->yyla
.location
);
2263 this->yyglrShift (yys
, yyaction
, yyposn
, this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);
2264 YYCDEBUG
<< "Stack " << yys
.get() << " now in state "
2265 << this->topState(yys
)->yylrState
<< '\n';
2268 // FIXME: User destructors.
2269 // Value type destructor.
2270 ]b4_symbol_variant([[yytoken_to_shift
]], [[this->yyla
.value
]], [[template destroy
]])])[
2272 if (this->yystateStack
.yytops
.size () == 1)
2274 YYCHK1 (this->yyresolveStack ());
2275 YYCDEBUG
<< "Returning to deterministic operation.\n";
2276 this->yystateStack
.yycompressStack ();
2282 this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla
.location
])[);
2283 yyposn
= this->firstTopState()->yyposn
;
2299 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[YY_("memory exhausted"));
2308 void yyreserveGlrStack ()
2310 if (!yystateStack
.yyexpandGLRStackIfNeeded ())
2311 yyMemoryExhausted ();
2315 yyMemoryExhausted ()
2317 YYLONGJMP (yyexception_buffer
, 2);
2321 yyFail (]b4_locations_if([location_type
* yylocp
, ])[const char* yymsg
)
2323 if (yymsg
!= YY_NULLPTR
)
2324 yyparser
.error (]b4_locations_if([*yylocp
, ])[yymsg
);
2325 YYLONGJMP (yyexception_buffer
, 1);
2331 /** Add a new semantic action that will execute the action for rule
2332 * YYRULE on the semantic values in YYRHS to the list of
2333 * alternative actions for YYSTATE. Assumes that YYRHS comes from
2334 * stack #YYK of *this. */
2336 yyaddDeferredAction (state_set_index yyk
, glr_state
* yystate
,
2337 glr_state
* yyrhs
, rule_num yyrule
)
2339 semantic_option
& yynewOption
=
2340 yystateStack
.yynewSemanticOption(semantic_option(yyrule
, ]b4_symbol(empty
, kind
)[));
2341 yynewOption
.setState(yyrhs
);
2342 yynewOption
.setNext(yystate
->firstVal());
2343 if (yystateStack
.yytops
.lookaheadNeeds(yyk
))
2345 yynewOption
.yytoken
= this->yyla
.kind ();]b4_variant_if([[
2346 ]b4_symbol_variant([this->yyla
.kind ()],
2347 [yynewOption
.yyval
], [copy
], [this->yyla
.value
])], [[
2348 yynewOption
.yyval
= this->yyla
.value
;]])[]b4_locations_if([
2349 yynewOption
.yyloc
= this->yyla
.location
;])[
2351 yystate
->setFirstVal (&yynewOption
);
2353 yyreserveGlrStack ();
2356 #if ]b4_api_PREFIX[DEBUG
2357 void yypdumpstack () const
2359 yystateStack
.dumpStack();
2364 yyreportSyntaxError ()
2366 if (yyerrState
!= 0)
2368 ]b4_parse_error_case(
2370 std::string msg
= YY_("syntax error");
2371 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]],
2373 context
yyctx (*this, yyla
);
2374 yyparser
.report_syntax_error (yyctx
);]],
2376 context
yyctx (*this, yyla
);
2377 std::string msg
= yyparser
.yysyntax_error_ (yyctx
);
2378 yyparser
.error (]b4_join(b4_locations_if([yyla
.location
]), [[YY_MOVE (msg
)]])[);]])[
2382 /* Recover from a syntax error on this, assuming that yytoken,
2383 yylval, and yylloc are the syntactic category, semantic value, and location
2384 of the lookahead. */
2386 yyrecoverSyntaxError (]b4_locations_if([location_type
* yylocp
])[)
2388 if (yyerrState
== 3)
2389 /* We just shifted the error token and (perhaps) took some
2390 reductions. Skip tokens until we can proceed. */
2393 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
2394 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2395 if (this->yyla
.kind () != ]b4_symbol(empty
, kind
)[)
2396 {]b4_locations_if([[
2397 /* We throw away the lookahead, but the error range
2398 of the shifted error token must take it into account. */
2399 glr_state
*yys
= firstTopState();
2400 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;
2401 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2402 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2403 yyparser
.yy_destroy_ ("Error: discarding",
2404 this->yyla
.kind (), this->yyla
.value
]b4_locations_if([, this->yyla
.location
])[);]b4_variant_if([[
2405 // Value type destructor.
2406 ]b4_symbol_variant([[this->yyla
.kind ()]], [[this->yyla
.value
]], [[template destroy
]])])[
2407 this->yyla
.kind_
= ]b4_symbol(empty
, kind
)[;
2410 int yyj
= yypact
[firstTopState()->yylrState
];
2411 if (yypact_value_is_default (yyj
))
2413 yyj
+= this->yyla
.kind ();
2414 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != this->yyla
.kind ())
2416 if (yydefact
[firstTopState()->yylrState
] != 0)
2419 else if (! yytable_value_is_error (yytable
[yyj
]))
2423 if (!yystateStack
.reduceToOneStack())
2424 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2426 /* Now pop stack until we find a state that shifts the error token. */
2428 while (firstTopState () != YY_NULLPTR
)
2430 glr_state
*yys
= firstTopState ();
2431 int yyj
= yypact
[yys
->yylrState
];
2432 if (! yypact_value_is_default (yyj
))
2435 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2436 && yy_is_shift_action (yytable
[yyj
]))
2438 /* Shift the error token. */]b4_locations_if([[
2439 /* First adjust its location.*/
2440 location_type yyerrloc
;
2441 yyerror_range
[2].getState().yyloc
= this->yyla
.location
;
2442 YYLLOC_DEFAULT (yyerrloc
, (yyerror_range
), 2);]])[
2443 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable
[yyj
]),
2444 this->yyla
.value
, yyerrloc
);
2445 yyglrShift (create_state_set_index(0), yytable
[yyj
],
2446 yys
->yyposn
, yyla
.value
]b4_locations_if([, yyerrloc
])[);
2447 yys
= firstTopState();
2450 }]b4_locations_if([[
2451 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;]])[
2452 if (yys
->pred() != YY_NULLPTR
)
2453 yys
->destroy ("Error: popping", yyparser
]b4_user_args
[);
2454 yystateStack
.setFirstTop(yys
->pred());
2455 yystateStack
.pop_back();
2457 if (firstTopState() == YY_NULLPTR
)
2458 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2462 yyprocessOneStack (state_set_index yyk
,
2463 size_t yyposn
]b4_locations_if([, location_type
* yylocp
])[)
2465 while (yystateStack
.topAt(yyk
) != YY_NULLPTR
)
2467 const state_num yystate
= topState(yyk
)->yylrState
;
2468 YYCDEBUG
<< "Stack " << yyk
.get()
2469 << " Entering state " << yystate
<< '\n';
2471 YYASSERT (yystate
!= YYFINAL
);
2473 if (yy_is_defaulted_state (yystate
))
2475 const rule_num yyrule
= yy_default_action (yystate
);
2478 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2479 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2482 const YYRESULTTAG yyflag
2483 = yyglrReduce (yyk
, yyrule
, yyimmediate
[yyrule
]);
2484 if (yyflag
== yyerr
)
2486 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2487 " (predicate failure or explicit user error).\n";
2488 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2496 yystateStack
.yytops
.setLookaheadNeeds(yyk
, true);
2498 const short* yyconflicts
;
2499 const int yyaction
= yygetLRActions (yystate
, this->yyla
.kind (), yyconflicts
);
2501 for (; *yyconflicts
!= 0; ++yyconflicts
)
2503 state_set_index yynewStack
= yystateStack
.yysplitStack (yyk
);
2504 YYCDEBUG
<< "Splitting off stack " << yynewStack
.get()
2505 << " from " << yyk
.get() << ".\n";
2506 YYRESULTTAG yyflag
=
2507 yyglrReduce (yynewStack
, *yyconflicts
, yyimmediate
[*yyconflicts
]);
2509 YYCHK (yyprocessOneStack (yynewStack
,
2510 yyposn
]b4_locations_if([, yylocp
])[));
2511 else if (yyflag
== yyerr
)
2513 YYCDEBUG
<< "Stack " << yynewStack
.get() << " dies.\n";
2514 yystateStack
.yytops
.yymarkStackDeleted (yynewStack
);
2520 if (yy_is_shift_action (yyaction
))
2522 else if (yy_is_error_action (yyaction
))
2524 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2525 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2531 = yyglrReduce (yyk
, -yyaction
, yyimmediate
[-yyaction
]);
2532 if (yyflag
== yyerr
)
2534 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2535 " (predicate failure or explicit user error).\n";
2536 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2539 else if (yyflag
!= yyok
)
2547 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2548 * and top stack item YYVSP. YYVALP points to place to put semantic
2549 * value ($$), and yylocp points to place for location information
2550 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2551 * yyerr for YYERROR, yyabort for YYABORT. */
2553 yyuserAction (rule_num yyrule
, int yyrhslen
, glr_stack_item
* yyvsp
, state_set_index yyk
,
2554 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2556 bool yynormal YY_ATTRIBUTE_UNUSED
= !yystateStack
.isSplit();
2558 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
2562 # define yyerrok (yyerrState = 0)
2564 # define YYACCEPT return yyaccept
2566 # define YYABORT return yyabort
2568 # define YYERROR return yyerrok, yyerr
2569 # undef YYRECOVERING
2570 # define YYRECOVERING() (yyerrState != 0)
2572 # define yytoken this->yyla.kind_
2574 # define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
2576 # define YYBACKUP(Token, Value) \
2577 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2581 /* Variants are always initialized to an empty instance of the
2582 correct type. The default '$$ = $1' action is NOT applied
2583 when using variants. */
2584 // However we really need to prepare yyvsp now if we want to get
2585 // correct locations, so invoke YYFILL for $1 anyway.
2586 (void) YYFILL (1-yyrhslen
);
2587 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [(*yyvalp
)], [emplace
])], [[
2589 *yyvalp
= yyval_default
;
2591 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].getState().value ();]])[]b4_locations_if([[
2592 /* Default location. */
2593 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
2594 yyerror_range
[1].getState().yyloc
= *yylocp
;
2596 /* If yyk == -1, we are running a deferred action on a temporary
2597 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2598 so pretend the stack is "normal". */
2599 YY_REDUCE_PRINT ((yynormal
|| yyk
== create_state_set_index (-1), yyvsp
, yyk
, yyrule
, yyparser
));
2601 typedef ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error syntax_error
;
2604 #endif // YY_EXCEPTIONS
2612 catch (const syntax_error
& yyexc
)
2614 YYCDEBUG
<< "Caught exception: " << yyexc
.what() << '\n';]b4_locations_if([
2615 *yylocp
= yyexc
.location
;])[
2616 yyparser
.error (]b4_locations_if([*yylocp
, ])[yyexc
.what ());
2619 #endif // YY_EXCEPTIONS
2620 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule
), *yyvalp
, *yylocp
);
2630 # undef YYRECOVERING
2636 if (yystateStack
.isSplit ())
2639 for (glr_state
* yys
= firstTopState ();
2640 yys
!= yystateStack
.yysplitPoint
;
2643 YYCHK (yyresolveStates (*firstTopState (), yyn
));
2648 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2649 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2650 * semantic values. Assumes that all ambiguities in semantic values
2651 * have been previously resolved. Set *YYVALP to the resulting value,
2652 * and *YYLOCP to the computed location (if any). Return value is as
2653 * for userAction. */
2655 yydoAction (state_set_index yyk
, rule_num yyrule
,
2656 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2658 const int yynrhs
= yyrhsLength (yyrule
);
2660 if (!yystateStack
.isSplit())
2662 /* Standard special case: single stack. */
2663 YYASSERT (yyk
.get() == 0);
2664 glr_stack_item
* yyrhs
= yystateStack
.firstTop()->asItem();
2665 const YYRESULTTAG res
2666 = yyuserAction (yyrule
, yynrhs
, yyrhs
, yyk
, yyvalp
]b4_locations_if([, yylocp
])[);
2667 yystateStack
.pop_back(static_cast<size_t>(yynrhs
));
2668 yystateStack
.setFirstTop(&yystateStack
[yystateStack
.size() - 1].getState());
2673 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2674 glr_state
* yys
= yystateStack
.topAt(yyk
);
2675 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yys
);]b4_locations_if([[
2677 /* Set default location. */
2678 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yys
->yyloc
;]])[
2679 for (int yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
2682 YYASSERT (yys
!= YY_NULLPTR
);
2684 yystateStack
.yyupdateSplit (*yys
);
2685 yystateStack
.setTopAt(yyk
, yys
);
2686 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2688 yyvalp
]b4_locations_if([, yylocp
])[);
2692 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2693 * and push back on the resulting nonterminal symbol. Perform the
2694 * semantic action associated with YYRULE and store its value with the
2695 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2696 * unambiguous. Otherwise, store the deferred semantic action with
2697 * the new state. If the new state would have an identical input
2698 * position, LR state, and predecessor to an existing state on the stack,
2699 * it is identified with that existing state, eliminating stack #YYK from
2700 * *YYSTACKP. In this case, the semantic value is
2701 * added to the options for the existing state's semantic value.
2704 yyglrReduce (state_set_index yyk
, rule_num yyrule
, bool yyforceEval
)
2706 size_t yyposn
= topState(yyk
)->yyposn
;
2708 if (yyforceEval
|| !yystateStack
.isSplit())
2710 value_type val
;]b4_locations_if([[
2711 location_type loc
;]])[
2713 YYRESULTTAG yyflag
= yydoAction (yyk
, yyrule
, &val
]b4_locations_if([, &loc
])[);
2714 if (yyflag
== yyerr
&& yystateStack
.isSplit())
2715 {]b4_parse_trace_if([[
2716 YYCDEBUG
<< "Parse on stack " << yyk
.get ()
2717 << " rejected by rule " << yyrule
- 1
2718 << " (line " << int (yyrline
[yyrule
]) << ").\n";
2723 yyLRgotoState (topState(yyk
)->yylrState
,
2724 yylhsNonterm (yyrule
)),
2725 yyposn
, val
]b4_locations_if([, loc
])[);]b4_variant_if([[
2726 // FIXME: User destructors.
2727 // Value type destructor.
2728 ]b4_symbol_variant([[yylhsNonterm (yyrule
)]], [[val
]], [[template destroy
]])])[
2732 glr_state
*yys
= yystateStack
.topAt(yyk
);
2733 glr_state
*yys0
= yys
;
2734 for (int yyn
= yyrhsLength (yyrule
); 0 < yyn
; yyn
-= 1)
2737 YYASSERT (yys
!= YY_NULLPTR
);
2739 yystateStack
.yyupdateSplit (*yys
);
2740 state_num yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));]b4_parse_trace_if([[
2741 YYCDEBUG
<< "Reduced stack " << yyk
.get ()
2742 << " by rule " << yyrule
- 1 << " (line " << int (yyrline
[yyrule
])
2743 << "); action deferred. Now in state " << yynewLRState
2745 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < yystateStack
.numTops(); ++yyi
)
2746 if (yyi
!= yyk
&& yystateStack
.topAt(yyi
) != YY_NULLPTR
)
2748 const glr_state
* yysplit
= yystateStack
.yysplitPoint
;
2749 glr_state
* yyp
= yystateStack
.topAt(yyi
);
2750 while (yyp
!= yys
&& yyp
!= yysplit
2751 && yyp
->yyposn
>= yyposn
)
2753 if (yyp
->yylrState
== yynewLRState
2754 && yyp
->pred() == yys
)
2756 yyaddDeferredAction (yyk
, yyp
, yys0
, yyrule
);
2757 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2758 YYCDEBUG
<< "Merging stack " << yyk
.get ()
2759 << " into stack " << yyi
.get () << ".\n";
2765 yystateStack
.setTopAt(yyk
, yys
);
2766 yyglrShiftDefer (yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
2771 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2772 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2773 * semantic value of YYRHS under the action for YYRULE. */
2775 yyglrShiftDefer (state_set_index yyk
, state_num yylrState
,
2776 size_t yyposn
, glr_state
* yyrhs
, rule_num yyrule
)
2778 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2779 glr_state (yylrState
, yyposn
));
2780 yynewState
.setPred (yystateStack
.topAt (yyk
));
2781 yystateStack
.setTopAt (yyk
, &yynewState
);
2783 /* Invokes yyreserveStack. */
2784 yyaddDeferredAction (yyk
, &yynewState
, yyrhs
, yyrule
);
2787 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2788 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2789 * value YYVAL_ARG and source location YYLOC_ARG. */
2791 yyglrShift (state_set_index yyk
, state_num yylrState
,
2793 const value_type
& yyval_arg
]b4_locations_if([, const location_type
& yyloc_arg
])[)
2795 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2796 glr_state (yylrState
, yyposn
, yyval_arg
]b4_locations_if([, yyloc_arg
])[));
2797 yynewState
.setPred (yystateStack
.topAt(yyk
));
2798 yystateStack
.setTopAt (yyk
, &yynewState
);
2799 yyreserveGlrStack ();
2802 #if ]b4_api_PREFIX[DEBUG
2804 yypstack (state_set_index yyk
) const
2806 yystateStack
.yypstates (yystateStack
.topAt (yyk
));
2810 glr_state
* topState(state_set_index i
) {
2811 return yystateStack
.topAt(i
);
2814 glr_state
* firstTopState() {
2815 return yystateStack
.firstTop();
2822 /* If the stack is well-formed, pop the stack until it is empty,
2823 destroying its entries as we go. But free the stack regardless
2824 of whether it is well-formed. */
2825 for (state_set_index k
= create_state_set_index(0); k
.uget() < yystateStack
.numTops(); k
+= 1)
2826 if (yystateStack
.topAt(k
) != YY_NULLPTR
)
2828 while (yystateStack
.topAt(k
) != YY_NULLPTR
)
2830 glr_state
* state
= topState(k
);]b4_locations_if([[
2831 yyerror_range
[1].getState().yyloc
= state
->yyloc
;]])[
2832 if (state
->pred() != YY_NULLPTR
)
2833 state
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
2834 yystateStack
.setTopAt(k
, state
->pred());
2835 yystateStack
.pop_back();
2841 /** Resolve the previous YYN states starting at and including state YYS
2842 * on *YYSTACKP. If result != yyok, some states may have been left
2843 * unresolved possibly with empty semantic option chains. Regardless
2844 * of whether result = yyok, each state has been left with consistent
2845 * data so that destroy can be invoked if necessary. */
2847 yyresolveStates (glr_state
& yys
, int yyn
)
2851 YYASSERT (yys
.pred() != YY_NULLPTR
);
2852 YYCHK (yyresolveStates (*yys
.pred(), yyn
-1));
2853 if (! yys
.yyresolved
)
2854 YYCHK (yyresolveValue (yys
));
2860 yyuserMerge (int yyn
, value_type
& yy0
, value_type
& yy1
)
2872 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2873 * perform the indicated actions, and set the semantic value of YYS.
2874 * If result != yyok, the chain of semantic options in YYS has been
2875 * cleared instead or it has been left unmodified except that
2876 * redundant options may have been removed. Regardless of whether
2877 * result = yyok, YYS has been left with consistent data so that
2878 * destroy can be invoked if necessary. */
2880 yyresolveValue (glr_state
& yys
)
2882 semantic_option
* yybest
= yys
.firstVal();
2883 YYASSERT(yybest
!= YY_NULLPTR
);
2884 bool yymerge
= false;
2885 YYRESULTTAG yyflag
;]b4_locations_if([
2886 location_type
*yylocp
= &yys
.yyloc
;])[
2888 semantic_option
* yypPrev
= yybest
;
2889 for (semantic_option
* yyp
= yybest
->next();
2890 yyp
!= YY_NULLPTR
; )
2892 if (yybest
->isIdenticalTo (*yyp
))
2894 yybest
->mergeWith (*yyp
);
2895 yypPrev
->setNext(yyp
->next());
2896 yyp
= yypPrev
->next();
2900 switch (yypreference (*yybest
, *yyp
))
2902 case 0:]b4_locations_if([[
2903 yyresolveLocations (yys
, 1);]])[
2904 return yystateStack
.yyreportAmbiguity (*yybest
, *yyp
, yyparser
]b4_locations_if([, *yylocp
])[);
2916 /* This cannot happen so it is not worth a YYASSERT (false),
2917 but some compilers complain if the default case is
2929 int yyprec
= yydprec
[yybest
->yyrule
];
2930 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2932 for (semantic_option
* yyp
= yybest
->next();
2936 if (yyprec
== yydprec
[yyp
->yyrule
])
2938 value_type yyval_other
;]b4_locations_if([
2939 location_type yydummy
;])[
2940 yyflag
= yyresolveAction (*yyp
, &yyval_other
]b4_locations_if([, &yydummy
])[);
2943 yyparser
.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2944 yy_accessing_symbol (yys
.yylrState
),
2945 this->yyla
.value
]b4_locations_if([, *yylocp
])[);
2948 yyuserMerge (yymerger
[yyp
->yyrule
], val
, yyval_other
);]b4_variant_if([[
2949 // FIXME: User destructors.
2950 // Value type destructor.
2951 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[yyval_other
]], [[template destroy
]])])[
2956 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2960 yys
.yyresolved
= true;
2961 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_variant_if([[
2962 new (&yys
.value ()) value_type ();
2963 ]b4_symbol_variant([yy_accessing_symbol (yys
.yylrState
)],
2964 [yys
.value ()], [copy
], [val
])], [[
2965 new (&yys
.value ()) value_type (val
);]])[
2967 YY_IGNORE_MAYBE_UNINITIALIZED_END
2970 yys
.setFirstVal(YY_NULLPTR
);
2972 // FIXME: User destructors.
2973 // Value type destructor.
2974 ]b4_symbol_variant([[yy_accessing_symbol (yys
.yylrState
)]], [[val
]], [[template destroy
]])])[
2978 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2979 * user action, and return the semantic value and location in *YYVALP
2980 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2981 * have been destroyed (assuming the user action destroys all RHS
2982 * semantic values if invoked). */
2984 yyresolveAction (semantic_option
& yyopt
, value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2986 glr_state
* yyoptState
= yyopt
.state();
2987 YYASSERT(yyoptState
!= YY_NULLPTR
);
2988 int yynrhs
= yyrhsLength (yyopt
.yyrule
);
2989 YYRESULTTAG yyflag
= yyresolveStates (*yyoptState
, yynrhs
);
2992 for (glr_state
*yys
= yyoptState
; yynrhs
> 0; yys
= yys
->pred(), yynrhs
-= 1)
2993 yys
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
2997 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2998 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yyopt
.state());]b4_locations_if([[
3000 /* Set default location. */
3001 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yyoptState
->yyloc
;]])[
3003 symbol_type yyla_current
= std::move (this->yyla
);
3004 this->yyla
.kind_
= yyopt
.yytoken
;]b4_variant_if([[
3005 ]b4_symbol_variant([this->yyla
.kind ()],
3006 [this->yyla
.value
], [move
], [yyopt
.yyval
])], [[
3007 this->yyla
.value
= yyopt
.yyval
;]])[]b4_locations_if([
3008 this->yyla
.location
= yyopt
.yyloc
;])[
3009 yyflag
= yyuserAction (yyopt
.yyrule
, yynrhs
,
3010 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
3011 create_state_set_index (-1),
3012 yyvalp
]b4_locations_if([, yylocp
])[);
3014 this->yyla
= std::move (yyla_current
);
3017 }]b4_locations_if([[
3019 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
3020 * ending at YYS1. Has no effect on previously resolved states.
3021 * The first semantic option of a state is always chosen. */
3023 yyresolveLocations (glr_state
&yys1
, int yyn1
)
3027 yyresolveLocations (*yys1
.pred(), yyn1
- 1);
3028 if (!yys1
.yyresolved
)
3030 glr_stack_item yyrhsloc
[1 + YYMAXRHS
];
3031 YYASSERT (yys1
.firstVal() != YY_NULLPTR
);
3032 semantic_option
& yyoption
= *yys1
.firstVal();
3033 const int yynrhs
= yyrhsLength (yyoption
.yyrule
);
3036 yyresolveLocations (*yyoption
.state(), yynrhs
);
3037 const glr_state
*yys
= yyoption
.state();
3038 for (int yyn
= yynrhs
; yyn
> 0; yyn
-= 1)
3040 yyrhsloc
[yyn
].getState().yyloc
= yys
->yyloc
;
3046 /* Both yyresolveAction and yyresolveLocations traverse the GSS
3047 in reverse rightmost order. It is only necessary to invoke
3048 yyresolveLocations on a subforest for which yyresolveAction
3049 would have been invoked next had an ambiguity not been
3050 detected. Thus the location of the previous state (but not
3051 necessarily the previous state itself) is guaranteed to be
3052 resolved already. */
3053 YY_IGNORE_NULL_DEREFERENCE_BEGIN
3054 yyrhsloc
[0].getState().yyloc
= yyoption
.state()->yyloc
;
3055 YY_IGNORE_NULL_DEREFERENCE_END
3057 YYLLOC_DEFAULT ((yys1
.yyloc
), yyrhsloc
, yynrhs
);
3062 /** If yytoken is empty, fetch the next token. */
3066 ]b4_parse_param_use()dnl
3067 [ if (this->yyla
.empty ())
3069 YYCDEBUG
<< "Reading a token\n";
3072 #endif // YY_EXCEPTIONS
3073 {]b4_token_ctor_if([[
3074 symbol_type
yylookahead (]b4_yylex
[);
3075 yyla
.move (yylookahead
);]], [[
3076 yyla
.kind_
= yyparser
.yytranslate_ (]b4_yylex
[);]])[
3079 catch (const ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error
& yyexc
)
3081 YYCDEBUG
<< "Caught exception: " << yyexc
.what () << '\n';]b4_locations_if([
3082 this->yyla
.location
= yyexc
.location
;])[
3083 yyparser
.error (]b4_locations_if([this->yyla
.location
, ])[yyexc
.what ());
3084 // Map errors caught in the scanner to the error token, so that error
3085 // handling is started.
3086 this->yyla
.kind_
= ]b4_symbol(error
, kind
)[;
3089 #endif // YY_EXCEPTIONS
3090 if (this->yyla
.kind () == ]b4_symbol(eof
, kind
)[)
3091 YYCDEBUG
<< "Now at end of input.\n";
3093 YY_SYMBOL_PRINT ("Next token is", this->yyla
.kind (), this->yyla
.value
, this->yyla
.location
);
3097 /* Bison grammar-table manipulation. */
3099 /** The action to take in YYSTATE on seeing YYTOKEN.
3101 * R < 0: Reduce on rule -R.
3103 * R > 0: Shift to state R.
3104 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
3105 * of conflicting reductions.
3108 yygetLRActions (state_num yystate
, yysymbol_kind_t yytoken
, const short*& yyconflicts
)
3110 int yyindex
= yypact
[yystate
] + yytoken
;
3111 if (yytoken
== ]b4_symbol(error
, kind
)[)
3113 // This is the error token.
3114 yyconflicts
= yyconfl
;
3117 else if (yy_is_defaulted_state (yystate
)
3118 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
3120 yyconflicts
= yyconfl
;
3121 return -yydefact
[yystate
];
3123 else if (! yytable_value_is_error (yytable
[yyindex
]))
3125 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3126 return yytable
[yyindex
];
3130 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
3135 /** Compute post-reduction state.
3136 * \param yystate the current state
3137 * \param yysym the nonterminal to push on the stack
3140 yyLRgotoState (state_num yystate
, yysymbol_kind_t yysym
)
3142 const int yyr
= yypgoto
[yysym
- YYNTOKENS
] + yystate
;
3143 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
3144 return yytable
[yyr
];
3146 return yydefgoto
[yysym
- YYNTOKENS
];
3150 yypact_value_is_default (state_num yystate
)
3152 return ]b4_table_value_equals([[pact
]], [[yystate
]], [b4_pact_ninf
], [YYPACT_NINF
])[;
3156 yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED
)
3158 return ]b4_table_value_equals([[table
]], [[yytable_value
]], [b4_table_ninf
], [YYTABLE_NINF
])[;
3162 yy_is_shift_action (int yyaction
)
3164 return 0 < yyaction
;
3168 yy_is_error_action (int yyaction
)
3170 return yyaction
== 0;
3173 /** Whether LR state YYSTATE has only a default reduction
3174 * (regardless of token). */
3176 yy_is_defaulted_state (state_num yystate
)
3178 return yypact_value_is_default (yypact
[yystate
]);
3181 /** The default reduction for YYSTATE, assuming it has one. */
3183 yy_default_action (state_num yystate
)
3185 return yydefact
[yystate
];
3190 /** Y0 and Y1 represent two possible actions to take in a given
3191 * parsing state; return 0 if no combination is possible,
3192 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
3194 yypreference (const semantic_option
& y0
, const semantic_option
& y1
)
3196 rule_num r0
= y0
.yyrule
, r1
= y1
.yyrule
;
3197 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
3201 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
3206 if (p0
== 0 || p1
== 0)
3215 ]b4_parse_param_vars
[
3220 /* DEBUGGING ONLY */
3221 #if ]b4_api_PREFIX[DEBUG
3225 yypstack (const glr_stack
& yystack
, size_t yyk
)
3227 yystack
.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk
)));
3231 yypdumpstack (const glr_stack
& yystack
)
3233 yystack
.yypdumpstack ();
3239 /// Build a parser object.
3240 ]b4_parser_class::b4_parser_class
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
3242 #if ]b4_api_PREFIX[DEBUG
3243 ]m4_ifset([b4_parse_param
], [ ], [ :])[yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
3244 #endif]b4_parse_param_cons[
3247 ]b4_parser_class::~b4_parser_class
[ ()
3250 ]b4_parser_class
[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
3254 ]b4_parser_class
[::operator() ()
3260 ]b4_parser_class
[::parse ()
3262 glr_stack
yystack(YYINITDEPTH
, *this]b4_user_args
[);
3263 return yystack
.parse ();
3266 ]b4_parse_error_bmatch([custom\
|detailed
],
3268 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3270 static const char *const yy_sname
[] =
3273 };]b4_has_translations_if([[
3274 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3275 internationalizable. */
3276 static ]b4_int_type_for([b4_translatable
])[ yytranslatable
[] =
3280 return (yysymbol
< YYNTOKENS
&& yytranslatable
[yysymbol
]
3281 ? _(yy_sname
[yysymbol
])
3282 : yy_sname
[yysymbol
]);]], [[
3283 return yy_sname
[yysymbol
];]])[
3287 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3289 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3291 return yytname_
[yysymbol
];
3293 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3296 [[ /* Return YYSTR after stripping away unnecessary quotes and
3297 backslashes, so that it's suitable for yyerror. The heuristic is
3298 that double-quoting is unnecessary unless the string contains an
3299 apostrophe, a comma, or backslash (other than backslash-backslash).
3300 YYSTR is taken from yytname. */
3302 ]b4_parser_class
[::yytnamerr_ (const char *yystr
)
3307 char const *yyp
= yystr
;
3314 goto do_not_strip_quotes
;
3318 goto do_not_strip_quotes
;
3330 do_not_strip_quotes
: ;
3337 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3339 return yytnamerr_ (yytname_
[yysymbol
]);
3343 ]b4_parse_error_bmatch([simple\
|verbose
],
3344 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3345 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3346 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3348 const ]b4_parser_class
[::yytname_
[] =
3355 ]b4_parse_error_bmatch([custom\
|detailed\
|verbose
], [[
3356 // ]b4_parser_class[::context.
3357 ]b4_parser_class
[::context::context (glr_stack
& yystack
, const symbol_type
& yyla
)
3358 : yystack_ (yystack
)
3363 ]b4_parser_class
[::context::expected_tokens (symbol_kind_type yyarg
[], int yyargn
) const
3365 // Actual number of expected tokens
3367 const int yyn
= yypact
[yystack_
.firstTopState()->yylrState
];
3368 if (!yystack_
.yypact_value_is_default (yyn
))
3370 /* Start YYX at -YYN if negative to avoid negative indexes in
3371 YYCHECK. In other words, skip the first -YYN actions for this
3372 state because they are default actions. */
3373 const int yyxbegin
= yyn
< 0 ? -yyn
: 0;
3374 /* Stay within bounds of both yycheck and yytname. */
3375 const int yychecklim
= YYLAST
- yyn
+ 1;
3376 const int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
3377 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
3378 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= ]b4_symbol(error
, kind
)[
3379 && !yystack_
.yytable_value_is_error (yytable
[yyx
+ yyn
]))
3383 else if (yycount
== yyargn
)
3386 yyarg
[yycount
++] = YY_CAST (symbol_kind_type
, yyx
);
3389 if (yyarg
&& yycount
== 0 && 0 < yyargn
)
3390 yyarg
[0] = ]b4_symbol(empty
, kind
)[;
3396 ]b4_parse_error_bmatch([detailed\
|verbose
], [[
3398 ]b4_parser_class
[::yy_syntax_error_arguments_ (const context
& yyctx
,
3399 symbol_kind_type yyarg
[], int yyargn
) const
3401 /* There are many possibilities here to consider:
3402 - If this state is a consistent state with a default action, then
3403 the only way this function was invoked is if the default action
3404 is an error action. In that case, don't check for expected
3405 tokens because there are none.
3406 - The only way there can be no lookahead present (in yyla) is
3407 if this state is a consistent state with a default action.
3408 Thus, detecting the absence of a lookahead is sufficient to
3409 determine that there is no unexpected or expected token to
3410 report. In that case, just report a simple "syntax error".
3411 - Don't assume there isn't a lookahead just because this state is
3412 a consistent state with a default action. There might have
3413 been a previous inconsistent state, consistent state with a
3414 non-default action, or user semantic action that manipulated
3415 yyla. (However, yyla is currently not documented for users.)
3418 if (!yyctx
.lookahead ().empty ())
3421 yyarg
[0] = yyctx
.token ();
3422 int yyn
= yyctx
.expected_tokens (yyarg
? yyarg
+ 1 : yyarg
, yyargn
- 1);
3428 // Generate an error message.
3430 ]b4_parser_class
[::yysyntax_error_ (const context
& yyctx
) const
3433 enum { YYARGS_MAX
= 5 };
3434 // Arguments of yyformat.
3435 symbol_kind_type yyarg
[YYARGS_MAX
];
3436 int yycount
= yy_syntax_error_arguments_ (yyctx
, yyarg
, YYARGS_MAX
);
3438 char const* yyformat
= YY_NULLPTR
;
3441 #define YYCASE_(N, S) \
3445 default: // Avoid compiler warnings.
3446 YYCASE_ (0, YY_("syntax error"));
3447 YYCASE_ (1, YY_("syntax error, unexpected %s"));
3448 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
3449 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
3450 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
3451 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
3457 std::ptrdiff_t yyi
= 0;
3458 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
3459 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
3461 yyres
+= symbol_name (yyarg
[yyi
++]);
3470 ]b4_parser_class
[::yy_destroy_ (const char* yymsg
, symbol_kind_type yykind
,
3471 value_type
& yyval
]b4_locations_if([[,
3472 location_type
& yyloc
]])[)
3474 YY_USE (yyval
);]b4_locations_if([[
3478 ]b4_parser_class
[& yyparser
= *this;
3480 YY_SYMBOL_PRINT (yymsg
, yykind
, yyval
, yyloc
);
3482 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3483 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3484 [b4_symbol_actions([destructor
])],
3485 [m4_popdef([b4_symbol_action
])])[
3486 YY_IGNORE_MAYBE_UNINITIALIZED_END
3489 #if ]b4_api_PREFIX[DEBUG
3490 /*--------------------.
3491 | Print this symbol. |
3492 `--------------------*/
3495 ]b4_parser_class
[::yy_symbol_value_print_ (symbol_kind_type yykind
,
3496 const value_type
& yyval
]b4_locations_if([[,
3497 const location_type
& yyloc
]])[) const
3498 {]b4_locations_if([[
3501 std::ostream
& yyo
= debug_stream ();
3503 ]m4_do([m4_pushdef([b4_symbol_action
], m4_defn([b4_symbol_action_for_yyval
]))],
3504 [b4_symbol_actions([printer
])],
3505 [m4_popdef([b4_symbol_action
])])[
3509 ]b4_parser_class
[::yy_symbol_print_ (symbol_kind_type yykind
,
3510 const value_type
& yyval
]b4_locations_if([[,
3511 const location_type
& yyloc
]])[) const
3513 *yycdebug_
<< (yykind
< YYNTOKENS
? "token" : "nterm")
3514 << ' ' << symbol_name (yykind
) << " ("]b4_locations_if([[
3515 << yyloc
<< ": "]])[;
3516 yy_symbol_value_print_ (yykind
, yyval
]b4_locations_if([[, yyloc
]])[);
3521 ]b4_parser_class
[::debug_stream () const
3527 ]b4_parser_class
[::set_debug_stream (std::ostream
& o
)
3533 ]b4_parser_class
[::debug_level_type
3534 ]b4_parser_class
[::debug_level () const
3540 ]b4_parser_class
[::set_debug_level (debug_level_type l
)
3542 // Actually, it is yydebug which is really used.
3545 #endif // ]b4_api_PREFIX[DEBUG
3547 ]b4_token_ctor_if([], [b4_yytranslate_define([cc
])])[
3549 ]b4_token_ctor_if([], [[
3553 ]b4_public_types_define([cc
])])[
3554 ]b4_namespace_close
[]dnl