diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-08-10 10:33:06 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-08-10 10:42:26 +0300 |
commit | f606bdbedff44a60218a7007de93ee20833c7b17 (patch) | |
tree | 0fd57c06f31dff131521686b3d9eb7def12769ec /contrib/tools/bison/data/skeletons | |
parent | 57386fad9537813e2135b5b19949e5597d7b5b50 (diff) | |
download | ydb-f606bdbedff44a60218a7007de93ee20833c7b17.tar.gz |
Update contrib/tools/bison to 3.6.4
9febd1b3a041f2e2083c076fbde9680a7cdc9b9e
Diffstat (limited to 'contrib/tools/bison/data/skeletons')
-rw-r--r-- | contrib/tools/bison/data/skeletons/README-D.txt | 4 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/bison.m4 | 147 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/c++.m4 | 223 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/c-like.m4 | 8 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/c.m4 | 243 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/glr.cc | 155 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/lalr1.cc | 578 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/stack.hh | 25 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/variant.hh | 14 | ||||
-rw-r--r-- | contrib/tools/bison/data/skeletons/yacc.c | 897 |
10 files changed, 1426 insertions, 868 deletions
diff --git a/contrib/tools/bison/data/skeletons/README-D.txt b/contrib/tools/bison/data/skeletons/README-D.txt index 214e309923..e6068b4edb 100644 --- a/contrib/tools/bison/data/skeletons/README-D.txt +++ b/contrib/tools/bison/data/skeletons/README-D.txt @@ -27,7 +27,7 @@ public interface Lexer * to the next token and prepares to return the semantic value * and beginning/ending positions of the token. * @return the token identifier corresponding to the next token. */ - YYTokenType yylex (); + TokenKind yylex (); /** * Entry point for error reporting. Emits an error @@ -39,7 +39,7 @@ public interface Lexer void yyerror (YYLocation loc, string s); } -- semantic types are handled by D usions (same as for C/C++ parsers) +- semantic types are handled by D unions (same as for C/C++ parsers) - the following (non-standard) %defines are supported: diff --git a/contrib/tools/bison/data/skeletons/bison.m4 b/contrib/tools/bison/data/skeletons/bison.m4 index 8e01bd6a6d..637d2fcbf2 100644 --- a/contrib/tools/bison/data/skeletons/bison.m4 +++ b/contrib/tools/bison/data/skeletons/bison.m4 @@ -19,6 +19,27 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. + +# m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...) +# ---------------------------------------------- +# m4 equivalent of +# +# $_ = STRING; +# s/RE1/SUBST1/g; +# s/RE2/SUBST2/g; +# ... +# +# Really similar to m4_bpatsubsts, but behaves properly with quotes. +# See m4.at's "Generating Comments". Super inelegant, but so far, I +# did not find any better solution. +m4_define([b4_gsub], +[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]], + [$2], [$3]), + [$4], [$5]), + [$6], [$7])]) + + + ## ---------------- ## ## Identification. ## ## ---------------- ## @@ -72,8 +93,9 @@ version 2.2 of Bison.]) # ------------- # Issue a warning about private implementation details. m4_define([b4_disclaimer], -[b4_comment([Undocumented macros, especially those whose name start with YY_, -are private implementation details. Do not rely on them.]) +[b4_comment([DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, +especially those whose name start with YY_ or yy_. They are +private implementation details that can be changed or removed.]) ]) @@ -369,6 +391,7 @@ m4_define([b4_$3_if], # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. b4_define_flag_if([defines]) # Whether headers are requested. b4_define_flag_if([glr]) # Whether a GLR parser is requested. +b4_define_flag_if([has_translations]) # Whether some tokens are internationalized. b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. @@ -384,37 +407,64 @@ m4_define([b4_glr_cc_if], ## Symbols. ## ## --------- ## -# For a description of the Symbol handling, see README. +# For a description of the Symbol handling, see README.md. # # The following macros provide access to symbol related values. # __b4_symbol(NUM, FIELD) # ----------------------- -# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if -# undefined. +# Fetch FIELD of symbol #NUM. Fail if undefined. m4_define([__b4_symbol], [m4_indir([b4_symbol($1, $2)])]) # _b4_symbol(NUM, FIELD) # ---------------------- -# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if -# undefined. +# Fetch FIELD of symbol #NUM (or "orig NUM", see README.md). +# Fail if undefined. m4_define([_b4_symbol], [m4_ifdef([b4_symbol($1, number)], [__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)], [__b4_symbol([$1], [$2])])]) +# b4_symbol_token_kind(NUM) +# ------------------------- +# The token kind of this symbol. +m4_define([b4_symbol_token_kind], +[b4_percent_define_get([api.token.prefix])dnl +_b4_symbol([$1], [id])]) + + +# b4_symbol_kind(NUM) +# ------------------- +# Build the name of the kind of this symbol. It must always exist, +# otherwise some symbols might not be represented in the enum, which +# might be compiled into too small a type to contain all the symbol +# numbers. +m4_define([b4_symbol_prefix], [b4_percent_define_get([api.symbol.prefix])]) +m4_define([b4_symbol_kind], +[b4_percent_define_get([api.symbol.prefix])dnl +m4_case([$1], + [-2], [[YYEMPTY]], + [0], [[YYEOF]], + [1], [[YYerror]], + [2], [[YYUNDEF]], + [m4_case(b4_symbol([$1], [tag]), + [$accept], [[YYACCEPT]], + [b4_symbol_if([$1], [has_id], _b4_symbol([$1], [id]), + [m4_bpatsubst([$1-][]_b4_symbol([$1], [tag]), [[^a-zA-Z_0-9]+], [_])])])])]) + # b4_symbol(NUM, FIELD) # --------------------- -# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if -# undefined. If FIELD = id, prepend the token prefix. +# Fetch FIELD of symbol #NUM (or "orig NUM"). Fail if undefined. +# +# If FIELD = id, prepend the token prefix. m4_define([b4_symbol], [m4_case([$2], - [id], [m4_do([b4_percent_define_get([api.token.prefix])], - [_b4_symbol([$1], [id])])], + [id], [b4_symbol_token_kind([$1])], + [kind], [b4_symbol_kind([$1])], [_b4_symbol($@)])]) @@ -437,9 +487,9 @@ m4_define([b4_symbol_tag_comment], ]) -# b4_symbol_action(SYMBOL-NUM, KIND) -# ---------------------------------- -# Run the action KIND (destructor or printer) for SYMBOL-NUM. +# b4_symbol_action(SYMBOL-NUM, ACTION) +# ------------------------------------ +# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM. m4_define([b4_symbol_action], [b4_symbol_if([$1], [has_$2], [b4_dollar_pushdef([(*yyvaluep)], @@ -463,21 +513,21 @@ m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])]) m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])]) -# b4_symbol_actions(KIND, [TYPE = yytype]) -# ---------------------------------------- -# Emit the symbol actions for KIND ("printer" or "destructor"). -# Dispatch on TYPE. +# b4_symbol_actions(ACTION, [KIND = yykind]) +# ------------------------------------------ +# Emit the symbol actions for ACTION ("destructor" or "printer"). +# Dispatch on KIND. m4_define([b4_symbol_actions], [m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl m4_ifval(m4_defn([b4_actions_]), -[switch (m4_default([$2], [yytype])) +[switch (m4_default([$2], [yykind])) { m4_defn([b4_actions_])[]dnl default: break; }dnl ], -[YYUSE (m4_default([$2], [yytype]));])dnl +[YYUSE (m4_default([$2], [yykind]));])dnl m4_popdef([b4_actions_])dnl ]) @@ -507,13 +557,14 @@ m4_define([b4_symbol_map], # b4_token_visible_if(NUM, IF-TRUE, IF-FALSE) # ------------------------------------------- -# Whether NUM denotes a token that has an exported definition (i.e., -# shows in enum yytokentype). +# Whether NUM denotes a token kind that has an exported definition +# (i.e., shows in enum yytokentype). m4_define([b4_token_visible_if], [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], [$2], [$3])], [$3])]) + # b4_token_has_definition(NUM) # ---------------------------- # 1 if NUM is visible, nothing otherwise. @@ -530,12 +581,26 @@ m4_define([b4_any_token_visible_if], # b4_token_format(FORMAT, NUM) # ---------------------------- +# If token NUM has a visible ID, format FORMAT with ID, USER_NUMBER. m4_define([b4_token_format], [b4_token_visible_if([$2], [m4_format([[$1]], - m4_quote(b4_symbol([$2], [id])), - m4_quote(b4_symbol([$2], b4_api_token_raw_if([[number]], [[user_number]]))))])]) + m4_expand(b4_symbol([$2], [id])), + m4_expand(b4_symbol([$2], b4_api_token_raw_if([[number]], [[user_number]]))))])]) + + +# b4_last_enum_token +# ------------------ +# The code of the last token visible token. +m4_define([_b4_last_enum_token], +[b4_token_visible_if([$1], + [m4_define([b4_last_enum_token], [$1])])]) +b4_symbol_foreach([_b4_last_enum_token]) +# b4_last_symbol +# -------------- +# The code of the last symbol. +m4_define([b4_last_symbol], m4_eval(b4_tokens_number + b4_nterms_number - 1)) ## ------- ## ## Types. ## @@ -603,7 +668,7 @@ m4_define([b4_sync_end], [ b4_comment([$2:$1])] # This generates dependencies on the Bison skeletons hence lots of # useless 'git diff'. This location is useless for the regular # user (who does not care about the skeletons) and is actually not -# useful for Bison developpers too (I, Akim, never used this to locate +# useful for Bison developers too (I, Akim, never used this to locate # the code in skeletons that generated output). So disable it # completely. If someone thinks this was actually useful, a %define # variable should be provided to control the level of verbosity of @@ -1016,21 +1081,23 @@ m4_define([b4_bison_locations_if], [b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])]) -# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT]) + +# %define parse.error "(custom|detailed|simple|verbose)" # ------------------------------------------------------ -# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and -# b4_error_verbose_flag. b4_percent_define_default([[parse.error]], [[simple]]) b4_percent_define_check_values([[[[parse.error]], - [[simple]], [[verbose]]]]) -m4_define([b4_error_verbose_flag], - [m4_case(b4_percent_define_get([[parse.error]]), - [simple], [[0]], - [verbose], [[1]])]) -b4_define_flag_if([error_verbose]) + [[custom]], [[detailed]], [[simple]], [[verbose]]]]) + +# b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE) +# ---------------------------------------------------------- +m4_define([b4_parse_error_case], +[m4_case(b4_percent_define_get([[parse.error]]), $@)]) + +# b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE) +# ------------------------------------------------------------------ +m4_define([b4_parse_error_bmatch], +[m4_bmatch(b4_percent_define_get([[parse.error]]), $@)]) -# yytoken_table is needed to support verbose errors. -b4_error_verbose_if([m4_define([b4_token_table_flag], [1])]) # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT]) @@ -1116,3 +1183,11 @@ b4_percent_define_ifdef([api.value.type], # api.value.union.name. b4_percent_define_check_kind([api.value.union.name], [keyword]) + +# parse.error (custom|detailed) >< token-table. +b4_token_table_if( +[b4_parse_error_bmatch([custom\|detailed], +[b4_complain_at(b4_percent_define_get_loc([parse.error]), + [['%s' and '%s' cannot be used together]], + [%token-table], + [%define parse.error (custom|detailed)])])]) diff --git a/contrib/tools/bison/data/skeletons/c++.m4 b/contrib/tools/bison/data/skeletons/c++.m4 index c52f034c56..b862bf3ca7 100644 --- a/contrib/tools/bison/data/skeletons/c++.m4 +++ b/contrib/tools/bison/data/skeletons/c++.m4 @@ -22,6 +22,8 @@ b4_percent_define_ifdef([[api.value.union.name]], [b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]), [named %union is invalid in C++])]) +b4_percent_define_default([[api.symbol.prefix]], [[S_]]) + m4_include(b4_skeletonsdir/[c.m4]) b4_percent_define_check_kind([api.namespace], [code], [deprecated]) @@ -160,20 +162,42 @@ m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]), [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])]) +## ------------- ## +## Token kinds. ## +## ------------- ## + + # b4_token_enums # -------------- -# Output the definition of the tokens as enums. +# Output the definition of the token kinds. m4_define([b4_token_enums], -[[enum yytokentype +[[enum token_kind_type { - ]m4_join([, - ], - b4_symbol_map([b4_token_enum]))[ - };]dnl + ]b4_symbol([-2], [id])[ = -2, +]b4_symbol_foreach([b4_token_enum])dnl +[ };]dnl ]) +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[enum symbol_kind_type + { + YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens. + ]b4_symbol_kind([-2])[ = -2, +]b4_symbol_foreach([ b4_symbol_enum])dnl +[ };]]) + + ## ----------------- ## ## Semantic Values. ## @@ -231,23 +255,31 @@ m4_define([b4_public_types_declare], location_type location;])[ }; - /// Tokens. + /// Token kinds. struct token { ]b4_token_enums[ + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type yytokentype; }; - /// (External) token type, as returned by yylex. - typedef token::yytokentype token_type; + /// Token kind, as returned by yylex. + typedef token::yytokentype token_kind_type; + + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type token_type; - /// Symbol type: an internal symbol number. - typedef int symbol_number_type; + /// Symbol kinds. + struct symbol_kind + { + ]b4_declare_symbol_enum[ + }; - /// The symbol type number to denote an empty symbol. - enum { empty_symbol = -2 }; + /// (Internal) symbol kind. + typedef symbol_kind::symbol_kind_type symbol_kind_type; - /// Internal symbol number for tokens (subsumed by symbol_number_type). - typedef ]b4_int_type_for([b4_translate])[ token_number_type; + /// The number of tokens. + static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS; ]]) @@ -258,8 +290,8 @@ m4_define([b4_public_types_declare], m4_define([b4_symbol_type_define], [[ /// A complete symbol. /// - /// Expects its Base type to provide access to the symbol type - /// via type_get (). + /// Expects its Base type to provide access to the symbol kind + /// via kind (). /// /// Provide access to semantic value]b4_locations_if([ and location])[. template <typename Base> @@ -276,7 +308,14 @@ m4_define([b4_symbol_type_define], #if 201103L <= YY_CPLUSPLUS /// Move constructor. - basic_symbol (basic_symbol&& that); + basic_symbol (basic_symbol&& that) + : Base (std::move (that)) + , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([ + , location (std::move (that.location))])[ + {]b4_variant_if([ + b4_symbol_variant([this->kind ()], [value], [move], + [std::move (that.value)]) + ])[} #endif /// Copy constructor. @@ -303,21 +342,47 @@ m4_define([b4_symbol_type_define], void clear () {]b4_variant_if([[ // User destructor. - symbol_number_type yytype = this->type_get (); + symbol_kind_type yykind = this->kind (); basic_symbol<Base>& yysym = *this; (void) yysym; - switch (yytype) + switch (yykind) { ]b4_symbol_foreach([b4_symbol_destructor])dnl [ default: break; } - // Type destructor. -]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[ + // Value type destructor. +]b4_symbol_variant([[yykind]], [[value]], [[template destroy]])])[ Base::clear (); } +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of this symbol. + std::string name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]])[ + + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT; + /// Whether empty. bool empty () const YY_NOEXCEPT; @@ -338,46 +403,51 @@ m4_define([b4_symbol_type_define], }; /// Type access provider for token (enum) based symbols. - struct by_type + struct by_kind { /// Default constructor. - by_type (); + by_kind (); #if 201103L <= YY_CPLUSPLUS /// Move constructor. - by_type (by_type&& that); + by_kind (by_kind&& that); #endif /// Copy constructor. - by_type (const by_type& that); + by_kind (const by_kind& that); - /// The symbol type as needed by the constructor. - typedef token_type kind_type; + /// The symbol kind as needed by the constructor. + typedef token_kind_type kind_type; /// Constructor from (external) token numbers. - by_type (kind_type t); + by_kind (kind_type t); /// Record that this symbol is empty. void clear (); - /// Steal the symbol type from \a that. - void move (by_type& that); + /// Steal the symbol kind from \a that. + void move (by_kind& that); /// The (internal) type number (corresponding to \a type). /// \a empty when empty. - symbol_number_type type_get () const YY_NOEXCEPT; + symbol_kind_type kind () const YY_NOEXCEPT; - /// The symbol type. - /// \a empty_symbol when empty. - /// An int, not token_number_type, to be able to store empty_symbol. - int type; + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT; + + /// The symbol kind. + /// \a ]b4_symbol_prefix[YYEMPTY when empty. + symbol_kind_type kind_; }; + /// Backward compatibility for a private implementation detail (Bison 3.6). + typedef by_kind by_type; + /// "External" symbols: returned by the scanner. - struct symbol_type : basic_symbol<by_type> + struct symbol_type : basic_symbol<by_kind> {]b4_variant_if([[ /// Superclass. - typedef basic_symbol<by_type> super_type; + typedef basic_symbol<by_kind> super_type; /// Empty symbol. symbol_type () {} @@ -393,25 +463,13 @@ m4_define([b4_symbol_type_define], # Provide the implementation needed by the public types. m4_define([b4_public_types_define], [[ // basic_symbol. -#if 201103L <= YY_CPLUSPLUS - template <typename Base> - ]b4_parser_class[::basic_symbol<Base>::basic_symbol (basic_symbol&& that) - : Base (std::move (that)) - , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([ - , location (std::move (that.location))])[ - {]b4_variant_if([ - b4_symbol_variant([this->type_get ()], [value], [move], - [std::move (that.value)]) - ])[} -#endif - template <typename Base> ]b4_parser_class[::basic_symbol<Base>::basic_symbol (const basic_symbol& that) : Base (that) , value (]b4_variant_if([], [that.value]))b4_locations_if([ , location (that.location)])[ {]b4_variant_if([ - b4_symbol_variant([this->type_get ()], [value], [copy], + b4_symbol_variant([this->kind ()], [value], [copy], [YY_MOVE (that.value)]) ])[} @@ -436,13 +494,20 @@ m4_define([b4_public_types_define], , location (YY_MOVE (l))])[ {]b4_variant_if([[ (void) v; - ]b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[ + ]b4_symbol_variant([this->kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[ + + template <typename Base> + ]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::basic_symbol<Base>::type_get () const YY_NOEXCEPT + { + return this->kind (); + } template <typename Base> bool ]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT { - return Base::type_get () == empty_symbol; + return this->kind () == symbol_kind::]b4_symbol_prefix[YYEMPTY; } template <typename Base> @@ -450,50 +515,56 @@ m4_define([b4_public_types_define], ]b4_parser_class[::basic_symbol<Base>::move (basic_symbol& s) { super_type::move (s); - ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move], + ]b4_variant_if([b4_symbol_variant([this->kind ()], [value], [move], [YY_MOVE (s.value)])], [value = YY_MOVE (s.value);])[]b4_locations_if([ location = YY_MOVE (s.location);])[ } - // by_type. - ]b4_inline([$1])b4_parser_class[::by_type::by_type () - : type (empty_symbol) + // by_kind. + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind () + : kind_ (symbol_kind::]b4_symbol_prefix[YYEMPTY) {} #if 201103L <= YY_CPLUSPLUS - ]b4_inline([$1])b4_parser_class[::by_type::by_type (by_type&& that) - : type (that.type) + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that) + : kind_ (that.kind_) { that.clear (); } #endif - ]b4_inline([$1])b4_parser_class[::by_type::by_type (const by_type& that) - : type (that.type) + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that) + : kind_ (that.kind_) {} - ]b4_inline([$1])b4_parser_class[::by_type::by_type (token_type t) - : type (yytranslate_ (t)) + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t) + : kind_ (yytranslate_ (t)) {} ]b4_inline([$1])[void - ]b4_parser_class[::by_type::clear () + ]b4_parser_class[::by_kind::clear () { - type = empty_symbol; + kind_ = symbol_kind::]b4_symbol_prefix[YYEMPTY; } ]b4_inline([$1])[void - ]b4_parser_class[::by_type::move (by_type& that) + ]b4_parser_class[::by_kind::move (by_kind& that) { - type = that.type; + kind_ = that.kind_; that.clear (); } - ]b4_inline([$1])[int - ]b4_parser_class[::by_type::type_get () const YY_NOEXCEPT + ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_kind::kind () const YY_NOEXCEPT + { + return kind_; + } + + ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_kind::type_get () const YY_NOEXCEPT { - return type; + return this->kind (); } ]]) @@ -510,15 +581,15 @@ m4_define([b4_token_constructor_define], []) # Define yytranslate_. Sometimes used in the header file ($1=hh), # sometimes in the cc file. m4_define([b4_yytranslate_define], -[ b4_inline([$1])b4_parser_class[::token_number_type +[ b4_inline([$1])b4_parser_class[::symbol_kind_type ]b4_parser_class[::yytranslate_ (int t) { ]b4_api_token_raw_if( -[[ return static_cast<token_number_type> (t);]], +[[ return static_cast<symbol_kind_type> (t);]], [[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to // TOKEN-NUM as returned by yylex. static - const token_number_type + const ]b4_int_type_for([b4_translate])[ translate_table[] = { ]b4_translate[ @@ -526,11 +597,11 @@ m4_define([b4_yytranslate_define], const int user_token_number_max_ = ]b4_user_token_number_max[; if (t <= 0) - return yyeof_; + return symbol_kind::]b4_symbol_prefix[YYEOF; else if (t <= user_token_number_max_) - return translate_table[t]; + return YY_CAST (symbol_kind_type, translate_table[t]); else - return yy_undef_token_;]])[ + return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[ } ]]) diff --git a/contrib/tools/bison/data/skeletons/c-like.m4 b/contrib/tools/bison/data/skeletons/c-like.m4 index e0460d4834..1e5ab02c8a 100644 --- a/contrib/tools/bison/data/skeletons/c-like.m4 +++ b/contrib/tools/bison/data/skeletons/c-like.m4 @@ -17,15 +17,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. + # _b4_comment(TEXT, OPEN, CONTINUE, END) # -------------------------------------- # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. # Avoid adding indentation to the first line, as the indentation comes # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). +# Turn "*/" in TEXT into "* /" so that we don't unexpectedly close +# the comments before its end. # # Prefix all the output lines with PREFIX. m4_define([_b4_comment], -[$2[]m4_bpatsubst(m4_expand([[$1]]), [ +[$2[]b4_gsub(m4_expand([$1]), + [[*]/], [*\\/], + [/[*]], [/\\*], + [ \(.\)], [ $3\1])$4]) diff --git a/contrib/tools/bison/data/skeletons/c.m4 b/contrib/tools/bison/data/skeletons/c.m4 index 0987ef777a..3c6daef23a 100644 --- a/contrib/tools/bison/data/skeletons/c.m4 +++ b/contrib/tools/bison/data/skeletons/c.m4 @@ -101,6 +101,7 @@ m4_define_default([b4_prefix], [b4_api_prefix]) b4_percent_define_default([[api.value.union.name]], [b4_api_PREFIX[][STYPE]]) +b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]]) ## ------------------------ ## ## Pure/impure interfaces. ## @@ -129,6 +130,13 @@ m4_define([b4_user_args], [m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])]) +# b4_user_formals +# --------------- +# The possible parse-params formal arguments preceded by a comma. +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) + + # b4_parse_param # -------------- # If defined, b4_parse_param arrives double quoted, but below we prefer @@ -197,7 +205,11 @@ m4_define([b4_c99_int_type], # Define private types suitable for holding small integers in C99 or later. m4_define([b4_c99_int_type_define], [m4_copy_force([b4_c99_int_type], [b4_int_type])dnl -[/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure +[#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure <limits.h> and (if available) <stdint.h> are included so that the code can choose integer types of a good width. */ @@ -253,6 +265,50 @@ typedef int yytype_uint16; #endif]]) +# b4_sizes_types_define +# --------------------- +# Define YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM, +# and YYSIZEOF. +m4_define([b4_sizes_types_define], +[[#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) +]]) + + # b4_int_type_for(NAME) # --------------------- # Return a narrow int type able to handle numbers ranging from @@ -418,9 +474,22 @@ static const b4_int_type_for([$2]) yy$1[[]] = ]) -## ------------------------- ## -## Assigning token numbers. ## -## ------------------------- ## +## ------------- ## +## Token kinds. ## +## ------------- ## + +# Because C enums are not scoped, because tokens are exposed in the +# header, and because these tokens are common to all the parsers, we +# need to make sure their names don't collide: use the api.prefix. +# YYEOF is special, since the user may give it a different name. +m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]]) +m4_define([b4_symbol(-2, tag)], [[No symbol.]]) + +m4_if(b4_symbol(0, id), [YYEOF], + [m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])]) +m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][error]]) +m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]]) + # b4_token_define(TOKEN-NUM) # -------------------------- @@ -432,7 +501,7 @@ m4_define([b4_token_define], # ---------------- # Output the definition of the tokens. m4_define([b4_token_defines], -[b4_any_token_visible_if([/* Tokens. */ +[b4_any_token_visible_if([/* Token kinds. */ m4_join([ ], b4_symbol_map([b4_token_define])) ])]) @@ -442,34 +511,81 @@ m4_join([ # ------------------------ # Output the definition of this token as an enum. m4_define([b4_token_enum], -[b4_token_format([%s = %s], [$1])]) +[b4_token_visible_if([$1], + [m4_format([ %-30s %s], + m4_format([[%s = %s%s%s]], + b4_symbol([$1], [id]), + b4_symbol([$1], b4_api_token_raw_if([[number]], [[user_number]])), + m4_if([$1], b4_last_enum_token, [], [[,]])), + [b4_symbol_tag_comment([$1])])])]) # b4_token_enums # -------------- -# Output the definition of the tokens (if there are) as enums. +# The definition of the token kinds. m4_define([b4_token_enums], -[b4_any_token_visible_if([[/* Token type. */ +[b4_any_token_visible_if([[/* Token kinds. */ #ifndef ]b4_api_PREFIX[TOKENTYPE # define ]b4_api_PREFIX[TOKENTYPE enum ]b4_api_prefix[tokentype { - ]m4_join([, - ], - b4_symbol_map([b4_token_enum]))[ - }; + ]b4_symbol([-2], [id])[ = -2, +]b4_symbol_foreach([b4_token_enum])dnl +[ }; + typedef enum ]b4_api_prefix[tokentype ]b4_api_prefix[token_kind_t; #endif ]])]) # b4_token_enums_defines # ---------------------- -# Output the definition of the tokens (if there are any) as enums and, +# The definition of the tokens (if there are any) as enums and, # if POSIX Yacc is enabled, as #defines. m4_define([b4_token_enums_defines], [b4_token_enums[]b4_yacc_if([b4_token_defines])]) +# b4_symbol_translate(STRING) +# --------------------------- +# Used by "bison" in the array of symbol names to mark those that +# require translation. +m4_define([b4_symbol_translate], +[[N_($1)]]) + + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_symbol_enum(SYMBOL-NUM) +# -------------------------- +# Output the definition of this symbol as an enum. +m4_define([b4_symbol_enum], +[m4_format([ %-40s %s], + m4_format([[%s = %s%s%s]], + b4_symbol([$1], [kind]), + [$1], + m4_if([$1], b4_last_symbol, [], [[,]])), + [b4_symbol_tag_comment([$1])])]) + + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[/* Symbol kind. */ +enum yysymbol_kind_t +{ + ]b4_symbol_kind([-2])[ = -2, +]b4_symbol_foreach([b4_symbol_enum])dnl +[}; +typedef enum yysymbol_kind_t yysymbol_kind_t; +]])]) + + ## ----------------- ## ## Semantic Values. ## ## ----------------- ## @@ -493,15 +609,6 @@ m4_define([b4_symbol_value], ## ---------------------- ## -# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...) -# ----------------------------------------------------------- -# Declare the function NAME in C. -m4_define([b4_function_define], -[$2 -$1 (b4_formals(m4_shift2($@)))[]dnl -]) - - # b4_formals([DECL1, NAME1], ...) # ------------------------------- # The formal arguments of a C function definition. @@ -515,21 +622,6 @@ m4_define([b4_formal], -## ----------------------- ## -## Declaring C functions. ## -## ----------------------- ## - - -# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...) -# ------------------------------------------------------------ -# Declare the function NAME. -m4_define([b4_function_declare], -[$2 $1 (b4_formals(m4_shift2($@)));[]dnl -]) - - - - ## --------------------- ## ## Calling C functions. ## ## --------------------- ## @@ -593,18 +685,15 @@ m4_define_default([b4_yydestruct_define], | Release the memory associated to this symbol. | `-----------------------------------------------*/ -]b4_function_define([yydestruct], - [static void], - [[const char *yymsg], [yymsg]], - [[int yytype], [yytype]], - [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl -b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl -m4_ifset([b4_parse_param], [, b4_parse_param]))[ +static void +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep]b4_locations_if(dnl +[[, YYLTYPE *yylocationp]])[]b4_user_formals[) { ]b4_parse_param_use([yyvaluep], [yylocationp])dnl [ if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN ]b4_symbol_actions([destructor])[ @@ -622,13 +711,10 @@ m4_define_default([b4_yy_symbol_print_define], | Print this symbol's value on YYO. | `-----------------------------------*/ -]b4_function_define([yy_symbol_value_print], - [static void], - [[FILE *yyo], [yyo]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl -b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl -m4_ifset([b4_parse_param], [, b4_parse_param]))[ +static void +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl +[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) { FILE *yyoutput = yyo; ]b4_parse_param_use([yyoutput], [yylocationp])dnl @@ -637,8 +723,8 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[ dnl glr.c does not feature yytoknum. m4_if(b4_skeleton, ["yacc.c"], [[# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyo, yytoknum[yytype], *yyvaluep); + if (yykind < YYNTOKENS) + YYPRINT (yyo, yytoknum[yykind], *yyvaluep); # endif ]])dnl b4_percent_code_get([[pre-printer]])dnl @@ -653,21 +739,18 @@ b4_percent_code_get([[post-printer]])dnl | Print this symbol on YYO. | `---------------------------*/ -]b4_function_define([yy_symbol_print], - [static void], - [[FILE *yyo], [yyo]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl -b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl -m4_ifset([b4_parse_param], [, b4_parse_param]))[ +static void +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl +[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) { YYFPRINTF (yyo, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); ]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp); YYFPRINTF (yyo, ": "); ])dnl -[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl +[ yy_symbol_value_print (yyo, yykind, yyvaluep]dnl b4_locations_if([, yylocationp])[]b4_user_args[); YYFPRINTF (yyo, ")"); }]dnl @@ -693,11 +776,11 @@ m4_define([b4_symbol_type_register], [m4_define([b4_symbol($1, type_tag)], [b4_symbol_if([$1], [has_id], [b4_symbol([$1], [id])], - [yytype_[]b4_symbol([$1], [number])])])dnl + [yykind_[]b4_symbol([$1], [number])])])dnl m4_append([b4_union_members], -m4_expand([ - b4_symbol_tag_comment([$1])dnl - b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);])) +m4_expand([m4_format([ %-40s %s], + m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]), + [b4_symbol_tag_comment([$1])])])) ]) @@ -930,16 +1013,14 @@ m4_define([b4_yy_location_print_define], This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ -#ifndef YY_LOCATION_PRINT -# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL +# ifndef YY_LOCATION_PRINT +# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL /* Print *YYLOCP on YYO. Private, do not rely on its existence. */ YY_ATTRIBUTE_UNUSED -]b4_function_define([yy_location_print_], - [static int], - [[FILE *yyo], [yyo]], - [[YYLTYPE const * const yylocp], [yylocp]])[ +static int +yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) { int res = 0; int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; @@ -963,17 +1044,17 @@ YY_ATTRIBUTE_UNUSED return res; } -# define YY_LOCATION_PRINT(File, Loc) \ +# define YY_LOCATION_PRINT(File, Loc) \ yy_location_print_ (File, &(Loc)) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif -#endif]], +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +# endif /* !defined YY_LOCATION_PRINT */]], [[/* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif]]) +# ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif]]) ]) # b4_yyloc_default diff --git a/contrib/tools/bison/data/skeletons/glr.cc b/contrib/tools/bison/data/skeletons/glr.cc index 887b6146b4..658b9f20ca 100644 --- a/contrib/tools/bison/data/skeletons/glr.cc +++ b/contrib/tools/bison/data/skeletons/glr.cc @@ -66,30 +66,29 @@ m4_defn([b4_parse_param]))], [[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]]]) ]) +# b4_declare_symbol_enum +# ---------------------- +m4_append([b4_declare_symbol_enum], +[[typedef symbol_kind_type yysymbol_kind_t; +]]) + # b4_yy_symbol_print_define # ------------------------- # Bypass the default implementation to generate the "yy_symbol_print" # and "yy_symbol_value_print" functions. m4_define([b4_yy_symbol_print_define], -[[ -/*--------------------. +[[/*--------------------. | Print this symbol. | `--------------------*/ -]b4_function_define([yy_symbol_print], - [static void], - [[FILE *], []], - [[int yytype], [yytype]], - [[const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep], - [yyvaluep]][]dnl -b4_locations_if([, - [[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], - [yylocationp]]]), - b4_parse_param)[ +static void +yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken, + const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep]b4_locations_if([[, + const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[) { ]b4_parse_param_use[]dnl -[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[); +[ yyparser.yy_symbol_print_ (yytoken, yyvaluep]b4_locations_if([, yylocationp])[); } ]])[ @@ -101,45 +100,24 @@ m4_defn([b4_initial_action])]))])[ # Hijack the post prologue to declare yyerror. ]m4_append([b4_post_prologue], [b4_syncline([@oline@], [@ofile@])dnl -b4_function_declare([yyerror], - [static void],b4_locations_if([ - [[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], - [yylocationp]],]) - b4_parse_param, - [[const char* msg], [msg]])])[ - - -#undef yynerrs -#undef yychar -#undef yylval]b4_locations_if([ -#undef yylloc]) - -m4_if(b4_prefix, [yy], [], -[[/* Substitute the variable and function names. */ -#define yyparse ]b4_prefix[parse -#define yylex ]b4_prefix[lex -#define yyerror ]b4_prefix[error -#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[ -#define yylval ]b4_prefix[lval -#define yychar ]b4_prefix[char -#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ -#define yylloc ]b4_prefix[lloc]])])) +[static void +yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp, + ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param), + ])[const char* msg);]])[ # Hijack the epilogue to define implementations (yyerror, parser member # functions etc.). -m4_append([b4_epilogue], +]m4_append([b4_epilogue], [b4_syncline([@oline@], [@ofile@])dnl [ /*------------------. | Report an error. | `------------------*/ -]b4_function_define([yyerror], - [static void],b4_locations_if([ - [[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], - [yylocationp]],]) - b4_parse_param, - [[const char* msg], [msg]])[ +static void +yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp, + ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param), + ])[const char* msg) { ]b4_parse_param_use[]dnl [ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg); @@ -181,9 +159,9 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl `--------------------*/ void - ]b4_parser_class[::yy_symbol_value_print_ (int yytype, + ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, const semantic_type* yyvaluep]b4_locations_if([[, - const location_type* yylocationp]])[) + const location_type* yylocationp]])[) const {]b4_locations_if([[ YYUSE (yylocationp);]])[ YYUSE (yyvaluep); @@ -195,14 +173,14 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl void - ]b4_parser_class[::yy_symbol_print_ (int yytype, + ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, const semantic_type* yyvaluep]b4_locations_if([[, - const location_type* yylocationp]])[) + const location_type* yylocationp]])[) const { - *yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm") - << ' ' << yytname[yytype] << " ("]b4_locations_if([[ + *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << yytname[yykind] << " ("]b4_locations_if([[ << *yylocationp << ": "]])[; - yy_symbol_value_print_ (yytype, yyvaluep]b4_locations_if([[, yylocationp]])[); + yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[); *yycdebug_ << ')'; } @@ -238,6 +216,53 @@ b4_namespace_close[]dnl ]) +# b4_glr_cc_setup +# --------------- +# Setup redirections for glr.c: Map the names used in c.m4 to the ones used +# in c++.m4. +m4_define([b4_glr_cc_setup], +[[#undef ]b4_symbol(-2, [id])[ +#define ]b4_symbol(-2, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(-2, [id])[ +#undef ]b4_symbol(0, [id])[ +#define ]b4_symbol(0, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(0, [id])[ +#undef ]b4_symbol(1, [id])[ +#define ]b4_symbol(1, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(1, [id])[ + +#ifndef ]b4_api_PREFIX[STYPE +# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type +#endif +#ifndef ]b4_api_PREFIX[LTYPE +# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type +#endif + +typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t; +#define ]b4_symbol_prefix[YYEMPTY ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEMPTY +#define ]b4_symbol_prefix[YYerror ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYerror +#define ]b4_symbol_prefix[YYEOF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEOF +#define ]b4_symbol_prefix[YYUNDEF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYUNDEF +]]) + + +# b4_glr_cc_cleanup +# ----------------- +# Remove redirections for glr.c. +m4_define([b4_glr_cc_cleanup], +[b4_percent_define_flag_if([[global_tokens_and_yystype]], [], +[[#undef ]b4_symbol(-2, [id])[ +#undef ]b4_symbol(0, [id])[ +#undef ]b4_symbol(1, [id])[ +]])[ + +#undef ]b4_api_PREFIX[STYPE +#undef ]b4_api_PREFIX[LTYPE + +#undef ]b4_symbol_prefix[YYEMPTY +#undef ]b4_symbol_prefix[YYerror +#undef ]b4_symbol_prefix[YYEOF +#undef ]b4_symbol_prefix[YYUNDEF +]]) + + # b4_shared_declarations(hh|cc) # ----------------------------- # Declaration that might either go into the header (if --defines, $1 = hh) @@ -328,21 +353,21 @@ b4_percent_code_get([[requires]])[ # if ]b4_api_PREFIX[DEBUG public: /// \brief Report a symbol value on the debug stream. - /// \param yytype The token type. + /// \param yykind The symbol kind. /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ - virtual void yy_symbol_value_print_ (int yytype, + virtual void yy_symbol_value_print_ (symbol_kind_type yykind, const semantic_type* yyvaluep]b4_locations_if([[, - const location_type* yylocationp]])[); + const location_type* yylocationp]])[) const; /// \brief Report a symbol on the debug stream. - /// \param yytype The token type. + /// \param yykind The symbol kind. /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ - virtual void yy_symbol_print_ (int yytype, + virtual void yy_symbol_print_ (symbol_kind_type yykind, const semantic_type* yyvaluep]b4_locations_if([[, - const location_type* yylocationp]])[); + const location_type* yylocationp]])[) const; private: - // Debugging. + /// Debug stream. std::ostream* yycdebug_; #endif @@ -351,21 +376,15 @@ b4_percent_code_get([[requires]])[ ]dnl Redirections for glr.c. b4_percent_define_flag_if([[global_tokens_and_yystype]], -[b4_token_defines]) -[ -#ifndef ]b4_api_PREFIX[STYPE -# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type -#endif -#ifndef ]b4_api_PREFIX[LTYPE -# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type -#endif - +[b4_token_defines +])[ ]b4_namespace_close[ + ]b4_percent_code_get([[provides]])[ ]m4_popdef([b4_parse_param])dnl -]) +])[ -b4_defines_if( +]b4_defines_if( [b4_output_begin([b4_spec_header_file]) b4_copyright([Skeleton interface for Bison GLR parsers in C++], [2002-2015, 2018-2020])[ diff --git a/contrib/tools/bison/data/skeletons/lalr1.cc b/contrib/tools/bison/data/skeletons/lalr1.cc index dc674a2d60..dfffb74b8e 100644 --- a/contrib/tools/bison/data/skeletons/lalr1.cc +++ b/contrib/tools/bison/data/skeletons/lalr1.cc @@ -30,6 +30,15 @@ m4_define([b4_lac_flag], [none], [[0]], [[1]])]) +# b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED) +# ------------------------------------------- +m4_define([b4_tname_if], +[m4_case(b4_percent_define_get([[parse.error]]), + [verbose], [$1], + [b4_token_table_if([$1], + [$2])])]) + + # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT) # -------------------------------------------------------------- # Declare "parser::yy<TABLE-NAME>_" whose contents is CONTENT. @@ -195,6 +204,13 @@ m4_define([b4_shared_declarations], ]b4_parser_class[ (]b4_parse_param_decl[); virtual ~]b4_parser_class[ (); +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + ]b4_parser_class[ (const ]b4_parser_class[&) = delete; + /// Non copyable. + ]b4_parser_class[& operator= (const ]b4_parser_class[&) = delete; +#endif + /// Parse. An alias for parse (). /// \returns 0 iff parsing succeeded. int operator() (); @@ -225,19 +241,57 @@ m4_define([b4_shared_declarations], /// Report a syntax error. void error (const syntax_error& err); -]b4_token_constructor_define[ +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol);]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol); +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static std::string symbol_name (symbol_kind_type yysymbol);]])[ +]b4_token_constructor_define[ +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + class context + { + public: + context (const ]b4_parser_class[& yyparser, const symbol_type& yyla); + const symbol_type& lookahead () const { return yyla_; } + symbol_kind_type token () const { return yyla_.kind (); }]b4_locations_if([[ + const location_type& location () const { return yyla_.location; } +]])[ + /// Put in YYARG at most YYARGN of the expected tokens, and return the + /// number of tokens stored in YYARG. If YYARG is null, return the + /// number of expected tokens (guaranteed to be less than YYNTOKENS). + int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; + + private: + const ]b4_parser_class[& yyparser_; + const symbol_type& yyla_; + }; +]])[ private: - /// This class is not copyable. +#if YY_CPLUSPLUS < 201103L + /// Non copyable. ]b4_parser_class[ (const ]b4_parser_class[&); - ]b4_parser_class[& operator= (const ]b4_parser_class[&);]b4_lac_if([[ - + /// Non copyable. + ]b4_parser_class[& operator= (const ]b4_parser_class[&); +#endif +]b4_lac_if([[ /// Check the lookahead yytoken. /// \returns true iff the token will be eventually shifted. - bool yy_lac_check_ (int yytoken) const; + bool yy_lac_check_ (symbol_kind_type yytoken) const; /// Establish the initial context if no initial context currently exists. /// \returns true iff the token will be eventually shifted. - bool yy_lac_establish_ (int yytoken); + bool yy_lac_establish_ (symbol_kind_type yytoken); /// Discard any previous initial lookahead context because of event. /// \param event the event which caused the lookahead to be discarded. /// Only used for debbuging output. @@ -245,13 +299,19 @@ m4_define([b4_shared_declarations], /// Stored state numbers (used for stacks). typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type; +]b4_parse_error_bmatch( + [custom], [[ + /// Report a syntax error + /// \param yyctx the context in which the error occurred. + void report_syntax_error (const context& yyctx) const;]], + [detailed\|verbose], [[ + /// The arguments of the error message. + int yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const; /// Generate an error message. - /// \param yystate the state where the error occurred. - /// \param yyla the lookahead token. - virtual std::string yysyntax_error_ (state_type yystate, - const symbol_type& yyla) const; - + /// \param yyctx the context in which the error occurred. + virtual std::string yysyntax_error_ (const context& yyctx) const;]])[ /// Compute post-reduction state. /// \param yystate the current state /// \param yysym the nonterminal to push on the stack @@ -268,34 +328,43 @@ m4_define([b4_shared_declarations], static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; - /// Convert a scanner token number \a t to a symbol number. - /// In theory \a t should be a token_type, but character literals + /// Convert a scanner token kind \a t to a symbol kind. + /// In theory \a t should be a token_kind_type, but character literals /// are valid, yet not members of the token_type enum. - static token_number_type yytranslate_ (int t); + static symbol_kind_type yytranslate_ (int t); - // Tables. -]b4_parser_tables_declare[]b4_error_verbose_if([ - - /// Convert the symbol name \a n to a form suitable for a diagnostic. - static std::string yytnamerr_ (const char *n);])[ +]b4_parse_error_bmatch( +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// Convert the symbol name \a n to a form suitable for a diagnostic. + static std::string yytnamerr_ (const char *yystr); -]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[ /// For a symbol, its name in clear. static const char* const yytname_[]; -]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[ +]])[ + + // Tables. +]b4_parser_tables_declare[ + +#if ]b4_api_PREFIX[DEBUG ]b4_integral_parser_table_declare([rline], [b4_rline], [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ /// Report on the debug stream that the rule \a r is going to be reduced. - virtual void yy_reduce_print_ (int r); + virtual void yy_reduce_print_ (int r) const; /// Print the state stack on the debug stream. - virtual void yystack_print_ (); + virtual void yy_stack_print_ () const; /// Debugging level. int yydebug_; /// Debug stream. std::ostream* yycdebug_; - /// \brief Display a symbol type, value and location. + /// \brief Display a symbol kind, value and location. /// \param yyo The output stream. /// \param yysym The symbol. template <typename Base> @@ -316,7 +385,7 @@ m4_define([b4_shared_declarations], /// Default constructor. by_state () YY_NOEXCEPT; - /// The symbol type as needed by the constructor. + /// The symbol kind as needed by the constructor. typedef state_type kind_type; /// Constructor. @@ -328,12 +397,12 @@ m4_define([b4_shared_declarations], /// Record that this symbol is empty. void clear () YY_NOEXCEPT; - /// Steal the symbol type from \a that. + /// Steal the symbol kind from \a that. void move (by_state& that); - /// The (internal) type number (corresponding to \a state). - /// \a empty_symbol when empty. - symbol_number_type type_get () const YY_NOEXCEPT; + /// The symbol kind (corresponding to \a state). + /// \a ]b4_symbol(-2, kind)[ when empty. + symbol_kind_type kind () const YY_NOEXCEPT; /// The state number used to denote an empty symbol. /// We use the initial state, as it does not have a value. @@ -401,21 +470,16 @@ m4_define([b4_shared_declarations], /// Pop \a n symbols from the stack. void yypop_ (int n = 1); - /// Some specific tokens. - static const token_number_type yy_error_token_ = 1; - static const token_number_type yy_undef_token_ = ]b4_undef_token_number[; - /// Constants. enum { - yyeof_ = 0, yylast_ = ]b4_last[, ///< Last index in yytable_. yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols. - yyfinal_ = ]b4_final_state_number[, ///< Termination state number. - yyntokens_ = ]b4_tokens_number[ ///< Number of tokens. + yyfinal_ = ]b4_final_state_number[ ///< Termination state number. }; ]b4_parse_param_vars[ +]b4_percent_code_get([[yy_bison_internal_hook]])[ }; ]b4_token_ctor_if([b4_yytranslate_define([$1])[ @@ -484,6 +548,11 @@ m4_if(b4_prefix, [yy], [], # define YY_(msgid) msgid # endif #endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ // Whether we are compiled with exception support. #ifndef YY_EXCEPTIONS @@ -523,7 +592,7 @@ m4_if(b4_prefix, [yy], [], # define YY_STACK_PRINT() \ do { \ if (yydebug_) \ - yystack_print_ (); \ + yy_stack_print_ (); \ } while (false) #else // !]b4_api_PREFIX[DEBUG @@ -543,49 +612,7 @@ m4_if(b4_prefix, [yy], [], #define YYERROR goto yyerrorlab #define YYRECOVERING() (!!yyerrstatus_) -]b4_namespace_open[]b4_error_verbose_if([[ - - /* Return YYSTR after stripping away unnecessary quotes and - backslashes, so that it's suitable for yyerror. The heuristic is - that double-quoting is unnecessary unless the string contains an - apostrophe, a comma, or backslash (other than backslash-backslash). - YYSTR is taken from yytname. */ - std::string - ]b4_parser_class[::yytnamerr_ (const char *yystr) - { - if (*yystr == '"') - { - std::string yyr; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - else - goto append; - - append: - default: - yyr += *yyp; - break; - - case '"': - return yyr; - } - do_not_strip_quotes: ; - } - - return yystr; - } -]])[ - +]b4_namespace_open[ /// Build a parser object. ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[) #if ]b4_api_PREFIX[DEBUG @@ -604,7 +631,7 @@ m4_if(b4_prefix, [yy], [], {} /*---------------. - | Symbol types. | + | symbol kinds. | `---------------*/ ]b4_token_ctor_if([], [b4_public_types_define([cc])])[ @@ -635,13 +662,13 @@ m4_if(b4_prefix, [yy], [], : state (s) {} - ]b4_parser_class[::symbol_number_type - ]b4_parser_class[::by_state::type_get () const YY_NOEXCEPT + ]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_state::kind () const YY_NOEXCEPT { if (state == empty_state) - return empty_symbol; + return symbol_kind::]b4_symbol(-2, kind)[; else - return yystos_[+state]; + return YY_CAST (symbol_kind_type, yystos_[+state]); } ]b4_parser_class[::stack_symbol_type::stack_symbol_type () @@ -650,7 +677,7 @@ m4_if(b4_prefix, [yy], [], ]b4_parser_class[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that) : super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[) {]b4_variant_if([ - b4_symbol_variant([that.type_get ()], + b4_symbol_variant([that.kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[ #if 201103L <= YY_CPLUSPLUS // that is emptied. @@ -661,10 +688,10 @@ m4_if(b4_prefix, [yy], [], ]b4_parser_class[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that) : super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[) {]b4_variant_if([ - b4_symbol_variant([that.type_get ()], + b4_symbol_variant([that.kind ()], [value], [move], [YY_MOVE (that.value)])])[ // that is emptied. - that.type = empty_symbol; + that.kind_ = symbol_kind::]b4_symbol(-2, kind)[; } #if YY_CPLUSPLUS < 201103L @@ -672,7 +699,7 @@ m4_if(b4_prefix, [yy], [], ]b4_parser_class[::stack_symbol_type::operator= (const stack_symbol_type& that) { state = that.state; - ]b4_variant_if([b4_symbol_variant([that.type_get ()], + ]b4_variant_if([b4_symbol_variant([that.kind ()], [value], [copy], [that.value])], [[value = that.value;]])[]b4_locations_if([ location = that.location;])[ @@ -683,7 +710,7 @@ m4_if(b4_prefix, [yy], [], ]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that) { state = that.state; - ]b4_variant_if([b4_symbol_variant([that.type_get ()], + ]b4_variant_if([b4_symbol_variant([that.kind ()], [value], [move], [that.value])], [[value = that.value;]])[]b4_locations_if([ location = that.location;])[ @@ -701,29 +728,27 @@ m4_if(b4_prefix, [yy], [], YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [ // User destructor. - b4_symbol_actions([destructor], [yysym.type_get ()])])[ + b4_symbol_actions([destructor], [yysym.kind ()])])[ } #if ]b4_api_PREFIX[DEBUG template <typename Base> void - ]b4_parser_class[::yy_print_ (std::ostream& yyo, - const basic_symbol<Base>& yysym) const + ]b4_parser_class[::yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const { std::ostream& yyoutput = yyo; YYUSE (yyoutput); - symbol_number_type yytype = yysym.type_get (); -#if defined __GNUC__ && ! defined __clang__ && ! defined __ICC && __GNUC__ * 100 + __GNUC_MINOR__ <= 408 - // Avoid a (spurious) G++ 4.8 warning about "array subscript is - // below array bounds". if (yysym.empty ()) - std::abort (); -#endif - yyo << (yytype < yyntokens_ ? "token" : "nterm") - << ' ' << yytname_[yytype] << " ("]b4_locations_if([ - << yysym.location << ": "])[; - ]b4_symbol_actions([printer])[ - yyo << ')'; + yyo << "empty symbol"; + else + { + symbol_kind_type yykind = yysym.kind (); + yyo << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << yysym.name () << " ("]b4_locations_if([ + << yysym.location << ": "])[; + ]b4_symbol_actions([printer])[ + yyo << ')'; + } } #endif @@ -782,11 +807,11 @@ m4_if(b4_prefix, [yy], [], ]b4_parser_class[::state_type ]b4_parser_class[::yy_lr_goto_state_ (state_type yystate, int yysym) { - int yyr = yypgoto_[yysym - yyntokens_] + yystate; + int yyr = yypgoto_[yysym - YYNTOKENS] + yystate; if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) return yytable_[yyr]; else - return yydefgoto_[yysym - yyntokens_]; + return yydefgoto_[yysym - YYNTOKENS]; } bool @@ -854,6 +879,7 @@ b4_dollar_popdef])[]dnl `-----------------------------------------------*/ yynewstate: YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n'; + YY_STACK_PRINT (); // Accept? if (yystack_[0].state == yyfinal_) @@ -874,14 +900,14 @@ b4_dollar_popdef])[]dnl // Read a lookahead token. if (yyla.empty ()) { - YYCDEBUG << "Reading a token: "; + YYCDEBUG << "Reading a token\n"; #if YY_EXCEPTIONS try #endif // YY_EXCEPTIONS {]b4_token_ctor_if([[ symbol_type yylookahead (]b4_lex[); yyla.move (yylookahead);]], [[ - yyla.type = yytranslate_ (]b4_lex[);]])[ + yyla.kind_ = yytranslate_ (]b4_lex[);]])[ } #if YY_EXCEPTIONS catch (const syntax_error& yyexc) @@ -894,12 +920,22 @@ b4_dollar_popdef])[]dnl } YY_SYMBOL_PRINT ("Next token is", yyla); + if (yyla.kind () == ]symbol_kind::b4_symbol(1, kind)[) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yyla.kind_ = ]symbol_kind::b4_symbol(2, kind)[; + goto yyerrlab1; + } + /* If the proper action on seeing token YYLA.TYPE is to reduce or to detect an error, take that action. */ - yyn += yyla.type_get (); - if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ()) + yyn += yyla.kind (); + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ()) {]b4_lac_if([[ - if (!yy_lac_establish_ (yyla.type_get ())) + if (!yy_lac_establish_ (yyla.kind ())) goto yyerrlab;]])[ goto yydefault; } @@ -910,7 +946,7 @@ b4_dollar_popdef])[]dnl { if (yy_table_value_is_error_ (yyn)) goto yyerrlab;]b4_lac_if([[ - if (!yy_lac_establish_ (yyla.type_get ())) + if (!yy_lac_establish_ (yyla.kind ())) goto yyerrlab; ]])[ yyn = -yyn; @@ -992,7 +1028,6 @@ b4_dollar_popdef])[]dnl YY_SYMBOL_PRINT ("-> $$ =", yylhs); yypop_ (yylen); yylen = 0; - YY_STACK_PRINT (); // Shift the result of the reduction. yypush_ (YY_NULLPTR, YY_MOVE (yylhs)); @@ -1007,9 +1042,17 @@ b4_dollar_popdef])[]dnl // If not already recovering from an error, report this error. if (!yyerrstatus_) { - ++yynerrs_; - error (]b4_join(b4_locations_if([yyla.location]), - [[yysyntax_error_ (yystack_[0].state, yyla)]])[); + ++yynerrs_;]b4_parse_error_case( + [simple], [[ + std::string msg = YY_("syntax error"); + error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]], + [custom], [[ + context yyctx (*this, yyla); + report_syntax_error (yyctx);]], + [[ + context yyctx (*this, yyla); + std::string msg = yysyntax_error_ (yyctx); + error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[ } ]b4_locations_if([[ @@ -1020,7 +1063,7 @@ b4_dollar_popdef])[]dnl error, discard it. */ // Return failure if at end of input. - if (yyla.type_get () == yyeof_) + if (yyla.kind () == symbol_kind::]b4_symbol_prefix[YYEOF) YYABORT; else if (!yyla.empty ()) { @@ -1046,6 +1089,7 @@ b4_dollar_popdef])[]dnl this YYERROR. */ yypop_ (yylen); yylen = 0; + YY_STACK_PRINT (); goto yyerrlab1; @@ -1054,31 +1098,33 @@ b4_dollar_popdef])[]dnl `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus_ = 3; // Each real token shifted decrements this. - { - stack_symbol_type error_token; - for (;;) - { - yyn = yypact_[+yystack_[0].state]; - if (!yy_pact_value_is_default_ (yyn)) - { - yyn += yy_error_token_; - if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yy_error_token_) - { - yyn = yytable_[yyn]; - if (0 < yyn) - break; - } - } + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[+yystack_[0].state]; + if (!yy_pact_value_is_default_ (yyn)) + { + yyn += symbol_kind::]b4_symbol(1, kind)[; + if (0 <= yyn && yyn <= yylast_ + && yycheck_[yyn] == symbol_kind::]b4_symbol(1, kind)[) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } - // Pop the current state because it cannot handle the error token. - if (yystack_.size () == 1) - YYABORT; + // Pop the current state because it cannot handle the error token. + if (yystack_.size () == 1) + YYABORT; ]b4_locations_if([[ - yyerror_range[1].location = yystack_[0].location;]])[ - yy_destroy_ ("Error: popping", yystack_[0]); - yypop_ (); - YY_STACK_PRINT (); - } + yyerror_range[1].location = yystack_[0].location;]])[ + yy_destroy_ ("Error: popping", yystack_[0]); + yypop_ (); + YY_STACK_PRINT (); + } + { + stack_symbol_type error_token; ]b4_locations_if([[ yyerror_range[2].location = yyla.location; YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[ @@ -1117,6 +1163,7 @@ b4_dollar_popdef])[]dnl /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ yypop_ (yylen); + YY_STACK_PRINT (); while (1 < yystack_.size ()) { yy_destroy_ ("Cleanup: popping", yystack_[0]); @@ -1149,17 +1196,158 @@ b4_dollar_popdef])[]dnl { error (]b4_join(b4_locations_if([yyexc.location]), [[yyexc.what ()]])[); - }]b4_lac_if([[ + } +]b4_parse_error_bmatch([custom\|detailed], +[[ const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ + } +]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytname_[yysymbol]; + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + ]b4_parser_class[::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + + std::string + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytnamerr_ (yytname_[yysymbol]); + } +]])[ + +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + // ]b4_parser_class[::context. + ]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla) + : yyparser_ (yyparser) + , yyla_ (yyla) + {} + + int + ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const + { + // Actual number of expected tokens + int yycount = 0; +]b4_lac_if([[ +#if ]b4_api_PREFIX[DEBUG + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + if (!yyparser_.yy_lac_established_) + yyparser_.yy_lac_check_ (yyla_.kind ()); +#endif + + for (int yyx = 0; yyx < YYNTOKENS; ++yyx) + { + symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx); + if (yysym != symbol_kind::]b4_symbol(1, kind)[ + && yysym != symbol_kind::]b4_symbol_prefix[YYUNDEF + && yyparser_.yy_lac_check_ (yysym)) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], [[ + int yyn = yypact_[+yyparser_.yystack_[0].state]; + if (!yy_pact_value_is_default_ (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + // Stay within bounds of both yycheck and yytname. + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != symbol_kind::]b4_symbol(1, kind)[ + && !yy_table_value_is_error_ (yytable_[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx); + } + } +]])[ + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = symbol_kind::]b4_symbol(-2, kind)[; + return yycount; + } + +]])b4_lac_if([[ bool - ]b4_parser_class[::yy_lac_check_ (int yytoken) const + ]b4_parser_class[::yy_lac_check_ (symbol_kind_type yytoken) const { // Logically, the yylac_stack's lifetime is confined to this function. // Clear it, to get rid of potential left-overs from previous call. yylac_stack_.clear (); // Reduce until we encounter a shift and thereby accept the token. #if ]b4_api_PREFIX[DEBUG - YYCDEBUG << "LAC: checking lookahead " << yytname_[yytoken] << ':'; + YYCDEBUG << "LAC: checking lookahead " << symbol_name (yytoken) << ':'; #endif std::ptrdiff_t lac_top = 0; while (true) @@ -1223,14 +1411,14 @@ b4_dollar_popdef])[]dnl : yylac_stack_.back ()); // Push the resulting state of the reduction. state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]); - YYCDEBUG << " G" << state; + YYCDEBUG << " G" << int (state); yylac_stack_.push_back (state); } } // Establish the initial context if no initial context currently exists. bool - ]b4_parser_class[::yy_lac_establish_ (int yytoken) + ]b4_parser_class[::yy_lac_establish_ (symbol_kind_type yytoken) { /* Establish the initial context for the current lookahead if no initial context is currently established. @@ -1259,7 +1447,7 @@ b4_dollar_popdef])[]dnl { #if ]b4_api_PREFIX[DEBUG YYCDEBUG << "LAC: initial context established for " - << yytname_[yytoken] << '\n'; + << symbol_name (yytoken) << '\n'; #endif yy_lac_established_ = true; return yy_lac_check_ (yytoken); @@ -1288,22 +1476,12 @@ b4_dollar_popdef])[]dnl << evt << '\n'; yy_lac_established_ = false; } - }]])[ - - // Generate an error message. - std::string - ]b4_parser_class[::yysyntax_error_ (]dnl -b4_error_verbose_if([state_type yystate, const symbol_type& yyla], - [state_type, const symbol_type&])[) const - {]b4_error_verbose_if([[ - // Number of reported tokens (one for the "unexpected", one per - // "expected"). - std::ptrdiff_t yycount = 0; - // Its maximum. - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - // Arguments of yyformat. - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + }]])b4_parse_error_bmatch([detailed\|verbose], [[ + int + ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const + { /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then the only way this function was invoked is if the default action @@ -1334,46 +1512,26 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], one exception: it will still contain any token that will not be accepted due to an error action in a later state.]])[ */ - if (!yyla.empty ()) - { - symbol_number_type yytoken = yyla.type_get (); - yyarg[yycount++] = yytname_[yytoken];]b4_lac_if([[ - -#if ]b4_api_PREFIX[DEBUG - // Execute LAC once. We don't care if it is successful, we - // only do it for the sake of debugging output. - if (!yy_lac_established_) - yy_lac_check_ (yytoken); -#endif]])[ - int yyn = yypact_[+yystate]; - if (!yy_pact_value_is_default_ (yyn)) - {]b4_lac_if([[ - for (int yyx = 0; yyx < yyntokens_; ++yyx) - if (yyx != yy_error_token_ && yyx != yy_undef_token_ - && yy_lac_check_ (yyx)) - {]], [[ - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - // Stay within bounds of both yycheck and yytname. - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - for (int yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck_[yyx + yyn] == yyx && yyx != yy_error_token_ - && !yy_table_value_is_error_ (yytable_[yyx + yyn])) - {]])[ - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - break; - } - else - yyarg[yycount++] = yytname_[yyx]; - } - } + if (!yyctx.lookahead ().empty ()) + { + if (yyarg) + yyarg[0] = yyctx.token (); + int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1); + return yyn + 1; } + return 0; + } + + // Generate an error message. + std::string + ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const + { + // Its maximum. + enum { YYARGS_MAX = 5 }; + // Arguments of yyformat. + symbol_kind_type yyarg[YYARGS_MAX]; + int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX); char const* yyformat = YY_NULLPTR; switch (yycount) @@ -1398,14 +1556,13 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], for (char const* yyp = yyformat; *yyp; ++yyp) if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) { - yyres += yytnamerr_ (yyarg[yyi++]); + yyres += symbol_name (yyarg[yyi++]); ++yyp; } else yyres += *yyp; - return yyres;]], [[ - return YY_("syntax error");]])[ - } + return yyres; + }]])[ const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class::yypact_ninf_ = b4_pact_ninf[; @@ -1414,21 +1571,23 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], ]b4_parser_tables_define[ -]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[ +]b4_parse_error_bmatch([simple\|verbose], +[[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[ // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - // First, the terminals, then, starting at \a yyntokens_, nonterminals. + // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. const char* const ]b4_parser_class[::yytname_[] = { ]b4_tname[ }; +#endif +]])[ -]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[ +#if ]b4_api_PREFIX[DEBUG][ ]b4_integral_parser_table_define([rline], [b4_rline])[ - // Print the state stack on the debug stream. void - ]b4_parser_class[::yystack_print_ () + ]b4_parser_class[::yy_stack_print_ () const { *yycdebug_ << "Stack now"; for (stack_type::const_iterator @@ -1439,9 +1598,8 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], *yycdebug_ << '\n'; } - // Report on the debug stream that the rule \a yyrule is going to be reduced. void - ]b4_parser_class[::yy_reduce_print_ (int yyrule) + ]b4_parser_class[::yy_reduce_print_ (int yyrule) const { int yylno = yyrline_[yyrule]; int yynrhs = yyr2_[yyrule]; diff --git a/contrib/tools/bison/data/skeletons/stack.hh b/contrib/tools/bison/data/skeletons/stack.hh index 5eb485696a..0fd3625836 100644 --- a/contrib/tools/bison/data/skeletons/stack.hh +++ b/contrib/tools/bison/data/skeletons/stack.hh @@ -32,8 +32,8 @@ m4_define([b4_stack_define], { public: // Hide our reversed order. - typedef typename S::reverse_iterator iterator; - typedef typename S::const_reverse_iterator const_iterator; + typedef typename S::iterator iterator; + typedef typename S::const_iterator const_iterator; typedef typename S::size_type size_type; typedef typename std::ptrdiff_t index_type; @@ -41,6 +41,13 @@ m4_define([b4_stack_define], : seq_ (n) {} +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + stack (const stack&) = delete; + /// Non copyable. + stack& operator= (const stack&) = delete; +#endif + /// Random access. /// /// Index 0 returns the topmost element. @@ -91,24 +98,18 @@ m4_define([b4_stack_define], return index_type (seq_.size ()); } - std::ptrdiff_t - ssize () const YY_NOEXCEPT - { - return std::ptrdiff_t (size ()); - } - /// Iterator on top of the stack (going downwards). const_iterator begin () const YY_NOEXCEPT { - return seq_.rbegin (); + return seq_.begin (); } /// Bottom of the stack. const_iterator end () const YY_NOEXCEPT { - return seq_.rend (); + return seq_.end (); } /// Present a slice of the top of a stack. @@ -132,8 +133,12 @@ m4_define([b4_stack_define], }; private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. stack (const stack&); + /// Non copyable. stack& operator= (const stack&); +#endif /// The wrapped container. S seq_; }; diff --git a/contrib/tools/bison/data/skeletons/variant.hh b/contrib/tools/bison/data/skeletons/variant.hh index 13a35c6dd5..b594af3808 100644 --- a/contrib/tools/bison/data/skeletons/variant.hh +++ b/contrib/tools/bison/data/skeletons/variant.hh @@ -115,6 +115,13 @@ m4_define([b4_value_type_declare], new (yyas_<T> ()) T (YY_MOVE (t)); } +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + semantic_type (const self_type&) = delete; + /// Non copyable. + self_type& operator= (const self_type&) = delete; +#endif + /// Destruction, allowed only if empty. ~semantic_type () YY_NOEXCEPT {]b4_parse_assert_if([ @@ -258,9 +265,12 @@ m4_define([b4_value_type_declare], } private: - /// Prohibit blind copies. - self_type& operator= (const self_type&); +#if YY_CPLUSPLUS < 201103L + /// Non copyable. semantic_type (const self_type&); + /// Non copyable. + self_type& operator= (const self_type&); +#endif /// Accessor to raw memory as \a T. template <typename T> diff --git a/contrib/tools/bison/data/skeletons/yacc.c b/contrib/tools/bison/data/skeletons/yacc.c index add9435192..bd5e7d8448 100644 --- a/contrib/tools/bison/data/skeletons/yacc.c +++ b/contrib/tools/bison/data/skeletons/yacc.c @@ -132,6 +132,7 @@ m4_define([b4_rhs_value], # b4_lhs_location() # ----------------- # Expansion of @$. +# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar". m4_define([b4_lhs_location], [(yyloc)]) @@ -140,6 +141,7 @@ m4_define([b4_lhs_location], # --------------------------------- # Expansion of @POS, where the current rule has RULE-LENGTH symbols # on RHS. +# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar". m4_define([b4_rhs_location], [(yylsp@{b4_subtract([$2], [$1])@})]) @@ -178,7 +180,8 @@ int yynerrs;]])]) # --------------------------------- # Declare all the variables that are needed to maintain the parser state # between calls to yypush_parse. -m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ +m4_define([b4_declare_parser_state_variables], +[b4_pure_if([[ /* Number of syntax errors so far. */ int yynerrs; ]])[ @@ -194,6 +197,9 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ + /* Their size. */ + YYPTRDIFF_T yystacksize; + /* The state stack. */ yy_state_t yyssa[YYINITDEPTH]; yy_state_t *yyss; @@ -207,18 +213,65 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ /* The location stack. */ YYLTYPE yylsa[YYINITDEPTH]; YYLTYPE *yyls; - YYLTYPE *yylsp; - - /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[3];]])[ - - YYPTRDIFF_T yystacksize;]b4_lac_if([[ + YYLTYPE *yylsp;]])[]b4_lac_if([[ yy_state_t yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@}; yy_state_t *yyes; YYPTRDIFF_T yyes_capacity;]])]) +# b4_initialize_parser_state_variables +# ------------------------------------ +# Initialize these variables. +m4_define([b4_initialize_parser_state_variables], +[[ yynerrs = 0; + yystate = 0; + yyerrstatus = 0; + + yystacksize = YYINITDEPTH; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa;]b4_locations_if([[ + yylsp = yyls = yylsa;]])[]b4_lac_if([[ + + yyes = yyesa; + yyes_capacity = ]b4_percent_define_get([[parse.lac.es-capacity-initial]])[; + if (YYMAXDEPTH < yyes_capacity) + yyes_capacity = YYMAXDEPTH;]])[ +]]) + + +m4_define([b4_macro_define], +[[#]define $1 $2]) + +m4_define([b4_macro_undef], +[[#]undef $1]) + +m4_define([b4_pstate_macro_define], +[b4_macro_define([$1], [yyps->$1])]) + +# b4_parse_state_variable_macros(b4_macro_define|b4_macro_undef) +# -------------------------------------------------------------- +m4_define([b4_parse_state_variable_macros], +[b4_pure_if([$1([b4_prefix[]nerrs])]) +$1([yystate]) +$1([yyerrstatus]) +$1([yyssa]) +$1([yyss]) +$1([yyssp]) +$1([yyvsa]) +$1([yyvs]) +$1([yyvsp])[]b4_locations_if([ +$1([yylsa]) +$1([yyls]) +$1([yylsp])]) +$1([yystacksize])[]b4_lac_if([ +$1([yyesa]) +$1([yyes]) +$1([yyes_capacity])])]) + + + + # _b4_declare_yyparse_push # ------------------------ # Declaration of yyparse (and dependencies) when using the push parser @@ -231,27 +284,20 @@ enum { YYPUSH_MORE = 4 }; typedef struct ]b4_prefix[pstate ]b4_prefix[pstate; -]b4_pull_if([b4_function_declare([b4_prefix[parse]], [[int]], b4_parse_param) -])b4_function_declare([b4_prefix[push_parse]], [[int]], - [[b4_prefix[pstate *ps]], [[ps]]]b4_pure_if([, - [[[int pushed_char]], [[pushed_char]]], - [[b4_api_PREFIX[STYPE const *pushed_val]], [[pushed_val]]]b4_locations_if([, - [[b4_api_PREFIX[LTYPE *pushed_loc]], [[pushed_loc]]]])])m4_ifset([b4_parse_param], [, - b4_parse_param])) -b4_pull_if([b4_function_declare([b4_prefix[pull_parse]], [[int]], - [[b4_prefix[pstate *ps]], [[ps]]]m4_ifset([b4_parse_param], [, - b4_parse_param]))]) -b4_function_declare([b4_prefix[pstate_new]], [b4_prefix[pstate *]], - [[[void]], []]) -b4_function_declare([b4_prefix[pstate_delete]], [[void]], - [[b4_prefix[pstate *ps]], [[ps]]])dnl -]) +]b4_pull_if([[ +int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[);]])[ +int ]b4_prefix[push_parse (]b4_prefix[pstate *ps]b4_pure_if([[, + int pushed_char, ]b4_api_PREFIX[STYPE const *pushed_val]b4_locations_if([[, ]b4_api_PREFIX[LTYPE *pushed_loc]])])b4_user_formals[); +]b4_pull_if([[int ]b4_prefix[pull_parse (]b4_prefix[pstate *ps]b4_user_formals[);]])[ +]b4_prefix[pstate *]b4_prefix[pstate_new (void); +void ]b4_prefix[pstate_delete (]b4_prefix[pstate *ps); +]]) # _b4_declare_yyparse # ------------------- # When not the push parser. m4_define([_b4_declare_yyparse], -[b4_function_declare(b4_prefix[parse], [int], b4_parse_param)]) +[[int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[);]]) # b4_declare_yyparse @@ -314,6 +360,7 @@ b4_output_begin([b4_parser_file_name])[ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +]b4_disclaimer[ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -321,7 +368,6 @@ b4_output_begin([b4_parser_file_name])[ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -]b4_disclaimer[ ]b4_identification[ ]b4_percent_code_get([[top]])[]dnl m4_if(b4_api_prefix, [yy], [], @@ -334,6 +380,7 @@ m4_if(b4_api_prefix, [yy], [], #define yypush_parse ]b4_prefix[push_parse]b4_pull_if([[ #define yypull_parse ]b4_prefix[pull_parse]])[ #define yypstate_new ]b4_prefix[pstate_new +#define yypstate_clear ]b4_prefix[pstate_clear #define yypstate_delete ]b4_prefix[pstate_delete #define yypstate ]b4_prefix[pstate]])[ #define yylex ]b4_prefix[lex @@ -348,65 +395,18 @@ m4_if(b4_api_prefix, [yy], [], ]b4_cast_define[ ]b4_null_define[ -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[ -#endif - ]b4_header_include_if([[#include ]b4_percent_define_get([[api.header.include]])], [m4_ifval(m4_quote(b4_spec_header_file), [/* Use api.header.include to #include this header instead of duplicating it here. */ ])b4_shared_declarations])[ +]b4_declare_symbol_enum[ ]b4_user_post_prologue[ -]b4_percent_code_get[]dnl - -[#ifdef short -# undef short -#endif - +]b4_percent_code_get[ ]b4_c99_int_type_define[ -#ifndef YYPTRDIFF_T -# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ -# define YYPTRDIFF_T __PTRDIFF_TYPE__ -# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ -# elif defined PTRDIFF_MAX -# ifndef ptrdiff_t -# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ -# endif -# define YYPTRDIFF_T ptrdiff_t -# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX -# else -# define YYPTRDIFF_T long -# define YYPTRDIFF_MAXIMUM LONG_MAX -# endif -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ -# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned -# endif -#endif - -#define YYSIZE_MAXIMUM \ - YY_CAST (YYPTRDIFF_T, \ - (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ - ? YYPTRDIFF_MAXIMUM \ - : YY_CAST (YYSIZE_T, -1))) - -#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) +]b4_sizes_types_define[ /* Stored state numbers (used for stacks). */ typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_t; @@ -425,6 +425,11 @@ typedef int yy_state_fast_t; # define YY_(Msgid) Msgid # endif #endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ ]b4_attribute_define[ @@ -437,7 +442,7 @@ typedef int yy_state_fast_t; ]], [[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ -#if ]b4_lac_if([[1]], [[! defined yyoverflow || YYERROR_VERBOSE]])[ +#if ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ /* The parser invokes alloca or malloc; define the necessary symbols. */]dnl b4_push_if([], [b4_lac_if([], [[ @@ -504,8 +509,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif]b4_lac_if([[ # define YYCOPY_NEEDED 1]])[ -#endif]b4_lac_if([], [[ /* ! defined yyoverflow || YYERROR_VERBOSE */]])[ - +#endif /* ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ */ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -588,16 +592,17 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES ]b4_states_number[ -#define YYUNDEFTOK ]b4_undef_token_number[ #define YYMAXUTOK ]b4_user_token_number_max[ /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ ]b4_api_token_raw_if(dnl -[[#define YYTRANSLATE(YYX) (YYX)]], -[[#define YYTRANSLATE(YYX) \ - (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +[[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)]], +[[#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : ]b4_symbol_prefix[YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ @@ -611,23 +616,55 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ #endif -#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +]b4_parse_error_bmatch([simple\|verbose], +[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { ]b4_tname[ }; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +}]], +[[static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ +}]])[ #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = { ]b4_toknum[ }; -# endif +#endif #define YYPACT_NINF (]b4_pact_ninf[) @@ -641,10 +678,10 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = ]b4_parser_tables_define[ +enum { YYENOMEM = -2 }; + #define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 +#define yyclearin (yychar = ]b4_symbol(-2, id)[) #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab @@ -655,7 +692,7 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = #define YYBACKUP(Token, Value) \ do \ - if (yychar == YYEMPTY) \ + if (yychar == ]b4_symbol(-2, id)[) \ { \ yychar = (Token); \ yylval = (Value); \ @@ -671,10 +708,9 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = } \ while (0) -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE ]b4_symbol(1, user_number)[ - +/* Backward compatibility with an undocumented macro. + Use ]b4_symbol(1, id)[ or ]b4_symbol(2, id)[. */ +#define YYERRCODE ]b4_symbol(2, id)[ ]b4_locations_if([[ ]b4_yylloc_default_define[ #define YYRHSLOC(Rhs, K) ((Rhs)[K]) @@ -696,13 +732,13 @@ do { \ ]b4_yy_location_print_define[ -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value]b4_locations_if([, Location])[]b4_user_args[); \ + Kind, Value]b4_locations_if([, Location])[]b4_user_args[); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -714,9 +750,8 @@ do { \ | TOP (included). | `------------------------------------------------------------------*/ -]b4_function_define([yy_stack_print], [static void], - [[yy_state_t *yybottom], [yybottom]], - [[yy_state_t *yytop], [yytop]])[ +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -738,12 +773,9 @@ do { \ | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -]b4_function_define([yy_reduce_print], [static void], - [[yy_state_t *yyssp], [yyssp]], - [[YYSTYPE *yyvsp], [yyvsp]], - b4_locations_if([[[YYLTYPE *yylsp], [yylsp]], - ])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [, - b4_parse_param]))[ +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,]b4_locations_if([[ YYLTYPE *yylsp,]])[ + int yyrule]b4_user_formals[) { int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -755,10 +787,9 @@ do { \ { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[+yyssp[yyi + 1 - yynrhs]], - &]b4_rhs_value(yynrhs, yyi + 1)[ - ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl - b4_user_args[); + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &]b4_rhs_value(yynrhs, yyi + 1)[]b4_locations_if([, + &]b4_rhs_location(yynrhs, yyi + 1))[]b4_user_args[); YYFPRINTF (stderr, "\n"); } } @@ -773,8 +804,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !]b4_api_PREFIX[DEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !]b4_api_PREFIX[DEBUG */ @@ -794,7 +825,17 @@ int yydebug; #ifndef YYMAXDEPTH # define YYMAXDEPTH ]b4_stack_depth_max[ -#endif]b4_lac_if([[ +#endif]b4_push_if([[ +/* Parser data structure. */ +struct yypstate + {]b4_declare_parser_state_variables[ + /* Whether this instance has not started parsing yet. */ + int yynew; + };]b4_pure_if([], [[ + +/* Whether the only allowed instance of yypstate is allocated. */ +static char yypstate_allocated = 0;]])])[ +]b4_lac_if([[ /* Given a state stack such that *YYBOTTOM is its bottom, such that *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty @@ -805,7 +846,7 @@ int yydebug; *YYTOP, and *YYCAPACITY to reflect the new capacity and memory location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack using YYSTACK_FREE. Return 0 if successful or if no reallocation is - required. Return 1 if memory is exhausted. */ + required. Return YYENOMEM if memory is exhausted. */ static int yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, #if ]b4_api_PREFIX[DEBUG @@ -830,7 +871,7 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, { YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix, yydebug_suffix)); - return 1; + return YYENOMEM; } if (YYMAXDEPTH < yyalloc) yyalloc = YYMAXDEPTH; @@ -842,7 +883,7 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, { YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix, yydebug_suffix)); - return 1; + return YYENOMEM; } if (*yytop != yytop_empty) { @@ -888,23 +929,22 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, current lookahead, then check if that lookahead can eventually be shifted if syntactic actions continue from the current context. Report a syntax error if it cannot. */ -#define YY_LAC_ESTABLISH \ -do { \ - if (!yy_lac_established) \ - { \ - YYDPRINTF ((stderr, \ - "LAC: initial context established for %s\n", \ - yytname[yytoken])); \ - yy_lac_established = 1; \ - { \ - int yy_lac_status = \ - yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken); \ - if (yy_lac_status == 2) \ - goto yyexhaustedlab; \ - if (yy_lac_status == 1) \ - goto yyerrlab; \ - } \ - } \ +#define YY_LAC_ESTABLISH \ +do { \ + if (!yy_lac_established) \ + { \ + YYDPRINTF ((stderr, \ + "LAC: initial context established for %s\n", \ + yysymbol_name (yytoken))); \ + yy_lac_established = 1; \ + switch (yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken)) \ + { \ + case YYENOMEM: \ + goto yyexhaustedlab; \ + case 1: \ + goto yyerrlab; \ + } \ + } \ } while (0) /* Discard any previous initial lookahead context because of Event, @@ -923,9 +963,8 @@ do { \ do { \ if (yy_lac_established) \ { \ - if (yydebug) \ - YYFPRINTF (stderr, "LAC: initial context discarded due to " \ - Event "\n"); \ + YYDPRINTF ((stderr, "LAC: initial context discarded due to " \ + Event "\n")); \ yy_lac_established = 0; \ } \ } while (0) @@ -935,7 +974,7 @@ do { \ /* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can eventually (after perhaps some reductions) be shifted, return 1 if - not, or return 2 if memory is exhausted. As preconditions and + not, or return YYENOMEM if memory is exhausted. As preconditions and postconditions: *YYES_CAPACITY is the allocated size of the array to which *YYES points, and either *YYES = YYESA or *YYES points to an array allocated with YYSTACK_ALLOC. yy_lac may overwrite the @@ -943,12 +982,13 @@ do { \ any old *YYES other than YYESA. */ static int yy_lac (yy_state_t *yyesa, yy_state_t **yyes, - YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, int yytoken) + YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, yysymbol_kind_t yytoken) { yy_state_t *yyes_prev = yyssp; yy_state_t *yyesp = yyes_prev; - YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken])); - if (yytoken == YYUNDEFTOK) + /* Reduce until we encounter a shift and thereby accept the token. */ + YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yysymbol_name (yytoken))); + if (yytoken == ]b4_symbol_prefix[YYUNDEF) { YYDPRINTF ((stderr, " Always Err\n")); return 1; @@ -960,6 +1000,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, || (yyrule += yytoken) < 0 || YYLAST < yyrule || yycheck[yyrule] != yytoken) { + /* Use the default action. */ yyrule = yydefact[+*yyesp]; if (yyrule == 0) { @@ -969,6 +1010,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, } else { + /* Use the action from yytable. */ yyrule = yytable[yyrule]; if (yytable_value_is_error (yyrule)) { @@ -982,9 +1024,12 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, } yyrule = -yyrule; } + /* By now we know we have to simulate a reduce. */ + YYDPRINTF ((stderr, " R%d", yyrule - 1)); { + /* Pop the corresponding number of values from the stack. */ YYPTRDIFF_T yylen = yyr2[yyrule]; - YYDPRINTF ((stderr, " R%d", yyrule - 1)); + /* First pop from the LAC stack as many tokens as possible. */ if (yyesp != yyes_prev) { YYPTRDIFF_T yysize = yyesp - *yyes + 1; @@ -995,13 +1040,15 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, } else { - yylen -= yysize; yyesp = yyes_prev; + yylen -= yysize; } } + /* Only afterwards look at the main stack. */ if (yylen) yyesp = yyes_prev -= yylen; } + /* Push the resulting state of the reduction. */ { yy_state_fast_t yystate; { @@ -1027,7 +1074,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, yyes, yyesa, &yyesp, yyes_prev)) { YYDPRINTF ((stderr, "\n")); - return 2; + return YYENOMEM; } YY_IGNORE_USELESS_CAST_BEGIN *++yyesp = YY_CAST (yy_state_t, yystate); @@ -1038,33 +1085,144 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, } }]])[ +]b4_parse_error_case([simple], [], +[[/* Context of a parse error. */ +typedef struct +{]b4_push_if([[ + yypstate* yyps;]], [[ + yy_state_t *yyssp;]b4_lac_if([[ + yy_state_t *yyesa; + yy_state_t **yyes; + YYPTRDIFF_T *yyes_capacity;]])])[ + yysymbol_kind_t yytoken;]b4_locations_if([[ + YYLTYPE *yylloc;]])[ +} yypcontext_t; + +/* Put in YYARG at most YYARGN of the expected tokens given the + current YYCTX, and return the number of tokens stored in YYARG. If + YYARG is null, return the number of expected tokens (guaranteed to + be less than YYNTOKENS). Return YYENOMEM on memory exhaustion. + Return 0 if there are more than YYARGN expected tokens, yet fill + YYARG up to YYARGN. */]b4_push_if([[ +static int +yypstate_expected_tokens (yypstate *yyps, + yysymbol_kind_t yyarg[], int yyargn)]], [[ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn)]])[ +{ + /* Actual size of YYARG. */ + int yycount = 0; +]b4_lac_if([[ + int yyx; + for (yyx = 0; yyx < YYNTOKENS; ++yyx) + { + yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx); + if (yysym != ]b4_symbol(1, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF) + switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, &yyps->yyes_capacity, yyps->yyssp, yysym]], + [[yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym]])[)) + { + case YYENOMEM: + return YYENOMEM; + case 1: + continue; + default: + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], +[[ int yyn = yypact@{+*]b4_push_if([yyps], [yyctx])[->yyssp@}; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[ + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); + } + }]])[ + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(-2, kind)[; + return yycount; +} -#if YYERROR_VERBOSE +]b4_push_if([[ +/* Similar to the previous function. */ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) +{ + return yypstate_expected_tokens (yyctx->yyps, yyarg, yyargn); +}]])[ +]])[ -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) -# else +]b4_parse_error_bmatch( + [custom], +[[/* The kind of the lookahead of this context. */ +static yysymbol_kind_t +yypcontext_token (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED; + +static yysymbol_kind_t +yypcontext_token (const yypcontext_t *yyctx) +{ + return yyctx->yytoken; +} + +]b4_locations_if([[/* The location of the lookahead of this context. */ +static YYLTYPE * +yypcontext_location (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED; + +static YYLTYPE * +yypcontext_location (const yypcontext_t *yyctx) +{ + return yyctx->yylloc; +}]])[ + +/* User defined function to report a syntax error. */ +static int +yyreport_syntax_error (const yypcontext_t *yyctx]b4_user_formals[);]], + [detailed\|verbose], +[[#ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +# else /* Return the length of YYSTR. */ -]b4_function_define([yystrlen], [static YYPTRDIFF_T], - [[const char *yystr], [yystr]])[ +static YYPTRDIFF_T +yystrlen (const char *yystr) { YYPTRDIFF_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } -# endif # endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -]b4_function_define([yystpcpy], [static char *], - [[char *yydest], [yydest]], [[const char *yysrc], [yysrc]])[ +static char * +yystpcpy (char *yydest, const char *yysrc) { char *yyd = yydest; const char *yys = yysrc; @@ -1074,10 +1232,12 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, return yyd - 1; } -# endif # endif +#endif -# ifndef yytnamerr +]b4_parse_error_case( + [verbose], +[[#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -1092,7 +1252,6 @@ yytnamerr (char *yyres, const char *yystr) { YYPTRDIFF_T yyn = 0; char const *yyp = yystr; - for (;;) switch (*++yyp) { @@ -1126,34 +1285,15 @@ yytnamerr (char *yyres, const char *yystr) else return yystrlen (yystr); } -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP.]b4_lac_if([[ In order to see if a particular token T is a - valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).]])[ +#endif +]])[ - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store]b4_lac_if([[ or if - yy_lac returned 2]])[. */ static int -yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, - ]b4_lac_if([[yy_state_t *yyesa, yy_state_t **yyes, - YYPTRDIFF_T *yyes_capacity, ]])[yy_state_t *yyssp, int yytoken) +yy_syntax_error_arguments (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) { - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat: reported tokens (one for the "unexpected", - one per "expected"). */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Actual size of YYARG. */ int yycount = 0; - /* Cumulated lengths of YYARG. */ - YYPTRDIFF_T yysize = 0; - /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then the only way this function was invoked is if the default action @@ -1182,70 +1322,59 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, one exception: it will still contain any token that will not be accepted due to an error action in a later state.]])[ */ - if (yytoken != YYEMPTY) + if (yyctx->yytoken != ]b4_symbol(-2, kind)[) { - int yyn = yypact[+*yyssp]; - YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - yysize = yysize0;]b4_lac_if([[ + int yyn;]b4_lac_if([[ YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[ - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - {]b4_lac_if([[ - int yyx; - - for (yyx = 0; yyx < YYNTOKENS; ++yyx) - if (yyx != YYTERROR && yyx != YYUNDEFTOK) - { - { - int yy_lac_status = yy_lac (yyesa, yyes, yyes_capacity, - yyssp, yyx); - if (yy_lac_status == 2) - return 2; - if (yy_lac_status == 1) - continue; - }]], [[ - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - {]])[ - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYPTRDIFF_T yysize1 - = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - } - }]b4_lac_if([[ -# if ]b4_api_PREFIX[DEBUG - else if (yydebug) - YYFPRINTF (stderr, "No expected tokens.\n"); -# endif]])[ + if (yyarg) + yyarg[yycount] = yyctx->yytoken; + ++yycount; + yyn = yypcontext_expected_tokens (yyctx, + yyarg ? yyarg + 1 : yyarg, yyargn - 1); + if (yyn == YYENOMEM) + return YYENOMEM;]b4_lac_if([[ + else if (yyn == 0) + YYDPRINTF ((stderr, "No expected tokens.\n"));]])[ + else + yycount += yyn; } + return yycount; +} + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP.]b4_lac_if([[ In order to see if a particular token T is a + valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).]])[ + + Return 0 if *YYMSG was successfully written. Return -1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return YYENOMEM if the + required number of bytes is too large to store]b4_lac_if([[ or if + yy_lac returned YYENOMEM]])[. */ +static int +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + const yypcontext_t *yyctx) +{ + enum { YYARGS_MAX = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + yysymbol_kind_t yyarg[YYARGS_MAX]; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* Actual size of YYARG. */ + int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX); + if (yycount == YYENOMEM) + return YYENOMEM; switch (yycount) { -# define YYCASE_(N, S) \ +#define YYCASE_(N, S) \ case N: \ yyformat = S; \ - break + break default: /* Avoid compiler warnings. */ YYCASE_(0, YY_("syntax error")); YYCASE_(1, YY_("syntax error, unexpected %s")); @@ -1253,17 +1382,25 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ +#undef YYCASE_ } + /* Compute error message size. Don't count the "%s"s, but reserve + room for the terminator. */ + yysize = yystrlen (yyformat) - 2 * yycount + 1; { - /* Don't count the "%s"s in the final size, but reserve room for - the terminator. */ - YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; + int yyi; + for (yyi = 0; yyi < yycount; ++yyi) + { + YYPTRDIFF_T yysize1 + = yysize + ]b4_parse_error_case( + [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], + [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return YYENOMEM; + } } if (*yymsg_alloc < yysize) @@ -1272,7 +1409,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, if (! (yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; + return -1; } /* Avoid sprintf, as that infringes on the user's name space. @@ -1283,8 +1420,9 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, int yyi = 0; while ((*yyp = *yyformat) != '\0') if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); + {]b4_parse_error_case([verbose], [[ + yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ + yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ yyformat += 2; } else @@ -1295,32 +1433,22 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, } return 0; } -#endif /* YYERROR_VERBOSE */ +]])[ ]b4_yydestruct_define[ -]b4_pure_if([], [ +]b4_pure_if([], [b4_declare_scanner_communication_variables])[ -b4_declare_scanner_communication_variables])[]b4_push_if([[ +]b4_push_if([b4_pull_if([[ -struct yypstate - {]b4_declare_parser_state_variables[ - /* Used to determine if this is the first time this instance has - been used. */ - int yynew; - };]b4_pure_if([], [[ - -static char yypstate_allocated = 0;]])b4_pull_if([ - -b4_function_define([[yyparse]], [[int]], b4_parse_param)[ +int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) { - return yypull_parse (YY_NULLPTR]m4_ifset([b4_parse_param], - [[, ]b4_args(b4_parse_param)])[); + return yypull_parse (YY_NULLPTR]b4_user_args[); } -]b4_function_define([[yypull_parse]], [[int]], - [[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [, - b4_parse_param]))[ +int +yypull_parse (yypstate *yyps]b4_user_formals[) {]b4_pure_if([b4_locations_if([[ static YYLTYPE yyloc_default][]b4_yyloc_default[; YYLTYPE yylloc = yyloc_default;]])])[ @@ -1339,19 +1467,31 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ } } int yystatus; - do {]b4_pure_if([[ - YYSTYPE yylval; + do { +]b4_pure_if([[ YYSTYPE yylval; int ]])[yychar = ]b4_lex[; - yystatus = - yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); + yystatus = yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); } while (yystatus == YYPUSH_MORE); if (!yyps) yypstate_delete (yyps_local); return yystatus; }]])[ +]b4_parse_state_variable_macros([b4_pstate_macro_define])[ + /* Initialize the parser data structure. */ -]b4_function_define([[yypstate_new]], [[yypstate *]])[ +static void +yypstate_clear (yypstate *yyps) +{ +]b4_initialize_parser_state_variables[ + /* Initialize the state stack, in case yypcontext_expected_tokens is + called before the first call to yyparse. */ + *yyssp = 0; +} + +/* Initialize the parser data structure. */ +yypstate * +yypstate_new (void) { yypstate *yyps;]b4_pure_if([], [[ if (yypstate_allocated) @@ -1361,63 +1501,44 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ return YY_NULLPTR; yyps->yynew = 1;]b4_pure_if([], [[ yypstate_allocated = 1;]])[ + yypstate_clear (yyps); return yyps; } -]b4_function_define([[yypstate_delete]], [[void]], - [[[yypstate *yyps]], [[yyps]]])[ +void +yypstate_delete (yypstate *yyps) { if (yyps) { #ifndef yyoverflow /* If the stack was reallocated but the parse did not complete, then the stack still needs to be freed. */ - if (!yyps->yynew && yyps->yyss != yyps->yyssa) - YYSTACK_FREE (yyps->yyss); + if (!yyps->yynew && yyss != yyssa) + YYSTACK_FREE (yyss); #endif]b4_lac_if([[ - if (!yyps->yynew && yyps->yyes != yyps->yyesa) - YYSTACK_FREE (yyps->yyes);]])[ + if (!yyps->yynew && yyes != yyesa) + YYSTACK_FREE (yyes);]])[ free (yyps);]b4_pure_if([], [[ yypstate_allocated = 0;]])[ } } -]b4_pure_if([[ -#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs]])[ -#define yystate yyps->yystate -#define yyerrstatus yyps->yyerrstatus -#define yyssa yyps->yyssa -#define yyss yyps->yyss -#define yyssp yyps->yyssp -#define yyvsa yyps->yyvsa -#define yyvs yyps->yyvs -#define yyvsp yyps->yyvsp]b4_locations_if([[ -#define yylsa yyps->yylsa -#define yyls yyps->yyls -#define yylsp yyps->yylsp -#define yyerror_range yyps->yyerror_range]])[ -#define yystacksize yyps->yystacksize]b4_lac_if([[ -#define yyesa yyps->yyesa -#define yyes yyps->yyes -#define yyes_capacity yyps->yyes_capacity]])[ - +]])[ +]b4_push_if([[ /*---------------. | yypush_parse. | `---------------*/ -]b4_function_define([[yypush_parse]], [[int]], - [[[yypstate *yyps]], [[yyps]]]b4_pure_if([, - [[[int yypushed_char]], [[yypushed_char]]], - [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([, - [[[YYLTYPE *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [, - b4_parse_param]))], [[ - - +int +yypush_parse (yypstate *yyps]b4_pure_if([[, + int yypushed_char, YYSTYPE const *yypushed_val]b4_locations_if([[, YYLTYPE *yypushed_loc]])])b4_user_formals[)]], +[[ /*----------. | yyparse. | `----------*/ -]b4_function_define([yyparse], [int], b4_parse_param)])[ +int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])[ {]b4_pure_if([b4_declare_scanner_communication_variables ])b4_push_if([b4_pure_if([], [[ int yypushed_char = yychar; @@ -1426,51 +1547,43 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ ])], [b4_declare_parser_state_variables ])b4_lac_if([[ + /* Whether LAC context is established. A Boolean. */ int yy_lac_established = 0;]])[ int yyn; + /* The return value of yyparse. */ int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + yysymbol_kind_t yytoken = ]b4_symbol(-2, kind)[; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval;]b4_locations_if([[ - YYLTYPE yyloc;]])[ + YYLTYPE yyloc; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3];]])[ -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ +]b4_parse_error_bmatch([detailed\|verbose], +[[ /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; - YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; -#endif + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;]])[ #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ - int yylen = 0;]b4_push_if([[ - + int yylen = 0; +]b4_push_if([[ if (!yyps->yynew) { yyn = yypact[yystate]; goto yyread_pushed_token; - }]])[ - - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa;]b4_locations_if([[ - yylsp = yyls = yylsa;]])[ - yystacksize = YYINITDEPTH;]b4_lac_if([[ - - yyes = yyesa; - yyes_capacity = ]b4_percent_define_get([[parse.lac.es-capacity-initial]])[; - if (YYMAXDEPTH < yyes_capacity) - yyes_capacity = YYMAXDEPTH;]])[ + }]], [ +b4_initialize_parser_state_variables])[ YYDPRINTF ((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ + yychar = ]b4_symbol(-2, id)[; /* Cause a token to be read. */ ]m4_ifdef([b4_initial_action], [ b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [], [b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl @@ -1501,6 +1614,7 @@ yysetstate: YY_IGNORE_USELESS_CAST_BEGIN *yyssp = YY_CAST (yy_state_t, yystate); YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE @@ -1550,7 +1664,7 @@ yysetstate: YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs);]b4_locations_if([ YYSTACK_RELOCATE (yyls_alloc, yyls);])[ -# undef YYSTACK_RELOCATE +# undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } @@ -1590,8 +1704,8 @@ yybackup: /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == ]b4_symbol(-2, id)[) {]b4_push_if([[ if (!yyps->yynew) {]b4_use_push_for_pull_if([], [[ @@ -1607,7 +1721,7 @@ yybackup: yylval = yypushed_val;]b4_locations_if([[ yylloc = yypushed_loc;]])])[ yyread_pushed_token:]])[ - YYDPRINTF ((stderr, "Reading a token: "));]b4_push_if([b4_pure_if([[ + YYDPRINTF ((stderr, "Reading a token\n"));]b4_push_if([b4_pure_if([[ yychar = yypushed_char; if (yypushed_val) yylval = *yypushed_val;]b4_locations_if([[ @@ -1616,11 +1730,23 @@ yyread_pushed_token:]])[ yychar = ]b4_lex[;]])[ } - if (yychar <= YYEOF) + if (yychar <= ]b4_symbol(0, [id])[) { - yychar = yytoken = YYEOF; + yychar = ]b4_symbol(0, [id])[; + yytoken = ]b4_symbol(0, [kind])[; YYDPRINTF ((stderr, "Now at end of input.\n")); } + else if (yychar == ]b4_symbol(1, [id])[) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = ]b4_symbol(2, [id])[; + yytoken = ]b4_symbol(1, [kind])[;]b4_locations_if([[ + yyerror_range[1] = yylloc;]])[ + goto yyerrlab1; + } else { yytoken = YYTRANSLATE (yychar); @@ -1660,7 +1786,7 @@ yyread_pushed_token:]])[ *++yylsp = yylloc;])[ /* Discard the shifted token. */ - yychar = YYEMPTY;]b4_lac_if([[ + yychar = ]b4_symbol(-2, id)[;]b4_lac_if([[ YY_LAC_DISCARD ("shift");]])[ goto yynewstate; @@ -1723,11 +1849,10 @@ yyreduce: case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval;]b4_locations_if([ *++yylsp = yyloc;])[ @@ -1752,69 +1877,76 @@ yyreduce: yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - + yytoken = yychar == ]b4_symbol(-2, id)[ ? ]b4_symbol(-2, kind)[ : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (]b4_yyerror_args[YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \]b4_lac_if([[ - yyesa, &yyes, &yyes_capacity, \]])[ - yyssp, yytoken) - { +]b4_parse_error_case( + [custom], +[[ { + yypcontext_t yyctx + = {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[};]b4_lac_if([[ + if (yychar != ]b4_symbol(-2, id)[) + YY_LAC_ESTABLISH;]])[ + if (yyreport_syntax_error (&yyctx]m4_ifset([b4_parse_param], + [[, ]b4_args(b4_parse_param)])[) == 2) + goto yyexhaustedlab; + }]], + [simple], +[[ yyerror (]b4_yyerror_args[YY_("syntax error"));]], +[[ { + yypcontext_t yyctx + = {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[}; char const *yymsgp = YY_("syntax error"); int yysyntax_error_status;]b4_lac_if([[ - if (yychar != YYEMPTY) + if (yychar != ]b4_symbol(-2, id)[) YY_LAC_ESTABLISH;]])[ - yysyntax_error_status = YYSYNTAX_ERROR; + yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); if (yysyntax_error_status == 0) yymsgp = yymsg; - else if (yysyntax_error_status == 1) + else if (yysyntax_error_status == -1) { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); - yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); - if (!yymsg) + yymsg = YY_CAST (char *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); + if (yymsg) { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; + yysyntax_error_status + = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); + yymsgp = yymsg; } else { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = YYENOMEM; } } yyerror (]b4_yyerror_args[yymsgp); - if (yysyntax_error_status == 2) + if (yysyntax_error_status == YYENOMEM) goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif + }]])[ } - -]b4_locations_if([[ yyerror_range[1] = yylloc;]])[ - +]b4_locations_if([[ + yyerror_range[1] = yylloc;]])[ if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ - if (yychar <= YYEOF) + if (yychar <= ]b4_symbol(0, [id])[) { /* Return failure if at end of input. */ - if (yychar == YYEOF) + if (yychar == ]b4_symbol(0, [id])[) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[); - yychar = YYEMPTY; + yychar = ]b4_symbol(-2, id)[; } } @@ -1847,13 +1979,14 @@ yyerrorlab: yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += ]b4_symbol(1, kind)[; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(1, kind)[) { yyn = yytable[yyn]; if (0 < yyn) @@ -1867,7 +2000,7 @@ yyerrlab1: ]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[ yydestruct ("Error: popping", - yystos[yystate], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); + YY_ACCESSING_SYMBOL (yystate), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1882,13 +2015,11 @@ yyerrlab1: YY_IGNORE_MAYBE_UNINITIALIZED_END ]b4_locations_if([[ yyerror_range[2] = yylloc; - /* Using YYLLOC is tempting, but would change the location of - the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT (yyloc, yyerror_range, 2); - *++yylsp = yyloc;]])[ + ++yylsp; + YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);]])[ /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -1910,7 +2041,7 @@ yyabortlab: goto yyreturn; -#if ]b4_lac_if([[1]], [[!defined yyoverflow || YYERROR_VERBOSE]])[ +#if ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -1925,7 +2056,7 @@ yyexhaustedlab: | yyreturn -- parsing is finished, return the result. | `-----------------------------------------------------*/ yyreturn: - if (yychar != YYEMPTY) + if (yychar != ]b4_symbol(-2, id)[) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ @@ -1940,7 +2071,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[+*yyssp], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1949,6 +2080,7 @@ yyreturn: #endif]b4_lac_if([[ if (yyes != yyesa) YYSTACK_FREE (yyes);]])b4_push_if([[ + yypstate_clear (yyps); yyps->yynew = 1; @@ -1956,11 +2088,12 @@ yyreturn: | yypushreturn -- ask for the next token. | `-----------------------------------------*/ yypushreturn:]])[ -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif +]b4_parse_error_bmatch([detailed\|verbose], +[[ if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg);]])[ return yyresult; } -]b4_epilogue[]dnl +]b4_push_if([b4_parse_state_variable_macros([b4_macro_undef])])[ +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl b4_output_end |