* data/lalr1.cc: Extensive Doxygenation.

(error_): Rename as...
(error): this, since it is visible to the user.
Adjust callers.
(Parser::message): Now an automatic variable from...
(Parser::yyreport_syntax_error_): here.
* tests/actions.at, tests/calc.at, tests/regression.at: Adjust to
Parser::error.
* tests/input.at: Escape $.
This commit is contained in:
Akim Demaille
2004-12-17 15:24:32 +00:00
parent 76dcf299b7
commit efeed02327
7 changed files with 59 additions and 17 deletions

View File

@@ -1,3 +1,15 @@
2004-12-17 Akim Demaille <akim@epita.fr>
* data/lalr1.cc: Extensive Doxygenation.
(error_): Rename as...
(error): this, since it is visible to the user.
Adjust callers.
(Parser::message): Now an automatic variable from...
(Parser::yyreport_syntax_error_): here.
* tests/actions.at, tests/calc.at, tests/regression.at: Adjust to
Parser::error.
* tests/input.at: Escape $.
2004-12-16 Paul Eggert <eggert@cs.ucla.edu> 2004-12-16 Paul Eggert <eggert@cs.ucla.edu>
* data/glr.c (b4_lhs_value, b4_rhs_value, b4_rhs-location): * data/glr.c (b4_lhs_value, b4_rhs_value, b4_rhs-location):

2
NEWS
View File

@@ -1,6 +1,8 @@
Bison News Bison News
---------- ----------
Changes in version 1.875f:
Changes in version 1.875e, 2004-12-10: Changes in version 1.875e, 2004-12-10:
* New directive: %initial-action. * New directive: %initial-action.

View File

