mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 09:13:04 +00:00
c++: clean up the handling of empty symbols
* data/c++.m4, data/lalr1.cc (yyempty_): Remove, replaced by... (empty_symbol, by_state::empty_state): these. (basic_symbol::empty): New.
This commit is contained in:
28
data/c++.m4
28
data/c++.m4
@@ -174,9 +174,12 @@ m4_define([b4_public_types_declare],
|
|||||||
/// (External) token type, as returned by yylex.
|
/// (External) token type, as returned by yylex.
|
||||||
typedef token::yytokentype token_type;
|
typedef token::yytokentype token_type;
|
||||||
|
|
||||||
/// Internal symbol number.
|
/// Symbol type: an internal symbol number.
|
||||||
typedef int symbol_number_type;
|
typedef int symbol_number_type;
|
||||||
|
|
||||||
|
/// The symbol type number to denote an empty symbol.
|
||||||
|
enum { empty_symbol = -2 };
|
||||||
|
|
||||||
/// Internal symbol number for tokens (subsumed by symbol_number_type).
|
/// Internal symbol number for tokens (subsumed by symbol_number_type).
|
||||||
typedef ]b4_int_type_for([b4_translate])[ token_number_type;
|
typedef ]b4_int_type_for([b4_translate])[ token_number_type;
|
||||||
|
|
||||||
@@ -212,6 +215,9 @@ m4_define([b4_public_types_declare],
|
|||||||
/// Destroy the symbol.
|
/// Destroy the symbol.
|
||||||
~basic_symbol ();
|
~basic_symbol ();
|
||||||
|
|
||||||
|
/// Whether empty.
|
||||||
|
bool empty () const;
|
||||||
|
|
||||||
/// Destructive move, \a s is emptied into this.
|
/// Destructive move, \a s is emptied into this.
|
||||||
void move (basic_symbol& s);
|
void move (basic_symbol& s);
|
||||||
|
|
||||||
@@ -251,12 +257,10 @@ m4_define([b4_public_types_declare],
|
|||||||
/// The token.
|
/// The token.
|
||||||
token_type token () const;
|
token_type token () const;
|
||||||
|
|
||||||
/// The type number used to denote an empty symbol.
|
|
||||||
enum { empty = 0 };
|
|
||||||
|
|
||||||
/// The symbol type.
|
/// The symbol type.
|
||||||
/// \a empty when empty.
|
/// \a empty_symbol when empty.
|
||||||
token_number_type type;
|
/// An int, not token_number_type, to be able to store empty_symbol.
|
||||||
|
int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// "External" symbols: returned by the scanner.
|
/// "External" symbols: returned by the scanner.
|
||||||
@@ -339,6 +343,14 @@ m4_define([b4_public_types_define],
|
|||||||
]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[
|
]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Base>
|
||||||
|
inline
|
||||||
|
bool
|
||||||
|
]b4_parser_class_name[::basic_symbol<Base>::empty () const
|
||||||
|
{
|
||||||
|
return Base::type_get () == empty_symbol;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
inline
|
inline
|
||||||
void
|
void
|
||||||
@@ -354,7 +366,7 @@ m4_define([b4_public_types_define],
|
|||||||
// by_type.
|
// by_type.
|
||||||
inline
|
inline
|
||||||
]b4_parser_class_name[::by_type::by_type ()
|
]b4_parser_class_name[::by_type::by_type ()
|
||||||
: type (empty)
|
: type (empty_symbol)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -372,7 +384,7 @@ m4_define([b4_public_types_define],
|
|||||||
]b4_parser_class_name[::by_type::move (by_type& that)
|
]b4_parser_class_name[::by_type::move (by_type& that)
|
||||||
{
|
{
|
||||||
type = that.type;
|
type = that.type;
|
||||||
that.type = empty;
|
that.type = empty_symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ b4_location_define])])[
|
|||||||
|
|
||||||
/// Generate an error message.
|
/// Generate an error message.
|
||||||
/// \param yystate the state where the error occurred.
|
/// \param yystate the state where the error occurred.
|
||||||
/// \param yytoken the lookahead token type, or yyempty_.
|
/// \param yytoken the lookahead token type, or empty_symbol.
|
||||||
virtual std::string yysyntax_error_ (state_type yystate,
|
virtual std::string yysyntax_error_ (state_type yystate,
|
||||||
symbol_number_type yytoken) const;
|
symbol_number_type yytoken) const;
|
||||||
|
|
||||||
@@ -292,11 +292,11 @@ b4_location_define])])[
|
|||||||
void move (by_state& that);
|
void move (by_state& that);
|
||||||
|
|
||||||
/// The (internal) type number (corresponding to \a state).
|
/// The (internal) type number (corresponding to \a state).
|
||||||
/// \a empty when empty.
|
/// \a empty_symbol when empty.
|
||||||
symbol_number_type type_get () const;
|
symbol_number_type type_get () const;
|
||||||
|
|
||||||
/// The state number used to denote an empty symbol.
|
/// The state number used to denote an empty symbol.
|
||||||
enum { empty = 0 };
|
enum { empty_state = -1 };
|
||||||
|
|
||||||
/// The state.
|
/// The state.
|
||||||
/// \a empty when empty.
|
/// \a empty when empty.
|
||||||
@@ -346,7 +346,6 @@ b4_location_define])])[
|
|||||||
yyeof_ = 0,
|
yyeof_ = 0,
|
||||||
yylast_ = ]b4_last[, ///< Last index in yytable_.
|
yylast_ = ]b4_last[, ///< Last index in yytable_.
|
||||||
yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols.
|
yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols.
|
||||||
yyempty_ = -2,
|
|
||||||
yyfinal_ = ]b4_final_state_number[, ///< Termination state number.
|
yyfinal_ = ]b4_final_state_number[, ///< Termination state number.
|
||||||
yyterror_ = 1,
|
yyterror_ = 1,
|
||||||
yyerrcode_ = 256,
|
yyerrcode_ = 256,
|
||||||
@@ -535,7 +534,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
// by_state.
|
// by_state.
|
||||||
inline
|
inline
|
||||||
]b4_parser_class_name[::by_state::by_state ()
|
]b4_parser_class_name[::by_state::by_state ()
|
||||||
: state (empty)
|
: state (empty_state)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -548,7 +547,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_parser_class_name[::by_state::move (by_state& that)
|
]b4_parser_class_name[::by_state::move (by_state& that)
|
||||||
{
|
{
|
||||||
state = that.state;
|
state = that.state;
|
||||||
that.state = empty;
|
that.state = empty_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -560,7 +559,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_parser_class_name[::symbol_number_type
|
]b4_parser_class_name[::symbol_number_type
|
||||||
]b4_parser_class_name[::by_state::type_get () const
|
]b4_parser_class_name[::by_state::type_get () const
|
||||||
{
|
{
|
||||||
return state == empty ? 0 : yystos_[state];
|
return state == empty_state ? empty_symbol : yystos_[state];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -576,7 +575,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
[value], [move], [that.value])],
|
[value], [move], [that.value])],
|
||||||
[[value = that.value;]])[
|
[[value = that.value;]])[
|
||||||
// that is emptied.
|
// that is emptied.
|
||||||
that.type = empty;
|
that.type = empty_symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -876,7 +875,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
++yynerrs_;
|
++yynerrs_;
|
||||||
error (]b4_join(b4_locations_if([yyla.location]),
|
error (]b4_join(b4_locations_if([yyla.location]),
|
||||||
[[yysyntax_error_ (yystack_[0].state,
|
[[yysyntax_error_ (yystack_[0].state,
|
||||||
yyempty ? yyempty_ : yyla.type_get ())]])[);
|
yyempty ? empty_symbol : yyla.type_get ())]])[);
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
@@ -1046,7 +1045,7 @@ b4_error_verbose_if([state_type yystate, symbol_number_type yytoken],
|
|||||||
token that will not be accepted due to an error action in a
|
token that will not be accepted due to an error action in a
|
||||||
later state.
|
later state.
|
||||||
*/
|
*/
|
||||||
if (yytoken != yyempty_)
|
if (yytoken != empty_symbol)
|
||||||
{
|
{
|
||||||
yyarg[yycount++] = yytname_[yytoken];
|
yyarg[yycount++] = yytname_[yytoken];
|
||||||
int yyn = yypact_[yystate];
|
int yyn = yypact_[yystate];
|
||||||
|
|||||||
Reference in New Issue
Block a user