mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
c++: improvements on symbol kinds
Instead of
/// (Internal) symbol kind.
enum symbol_kind_type
{
YYNTOKENS = 5, ///< Number of tokens.
YYSYMBOL_YYEMPTY = -2,
YYSYMBOL_YYEOF = 0, // END_OF_FILE
YYSYMBOL_YYERROR = 1, // error
YYSYMBOL_YYUNDEF = 2, // $undefined
YYSYMBOL_TEXT = 3, // TEXT
YYSYMBOL_NUMBER = 4, // NUMBER
YYSYMBOL_YYACCEPT = 5, // $accept
YYSYMBOL_result = 6, // result
YYSYMBOL_list = 7, // list
YYSYMBOL_item = 8 // item
};
generate
/// Symbol kinds.
struct symbol_kind
{
enum symbol_kind_type
{
YYNTOKENS = 5, ///< Number of tokens.
S_YYEMPTY = -2,
S_YYEOF = 0, // END_OF_FILE
S_YYERROR = 1, // error
S_YYUNDEF = 2, // $undefined
S_TEXT = 3, // TEXT
S_NUMBER = 4, // NUMBER
S_YYACCEPT = 5, // $accept
S_result = 6, // result
S_list = 7, // list
S_item = 8 // item
};
};
* data/skeletons/c++.m4 (api.symbol.prefix): Define to S_.
Adjust all the uses.
(b4_public_types_declare): Nest the enum inside 'struct symbol_kind'.
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* tests/headers.at, tests/local.at: Adjust.
This commit is contained in:
@@ -22,6 +22,8 @@ b4_percent_define_ifdef([[api.value.union.name]],
|
|||||||
[b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]),
|
[b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]),
|
||||||
[named %union is invalid in C++])])
|
[named %union is invalid in C++])])
|
||||||
|
|
||||||
|
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
|
||||||
|
|
||||||
m4_include(b4_skeletonsdir/[c.m4])
|
m4_include(b4_skeletonsdir/[c.m4])
|
||||||
|
|
||||||
b4_percent_define_check_kind([api.namespace], [code], [deprecated])
|
b4_percent_define_check_kind([api.namespace], [code], [deprecated])
|
||||||
@@ -187,12 +189,11 @@ m4_define([b4_token_enums],
|
|||||||
# to use a signed type, which matters for yytoken.
|
# to use a signed type, which matters for yytoken.
|
||||||
m4_define([b4_declare_symbol_enum],
|
m4_define([b4_declare_symbol_enum],
|
||||||
[[enum symbol_kind_type
|
[[enum symbol_kind_type
|
||||||
{
|
{
|
||||||
YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens.
|
YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens.
|
||||||
]b4_symbol_kind([-2])[ = -2,
|
]b4_symbol_kind([-2])[ = -2,
|
||||||
]b4_symbol_foreach([ b4_symbol_enum])[
|
]b4_symbol_foreach([ b4_symbol_enum])dnl
|
||||||
};
|
[ };]])
|
||||||
]])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -252,7 +253,7 @@ m4_define([b4_public_types_declare],
|
|||||||
location_type location;])[
|
location_type location;])[
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Token numbers.
|
/// Token kinds.
|
||||||
struct token
|
struct token
|
||||||
{
|
{
|
||||||
]b4_token_enums[
|
]b4_token_enums[
|
||||||
@@ -261,8 +262,17 @@ m4_define([b4_public_types_declare],
|
|||||||
/// (External) token kind, as returned by yylex.
|
/// (External) token kind, as returned by yylex.
|
||||||
typedef token::yytokentype token_type;
|
typedef token::yytokentype token_type;
|
||||||
|
|
||||||
|
/// Symbol kinds.
|
||||||
|
struct symbol_kind
|
||||||
|
{
|
||||||
|
]b4_declare_symbol_enum[
|
||||||
|
};
|
||||||
|
|
||||||
/// (Internal) symbol kind.
|
/// (Internal) symbol kind.
|
||||||
]b4_declare_symbol_enum[
|
typedef symbol_kind::symbol_kind_type symbol_kind_type;
|
||||||
|
|
||||||
|
/// The number of tokens.
|
||||||
|
static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS;
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
@@ -456,7 +466,7 @@ m4_define([b4_public_types_define],
|
|||||||
bool
|
bool
|
||||||
]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
|
]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return Base::type_get () == ]b4_symbol_prefix[YYEMPTY;
|
return Base::type_get () == symbol_kind::]b4_symbol_prefix[YYEMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
@@ -472,7 +482,7 @@ m4_define([b4_public_types_define],
|
|||||||
|
|
||||||
// by_type.
|
// by_type.
|
||||||
]b4_inline([$1])b4_parser_class[::by_type::by_type ()
|
]b4_inline([$1])b4_parser_class[::by_type::by_type ()
|
||||||
: type (]b4_symbol_prefix[YYEMPTY)
|
: type (symbol_kind::]b4_symbol_prefix[YYEMPTY)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
@@ -494,7 +504,7 @@ m4_define([b4_public_types_define],
|
|||||||
]b4_inline([$1])[void
|
]b4_inline([$1])[void
|
||||||
]b4_parser_class[::by_type::clear ()
|
]b4_parser_class[::by_type::clear ()
|
||||||
{
|
{
|
||||||
type = ]b4_symbol_prefix[YYEMPTY;
|
type = symbol_kind::]b4_symbol_prefix[YYEMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_inline([$1])[void
|
]b4_inline([$1])[void
|
||||||
@@ -540,11 +550,11 @@ m4_define([b4_yytranslate_define],
|
|||||||
const int user_token_number_max_ = ]b4_user_token_number_max[;
|
const int user_token_number_max_ = ]b4_user_token_number_max[;
|
||||||
|
|
||||||
if (t <= 0)
|
if (t <= 0)
|
||||||
return ]b4_symbol_prefix[YYEOF;
|
return symbol_kind::]b4_symbol_prefix[YYEOF;
|
||||||
else if (t <= user_token_number_max_)
|
else if (t <= user_token_number_max_)
|
||||||
return YY_CAST (symbol_kind_type, translate_table[t]);
|
return YY_CAST (symbol_kind_type, translate_table[t]);
|
||||||
else
|
else
|
||||||
return ]b4_symbol_prefix[YYUNDEF;]])[
|
return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|||||||
@@ -357,10 +357,10 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]],
|
|||||||
]b4_namespace_close[
|
]b4_namespace_close[
|
||||||
]m4_define([b4_declare_symbol_enum],
|
]m4_define([b4_declare_symbol_enum],
|
||||||
[[typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
|
[[typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
|
||||||
#define ]b4_symbol_prefix[YYEMPTY ]b4_namespace_ref[::]b4_parser_class[::]b4_symbol_prefix[YYEMPTY
|
#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[::]b4_symbol_prefix[YYERROR
|
#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[::]b4_symbol_prefix[YYEOF
|
#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[::]b4_symbol_prefix[YYUNDEF
|
#define ]b4_symbol_prefix[YYUNDEF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYUNDEF
|
||||||
]])[
|
]])[
|
||||||
]b4_percent_code_get([[provides]])[
|
]b4_percent_code_get([[provides]])[
|
||||||
]m4_popdef([b4_parse_param])dnl
|
]m4_popdef([b4_parse_param])dnl
|
||||||
|
|||||||
@@ -700,7 +700,7 @@ b4_parse_error_case([verbose], [[
|
|||||||
]b4_parser_class[::by_state::type_get () const YY_NOEXCEPT
|
]b4_parser_class[::by_state::type_get () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (state == empty_state)
|
if (state == empty_state)
|
||||||
return ]b4_symbol_prefix[YYEMPTY;
|
return symbol_kind::]b4_symbol_prefix[YYEMPTY;
|
||||||
else
|
else
|
||||||
return YY_CAST (symbol_kind_type, yystos_[+state]);
|
return YY_CAST (symbol_kind_type, yystos_[+state]);
|
||||||
}
|
}
|
||||||
@@ -725,7 +725,7 @@ b4_parse_error_case([verbose], [[
|
|||||||
b4_symbol_variant([that.type_get ()],
|
b4_symbol_variant([that.type_get ()],
|
||||||
[value], [move], [YY_MOVE (that.value)])])[
|
[value], [move], [YY_MOVE (that.value)])])[
|
||||||
// that is emptied.
|
// that is emptied.
|
||||||
that.type = ]b4_symbol_prefix[YYEMPTY;
|
that.type = symbol_kind::]b4_symbol_prefix[YYEMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if YY_CPLUSPLUS < 201103L
|
#if YY_CPLUSPLUS < 201103L
|
||||||
@@ -1089,7 +1089,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
error, discard it. */
|
error, discard it. */
|
||||||
|
|
||||||
// Return failure if at end of input.
|
// Return failure if at end of input.
|
||||||
if (yyla.type_get () == ]b4_symbol_prefix[YYEOF)
|
if (yyla.type_get () == symbol_kind::]b4_symbol_prefix[YYEOF)
|
||||||
YYABORT;
|
YYABORT;
|
||||||
else if (!yyla.empty ())
|
else if (!yyla.empty ())
|
||||||
{
|
{
|
||||||
@@ -1131,8 +1131,9 @@ b4_dollar_popdef])[]dnl
|
|||||||
yyn = yypact_[+yystack_[0].state];
|
yyn = yypact_[+yystack_[0].state];
|
||||||
if (!yy_pact_value_is_default_ (yyn))
|
if (!yy_pact_value_is_default_ (yyn))
|
||||||
{
|
{
|
||||||
yyn += ]b4_symbol_prefix[YYERROR;
|
yyn += symbol_kind::]b4_symbol_prefix[YYERROR;
|
||||||
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == ]b4_symbol_prefix[YYERROR)
|
if (0 <= yyn && yyn <= yylast_
|
||||||
|
&& yycheck_[yyn] == symbol_kind::]b4_symbol_prefix[YYERROR)
|
||||||
{
|
{
|
||||||
yyn = yytable_[yyn];
|
yyn = yytable_[yyn];
|
||||||
if (0 < yyn)
|
if (0 < yyn)
|
||||||
@@ -1244,7 +1245,8 @@ b4_dollar_popdef])[]dnl
|
|||||||
for (int yyx = 0; yyx < YYNTOKENS; ++yyx)
|
for (int yyx = 0; yyx < YYNTOKENS; ++yyx)
|
||||||
{
|
{
|
||||||
symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx);
|
symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx);
|
||||||
if (yysym != ]b4_symbol_prefix[YYERROR && yysym != ]b4_symbol_prefix[YYUNDEF
|
if (yysym != symbol_kind::]b4_symbol_prefix[YYERROR
|
||||||
|
&& yysym != symbol_kind::]b4_symbol_prefix[YYUNDEF
|
||||||
&& yyparser_.yy_lac_check_ (yysym))
|
&& yyparser_.yy_lac_check_ (yysym))
|
||||||
{
|
{
|
||||||
if (!yyarg)
|
if (!yyarg)
|
||||||
@@ -1266,7 +1268,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
int yychecklim = yylast_ - yyn + 1;
|
int yychecklim = yylast_ - yyn + 1;
|
||||||
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
||||||
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
|
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol_prefix[YYERROR
|
if (yycheck_[yyx + yyn] == yyx && yyx != symbol_kind::]b4_symbol_prefix[YYERROR
|
||||||
&& !yy_table_value_is_error_ (yytable_[yyx + yyn]))
|
&& !yy_table_value_is_error_ (yytable_[yyx + yyn]))
|
||||||
{
|
{
|
||||||
if (!yyarg)
|
if (!yyarg)
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ AT_PERL_CHECK([[-n -0777 -e '
|
|||||||
|YYChar
|
|YYChar
|
||||||
|YYNTOKENS # This is actual scoped in a C++ class.
|
|YYNTOKENS # This is actual scoped in a C++ class.
|
||||||
|YYPUSH_MORE(?:_DEFINED)?
|
|YYPUSH_MORE(?:_DEFINED)?
|
||||||
|YYSYMBOL_(\w+) # These guys are scoped.
|
|S_(YY(ACCEPT|EMPTY|EOF|ERROR|UNDEF)) # These guys are scoped.
|
||||||
|YYUSE
|
|YYUSE
|
||||||
|YY_ATTRIBUTE(?:_PURE|_UNUSED)
|
|YY_ATTRIBUTE(?:_PURE|_UNUSED)
|
||||||
|YY(?:_REINTERPRET)?_CAST
|
|YY(?:_REINTERPRET)?_CAST
|
||||||
|
|||||||
@@ -756,7 +756,7 @@ void
|
|||||||
std::cerr << "syntax error";
|
std::cerr << "syntax error";
|
||||||
{
|
{
|
||||||
symbol_kind_type la = ctx.token ();
|
symbol_kind_type la = ctx.token ();
|
||||||
if (la != YYSYMBOL_YYEMPTY)
|
if (la != symbol_kind::S_YYEMPTY)
|
||||||
fprintf (stderr, " on token [%s]", yysymbol_name (la));
|
fprintf (stderr, " on token [%s]", yysymbol_name (la));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user