@@ -203,6 +203,7 @@ namespace yy
namespace yy namespace yy
{ {
/// A Bison parser.
class ]b4_parser_class_name[ class ]b4_parser_class_name[
{ {
public: public:
@@ -217,10 +218,14 @@ namespace yy
/// Symbol locations. /// Symbol locations.
typedef Traits<]b4_parser_class_name[>::LocationType LocationType; typedef Traits<]b4_parser_class_name[>::LocationType LocationType;
/// State stack type.
typedef Stack<StateType> StateStack; typedef Stack<StateType> StateStack;
/// Semantic value stack type.
typedef Stack<SemanticType> SemanticStack; typedef Stack<SemanticType> SemanticStack;
/// Location stack type.
typedef Stack<LocationType> LocationStack; typedef Stack<LocationType> LocationStack;
/// Build a parser object.
]b4_parser_class_name[ (]b4_parse_param_decl[) : ]b4_parser_class_name[ (]b4_parse_param_decl[) :
yydebug_ (false), yydebug_ (false),
yycdebug_ (&std::cerr)]b4_parse_param_cons[ yycdebug_ (&std::cerr)]b4_parse_param_cons[
@@ -251,9 +256,15 @@ namespace yy
/// Call the scanner. /// Call the scanner.
virtual void yylex_ (); virtual void yylex_ ();
virtual void error_ ();
/// Generate an error message, and invoke error. */ /// Report a syntax error.
/// \param loc where the syntax error is found.
/// \param msg a description of the syntax error.
virtual void error (const LocationType& loc, const std::string& msg);
/// Generate an error message, and invoke error.
virtual void yyreport_syntax_error_ (); virtual void yyreport_syntax_error_ ();
#if YYDEBUG #if YYDEBUG
/// \brief Report a symbol on the debug stream. /// \brief Report a symbol on the debug stream.
/// \param yytype The token type. /// \param yytype The token type.
@@ -273,19 +284,38 @@ namespace yy
LocationStack yylocation_stack_; LocationStack yylocation_stack_;
/* Tables. */ /* Tables. */
/// For a state, the index in \a yytable_ of its portion.
static const ]b4_int_type_for([b4_pact])[ yypact_[]; static const ]b4_int_type_for([b4_pact])[ yypact_[];
static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
/// For a state, default rule to reduce.
/// Unless\a yytable_ specifies something else to do.
/// Zero means the default is an error.
static const ]b4_int_type_for([b4_defact])[ yydefact_[]; static const ]b4_int_type_for([b4_defact])[ yydefact_[];
static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[]; static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[]; static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
/// What to do in a state.
/// \a yytable_[yypact_[s]]: what to do in state \a s.
/// - if positive, shift that token.
/// - if negative, reduce the rule which number is the opposite.
/// - if zero, do what YYDEFACT says.
static const ]b4_int_type_for([b4_table])[ yytable_[]; static const ]b4_int_type_for([b4_table])[ yytable_[];
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
static const ]b4_int_type_for([b4_check])[ yycheck_[]; static const ]b4_int_type_for([b4_check])[ yycheck_[];
/// For a state, its accessing symbol.
static const ]b4_int_type_for([b4_stos])[ yystos_[]; static const ]b4_int_type_for([b4_stos])[ yystos_[];
/// For a rule, its LHS.
static const ]b4_int_type_for([b4_r1])[ yyr1_[]; static const ]b4_int_type_for([b4_r1])[ yyr1_[];
/// For a rule, its RHS length.
static const ]b4_int_type_for([b4_r2])[ yyr2_[]; static const ]b4_int_type_for([b4_r2])[ yyr2_[];
#if YYDEBUG || YYERROR_VERBOSE #if YYDEBUG || YYERROR_VERBOSE
/// For a symbol, its name in clear.
static const char* const yyname_[]; static const char* const yyname_[];
#endif #endif
@@ -298,9 +328,9 @@ namespace yy
static const ]b4_int_type_for([b4_rline])[ yyrline_[]; static const ]b4_int_type_for([b4_rline])[ yyrline_[];
/// For each scanner token number, its symbol number. /// For each scanner token number, its symbol number.
static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[]; static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
/// Report on the debug stream that the rule \a yyrule is going to be reduced. /// Report on the debug stream that the rule \a r is going to be reduced.
virtual void yyreduce_print_ (int yyrule); virtual void yyreduce_print_ (int r);
/// Print the state stack on the debug stream. /// Print the state stack on the debug stream.
virtual void yystack_print_ (); virtual void yystack_print_ ();
#endif #endif
@@ -350,9 +380,6 @@ namespace yy
int yylooka_; int yylooka_;
int yyilooka_; int yyilooka_;
/* Message. */
std::string message;
/// Semantic value of the look-ahead. /// Semantic value of the look-ahead.
SemanticType value; SemanticType value;
/// Location of the look-ahead. /// Location of the look-ahead.
@@ -805,7 +832,7 @@ yy::]b4_parser_class_name[::yyreport_syntax_error_ ()
if (!yyerrstatus_) if (!yyerrstatus_)
{ {
++yynerrs_; ++yynerrs_;
std::string message;
#if YYERROR_VERBOSE #if YYERROR_VERBOSE
yyn_ = yypact_[yystate_]; yyn_ = yypact_[yystate_];
if (yypact_ninf_ < yyn_ && yyn_ < yylast_) if (yypact_ninf_ < yyn_ && yyn_ < yylast_)
@@ -838,7 +865,7 @@ yy::]b4_parser_class_name[::yyreport_syntax_error_ ()
else else
#endif #endif
message = "syntax error"; message = "syntax error";
error_ (); error (location, message);
} }
} }

View File

@@ -311,9 +311,9 @@ yylex (]AT_LEX_FORMALS[)
]AT_LALR1_CC_IF( ]AT_LALR1_CC_IF(
[/* A C++ error reporting function. */ [/* A C++ error reporting function. */
void void
yy::Parser::error_ () yy::Parser::error (const Location& l, const std::string& m)
{ {
printf ("%d-%d: %s\n", RANGE (location), message.c_str()); printf ("%d-%d: %s\n", RANGE (l), m.c_str());
} }
static bool yydebug; static bool yydebug;

View File

@@ -128,9 +128,10 @@ static FILE *yyin;
]AT_LALR1_CC_IF( ]AT_LALR1_CC_IF(
[/* A C++ error reporting function. */ [/* A C++ error reporting function. */
void void
yy::Parser::error_ () yy::Parser::error (const Location& l, const std::string& m)
{ {
std::cerr << AT_LOCATION_IF([location << ": " << ])message << std::endl; (void) l;
std::cerr << AT_LOCATION_IF([l << ": " << ])m << std::endl;
} }
int int

View File

@@ -25,7 +25,7 @@ AT_BANNER([[Input Processing.]])
## Invalid $n. ## ## Invalid $n. ##
## ------------ ## ## ------------ ##
AT_SETUP([Invalid $n]) AT_SETUP([Invalid \$n])
AT_DATA([input.y], AT_DATA([input.y],
[[%% [[%%

View File

@@ -727,9 +727,9 @@ member: STRING
AT_LALR1_CC_IF( AT_LALR1_CC_IF(
[/* A C++ error reporting function. */ [/* A C++ error reporting function. */
void void
yy::Parser::error_ () yy::Parser::error (const Location&, const std::string& m)
{ {
std::cerr << message << std::endl; std::cerr << m << std::endl;
} }
int int