1 # C++ GLR skeleton for Bison
3 # Copyright (C) 2002-2015, 2018-2020 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 <http://www.gnu.org/licenses/>.
18 m4_include(b4_skeletonsdir
/[c
++.m4
])
20 # b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED)
21 # -------------------------------------------
22 m4_define([b4_tname_if
],
23 [m4_case(b4_percent_define_get([[parse
.error
]]),
25 [b4_token_table_if([$
1],
28 b4_bison_locations_if([
29 m4_define([b4_location_constructors
])
30 m4_include(b4_skeletonsdir
/[location
.cc
])])
32 m4_define([b4_parser_class
],
33 [b4_percent_define_get([[api
.parser
.class]])])
35 # Save the parse parameters.
36 m4_define([b4_parse_param_orig
], m4_defn([b4_parse_param
]))
38 # Hijack the initial action to initialize the locations.
39 ]b4_bison_locations_if([m4_define([b4_initial_action
],
40 [yystack
.yylloc
.initialize ();]m4_ifdef([b4_initial_action
], [
41 m4_defn([b4_initial_action
])]))])[
43 ]m4_define([b4_define_symbol_kind
],
44 [m4_format([#define %-15s %s],
45 b4_symbol($
][1, kind_base
),
46 b4_namespace_ref
[::]b4_parser_class
[::symbol_kind::]b4_symbol($
1, kind_base
))
49 ## ---------------- ##
51 ## ---------------- ##
54 m4_define_default([b4_stack_depth_max
], [10000])
55 m4_define_default([b4_stack_depth_init
], [200])
65 # The possible parse-params formal arguments preceded by a comma.
67 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
68 # formal argument declarations.
69 m4_define([b4_user_formals
],
70 [m4_ifset([b4_parse_param
], [, b4_formals(b4_parse_param
)])])
75 m4_define([b4_symbol_kind
],
76 [symbol_kind::b4_symbol_kind_base($@
)])
79 ## ----------------- ##
80 ## Semantic Values. ##
81 ## ----------------- ##
84 # b4_lhs_value(SYMBOL-NUM, [TYPE])
85 # --------------------------------
87 m4_define([b4_lhs_value
],
88 [b4_symbol_value([(*yyvalp
)], [$
1], [$
2])])
91 # b4_rhs_data(RULE-LENGTH, POS)
92 # -----------------------------
94 m4_define([b4_rhs_data
],
95 [(static_cast<glr_stack_item
const *>(yyvsp
))@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.getState()])
98 # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
99 # --------------------------------------------------
100 # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
101 m4_define([b4_rhs_value
],
102 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value ()], [$
3], [$
4])])
113 m4_define([b4_lhs_location
],
117 # b4_rhs_location(RULE-LENGTH, NUM)
118 # ---------------------------------
119 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
121 m4_define([b4_rhs_location
],
122 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
125 # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
126 # ---------------------------------------------------
127 m4_define([b4_call_merger
],
129 [ b4_symbol_if([$
3], [has_type
],
130 [yy0
->b4_symbol($
3, slot
) = $
2 (*yy0
, *yy1
);],
131 [*yy0
= $
2 (*yy0
, *yy1
);])])])
138 [b4_function_call([yylex
],
139 [symbol_type
], m4_ifdef([b4_lex_param
], b4_lex_param
))],
140 [b4_function_call([yylex
], [int],
141 [b4_api_PREFIX
[STYPE
*], [&yystack
.yylval
]][]dnl
142 b4_locations_if([, [[location
*], [&yystack
.yylloc
]]])dnl
143 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))])])
146 # b4_shared_declarations(hh|cc)
147 # -----------------------------
148 # Declaration that might either go into the header (if --header, $1 = hh)
149 # or in the implementation file.
150 m4_define([b4_shared_declarations
],
151 [m4_pushdef([b4_parse_param
], m4_defn([b4_parse_param_orig
]))dnl
152 b4_percent_code_get([[requires
]])[
154 #include <cstddef> // ptrdiff_t
155 #include <cstring> // memcpy
165 ]m4_ifdef([b4_location_include
],
166 [[# include ]b4_location_include])[
167 ]b4_variant_if([b4_variant_includes
])[
169 // Whether we are compiled with exception support.
170 #ifndef YY_EXCEPTIONS
171 # if defined __GNUC__ && !defined __EXCEPTIONS
172 # define YY_EXCEPTIONS 0
174 # define YY_EXCEPTIONS 1
182 template <typename Parameter
>
183 class strong_index_alias
186 static strong_index_alias
create(std::ptrdiff_t value
) {
187 strong_index_alias result
;
188 result
.value_
= value
;
192 std::ptrdiff_t const& get() const { return value_
; }
194 size_t uget() const { return static_cast<size_t>(value_
); }
196 strong_index_alias
operator+(std::ptrdiff_t other
) const {
197 return strong_index_alias(get() + other
);
200 void operator+=(std::ptrdiff_t other
) {
204 strong_index_alias
operator-(std::ptrdiff_t other
) {
205 return strong_index_alias(get() - other
);
208 void operator-=(std::ptrdiff_t other
) {
212 size_t operator-(strong_index_alias other
) {
213 return strong_index_alias(get() - other
.get());
216 strong_index_alias
& operator++() {
221 bool isValid() const {
222 return value_
!= INVALID_INDEX
;
226 value_
= INVALID_INDEX
;
229 bool operator==(strong_index_alias other
) {
230 return get() == other
.get();
233 bool operator!=(strong_index_alias other
) {
234 return get() != other
.get();
237 bool operator<(strong_index_alias other
) {
238 return get() < other
.get();
242 static const std::ptrdiff_t INVALID_INDEX
;
244 // WARNING: 0-initialized.
245 std::ptrdiff_t value_
;
249 const std::ptrdiff_t strong_index_alias
<T
>::INVALID_INDEX
=
250 std::numeric_limits
<std::ptrdiff_t>::max();
252 ]b4_bison_locations_if([m4_ifndef([b4_location_file
],
253 [b4_location_define
])])[
256 class ]b4_parser_class
[
259 ]b4_public_types_declare
[
260 ]b4_symbol_type_define
[
262 /// Build a parser object.
263 ]b4_parser_class
[ (]b4_parse_param_decl
[);
264 virtual ~]b4_parser_class
[ ();
266 /// Parse. An alias for parse ().
267 /// \returns 0 iff parsing succeeded.
271 /// \returns 0 iff parsing succeeded.
272 virtual int parse ();
274 #if ]b4_api_PREFIX[DEBUG
275 /// The current debugging stream.
276 std::ostream
& debug_stream () const;
277 /// Set the current debugging stream.
278 void set_debug_stream (std::ostream
&);
280 /// Type for debugging levels.
281 typedef int debug_level_type
;
282 /// The current debugging level.
283 debug_level_type
debug_level () const;
284 /// Set the current debugging level.
285 void set_debug_level (debug_level_type l
);
288 /// Report a syntax error.]b4_locations_if([[
289 /// \param loc where the syntax error is found.]])[
290 /// \param msg a description of the syntax error.
291 virtual void error (]b4_locations_if([[const location_type
& loc
, ]])[const std::string
& msg
);
293 ]b4_parse_error_bmatch(
295 [[ /// The user-facing name of the symbol whose (internal) number is
296 /// YYSYMBOL. No bounds checking.
297 static const char *symbol_name (symbol_kind_type yysymbol
);]],
299 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
300 /// The user-facing name of the symbol whose (internal) number is
301 /// YYSYMBOL. No bounds checking.
302 static const char *symbol_name (symbol_kind_type yysymbol
);
303 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
306 [[ /// The user-facing name of the symbol whose (internal) number is
307 /// YYSYMBOL. No bounds checking.
308 static std::string
symbol_name (symbol_kind_type yysymbol
);]])[
310 # if ]b4_api_PREFIX[DEBUG
312 /// \brief Report a symbol value on the debug stream.
313 /// \param yykind The symbol kind.
314 /// \param yyvaluep Its semantic value.]b4_locations_if([[
315 /// \param yylocationp Its location.]])[
316 virtual void yy_symbol_value_print_ (symbol_kind_type yykind
,
317 const value_type
* yyvaluep
]b4_locations_if([[,
318 const location_type
* yylocationp
]])[) const;
319 /// \brief Report a symbol on the debug stream.
320 /// \param yykind The symbol kind.
321 /// \param yyvaluep Its semantic value.]b4_locations_if([[
322 /// \param yylocationp Its location.]])[
323 virtual void yy_symbol_print_ (symbol_kind_type yykind
,
324 const value_type
* yyvaluep
]b4_locations_if([[,
325 const location_type
* yylocationp
]])[) const;
328 std::ostream
* yycdebug_
;
331 public: // FIXME: Private
332 ]b4_parse_error_bmatch(
334 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
335 /// For a symbol, its name in clear.
336 static const char* const yytname_
[];
337 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
340 [[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
341 static std::string
yytnamerr_ (const char *yystr
);
343 /// For a symbol, its name in clear.
344 static const char* const yytname_
[];
347 /// \brief Reclaim the memory associated to a symbol.
348 /// \param yymsg Why this token is reclaimed.
349 /// If null, print nothing.
350 /// \param yykind The symbol kind.
351 void yy_destroy_ (const char* yymsg
, symbol_kind_type yykind
,
352 const value_type
* yyvaluep
]b4_locations_if([[,
353 const location_type
* yylocationp
]])[);
355 ]b4_parse_param_vars
[
360 ]b4_percent_code_get([[provides
]])[
361 ]m4_popdef([b4_parse_param
])dnl
375 ]b4_output_begin([b4_spec_header_file
])[
376 ]b4_copyright([Skeleton interface
for Bison GLR parsers in C
++],
377 [2002-2015, 2018-2020])[
378 // C++ GLR parser skeleton written by Valentin Tolmer.
381 ]b4_cpp_guard_open([b4_spec_mapped_header_file
])[
382 ]b4_shared_declarations
[
383 ]b4_cpp_guard_close([b4_spec_mapped_header_file
])[
387 # --------------------- #
388 # Implementation file. #
389 # --------------------- #
391 ]b4_output_begin([b4_parser_file_name
])[
392 ]b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
393 [2002-2015, 2018-2019])[
394 // C++ GLR parser skeleton written by Valentin Tolmer.
399 ]b4_percent_code_get([[top
]])[
400 ]m4_if(b4_prefix
, [yy
], [],
401 [[/* Substitute the variable and function names. */
402 #define yyparse ]b4_prefix[parse
403 #define yylex ]b4_prefix[lex
404 #define yyerror ]b4_prefix[error
405 #define yydebug ]b4_prefix[debug]])[
407 ]b4_user_pre_prologue
[
411 ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
412 [b4_shared_declarations
])[
414 typedef ]b4_namespace_ref
[::]b4_parser_class
[::symbol_kind_type yysymbol_kind_t
;
416 /* Default (constant) value used for initialization for null
417 right-hand sides. Unlike the standard yacc.c template, here we set
418 the default value of $$ to a zeroed-out value. Since the default
419 value is undefined, this behavior is technically correct. */
420 static ]b4_namespace_ref
[::]b4_parser_class
[::value_type yyval_default
;]b4_locations_if([[
421 static ]b4_namespace_ref
[::]b4_parser_class
[::location_type yyloc_default
][]b4_yyloc_default
;])[
423 ]b4_user_post_prologue
[
424 ]b4_percent_code_get
[]dnl
430 # if defined YYENABLE_NLS && YYENABLE_NLS
432 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
433 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
437 # define YY_(Msgid) Msgid
445 # define YYMALLOC malloc
450 # define YYJMP_BUF jmp_buf
451 # define YYSETJMP(Env) setjmp (Env)
452 /* Pacify Clang and ICC. */
453 # define YYLONGJMP(Env, Val) \
455 longjmp (Env, Val); \
460 ]b4_attribute_define([noreturn
])[
462 #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
463 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \
464 _Pragma ("GCC diagnostic push") \
465 _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"")
466 # define YY_IGNORE_NULL_DEREFERENCE_END \
467 _Pragma ("GCC diagnostic pop")
469 # define YY_IGNORE_NULL_DEREFERENCE_BEGIN
470 # define YY_IGNORE_NULL_DEREFERENCE_END
476 // FIXME: Use the same conventions as lalr1.cc.
479 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
483 # define YYDASSERT(Condition) YYASSERT(Condition)
485 # define YYDASSERT(Condition)
488 /* YYFINAL -- State number of the termination state. */
489 #define YYFINAL ]b4_final_state_number[
490 /* YYLAST -- Last index in YYTABLE. */
491 #define YYLAST ]b4_last[
493 /* YYNTOKENS -- Number of terminals. */
494 #define YYNTOKENS ]b4_tokens_number[
495 /* YYNNTS -- Number of nonterminals. */
496 #define YYNNTS ]b4_nterms_number[
497 /* YYNRULES -- Number of rules. */
498 #define YYNRULES ]b4_rules_number[
499 /* YYNSTATES -- Number of states. */
500 #define YYNSTATES ]b4_states_number[
501 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
502 #define YYMAXRHS ]b4_r2_max[
503 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
504 accessed by $0, $-1, etc., in any rule. */
505 #define YYMAXLEFT ]b4_max_left_semantic_context[
507 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
508 as returned by yylex, with out-of-bounds checking. */
509 ]b4_api_token_raw_if(dnl
510 [[#define YYTRANSLATE(YYX) static_cast<yysymbol_kind_t>(YYX)]],
511 [[#define YYTRANSLATE(YYX) \
512 (0 <= (YYX) && (YYX) <= ]b4_code_max[ \
513 ? static_cast<yysymbol_kind_t>(yytranslate[YYX]) \
514 : ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol(empty, kind)[)
516 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
517 as returned by yylex. */
518 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
523 #if ]b4_api_PREFIX[DEBUG
524 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
525 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
531 #define YYPACT_NINF ]b4_pact_ninf[
532 #define YYTABLE_NINF ]b4_table_ninf[
534 ]b4_parser_tables_define
[
536 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
537 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
542 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
543 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
548 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
549 in the case of predicates. */
550 static const bool yyimmediate
[] =
555 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
556 list of conflicting reductions corresponding to action entry for
557 state STATE-NUM in yytable. 0 means no conflicts. The list in
558 yyconfl is terminated by a rule number of 0. */
559 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
561 ]b4_conflict_list_heads
[
564 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
565 0, pointed into by YYCONFLP. */
566 ]dnl Do
not use b4_int_type_for here
, since there are places where
567 dnl pointers onto yyconfl are taken
, whose type is
"short*".
568 dnl We probably ought to introduce a type
for confl
.
569 [static const short yyconfl
[] =
571 ]b4_conflicting_rules
[
574 /* Error token number */
578 ]b4_yylloc_default_define
[
579 # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc)
582 enum YYRESULTTAG
{ yyok
, yyaccept
, yyabort
, yyerr
};
586 YYRESULTTAG yychk_flag = YYE; \
587 if (yychk_flag != yyok) \
591 #if ]b4_api_PREFIX[DEBUG
593 ]b4_yy_location_print_define
[
595 #define YYCDEBUG if (!yydebug) {} else std::cerr
597 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
601 std::cerr << Title << ' '; \
602 yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
607 # define YY_REDUCE_PRINT(Args) \
610 yystateStack.yy_reduce_print Args; \
613 /* Nonzero means print parse trace. It is left uninitialized so that
614 multiple parsers can coexist. */
618 static void yypstack (const glr_stack
& yystack
, size_t yyk
)
620 static void yypdumpstack (const glr_stack
& yystack
)
623 #else /* !]b4_api_PREFIX[DEBUG */
625 # define YYCDEBUG if (true) {} else std::cerr
626 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
627 # define YY_REDUCE_PRINT(Args)
629 #endif /* !]b4_api_PREFIX[DEBUG */
631 /* YYINITDEPTH -- initial size of the parser's stacks. */
633 # define YYINITDEPTH ]b4_stack_depth_init[
636 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
637 if the built-in stack extension method is used).
639 Do not make this value too large; the results are undefined if
640 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
641 evaluated with infinite-precision integer arithmetic. */
644 # define YYMAXDEPTH ]b4_stack_depth_max[
647 /* Minimum number of free items on the stack allowed after an
648 allocation. This is to allow allocation and initialization
649 to be completed by functions that call yyexpandGLRStack before the
650 stack is expanded, thus insuring that all necessary pointers get
651 properly redirected to new data. */
654 #ifndef YYSTACKEXPANDABLE
655 # define YYSTACKEXPANDABLE 1
658 /** State numbers, as in LALR(1) machine */
659 typedef int state_num
;
661 /** Rule numbers, as in LALR(1) machine */
662 typedef int rule_num
;
664 // Forward declarations.
666 class semantic_option
;
667 class glr_stack_item
;
670 typedef ]b4_namespace_ref
[::strong_index_alias
<struct glr_state_set_tag
> state_set_index
;
672 state_set_index
create_state_set_index(std::ptrdiff_t value
)
674 return state_set_index::create(value
);
677 #define yypact_value_is_default(Yystate) \
678 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf], [YYPACT_NINF])[
680 #define yytable_value_is_error(Yytable_value) \
681 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[
683 static inline yysymbol_kind_t
684 yygetToken (int& yycharp
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
, glr_stack
& yystack
]b4_user_formals
[);
687 yyisShiftAction (int yyaction
)
693 yyisErrorAction (int yyaction
)
695 return yyaction
== 0;
699 yygetLRActions (state_num yystate
, yysymbol_kind_t yytoken
, const short*& yyconflicts
);
701 /** Accessing symbol of state YYSTATE. */
702 static inline yysymbol_kind_t
703 yy_accessing_symbol (state_num yystate
)
705 return YY_CAST (yysymbol_kind_t
, yystos
[yystate
]);
708 /** True iff LR state YYSTATE has only a default reduction (regardless
711 yyisDefaultedState (state_num yystate
)
713 return yypact_value_is_default (yypact
[yystate
]);
716 /** The default reduction for YYSTATE, assuming it has one. */
717 static inline rule_num
718 yydefaultAction (state_num yystate
)
720 return yydefact
[yystate
];
723 /** Left-hand-side symbol for rule #YYRULE. */
724 static inline yysymbol_kind_t
725 yylhsNonterm (rule_num yyrule
)
727 return static_cast<yysymbol_kind_t
>(yyr1
[yyrule
]);
731 yyrhsLength (rule_num yyrule
);
737 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
738 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
744 , yypred (0)]b4_locations_if([[
745 , yyloc ()]])[]b4_parse_assert_if([[
749 /// Build with a semantic value.
750 glr_state (state_num lrState
, size_t posn
, value_type sval
]b4_locations_if([[, location_type loc
]])[)
752 , yylrState (lrState
)
755 , yyval (sval
)]b4_locations_if([[
756 , yyloc (loc
)]])[]b4_parse_assert_if([[
760 /// Build with a semantic option.
761 glr_state (state_num lrState
, size_t posn
)
763 , yylrState (lrState
)
766 , yyfirstVal (0)]b4_locations_if([[
767 , yyloc ()]])[]b4_parse_assert_if([[
771 glr_state (const glr_state
& other
)
772 : yyresolved (other
.yyresolved
)
773 , yylrState (other
.yylrState
)
774 , yyposn (other
.yyposn
)
775 , yypred (0)]b4_locations_if([[
776 , yyloc (other
.yyloc
)]])[]b4_parse_assert_if([[
779 setPred (other
.pred ());
780 if (other
.yyresolved
)
781 new (&yyval
) value_type (other
.value ());
783 setFirstVal (other
.firstVal ());]b4_parse_assert_if([[
788 {]b4_parse_assert_if([[
792 yyval
.~value_type ();
795 glr_state
& operator= (const glr_state
& other
)
796 {]b4_parse_assert_if([[
799 if (!yyresolved
&& other
.yyresolved
)
800 new (&yyval
) value_type
;
801 yyresolved
= other
.yyresolved
;
802 yylrState
= other
.yylrState
;
803 yyposn
= other
.yyposn
;
804 setPred (other
.pred ());
805 if (other
.yyresolved
)
806 value () = other
.value ();
808 setFirstVal (other
.firstVal ());]b4_locations_if([[
809 yyloc
= other
.yyloc
;]])[
813 /** Type tag for the semantic value. If true, yyval applies, otherwise
814 * yyfirstVal applies. */
816 /** Number of corresponding LALR(1) machine state. */
818 /** Source position of the last token produced by my symbol */
821 /// Only call pred() and setPred() on objects in yyitems, not temporaries.
823 const glr_state
* pred () const;
824 void setPred (const glr_state
* state
);
826 /// Only call firstVal() and setFirstVal() on objects in yyitems, not
828 semantic_option
* firstVal ();
829 const semantic_option
* firstVal () const;
830 void setFirstVal (const semantic_option
* option
);
833 {]b4_parse_assert_if([[
838 const value_type
& value () const
839 {]b4_parse_assert_if([[
845 destroy (char const *yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[);
848 #if ]b4_api_PREFIX[DEBUG
849 void yy_yypstack () const
850 {]b4_parse_assert_if([[
852 if (pred () != YY_NULLPTR
)
854 pred ()->yy_yypstack ();
857 std::cerr
<< yylrState
<< "@@" << yyposn
;
861 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const;
863 glr_stack_item
* asItem ()
864 {]b4_parse_assert_if([[
869 const glr_stack_item
* asItem () const
870 {]b4_parse_assert_if([[
872 return asItem (this);
876 template <typename T
>
877 static const glr_stack_item
* asItem (const T
* state
)
879 return reinterpret_cast<const glr_stack_item
*>(state
);
881 template <typename T
>
882 static glr_stack_item
* asItem (T
* state
)
884 return reinterpret_cast<glr_stack_item
*> (state
);
886 static const char *as_pointer_ (const glr_state
*state
)
888 return reinterpret_cast<const char *> (state
);
890 static char *as_pointer_ (glr_state
*state
)
892 return reinterpret_cast<char *> (state
);
894 /** Preceding state in this stack */
895 std::ptrdiff_t yypred
;
897 /** First in a chain of alternative reductions producing the
898 * nonterminal corresponding to this state, threaded through
899 * yyfirstVal. Value "0" means empty. */
900 std::ptrdiff_t yyfirstVal
;
901 /** Semantic value for this state. */
903 };]b4_locations_if([[
904 // FIXME: Why public?
906 /** Source location for this state. */
907 location_type yyloc
;]])[
909 ]b4_parse_assert_if([[
914 YY_IGNORE_NULL_DEREFERENCE_BEGIN
915 YYASSERT (this->magic_
== MAGIC
);
916 YY_IGNORE_NULL_DEREFERENCE_END
919 // A magic number to check our pointer arithmetics is sane.
920 enum { MAGIC
= 713705 };
921 unsigned int magic_
;]])[
924 /** A stack of GLRState representing the different heads during
925 * nondeterministic evaluation. */
929 /** Initialize YYSET to a singleton set containing an empty stack. */
931 : yylastDeleted (YY_NULLPTR
)
933 yystates
.push_back (YY_NULLPTR
);
934 yylookaheadNeeds
.push_back (false);
937 // Behave like a vector of states.
938 glr_state
*& operator[] (state_set_index index
)
940 return yystates
[index
.uget()];
943 glr_state
* operator[] (state_set_index index
) const
945 return yystates
[index
.uget()];
950 return yystates
.size ();
953 std::vector
<glr_state
*>::iterator
begin ()
955 return yystates
.begin ();
958 std::vector
<glr_state
*>::iterator
end ()
960 return yystates
.end ();
963 bool lookaheadNeeds (state_set_index index
) const
965 return yylookaheadNeeds
[index
.uget ()];
968 bool setLookaheadNeeds (state_set_index index
, bool value
)
970 return yylookaheadNeeds
[index
.uget ()] = value
;
973 /** Invalidate stack #YYK. */
975 yymarkStackDeleted (state_set_index yyk
)
977 size_t k
= yyk
.uget ();
978 if (yystates
[k
] != YY_NULLPTR
)
979 yylastDeleted
= yystates
[k
];
980 yystates
[k
] = YY_NULLPTR
;
983 /** Undelete the last stack in *this that was marked as deleted. Can
984 only be done once after a deletion, and only when all other stacks have
987 yyundeleteLastStack ()
989 if (yylastDeleted
== YY_NULLPTR
|| !yystates
.empty ())
991 yystates
.push_back (yylastDeleted
);
992 YYCDEBUG
<< "Restoring last deleted stack as stack #0.\n";
996 /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later
1001 size_t newsize
= yystates
.size ();
1002 /* j is the number of live stacks we have seen. */
1003 for (size_t i
= 0, j
= 0; j
< newsize
; ++i
)
1005 if (yystates
[i
] == YY_NULLPTR
)
1009 YYCDEBUG
<< "Removing dead stacks.\n";
1015 yystates
[j
] = yystates
[i
];
1016 /* In the current implementation, it's unnecessary to copy
1017 yylookaheadNeeds[i] since, after
1018 yyremoveDeletes returns, the parser immediately either enters
1019 deterministic operation or shifts a token. However, it doesn't
1020 hurt, and the code might evolve to need it. */
1021 yylookaheadNeeds
[j
] = yylookaheadNeeds
[i
];
1024 YYCDEBUG
<< "Rename stack " << i
<< " -> " << j
<< ".\n";
1029 yystates
.resize (newsize
);
1030 yylookaheadNeeds
.resize (newsize
);
1035 yysplitStack (state_set_index yyk
)
1037 const size_t k
= yyk
.uget ();
1038 yystates
.push_back (yystates
[k
]);
1039 yylookaheadNeeds
.push_back (yylookaheadNeeds
[k
]);
1040 return create_state_set_index (static_cast<std::ptrdiff_t> (yystates
.size () - 1));
1043 void clearLastDeleted ()
1045 yylastDeleted
= YY_NULLPTR
;
1050 std::vector
<glr_state
*> yystates
;
1051 /** During nondeterministic operation, yylookaheadNeeds tracks which
1052 * stacks have actually needed the current lookahead. During deterministic
1053 * operation, yylookaheadNeeds[0] is not maintained since it would merely
1054 * duplicate yychar != ]b4_symbol(empty, id)[. */
1055 std::vector
<bool> yylookaheadNeeds
;
1057 /** The last stack we invalidated. */
1058 glr_state
* yylastDeleted
;
1061 class semantic_option
1064 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1065 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1071 , yychar (0)]b4_parse_assert_if([[
1072 , magic_ (MAGIC
)]])[
1075 semantic_option (rule_num rule
, int rawChar
)
1079 , yychar (rawChar
)]b4_parse_assert_if([[
1080 , magic_ (MAGIC
)]])[
1083 /// Only call state() and setState() on objects in yyitems, not temporaries.
1085 const glr_state
* state() const;
1086 void setState(const glr_state
* s
);
1088 const semantic_option
* next () const;
1089 semantic_option
* next ();
1090 void setNext (const semantic_option
* s
);
1092 std::ptrdiff_t indexIn (const glr_stack_item
* array
) const;
1094 /** True iff YYY0 and YYY1 represent identical options at the top level.
1095 * That is, they represent the same rule applied to RHS symbols
1096 * that produce the same terminal symbols. */
1098 isIdenticalTo (const semantic_option
& yyy1
) const
1099 {]b4_parse_assert_if([[
1102 if (this->yyrule
== yyy1
.yyrule
)
1104 const glr_state
*yys0
, *yys1
;
1106 for (yys0
= this->state(),
1107 yys1
= yyy1
.state(),
1108 yyn
= yyrhsLength (this->yyrule
);
1110 yys0
= yys0
->pred(),
1111 yys1
= yys1
->pred(), yyn
-= 1)
1112 if (yys0
->yyposn
!= yys1
->yyposn
)
1120 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1121 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1123 mergeWith (semantic_option
& yyy1
)
1124 {]b4_parse_assert_if([[
1127 glr_state
*yys0
= this->state ();
1128 glr_state
*yys1
= yyy1
.state ();
1129 for (int yyn
= yyrhsLength (this->yyrule
);
1131 yyn
-= 1, yys0
= yys0
->pred (), yys1
= yys1
->pred ())
1135 else if (yys0
->yyresolved
)
1137 yys1
->yyresolved
= true;
1138 yys1
->value () = yys0
->value ();
1140 else if (yys1
->yyresolved
)
1142 yys0
->yyresolved
= true;
1143 yys0
->value () = yys1
->value ();
1147 semantic_option
* yyz0prev
= YY_NULLPTR
;
1148 semantic_option
* yyz0
= yys0
->firstVal();
1149 semantic_option
* yyz1
= yys1
->firstVal();
1152 if (yyz1
== yyz0
|| yyz1
== YY_NULLPTR
)
1154 else if (yyz0
== YY_NULLPTR
)
1156 if (yyz0prev
!= YY_NULLPTR
)
1157 yyz0prev
->setNext (yyz1
);
1159 yys0
->setFirstVal (yyz1
);
1162 else if (yyz0
< yyz1
)
1164 semantic_option
* yyz
= yyz0
;
1165 if (yyz0prev
!= YY_NULLPTR
)
1166 yyz0prev
->setNext(yyz1
);
1168 yys0
->setFirstVal(yyz1
);
1169 yyz1
= yyz1
->next();
1173 yyz0
= yyz0
->next();
1175 yys1
->setFirstVal(yys0
->firstVal());
1180 #if ]b4_api_PREFIX[DEBUG
1181 void yyreportTree (size_t yyindent
= 2) const
1182 {]b4_parse_assert_if([[
1184 int yynrhs
= yyrhsLength (this->yyrule
);
1185 const glr_state
* yystates
[1 + YYMAXRHS
];
1186 glr_state yyleftmost_state
;
1189 const glr_state
* yys
= this->state();
1190 for (int yyi
= yynrhs
; 0 < yyi
; yyi
-= 1)
1192 yystates
[yyi
] = yys
;
1195 if (yys
== YY_NULLPTR
)
1197 yyleftmost_state
.yyposn
= 0;
1198 yystates
[0] = &yyleftmost_state
;
1204 std::string yylhs
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yylhsNonterm (this->yyrule
));
1205 YYASSERT(this->state());
1206 if (this->state()->yyposn
< yystates
[0]->yyposn
+ 1)
1207 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1208 << this->yyrule
- 1 << ", empty>\n";
1210 std::cerr
<< std::string(yyindent
, ' ') << yylhs
<< " -> <Rule "
1211 << this->yyrule
- 1 << ", tokens "
1212 << yystates
[0]->yyposn
+ 1 << " .. "
1213 << this->state()->yyposn
<< ">\n";
1214 for (int yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1216 if (yystates
[yyi
]->yyresolved
)
1218 std::string yysym
= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yy_accessing_symbol (yystates
[yyi
]->yylrState
));
1219 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1220 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1223 std::cerr
<< std::string(yyindent
+ 2, ' ') << yysym
1224 << " <tokens " << yystates
[yyi
-1]->yyposn
+ 1
1225 << " .. " << yystates
[yyi
]->yyposn
<< ">\n";
1228 yystates
[yyi
]->firstVal ()->yyreportTree (yyindent
+2);
1233 /** Rule number for this reduction */
1237 template <typename T
>
1238 static const glr_stack_item
* asItem(const T
* state
)
1240 return reinterpret_cast<const glr_stack_item
*>(state
);
1242 template <typename T
>
1243 static glr_stack_item
* asItem(T
* state
)
1245 return reinterpret_cast<glr_stack_item
*>(state
);
1247 /** The last RHS state in the list of states to be reduced. */
1248 std::ptrdiff_t yystate
;
1249 /** Next sibling in chain of options. To facilitate merging,
1250 * options are chained in decreasing order by address. */
1251 std::ptrdiff_t yynext
;
1254 /** The lookahead for this reduction. */
1256 value_type yyval
;]b4_locations_if([[
1257 location_type yyloc
;]])[
1259 ]b4_parse_assert_if([[
1261 // Check invariants.
1262 void check_ () const
1264 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1265 YYASSERT (this->magic_
== MAGIC
);
1266 YY_IGNORE_NULL_DEREFERENCE_END
1269 // A magic number to check our pointer arithmetics is sane.
1270 enum { MAGIC
= 0xeff1cace };
1271 unsigned int magic_
;]])[
1274 /** Type of the items in the GLR stack.
1275 * It can be either a glr_state or a semantic_option. The is_state_ field
1276 * indicates which item of the union is valid. */
1277 class glr_stack_item
1280 glr_stack_item (bool state
= true)
1281 : is_state_ (state
)]b4_parse_assert_if([[
1282 , magic_ (MAGIC
)]])[
1285 new (&raw_
) glr_state
;
1287 new (&raw_
) semantic_option
;
1290 glr_stack_item (const glr_stack_item
& other
) YY_NOEXCEPT YY_NOTHROW
1291 : is_state_ (other
.is_state_
)]b4_parse_assert_if([[
1292 , magic_ (MAGIC
)]])[
1293 {]b4_parse_assert_if([[
1294 other
.check_ ();]])[
1295 std::memcpy (raw_
, other
.raw_
, union_size
);
1298 glr_stack_item
& operator= (glr_stack_item other
)
1299 {]b4_parse_assert_if([[
1301 other
.check_ ();]])[
1302 std::swap (is_state_
, other
.is_state_
);
1303 std::swap (raw_
, other
.raw_
);
1308 {]b4_parse_assert_if([[
1311 getState().~glr_state();
1313 getOption().~semantic_option();
1316 void setState (const glr_state
&state
)
1317 {]b4_parse_assert_if([[
1319 state
.check_ ();]])[
1320 if (this != state
.asItem ())
1323 // FIXME: What about the previous content? Shouldn't it be
1324 // freed? It might be useful to have an explicit "void" state
1325 // when this item is in unused state (in the list of free
1326 // items), when parse.assert is set.
1327 new (&raw_
) glr_state (state
);
1331 glr_state
& getState ()
1332 {]b4_parse_assert_if([[
1334 YYDASSERT (is_state ());
1336 glr_state
& res
= *static_cast<glr_state
*> (yyp
);]b4_parse_assert_if([[
1341 const glr_state
& getState () const
1342 {]b4_parse_assert_if([[
1344 YYDASSERT (is_state ());
1345 const void *yyp
= raw_
;
1346 const glr_state
& res
= *static_cast<const glr_state
*> (yyp
);]b4_parse_assert_if([[
1351 semantic_option
& getOption ()
1352 {]b4_parse_assert_if([[
1354 YYDASSERT (!is_state ());
1356 return *static_cast<semantic_option
*> (yyp
);
1358 const semantic_option
& getOption () const
1359 {]b4_parse_assert_if([[
1361 YYDASSERT (!is_state ());
1362 const void *yyp
= raw_
;
1363 return *static_cast<const semantic_option
*> (yyp
);
1365 bool is_state () const
1366 {]b4_parse_assert_if([[
1372 /// The possible contents of raw_. Since they have constructors, they cannot
1373 /// be directly included in the union.
1376 char yystate
[sizeof (glr_state
)];
1377 char yyoption
[sizeof (semantic_option
)];
1379 enum { union_size
= sizeof (contents
) };
1381 /// Strongest alignment constraints.
1382 long double yyalign_me
;
1383 /// A buffer large enough to store the contents.
1384 char raw_
[union_size
];
1386 /** Type tag for the union. */
1388 ]b4_parse_assert_if([[
1390 // Check invariants.
1391 void check_ () const
1393 YYASSERT (this->magic_
== MAGIC
);
1394 YYASSERT (this->is_state_
== false || this->is_state_
== true);
1396 // A magic number to check our pointer arithmetics is sane.
1397 enum { MAGIC
= 0xDEAD1ACC }; // 3735886540.
1398 const unsigned int magic_
;]])[
1401 glr_state
* glr_state::pred ()
1402 {]b4_parse_assert_if([[
1404 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1405 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1406 YY_IGNORE_NULL_DEREFERENCE_END
1409 const glr_state
* glr_state::pred () const
1410 {]b4_parse_assert_if([[
1412 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1413 return yypred
? &asItem (as_pointer_ (this) - yypred
)->getState () : YY_NULLPTR
;
1414 YY_IGNORE_NULL_DEREFERENCE_END
1417 void glr_state::setPred (const glr_state
* state
)
1418 {]b4_parse_assert_if([[
1421 state
->check_ ();]])[
1422 yypred
= state
? as_pointer_ (this) - as_pointer_ (state
) : 0;
1425 semantic_option
* glr_state::firstVal ()
1426 {]b4_parse_assert_if([[
1428 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1431 const semantic_option
* glr_state::firstVal () const
1432 {]b4_parse_assert_if([[
1434 return yyfirstVal
? &(asItem(this) - yyfirstVal
)->getOption() : YY_NULLPTR
;
1437 void glr_state::setFirstVal (const semantic_option
* option
)
1438 {]b4_parse_assert_if([[
1440 yyfirstVal
= option
? asItem(this) - asItem(option
) : 0;
1443 std::ptrdiff_t glr_state::indexIn (const glr_stack_item
* array
) const
1444 {]b4_parse_assert_if([[
1446 return asItem(this) - array
;
1449 std::ptrdiff_t semantic_option::indexIn (const glr_stack_item
* array
) const
1451 return asItem(this) - array
;
1454 glr_state
* semantic_option::state ()
1456 YY_IGNORE_NULL_DEREFERENCE_BEGIN
1457 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1458 YY_IGNORE_NULL_DEREFERENCE_END
1461 const glr_state
* semantic_option::state () const
1463 return yystate
? &(asItem(this) - yystate
)->getState() : YY_NULLPTR
;
1466 void semantic_option::setState (const glr_state
* s
)
1468 yystate
= s
? asItem(this) - asItem(s
) : 0;
1471 const semantic_option
* semantic_option::next () const
1473 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1476 semantic_option
* semantic_option::next ()
1478 return yynext
? &(asItem(this) - yynext
)->getOption() : YY_NULLPTR
;
1481 void semantic_option::setNext (const semantic_option
* s
)
1483 yynext
= s
? asItem(this) - asItem(s
) : 0;
1486 void glr_state::destroy (char const* yymsg
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_user_formals
[)
1487 {]b4_parse_assert_if([[
1490 yyparser
.yy_destroy_ (yymsg
, yy_accessing_symbol(yylrState
),
1491 &value ()]b4_locations_if([, &yyloc
])[);
1494 YY_SYMBOL_PRINT (yymsg
<< (firstVal() ? " unresolved" : " incomplete"),
1495 yy_accessing_symbol(yylrState
), YY_NULLPTR
, &yyloc
);
1497 if (firstVal() != YY_NULLPTR
)
1499 semantic_option
& yyoption
= *firstVal ();
1500 glr_state
*yyrh
= yyoption
.state ();
1501 for (int yyn
= yyrhsLength (yyoption
.yyrule
); yyn
> 0; yyn
-= 1)
1503 yyrh
->destroy (yymsg
, yyparser
]b4_user_args
[);
1504 yyrh
= yyrh
->pred();
1512 yypreference (const semantic_option
& y0
, const semantic_option
& y1
);
1514 static inline state_num
1515 yyLRgotoState (state_num yystate
, yysymbol_kind_t yysym
);
1518 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
1523 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1524 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1526 /** Initialize to a single empty stack, with total maximum
1527 * capacity for all stacks of YYSIZE. */
1528 state_stack (size_t yysize
)
1529 : yysplitPoint (YY_NULLPTR
)
1531 yyitems
.reserve (yysize
);
1534 #if YYSTACKEXPANDABLE
1535 /** Returns false if it tried to expand but could not. */
1537 yyexpandGLRStackIfNeeded ()
1539 return YYHEADROOM
<= spaceLeft () || yyexpandGLRStack ();
1543 /** If *this is expandable, extend it. WARNING: Pointers into the
1544 stack from outside should be considered invalid after this call.
1545 We always expand when there are 1 or fewer items left AFTER an
1546 allocation, so that we can avoid having external pointers exist
1547 across an allocation. */
1551 const size_t oldsize
= yyitems
.size();
1552 if (YYMAXDEPTH
- YYHEADROOM
< oldsize
)
1554 const size_t yynewSize
= YYMAXDEPTH
< 2 * oldsize
? YYMAXDEPTH
: 2 * oldsize
;
1555 const glr_stack_item
*oldbase
= &yyitems
[0];
1557 yyitems
.reserve (yynewSize
);
1558 const glr_stack_item
*newbase
= &yyitems
[0];
1560 // Adjust the pointers. Perform raw pointer arithmetics, as there
1561 // is no reason for objects to be aligned on their size.
1562 const ptrdiff_t disp
1563 = reinterpret_cast<const char*> (newbase
) - reinterpret_cast<const char*> (oldbase
);
1565 const_cast<glr_state
*&> (yysplitPoint
)
1566 = reinterpret_cast<glr_state
*> (reinterpret_cast<char*> (const_cast<glr_state
*> (yysplitPoint
)) + disp
);
1568 for (std::vector
<glr_state
*>::iterator
1569 i
= yytops
.begin (),
1570 yyend
= yytops
.end ();
1572 if (glr_state_not_null (*i
))
1573 *i
= reinterpret_cast<glr_state
*>(reinterpret_cast<char*>(*i
) + disp
);
1580 bool yyexpandGLRStackIfNeeded ()
1582 return YYHEADROOM
<= spaceLeft ();
1586 static bool glr_state_not_null (glr_state
* s
)
1588 return s
!= YY_NULLPTR
;
1594 typedef std::vector
<glr_state
*>::iterator iterator
;
1595 const iterator yybegin
= yytops
.begin();
1596 const iterator yyend
= yytops
.end();
1597 const iterator yyit
= std::find_if(yybegin
, yyend
, glr_state_not_null
);
1600 for (state_set_index yyk
= create_state_set_index(yyit
+ 1 - yybegin
);
1601 yyk
.uget() != numTops(); ++yyk
)
1602 yytops
.yymarkStackDeleted (yyk
);
1603 yytops
.yyremoveDeletes ();
1608 /** Called when returning to deterministic operation to clean up the extra
1613 if (yytops
.size() != 1 || !isSplit())
1616 // yyr is the state after the split point.
1617 glr_state
* yyr
= YY_NULLPTR
;
1618 for (glr_state
*yyp
= firstTop(), *yyq
= yyp
->pred();
1619 yyp
!= yysplitPoint
;
1620 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->pred())
1623 // This const_cast is okay, since anyway we have access to the mutable
1624 // yyitems into which yysplitPoint points.
1625 glr_stack_item
* nextFreeItem
1626 = const_cast<glr_state
*> (yysplitPoint
)->asItem () + 1;
1627 yysplitPoint
= YY_NULLPTR
;
1628 yytops
.clearLastDeleted ();
1630 while (yyr
!= YY_NULLPTR
)
1632 nextFreeItem
->setState (*yyr
);
1633 glr_state
& nextFreeState
= nextFreeItem
->getState();
1635 nextFreeState
.setPred(&(nextFreeItem
- 1)->getState());
1636 setFirstTop (&nextFreeState
);
1639 yyitems
.resize(static_cast<size_t>(nextFreeItem
- yyitems
.data()));
1642 bool isSplit() const {
1643 return yysplitPoint
!= YY_NULLPTR
;
1646 // Present the interface of a vector of glr_stack_item.
1647 std::vector
<glr_stack_item
>::const_iterator
begin () const
1649 return yyitems
.begin ();
1652 std::vector
<glr_stack_item
>::const_iterator
end () const
1654 return yyitems
.end ();
1659 return yyitems
.size ();
1662 glr_stack_item
& operator[] (size_t i
)
1667 glr_stack_item
& stackItemAt (size_t index
)
1669 return yyitems
[index
];
1672 size_t numTops() const {
1673 return yytops
.size();
1676 glr_state
* firstTop() const {
1677 return yytops
[create_state_set_index(0)];
1680 glr_state
* topAt(state_set_index i
) const {
1684 void setFirstTop(glr_state
* value
) {
1685 yytops
[create_state_set_index(0)] = value
;
1688 void setTopAt(state_set_index i
, glr_state
* value
) {
1696 void pop_back(size_t n
) {
1697 yyitems
.resize(yyitems
.size() - n
);
1701 yysplitStack (state_set_index yyk
)
1705 YYASSERT (yyk
.get() == 0);
1706 yysplitPoint
= topAt(yyk
);
1708 return yytops
.yysplitStack(yyk
);
1711 /** Assuming that YYS is a GLRState somewhere on *this, update the
1712 * splitpoint of *this, if needed, so that it is at least as deep as
1715 yyupdateSplit (glr_state
& yys
)
1717 if (isSplit() && &yys
< yysplitPoint
)
1718 yysplitPoint
= &yys
;
1721 /** Return a fresh GLRState.
1722 * Callers should call yyreserveStack afterwards to make sure there is
1723 * sufficient headroom. */
1724 glr_state
& yynewGLRState(glr_state newState
) {
1725 glr_state
& state
= yyitems
[yynewGLRStackItem(true)].getState();
1726 #if 201103L <= YY_CPLUSPLUS
1727 state
= std::move(newState
);
1734 /** Return a fresh SemanticOption.
1735 * Callers should call yyreserveStack afterwards to make sure there is
1736 * sufficient headroom. */
1737 semantic_option
& yynewSemanticOption (semantic_option newOption
)
1739 semantic_option
& option
= yyitems
[yynewGLRStackItem (false)].getOption ();
1740 #if 201103L <= YY_CPLUSPLUS
1741 option
= std::move (newOption
);
1748 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
1749 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
1750 * For convenience, always return YYLOW1. */
1752 yyfill (glr_stack_item
*yyvsp
, int &yylow
, int yylow1
, bool yynormal
)
1754 if (!yynormal
&& yylow1
< yylow
)
1756 yyfillin (yyvsp
, yylow
, yylow1
);
1762 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
1763 * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred()
1764 * containing the pointer to the next state in the chain. */
1766 yyfillin (glr_stack_item
*yyvsp
, int yylow0
, int yylow1
)
1768 glr_state
* s
= yyvsp
[yylow0
].getState().pred();
1769 YYASSERT(s
!= YY_NULLPTR
);
1770 for (int i
= yylow0
-1; i
>= yylow1
; i
-= 1, s
= s
->pred())
1772 glr_state
& yys
= yyvsp
[i
].getState();
1773 #if ]b4_api_PREFIX[DEBUG
1774 yys
.yylrState
= s
->yylrState
;
1776 yys
.yyresolved
= s
->yyresolved
;
1778 new (&yys
.value ()) value_type (s
->value ());
1780 /* The effect of using yyval or yyloc (in an immediate
1781 * rule) is undefined. */
1782 yys
.setFirstVal (YY_NULLPTR
);]b4_locations_if([[
1783 yys
.yyloc
= s
->yyloc
;]])[
1784 yys
.setPred(s
->pred());
1788 #if ]b4_api_PREFIX[DEBUG
1790 /*----------------------------------------------------------------------.
1791 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1792 `----------------------------------------------------------------------*/
1795 yy_reduce_print (bool yynormal
, glr_stack_item
* yyvsp
, state_set_index yyk
,
1796 rule_num yyrule
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
)
1798 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1801 std::cerr
<< "Reducing stack " << yyk
.get() << " by rule " << yyrule
- 1
1802 << " (line " << int (yyrline
[yyrule
]) << "):\n";
1804 yyfillin (yyvsp
, 1, -yynrhs
);
1805 /* The symbols being reduced. */
1806 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1808 std::cerr
<< " $" << yyi
+ 1 << " = ";
1809 yyparser
.yy_symbol_print_
1810 (yy_accessing_symbol (yyvsp
[yyi
- yynrhs
+ 1].getState().yylrState
),
1811 &yyvsp
[yyi
- yynrhs
+ 1].getState().value ()]b4_locations_if([[,
1812 &]b4_rhs_location(yynrhs
, yyi
+ 1)])[);
1813 if (!yyvsp
[yyi
- yynrhs
+ 1].getState().yyresolved
)
1814 std::cerr
<< " (unresolved)";
1820 #define YYINDEX(YYX) \
1821 ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ()))
1826 for (size_t yyi
= 0; yyi
< size(); ++yyi
)
1828 const glr_stack_item
& item
= yyitems
[yyi
];
1829 std::cerr
<< std::setw(3) << yyi
<< ". ";
1830 if (item
.is_state())
1832 std::cerr
<< "Res: " << item
.getState().yyresolved
1833 << ", LR State: " << item
.getState().yylrState
1834 << ", posn: " << item
.getState().yyposn
1835 << ", pred: " << YYINDEX(item
.getState().pred());
1836 if (! item
.getState().yyresolved
)
1837 std::cerr
<< ", firstVal: "
1838 << YYINDEX(item
.getState().firstVal());
1842 std::cerr
<< "Option. rule: " << item
.getOption().yyrule
- 1
1843 << ", state: " << YYINDEX(item
.getOption().state())
1844 << ", next: " << YYINDEX(item
.getOption().next());
1848 std::cerr
<< "Tops:";
1849 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < numTops(); ++yyi
) {
1850 std::cerr
<< yyi
.get() << ": " << YYINDEX(topAt(yyi
)) << "; ";
1859 yyreportAmbiguity (const semantic_option
& yyx0
,
1860 const semantic_option
& yyx1
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
]b4_locations_if([, const location_type
& yyloc
])[)
1865 #if ]b4_api_PREFIX[DEBUG
1866 std::cerr
<< "Ambiguity detected.\n"
1868 yyx0
.yyreportTree ();
1869 std::cerr
<< "\nOption 2,\n";
1870 yyx1
.yyreportTree ();
1874 yyparser
.error (]b4_locations_if([yyloc
, ])[YY_("syntax is ambiguous"));
1878 /* DEBUGGING ONLY */
1879 #if ]b4_api_PREFIX[DEBUG
1880 /* Print YYS (possibly NULL) and its predecessors. */
1882 yypstates (const glr_state
* yys
) const
1884 if (yys
!= YY_NULLPTR
)
1887 std::cerr
<< "<null>";
1893 size_t spaceLeft() const
1895 return yyitems
.capacity() - yyitems
.size();
1898 /** Return a fresh GLRStackItem in this. The item is an LR state
1899 * if YYIS_STATE, and otherwise a semantic option. Callers should call
1900 * yyreserveStack afterwards to make sure there is sufficient
1903 yynewGLRStackItem (bool yyis_state
)
1905 YYDASSERT(yyitems
.size() < yyitems
.capacity());
1906 yyitems
.push_back(glr_stack_item(yyis_state
));
1907 return yyitems
.size() - 1;
1913 std::vector
<glr_stack_item
> yyitems
;
1914 // Where the stack splits. Anything below this address is deterministic.
1915 const glr_state
* yysplitPoint
;
1916 glr_state_set yytops
;
1920 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
1925 typedef ]b4_namespace_ref
[::]b4_parser_class
[::value_type value_type
;]b4_locations_if([[
1926 typedef ]b4_namespace_ref
[::]b4_parser_class
[::location_type location_type
;]])[
1928 glr_stack (size_t yysize
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser_yyarg
]m4_ifset([b4_parse_param
], [, b4_parse_param_decl
])[)
1930 , yystateStack (yysize
)
1933 , yyparser (yyparser_yyarg
)]m4_ifset([b4_parse_param
], [,b4_parse_param_cons
])[
1938 if (this->yychar
!= ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(empty
, id
)[)
1939 yyparser
.yy_destroy_ ("Cleanup: discarding lookahead",
1940 YYTRANSLATE (this->yychar
), &this->yylval
]b4_locations_if([, &this->yylloc
])[);
1945 ]b4_locations_if([[ /* To compute the location of the error token. */
1946 glr_stack_item yyerror_range
[3];]])[
1947 state_stack yystateStack
;
1950 value_type yylval
;]b4_locations_if([[
1951 location_type yylloc
;]])[
1952 YYJMP_BUF yyexception_buffer
;
1953 ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
;
1955 void yyreserveGlrStack() {
1956 if (!yystateStack
.yyexpandGLRStackIfNeeded ())
1957 yyMemoryExhausted();
1961 yyMemoryExhausted ()
1963 YYLONGJMP (yyexception_buffer
, 2);
1967 yyFail (]b4_locations_if([location_type
* yylocp
, ])[const char* yymsg
)
1969 if (yymsg
!= YY_NULLPTR
)
1970 yyparser
.error (]b4_locations_if([*yylocp
, ])[yymsg
);
1971 YYLONGJMP (yyexception_buffer
, 1);
1977 /** Add a new semantic action that will execute the action for rule
1978 * YYRULE on the semantic values in YYRHS to the list of
1979 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1980 * stack #YYK of *this. */
1982 yyaddDeferredAction (state_set_index yyk
, glr_state
* yystate
,
1983 glr_state
* yyrhs
, rule_num yyrule
)
1985 semantic_option
& yynewOption
=
1986 yystateStack
.yynewSemanticOption(semantic_option(yyrule
, ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(empty
, id
)[));
1987 yynewOption
.setState(yyrhs
);
1988 yynewOption
.setNext(yystate
->firstVal());
1989 if (yystateStack
.yytops
.lookaheadNeeds(yyk
))
1991 yynewOption
.yychar
= this->yychar
;
1992 yynewOption
.yyval
= this->yylval
;]b4_locations_if([
1993 yynewOption
.yyloc
= this->yylloc
;])[
1995 yystate
->setFirstVal(&yynewOption
);
1997 yyreserveGlrStack();
2000 #if ]b4_api_PREFIX[DEBUG
2001 void yypdumpstack () const
2003 yystateStack
.dumpStack();
2007 yyreportSyntaxError ()
2009 if (yyerrState
!= 0)
2011 ]b4_parse_error_bmatch(
2013 [[ yyparser
.error (]b4_locations_if([this->yylloc
, ])[YY_("syntax error"));]],
2015 yysymbol_kind_t yytoken
2016 = this->yychar
== ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(empty
, id
)[
2017 ? ]b4_namespace_ref
[::]b4_parser_class
[::]b4_symbol(empty
, kind
)[
2018 : YYTRANSLATE (this->yychar
);
2019 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2020 /* Arguments of yyformat. */
2021 yysymbol_kind_t yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
]
2022 = { ]b4_namespace_ref
[::]b4_parser_class
[::]b4_symbol(empty
, kind
)[ };
2023 /* Number of reported tokens (one for the "unexpected", one per
2027 /* There are many possibilities here to consider:
2028 - If this state is a consistent state with a default action, then
2029 the only way this function was invoked is if the default action
2030 is an error action. In that case, don't check for expected
2031 tokens because there are none.
2032 - The only way there can be no lookahead present (in yychar) is if
2033 this state is a consistent state with a default action. Thus,
2034 detecting the absence of a lookahead is sufficient to determine
2035 that there is no unexpected or expected token to report. In that
2036 case, just report a simple "syntax error".
2037 - Don't assume there isn't a lookahead just because this state is a
2038 consistent state with a default action. There might have been a
2039 previous inconsistent state, consistent state with a non-default
2040 action, or user semantic action that manipulated yychar.
2041 - Of course, the expected token list depends on states to have
2042 correct lookahead information, and it depends on the parser not
2043 to perform extra reductions after fetching a lookahead from the
2044 scanner and before detecting a syntax error. Thus, state merging
2045 (from LALR or IELR) and default reductions corrupt the expected
2046 token list. However, the list is correct for canonical LR with
2047 one exception: it will still contain any token that will not be
2048 accepted due to an error action in a later state.
2050 if (yytoken
!= ]b4_namespace_ref
[::]b4_parser_class
[::]b4_symbol(empty
, kind
)[)
2052 const int yyn
= yypact
[firstTopState()->yylrState
];
2053 yyarg
[yycount
++] = yytoken
;
2054 if (!yypact_value_is_default (yyn
))
2056 /* Start YYX at -YYN if negative to avoid negative indexes in
2057 YYCHECK. In other words, skip the first -YYN actions for this
2058 state because they are default actions. */
2059 const int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2060 /* Stay within bounds of both yycheck and yytname. */
2061 const int yychecklim
= YYLAST
- yyn
+ 1;
2062 const int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2063 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2064 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= ]b4_namespace_ref
[::]b4_parser_class
[::]b4_symbol(error
, kind
)[
2065 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2067 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2072 yyarg
[yycount
++] = static_cast<yysymbol_kind_t
>(yyx
);
2077 /* Internationalized format string. */
2078 const char *yyformat
= YY_NULLPTR
;
2081 #define YYCASE_(N, S) \
2085 default: /* Avoid compiler warnings. */
2086 YYCASE_(0, YY_("syntax error"));
2087 YYCASE_(1, YY_("syntax error, unexpected %s"));
2088 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2089 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2090 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2091 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2097 std::ptrdiff_t yyi
= 0;
2098 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
2099 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
2101 yymsg
+= ]b4_namespace_ref
[::]b4_parser_class
[::symbol_name (yyarg
[yyi
++]);
2106 yyparser
.error (]b4_locations_if([[yylloc
, ]])[yymsg
);
2113 /* Recover from a syntax error on this, assuming that YYTOKENP,
2114 yylval, and yylloc are the syntactic category, semantic value, and location
2115 of the lookahead. */
2117 yyrecoverSyntaxError (]b4_locations_if([location_type
* yylocp
])[)
2119 if (yyerrState
== 3)
2120 /* We just shifted the error token and (perhaps) took some
2121 reductions. Skip tokens until we can proceed. */
2124 if (this->yychar
== ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(eof
, id
)[)
2125 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2126 if (this->yychar
!= ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(empty
, id
)[)
2127 {]b4_locations_if([[
2128 /* We throw away the lookahead, but the error range
2129 of the shifted error token must take it into account. */
2130 glr_state
*yys
= firstTopState();
2131 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;
2132 yyerror_range
[2].getState().yyloc
= this->yylloc
;
2133 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2134 yysymbol_kind_t yytoken
= YYTRANSLATE (this->yychar
);
2135 yyparser
.yy_destroy_ ("Error: discarding",
2136 yytoken
, &yylval
]b4_locations_if([, &yylloc
])[);
2137 this->yychar
= ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(empty
, id
)[;
2139 yysymbol_kind_t yytoken
= yygetToken (this->yychar
, yyparser
, *this]b4_user_args
[);
2140 int yyj
= yypact
[firstTopState()->yylrState
];
2141 if (yypact_value_is_default (yyj
))
2144 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2146 if (yydefact
[firstTopState()->yylrState
] != 0)
2149 else if (! yytable_value_is_error (yytable
[yyj
]))
2153 if (!yystateStack
.reduceToOneStack())
2154 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2156 /* Now pop stack until we find a state that shifts the error token. */
2158 while (firstTopState () != YY_NULLPTR
)
2160 glr_state
*yys
= firstTopState ();
2161 int yyj
= yypact
[yys
->yylrState
];
2162 if (! yypact_value_is_default (yyj
))
2165 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2166 && yyisShiftAction (yytable
[yyj
]))
2168 /* Shift the error token. */]b4_locations_if([[
2169 /* First adjust its location.*/
2170 location_type yyerrloc
;
2171 yyerror_range
[2].getState().yyloc
= this->yylloc
;
2172 YYLLOC_DEFAULT (yyerrloc
, (yyerror_range
), 2);]])[
2173 YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol(yytable
[yyj
]),
2174 &yylval
, &yyerrloc
);
2175 yyglrShift (create_state_set_index(0), yytable
[yyj
],
2176 yys
->yyposn
, yylval
]b4_locations_if([, yyerrloc
])[);
2177 yys
= firstTopState();
2180 }]b4_locations_if([[
2181 yyerror_range
[1].getState().yyloc
= yys
->yyloc
;]])[
2182 if (yys
->pred() != YY_NULLPTR
)
2183 yys
->destroy ("Error: popping", yyparser
]b4_user_args
[);
2184 yystateStack
.setFirstTop(yys
->pred());
2185 yystateStack
.pop_back();
2187 if (firstTopState() == YY_NULLPTR
)
2188 yyFail (]b4_locations_if([yylocp
, ])[YY_NULLPTR
);
2192 yyprocessOneStack (state_set_index yyk
,
2193 size_t yyposn
]b4_locations_if([, location_type
* yylocp
])[)
2195 while (yystateStack
.topAt(yyk
) != YY_NULLPTR
)
2197 const state_num yystate
= topState(yyk
)->yylrState
;
2198 YYCDEBUG
<< "Stack " << yyk
.get()
2199 << " Entering state " << yystate
<< '\n';
2201 YYASSERT (yystate
!= YYFINAL
);
2203 if (yyisDefaultedState (yystate
))
2205 const rule_num yyrule
= yydefaultAction (yystate
);
2208 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2209 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2212 const YYRESULTTAG yyflag
2213 = yyglrReduce (yyk
, yyrule
, yyimmediate
[yyrule
]);
2214 if (yyflag
== yyerr
)
2216 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2217 " (predicate failure or explicit user error).\n";
2218 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2226 yystateStack
.yytops
.setLookaheadNeeds(yyk
, true);
2227 const yysymbol_kind_t yytoken
= yygetToken (this->yychar
, yyparser
, *this]b4_user_args
[);
2228 const short* yyconflicts
;
2229 const int yyaction
= yygetLRActions (yystate
, yytoken
, yyconflicts
);
2231 for (; *yyconflicts
!= 0; ++yyconflicts
)
2233 state_set_index yynewStack
= yystateStack
.yysplitStack (yyk
);
2234 YYCDEBUG
<< "Splitting off stack " << yynewStack
.get()
2235 << " from " << yyk
.get() << ".\n";
2236 YYRESULTTAG yyflag
=
2237 yyglrReduce (yynewStack
, *yyconflicts
, yyimmediate
[*yyconflicts
]);
2239 YYCHK (yyprocessOneStack (yynewStack
,
2240 yyposn
]b4_locations_if([, yylocp
])[));
2241 else if (yyflag
== yyerr
)
2243 YYCDEBUG
<< "Stack " << yynewStack
.get() << " dies.\n";
2244 yystateStack
.yytops
.yymarkStackDeleted (yynewStack
);
2250 if (yyisShiftAction (yyaction
))
2252 else if (yyisErrorAction (yyaction
))
2254 YYCDEBUG
<< "Stack " << yyk
.get() << " dies.\n";
2255 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2261 = yyglrReduce (yyk
, -yyaction
, yyimmediate
[-yyaction
]);
2262 if (yyflag
== yyerr
)
2264 YYCDEBUG
<< "Stack " << yyk
.get() << " dies"
2265 " (predicate failure or explicit user error).\n";
2266 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2269 else if (yyflag
!= yyok
)
2277 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
2278 * and top stack item YYVSP. YYVALP points to place to put semantic
2279 * value ($$), and yylocp points to place for location information
2280 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
2281 * yyerr for YYERROR, yyabort for YYABORT. */
2283 yyuserAction (rule_num yyrule
, int yyrhslen
, glr_stack_item
* yyvsp
, state_set_index yyk
,
2284 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2286 bool yynormal YY_ATTRIBUTE_UNUSED
= !yystateStack
.isSplit();
2288 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
2292 # define yyerrok (yyerrState = 0)
2294 # define YYACCEPT return yyaccept
2296 # define YYABORT return yyabort
2298 # define YYERROR return yyerrok, yyerr
2299 # undef YYRECOVERING
2300 # define YYRECOVERING() (yyerrState != 0)
2302 # define yychar this->yychar
2304 # define yyclearin (yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, id)[)
2306 # define YYBACKUP(Token, Value) \
2307 return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
2311 *yyvalp
= yyval_default
;
2313 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].getState().value ();]b4_locations_if([[
2314 /* Default location. */
2315 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
2316 yyerror_range
[1].getState().yyloc
= *yylocp
;
2318 /* If yyk == -1, we are running a deferred action on a temporary
2319 stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
2320 so pretend the stack is "normal". */
2321 YY_REDUCE_PRINT ((yynormal
|| yyk
== create_state_set_index (-1), yyvsp
, yyk
, yyrule
, yyparser
));
2323 typedef ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error syntax_error
;
2326 #endif // YY_EXCEPTIONS
2334 catch (const syntax_error
& yyexc
)
2336 YYCDEBUG
<< "Caught exception: " << yyexc
.what() << '\n';]b4_locations_if([
2337 *yylocp
= yyexc
.location
;])[
2338 yyparser
.error (]b4_locations_if([*yylocp
, ])[yyexc
.what ());
2341 #endif // YY_EXCEPTIONS
2342 YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule
), yyvalp
, yylocp
);
2352 # undef YYRECOVERING
2358 if (yystateStack
.isSplit())
2361 for (glr_state
* yys
= firstTopState();
2362 yys
!= yystateStack
.yysplitPoint
;
2365 YYCHK (yyresolveStates (*firstTopState(), yyn
));
2370 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
2371 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
2372 * semantic values. Assumes that all ambiguities in semantic values
2373 * have been previously resolved. Set *YYVALP to the resulting value,
2374 * and *YYLOCP to the computed location (if any). Return value is as
2375 * for userAction. */
2377 yydoAction (state_set_index yyk
, rule_num yyrule
,
2378 value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2380 const int yynrhs
= yyrhsLength (yyrule
);
2382 if (!yystateStack
.isSplit())
2384 /* Standard special case: single stack. */
2385 YYASSERT (yyk
.get() == 0);
2386 glr_stack_item
* yyrhs
= yystateStack
.firstTop()->asItem();
2387 const YYRESULTTAG res
2388 = yyuserAction (yyrule
, yynrhs
, yyrhs
, yyk
, yyvalp
]b4_locations_if([, yylocp
])[);
2389 yystateStack
.pop_back(static_cast<size_t>(yynrhs
));
2390 yystateStack
.setFirstTop(&yystateStack
[yystateStack
.size() - 1].getState());
2395 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2396 glr_state
* yys
= yystateStack
.topAt(yyk
);
2397 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yys
);]b4_locations_if([[
2399 /* Set default location. */
2400 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yys
->yyloc
;]])[
2401 for (int yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
2404 YYASSERT (yys
!= YY_NULLPTR
);
2406 yystateStack
.yyupdateSplit (*yys
);
2407 yystateStack
.setTopAt(yyk
, yys
);
2408 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2410 yyvalp
]b4_locations_if([, yylocp
])[);
2414 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
2415 * and push back on the resulting nonterminal symbol. Perform the
2416 * semantic action associated with YYRULE and store its value with the
2417 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
2418 * unambiguous. Otherwise, store the deferred semantic action with
2419 * the new state. If the new state would have an identical input
2420 * position, LR state, and predecessor to an existing state on the stack,
2421 * it is identified with that existing state, eliminating stack #YYK from
2422 * *YYSTACKP. In this case, the semantic value is
2423 * added to the options for the existing state's semantic value.
2426 yyglrReduce (state_set_index yyk
, rule_num yyrule
, bool yyforceEval
)
2428 size_t yyposn
= topState(yyk
)->yyposn
;
2430 if (yyforceEval
|| !yystateStack
.isSplit())
2432 value_type val
;]b4_locations_if([[
2433 location_type loc
;]])[
2435 YYRESULTTAG yyflag
= yydoAction (yyk
, yyrule
, &val
]b4_locations_if([, &loc
])[);
2436 if (yyflag
== yyerr
&& yystateStack
.isSplit())
2437 {]b4_parse_trace_if([[
2438 YYCDEBUG
<< "Parse on stack " << yyk
.get ()
2439 << " rejected by rule " << yyrule
- 1
2440 << " (line " << int (yyrline
[yyrule
]) << ").\n";
2445 yyLRgotoState (topState(yyk
)->yylrState
,
2446 yylhsNonterm (yyrule
)),
2447 yyposn
, val
]b4_locations_if([, loc
])[);
2451 glr_state
*yys
= yystateStack
.topAt(yyk
);
2452 glr_state
*yys0
= yys
;
2453 for (int yyn
= yyrhsLength (yyrule
); 0 < yyn
; yyn
-= 1)
2456 YYASSERT (yys
!= YY_NULLPTR
);
2458 yystateStack
.yyupdateSplit (*yys
);
2459 state_num yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));]b4_parse_trace_if([[
2460 YYCDEBUG
<< "Reduced stack " << yyk
.get ()
2461 << " by rule " << yyrule
- 1 << " (line " << int (yyrline
[yyrule
])
2462 << "); action deferred. Now in state " << yynewLRState
2464 for (state_set_index yyi
= create_state_set_index(0); yyi
.uget() < yystateStack
.numTops(); ++yyi
)
2465 if (yyi
!= yyk
&& yystateStack
.topAt(yyi
) != YY_NULLPTR
)
2467 const glr_state
* yysplit
= yystateStack
.yysplitPoint
;
2468 glr_state
* yyp
= yystateStack
.topAt(yyi
);
2469 while (yyp
!= yys
&& yyp
!= yysplit
2470 && yyp
->yyposn
>= yyposn
)
2472 if (yyp
->yylrState
== yynewLRState
2473 && yyp
->pred() == yys
)
2475 yyaddDeferredAction (yyk
, yyp
, yys0
, yyrule
);
2476 yystateStack
.yytops
.yymarkStackDeleted (yyk
);
2477 YYCDEBUG
<< "Merging stack " << yyk
.get ()
2478 << " into stack " << yyi
.get () << ".\n";
2484 yystateStack
.setTopAt(yyk
, yys
);
2485 yyglrShiftDefer (yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
2490 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
2491 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
2492 * semantic value of YYRHS under the action for YYRULE. */
2494 yyglrShiftDefer (state_set_index yyk
, state_num yylrState
,
2495 size_t yyposn
, glr_state
* yyrhs
, rule_num yyrule
)
2497 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2498 glr_state (yylrState
, yyposn
));
2499 yynewState
.setPred (yystateStack
.topAt (yyk
));
2500 yystateStack
.setTopAt (yyk
, &yynewState
);
2502 /* Invokes yyreserveStack. */
2503 yyaddDeferredAction (yyk
, &yynewState
, yyrhs
, yyrule
);
2506 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
2507 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
2508 * value YYVAL_ARG and source location YYLOC_ARG. */
2510 yyglrShift (state_set_index yyk
, state_num yylrState
,
2512 value_type
& yyval_arg
]b4_locations_if([, const location_type
& yyloc_arg
])[)
2514 glr_state
& yynewState
= yystateStack
.yynewGLRState (
2515 glr_state (yylrState
, yyposn
, yyval_arg
]b4_locations_if([, yyloc_arg
])[));
2516 yynewState
.setPred (yystateStack
.topAt(yyk
));
2517 yystateStack
.setTopAt (yyk
, &yynewState
);
2518 yyreserveGlrStack ();
2521 #if ]b4_api_PREFIX[DEBUG
2523 yypstack (state_set_index yyk
) const
2525 yystateStack
.yypstates (yystateStack
.topAt (yyk
));
2529 glr_state
* topState(state_set_index i
) {
2530 return yystateStack
.topAt(i
);
2533 glr_state
* firstTopState() {
2534 return yystateStack
.firstTop();
2541 /* If the stack is well-formed, pop the stack until it is empty,
2542 destroying its entries as we go. But free the stack regardless
2543 of whether it is well-formed. */
2544 for (state_set_index k
= create_state_set_index(0); k
.uget() < yystateStack
.numTops(); k
+= 1)
2545 if (yystateStack
.topAt(k
) != YY_NULLPTR
)
2547 while (yystateStack
.topAt(k
) != YY_NULLPTR
)
2549 glr_state
* state
= topState(k
);]b4_locations_if([[
2550 yyerror_range
[1].getState().yyloc
= state
->yyloc
;]])[
2551 if (state
->pred() != YY_NULLPTR
)
2552 state
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
2553 yystateStack
.setTopAt(k
, state
->pred());
2554 yystateStack
.pop_back();
2560 /** Resolve the previous YYN states starting at and including state YYS
2561 * on *YYSTACKP. If result != yyok, some states may have been left
2562 * unresolved possibly with empty semantic option chains. Regardless
2563 * of whether result = yyok, each state has been left with consistent
2564 * data so that destroy can be invoked if necessary. */
2566 yyresolveStates (glr_state
& yys
, int yyn
)
2570 YYASSERT (yys
.pred() != YY_NULLPTR
);
2571 YYCHK (yyresolveStates (*yys
.pred(), yyn
-1));
2572 if (! yys
.yyresolved
)
2573 YYCHK (yyresolveValue (yys
));
2579 yyuserMerge (int yyn
, value_type
* yy0
, value_type
* yy1
)
2591 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
2592 * perform the indicated actions, and set the semantic value of YYS.
2593 * If result != yyok, the chain of semantic options in YYS has been
2594 * cleared instead or it has been left unmodified except that
2595 * redundant options may have been removed. Regardless of whether
2596 * result = yyok, YYS has been left with consistent data so that
2597 * destroy can be invoked if necessary. */
2599 yyresolveValue (glr_state
& yys
)
2601 semantic_option
* yybest
= yys
.firstVal();
2602 YYASSERT(yybest
!= YY_NULLPTR
);
2603 bool yymerge
= false;
2604 YYRESULTTAG yyflag
;]b4_locations_if([
2605 location_type
*yylocp
= &yys
.yyloc
;])[
2607 semantic_option
* yypPrev
= yybest
;
2608 for (semantic_option
* yyp
= yybest
->next();
2609 yyp
!= YY_NULLPTR
; )
2611 if (yybest
->isIdenticalTo (*yyp
))
2613 yybest
->mergeWith (*yyp
);
2614 yypPrev
->setNext(yyp
->next());
2615 yyp
= yypPrev
->next();
2619 switch (yypreference (*yybest
, *yyp
))
2621 case 0:]b4_locations_if([[
2622 yyresolveLocations (yys
, 1);]])[
2623 return yystateStack
.yyreportAmbiguity (*yybest
, *yyp
, yyparser
]b4_locations_if([, *yylocp
])[);
2635 /* This cannot happen so it is not worth a YYASSERT (false),
2636 but some compilers complain if the default case is
2648 int yyprec
= yydprec
[yybest
->yyrule
];
2649 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2651 for (semantic_option
* yyp
= yybest
->next();
2655 if (yyprec
== yydprec
[yyp
->yyrule
])
2657 value_type yyval_other
;]b4_locations_if([
2658 location_type yydummy
;])[
2659 yyflag
= yyresolveAction (*yyp
, &yyval_other
]b4_locations_if([, &yydummy
])[);
2662 yyparser
.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
2663 yy_accessing_symbol (yys
.yylrState
),
2664 &this->yylval
]b4_locations_if([, yylocp
])[);
2667 yyuserMerge (yymerger
[yyp
->yyrule
], &val
, &yyval_other
);
2672 yyflag
= yyresolveAction (*yybest
, &val
]b4_locations_if([, yylocp
])[);
2676 yys
.yyresolved
= true;
2677 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2678 new (&yys
.value ()) value_type (val
);
2679 YY_IGNORE_MAYBE_UNINITIALIZED_END
2682 yys
.setFirstVal(YY_NULLPTR
);
2686 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
2687 * user action, and return the semantic value and location in *YYVALP
2688 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
2689 * have been destroyed (assuming the user action destroys all RHS
2690 * semantic values if invoked). */
2692 yyresolveAction (semantic_option
& yyopt
, value_type
* yyvalp
]b4_locations_if([, location_type
* yylocp
])[)
2694 glr_state
* yyoptState
= yyopt
.state();
2695 YYASSERT(yyoptState
!= YY_NULLPTR
);
2696 int yynrhs
= yyrhsLength (yyopt
.yyrule
);
2697 YYRESULTTAG yyflag
= yyresolveStates (*yyoptState
, yynrhs
);
2700 for (glr_state
*yys
= yyoptState
; yynrhs
> 0; yys
= yys
->pred(), yynrhs
-= 1)
2701 yys
->destroy ("Cleanup: popping", yyparser
]b4_user_args
[);
2705 glr_stack_item yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
2706 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].getState().setPred(yyopt
.state());]b4_locations_if([[
2708 /* Set default location. */
2709 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].getState().yyloc
= yyoptState
->yyloc
;]])[
2711 int yychar_current
= this->yychar
;
2712 value_type yylval_current
= this->yylval
;]b4_locations_if([
2713 location_type yylloc_current
= this->yylloc
;])[
2714 this->yychar
= yyopt
.yychar
;
2715 this->yylval
= yyopt
.yyval
;]b4_locations_if([
2716 this->yylloc
= yyopt
.yyloc
;])[
2717 yyflag
= yyuserAction (yyopt
.yyrule
, yynrhs
,
2718 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
2719 create_state_set_index (-1),
2720 yyvalp
]b4_locations_if([, yylocp
])[);
2721 this->yychar
= yychar_current
;
2722 this->yylval
= yylval_current
;]b4_locations_if([
2723 this->yylloc
= yylloc_current
;])[
2726 }]b4_locations_if([[
2728 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
2729 * ending at YYS1. Has no effect on previously resolved states.
2730 * The first semantic option of a state is always chosen. */
2732 yyresolveLocations (glr_state
&yys1
, int yyn1
)
2736 yyresolveLocations (*yys1
.pred(), yyn1
- 1);
2737 if (!yys1
.yyresolved
)
2739 glr_stack_item yyrhsloc
[1 + YYMAXRHS
];
2740 YYASSERT (yys1
.firstVal() != YY_NULLPTR
);
2741 semantic_option
& yyoption
= *yys1
.firstVal();
2742 const int yynrhs
= yyrhsLength (yyoption
.yyrule
);
2745 yyresolveLocations (*yyoption
.state(), yynrhs
);
2746 const glr_state
*yys
= yyoption
.state();
2747 for (int yyn
= yynrhs
; yyn
> 0; yyn
-= 1)
2749 yyrhsloc
[yyn
].getState().yyloc
= yys
->yyloc
;
2755 /* Both yyresolveAction and yyresolveLocations traverse the GSS
2756 in reverse rightmost order. It is only necessary to invoke
2757 yyresolveLocations on a subforest for which yyresolveAction
2758 would have been invoked next had an ambiguity not been
2759 detected. Thus the location of the previous state (but not
2760 necessarily the previous state itself) is guaranteed to be
2761 resolved already. */
2762 YY_IGNORE_NULL_DEREFERENCE_BEGIN
2763 yyrhsloc
[0].getState().yyloc
= yyoption
.state()->yyloc
;
2764 YY_IGNORE_NULL_DEREFERENCE_END
2766 YYLLOC_DEFAULT ((yys1
.yyloc
), yyrhsloc
, yynrhs
);
2771 ]b4_parse_param_vars
[
2775 #undef YYSTACKEXPANDABLE
2778 /** If yychar is empty, fetch the next token. */
2779 static inline yysymbol_kind_t
2780 yygetToken (int& yycharp
, ]b4_namespace_ref
[::]b4_parser_class
[& yyparser
, glr_stack
& yystack
]b4_user_formals
[)
2782 yysymbol_kind_t yytoken
;
2783 ]b4_parse_param_use()dnl
2784 [ if (yycharp
== ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(empty
, id
)[)
2786 YYCDEBUG
<< "Reading a token\n";
2790 #endif // YY_EXCEPTIONS
2794 catch (const ]b4_namespace_ref
[::]b4_parser_class
[::syntax_error
& yyexc
)
2796 YYCDEBUG
<< "Caught exception: " << yyexc
.what () << '\n';]b4_locations_if([
2797 yystack
.yylloc
= yyexc
.location
;])[
2798 yyparser
.error (]b4_locations_if([yystack
.yylloc
, ])[yyexc
.what ());
2799 // Map errors caught in the scanner to the error token, so that error
2800 // handling is started.
2801 yycharp
= ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(error
, id
)[;
2803 #endif // YY_EXCEPTIONS
2805 if (yycharp
<= ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(eof
, id
)[)
2807 yycharp
= ]b4_namespace_ref
[::]b4_parser_class
[::token::]b4_symbol(eof
, id
)[;
2808 yytoken
= ]b4_namespace_ref
[::]b4_parser_class
[::]b4_symbol(eof
, kind
)[;
2809 YYCDEBUG
<< "Now at end of input.\n";
2813 yytoken
= YYTRANSLATE (yycharp
);
2814 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yystack
.yylval
, &yystack
.yylloc
);
2820 /* Bison grammar-table manipulation. */
2822 /** Number of symbols composing the right hand side of rule #RULE. */
2824 yyrhsLength (rule_num yyrule
)
2826 return yyr2
[yyrule
];
2829 /** The action to take in YYSTATE on seeing YYTOKEN.
2831 * R < 0: Reduce on rule -R.
2833 * R > 0: Shift to state R.
2834 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
2835 * of conflicting reductions.
2838 yygetLRActions (state_num yystate
, yysymbol_kind_t yytoken
, const short*& yyconflicts
)
2840 int yyindex
= yypact
[yystate
] + yytoken
;
2841 if (yytoken
== ]b4_namespace_ref
[::]b4_parser_class
[::]b4_symbol(error
, kind
)[)
2843 // This is the error token.
2844 yyconflicts
= yyconfl
;
2847 else if (yyisDefaultedState (yystate
)
2848 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
2850 yyconflicts
= yyconfl
;
2851 return -yydefact
[yystate
];
2853 else if (! yytable_value_is_error (yytable
[yyindex
]))
2855 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
2856 return yytable
[yyindex
];
2860 yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
2865 /** Compute post-reduction state.
2866 * \param yystate the current state
2867 * \param yysym the nonterminal to push on the stack
2869 static inline state_num
2870 yyLRgotoState (state_num yystate
, yysymbol_kind_t yysym
)
2872 const int yyr
= yypgoto
[yysym
- YYNTOKENS
] + yystate
;
2873 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
2874 return yytable
[yyr
];
2876 return yydefgoto
[yysym
- YYNTOKENS
];
2881 /** Y0 and Y1 represent two possible actions to take in a given
2882 * parsing state; return 0 if no combination is possible,
2883 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
2885 yypreference (const semantic_option
& y0
, const semantic_option
& y1
)
2887 rule_num r0
= y0
.yyrule
, r1
= y1
.yyrule
;
2888 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
2892 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
2897 if (p0
== 0 || p1
== 0)
2906 #define YYCHK1(YYE) \
2916 goto yyuser_error; \
2923 /* DEBUGGING ONLY */
2924 #if ]b4_api_PREFIX[DEBUG
2926 yypstack (const glr_stack
& yystack
, size_t yyk
)
2928 yystack
.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk
)));
2930 static void yypdumpstack (const glr_stack
& yystack
)
2932 yystack
.yypdumpstack ();
2938 ]dnl In
this section
, the parse params are the original parse_params
.
2939 m4_pushdef([b4_parse_param
], m4_defn([b4_parse_param_orig
]))dnl
2940 [ /// Build a parser object.
2941 ]b4_parser_class::b4_parser_class
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
2943 #if ]b4_api_PREFIX[DEBUG
2944 ]m4_ifset([b4_parse_param
], [ ], [ :])[yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
2945 #endif]b4_parse_param_cons[
2948 ]b4_parser_class::~b4_parser_class
[ ()
2951 ]b4_parser_class
[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
2955 ]b4_parser_class
[::operator() ()
2961 ]b4_parser_class
[::parse ()
2963 ]b4_parser_class
[ &yyparser
= *this;
2965 glr_stack
yystack(YYINITDEPTH
, *this]b4_user_args
[);
2968 YYCDEBUG
<< "Starting parse\n";
2970 yystack
.yychar
= ]b4_namespace_ref::b4_parser_class
[::token::]b4_symbol(empty
, id
)[;
2971 yystack
.yylval
= yyval_default
;]b4_locations_if([
2972 yystack
.yylloc
= yyloc_default
;])[
2973 ]m4_ifdef([b4_initial_action
], [
2974 b4_dollar_pushdef([yystack
.yylval
], [], [], [yystack
.yylloc
])dnl
2975 b4_user_initial_action
2976 b4_dollar_popdef
])[]dnl
2978 switch (YYSETJMP (yystack
.yyexception_buffer
))
2981 case 1: goto yyabortlab
;
2982 case 2: goto yyexhaustedlab
;
2983 default: goto yybuglab
;
2985 yystack
.yyglrShift (create_state_set_index(0), 0, 0, yystack
.yylval
]b4_locations_if([, yystack
.yylloc
])[);
2990 /* For efficiency, we have two loops, the first of which is
2991 specialized to deterministic operation (single stack, no
2992 potential ambiguity). */
2996 const state_num yystate
= yystack
.firstTopState()->yylrState
;
2997 YYCDEBUG
<< "Entering state " << yystate
<< '\n';
2998 if (yystate
== YYFINAL
)
3000 if (yyisDefaultedState (yystate
))
3002 const rule_num yyrule
= yydefaultAction (yystate
);
3004 {]b4_locations_if([[
3005 yystack
.yyerror_range
[1].getState().yyloc
= yystack
.yylloc
;]])[
3006 yystack
.yyreportSyntaxError ();
3009 YYCHK1 (yystack
.yyglrReduce (create_state_set_index(0), yyrule
, true));
3013 const yysymbol_kind_t yytoken
= yygetToken (yystack
.yychar
, yyparser
, yystack
]b4_user_args
[);
3014 const short* yyconflicts
;
3015 const int yyaction
= yygetLRActions (yystate
, yytoken
, yyconflicts
);
3016 if (*yyconflicts
!= 0)
3018 if (yyisShiftAction (yyaction
))
3020 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yystack
.yylval
, &yystack
.yylloc
);
3021 yystack
.yychar
= token::]b4_symbol(empty
, id
)[;
3023 yystack
.yyglrShift (create_state_set_index(0), yyaction
, yyposn
, yystack
.yylval
]b4_locations_if([, yystack
.yylloc
])[);
3024 if (0 < yystack
.yyerrState
)
3025 yystack
.yyerrState
-= 1;
3027 else if (yyisErrorAction (yyaction
))
3028 {]b4_locations_if([[
3029 yystack
.yyerror_range
[1].getState().yyloc
= yystack
.yylloc
;]])[
3030 /* Don't issue an error message again for exceptions
3031 thrown from the scanner. */
3032 if (yystack
.yychar
!= token::]b4_symbol(error
, id
)[)
3033 yystack
.yyreportSyntaxError ();
3037 YYCHK1 (yystack
.yyglrReduce (create_state_set_index(0), -yyaction
, true));
3043 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < yystack
.yystateStack
.numTops(); ++yys
)
3044 yystack
.yystateStack
.yytops
.setLookaheadNeeds(yys
, yystack
.yychar
!= token::]b4_symbol(empty
, id
)[);
3046 /* yyprocessOneStack returns one of three things:
3048 - An error flag. If the caller is yyprocessOneStack, it
3049 immediately returns as well. When the caller is finally
3050 yyparse, it jumps to an error label via YYCHK1.
3052 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
3053 (yys), which sets the top state of yys to NULL. Thus,
3054 yyparse's following invocation of yyremoveDeletes will remove
3057 - yyok, when ready to shift a token.
3059 Except in the first case, yyparse will invoke yyremoveDeletes and
3060 then shift the next token onto all remaining stacks. This
3061 synchronization of the shift (that is, after all preceding
3062 reductions on all stacks) helps prevent double destructor calls
3063 on yylval in the event of memory exhaustion. */
3065 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < yystack
.yystateStack
.numTops(); ++yys
)
3066 YYCHK1 (yystack
.yyprocessOneStack (yys
, yyposn
]b4_locations_if([, &yystack
.yylloc
])[));
3067 yystack
.yystateStack
.yytops
.yyremoveDeletes ();
3068 if (yystack
.yystateStack
.yytops
.size() == 0)
3070 yystack
.yystateStack
.yytops
.yyundeleteLastStack ();
3071 if (yystack
.yystateStack
.yytops
.size() == 0)
3072 yystack
.yyFail (]b4_locations_if([&yystack
.yylloc
, ])[YY_("syntax error"));
3073 YYCHK1 (yystack
.yyresolveStack ());
3074 YYCDEBUG
<< "Returning to deterministic operation.\n";]b4_locations_if([[
3075 yystack
.yyerror_range
[1].getState().yyloc
= yystack
.yylloc
;]])[
3076 yystack
.yyreportSyntaxError ();
3080 /* If any yyglrShift call fails, it will fail after shifting. Thus,
3081 a copy of yylval will already be on stack 0 in the event of a
3082 failure in the following loop. Thus, yychar is set to ]b4_symbol(empty, id)[
3083 before the loop to make sure the user destructor for yylval isn't
3085 yysymbol_kind_t yytoken_to_shift
= YYTRANSLATE (yystack
.yychar
);
3086 yystack
.yychar
= token::]b4_symbol(empty
, id
)[;
3088 for (state_set_index yys
= create_state_set_index(0); yys
.uget() < yystack
.yystateStack
.numTops(); ++yys
)
3090 const state_num yystate
= yystack
.topState(yys
)->yylrState
;
3091 const short* yyconflicts
;
3093 = yygetLRActions (yystate
, yytoken_to_shift
, yyconflicts
);
3094 /* Note that yyconflicts were handled by yyprocessOneStack. */
3095 YYCDEBUG
<< "On stack " << yys
.get() << ", ";
3096 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yystack
.yylval
, &yystack
.yylloc
);
3097 yystack
.yyglrShift (yys
, yyaction
, yyposn
, yystack
.yylval
]b4_locations_if([, yystack
.yylloc
])[);
3098 YYCDEBUG
<< "Stack " << yys
.get() << " now in state #"
3099 << yystack
.topState(yys
)->yylrState
<< '\n';
3102 if (yystack
.yystateStack
.yytops
.size() == 1)
3104 YYCHK1 (yystack
.yyresolveStack ());
3105 YYCDEBUG
<< "Returning to deterministic operation.\n";
3106 yystack
.yystateStack
.yycompressStack ();
3112 yystack
.yyrecoverSyntaxError (]b4_locations_if([&yystack
.yylloc
])[);
3113 yyposn
= yystack
.firstTopState()->yyposn
;
3129 error (]b4_locations_if([yystack
.yylloc
, ])[YY_("memory exhausted"));
3137 ]b4_parse_error_bmatch([custom\
|detailed
],
3139 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3141 static const char *const yy_sname
[] =
3144 };]b4_has_translations_if([[
3145 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
3146 internationalizable. */
3147 static ]b4_int_type_for([b4_translatable
])[ yytranslatable
[] =
3151 return (yysymbol
< YYNTOKENS
&& yytranslatable
[yysymbol
]
3152 ? _(yy_sname
[yysymbol
])
3153 : yy_sname
[yysymbol
]);]], [[
3154 return yy_sname
[yysymbol
];]])[
3158 [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3160 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3162 return yytname_
[yysymbol
];
3164 #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
3167 [[ /* Return YYSTR after stripping away unnecessary quotes and
3168 backslashes, so that it's suitable for yyerror. The heuristic is
3169 that double-quoting is unnecessary unless the string contains an
3170 apostrophe, a comma, or backslash (other than backslash-backslash).
3171 YYSTR is taken from yytname. */
3173 ]b4_parser_class
[::yytnamerr_ (const char *yystr
)
3178 char const *yyp
= yystr
;
3185 goto do_not_strip_quotes
;
3189 goto do_not_strip_quotes
;
3201 do_not_strip_quotes
: ;
3208 ]b4_parser_class
[::symbol_name (symbol_kind_type yysymbol
)
3210 return yytnamerr_ (yytname_
[yysymbol
]);
3214 ]b4_parse_error_bmatch([simple\
|verbose
],
3215 [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
3216 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3217 // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
3219 const ]b4_parser_class
[::yytname_
[] =
3227 ]b4_parser_class
[::yy_destroy_ (const char* yymsg
, symbol_kind_type yykind
,
3228 const value_type
* yyvaluep
]b4_locations_if([[,
3229 const location_type
* yylocationp
]])[)
3231 YYUSE (yyvaluep
);]b4_locations_if([[
3232 YYUSE (yylocationp
);]])[
3235 ]b4_parser_class
[& yyparser
= *this;
3237 YY_SYMBOL_PRINT (yymsg
, yykind
, yyvaluep
, yylocationp
);
3239 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3240 ]b4_symbol_actions([destructor
])[
3241 YY_IGNORE_MAYBE_UNINITIALIZED_END
3244 #if ]b4_api_PREFIX[DEBUG
3245 /*--------------------.
3246 | Print this symbol. |
3247 `--------------------*/
3250 ]b4_parser_class
[::yy_symbol_value_print_ (symbol_kind_type yykind
,
3251 const value_type
* yyvaluep
]b4_locations_if([[,
3252 const location_type
* yylocationp
]])[) const
3253 {]b4_locations_if([[
3254 YYUSE (yylocationp
);]])[
3256 std::ostream
& yyo
= debug_stream ();
3257 std::ostream
& yyoutput
= yyo
;
3259 ]b4_symbol_actions([printer
])[
3263 ]b4_parser_class
[::yy_symbol_print_ (symbol_kind_type yykind
,
3264 const value_type
* yyvaluep
]b4_locations_if([[,
3265 const location_type
* yylocationp
]])[) const
3267 *yycdebug_
<< (yykind
< YYNTOKENS
? "token" : "nterm")
3268 << ' ' << symbol_name (yykind
) << " ("]b4_locations_if([[
3269 << *yylocationp
<< ": "]])[;
3270 yy_symbol_value_print_ (yykind
, yyvaluep
]b4_locations_if([[, yylocationp
]])[);
3275 ]b4_parser_class
[::debug_stream () const
3281 ]b4_parser_class
[::set_debug_stream (std::ostream
& o
)
3287 ]b4_parser_class
[::debug_level_type
3288 ]b4_parser_class
[::debug_level () const
3294 ]b4_parser_class
[::set_debug_level (debug_level_type l
)
3296 // Actually, it is yydebug which is really used.
3301 ]m4_popdef([b4_parse_param
])dnl
3302 b4_namespace_close
[]dnl
3307 m4_popdef([b4_parse_param
])