From a3cb6248932cfea1850ac4b981be80b36a98cb68 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 15 Dec 2004 16:18:12 +0000 Subject: [PATCH] Simplify the C++ parser constructor. * data/lalr1.cc (debug_): Rename as... (yydebug_): so that the parser's internals are always in the yy* pseudo namespace. Adjust uses. (b4_parse_param_decl): Remove the leading comma as it is now only called as unique argument list. (Parser::Parser): Remove the constructor accepting a location and an initial debugging level. Remove from the other ctor the argument for the debugging level. (debug_level_type, debug_level, set_debug_level): New. * tests/actions.at, tests/calc.at, tests/regression.at: Adjust constructor calls. --- ChangeLog | 20 +++++++++++++++++- data/lalr1.cc | 49 +++++++++++++++++++++++++++------------------ tests/actions.at | 3 ++- tests/calc.at | 3 ++- tests/regression.at | 3 ++- 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6835dbf..43cdc008 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,25 @@ +2004-12-15 Akim Demaille + + Simplify the C++ parser constructor. + + * data/lalr1.cc (debug_): Rename as... + (yydebug_): so that the parser's internals are always in the yy* + pseudo namespace. + Adjust uses. + (b4_parse_param_decl): Remove the leading comma as it is now only + called as unique argument list. + (Parser::Parser): Remove the constructor accepting a location and + an initial debugging level. + Remove from the other ctor the argument for the debugging level. + (debug_level_type, debug_level, set_debug_level): New. + + * tests/actions.at, tests/calc.at, tests/regression.at: Adjust + constructor calls. + 2004-12-15 Akim Demaille Remove b4_root related material: failure experiment - (which goal was to allow to derive from an class). + (which goal was to allow to derive from a class). * data/lalr1.cc (b4_root, b4_param, b4_constructor): Remove definitions and uses. diff --git a/data/lalr1.cc b/data/lalr1.cc index a68eecc3..0ba7720d 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -70,7 +70,7 @@ m4_define([b4_rhs_location], # argument name in the constructor. m4_define([b4_parse_param_decl], [m4_ifset([b4_parse_param], - [, m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])]) + [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])]) m4_define([b4_parse_param_decl_1], [$1_yyarg]) @@ -217,23 +217,12 @@ namespace yy typedef Stack SemanticStack; typedef Stack LocationStack; - ]b4_parser_class_name[ (bool debug]b4_parse_param_decl[) : - debug_ (debug), + ]b4_parser_class_name[ (]b4_parse_param_decl[) : + yydebug_ (false), yycdebug_ (&std::cerr)]b4_parse_param_cons[ { } - ]b4_parser_class_name[ (bool debug, - LocationType]b4_parse_param_decl[) : - debug_ (debug), - yycdebug_ (&std::cerr)]b4_parse_param_cons[ - { - *yycdebug_ << __FILE__ << ':' << __LINE__ - << ": this constructor is provided by backward compatibility" - << ", but will be removed in the near future." - << std::endl; - } - virtual ~]b4_parser_class_name[ () { } @@ -245,6 +234,13 @@ namespace yy /// Set the current debugging stream. void set_debug_stream (std::ostream &); + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); + private: virtual void lex_ (); @@ -321,7 +317,7 @@ namespace yy int errstatus_; /* Debugging. */ - int debug_; + int yydebug_; std::ostream* yycdebug_; /* Look-ahead and look-ahead in internal form. */ @@ -354,9 +350,9 @@ b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[ -/* A pseudo ostream that takes debug_ into account. */ +/* A pseudo ostream that takes yydebug_ into account. */ # define YYCDEBUG \ - for (bool yydebugcond_ = debug_; yydebugcond_; yydebugcond_ = false) \ + for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \ (*yycdebug_) /* Enable debugging if requested. */ @@ -364,7 +360,7 @@ m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[ # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ - if (debug_) \ + if (yydebug_) \ { \ *yycdebug_ << (Title) << ' '; \ symprint_ ((Type), (Value), (Location)); \ @@ -374,13 +370,13 @@ do { \ # define YY_REDUCE_PRINT(Rule) \ do { \ - if (debug_) \ + if (yydebug_) \ reduce_print_ (Rule); \ } while (0) # define YY_STACK_PRINT() \ do { \ - if (debug_) \ + if (yydebug_) \ stack_print_ (); \ } while (0) @@ -464,6 +460,19 @@ yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o) } +yy::]b4_parser_class_name[::debug_level_type +yy::]b4_parser_class_name[::debug_level () const +{ + return yydebug_; +} + +void +yy::]b4_parser_class_name[::set_debug_level (debug_level_type l) +{ + yydebug_ = l; +} + + int yy::]b4_parser_class_name[::parse () { diff --git a/tests/actions.at b/tests/actions.at index 15f25c03..fa779b39 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -320,7 +320,8 @@ static bool yydebug; int yyparse () { - yy::Parser parser (yydebug); + yy::Parser parser; + parser.set_debug_level (yydebug); return parser.parse (); } ], diff --git a/tests/calc.at b/tests/calc.at index 83ce2831..27598e61 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -136,7 +136,8 @@ yy::Parser::error_ () int yyparse (AT_PARAM_IF([semantic_value *result, int *count])) { - yy::Parser parser (!!YYDEBUG[]AT_PARAM_IF([, result, count])); + yy::Parser parser[]AT_PARAM_IF([ (result, count)]); + parser.set_debug_level (!!YYDEBUG); return parser.parse (); } ], diff --git a/tests/regression.at b/tests/regression.at index c199ecc1..ab0b71e8 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -735,7 +735,8 @@ yy::Parser::error_ () int yyparse (void) { - yy::Parser parser (!!YYDEBUG); + yy::Parser parser; + parser.set_debug_level (!!YYDEBUG); return parser.parse (); } ], -- 2.47.2