v4 preprocessor: minor improvement related to debugging of scanning & parsing

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1751 ac1d8469-bf42-47a9-8791-bf33cf982152
issue#70
sebastien 2008-03-28 17:21:45 +00:00
parent 32bf5c7525
commit 76da313b98
6 changed files with 22 additions and 40 deletions

View File

@ -32,8 +32,7 @@ using namespace std;
Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be
included simultaneously (because of Bison limitations). included simultaneously (because of Bison limitations).
*/ */
void main2(stringstream &in, string &basename, bool trace_scanning, bool trace_parsing, void main2(stringstream &in, string &basename, bool debug, bool clear_all);
bool clear_all);
int int
main(int argc, char** argv) main(int argc, char** argv)
@ -47,17 +46,13 @@ main(int argc, char** argv)
bool clear_all = true; bool clear_all = true;
bool save_macro = false; bool save_macro = false;
bool trace_scanning = false; bool debug = false;
bool trace_parsing = false;
// Parse options // Parse options
for (int arg = 2; arg < argc; arg++) for (int arg = 2; arg < argc; arg++)
{ {
if (string(argv[arg]) == string("debug")) if (string(argv[arg]) == string("debug"))
{ debug = true;
trace_scanning = true;
trace_parsing = true;
}
else if (string(argv[arg]) == string("noclearall")) else if (string(argv[arg]) == string("noclearall"))
clear_all = false; clear_all = false;
else if (string(argv[arg]) == string("savemacro")) else if (string(argv[arg]) == string("savemacro"))
@ -79,9 +74,8 @@ main(int argc, char** argv)
basename.erase(basename.size() - 4, 4); basename.erase(basename.size() - 4, 4);
// Do macro processing // Do macro processing
MacroDriver m; MacroDriver m(debug);
m.trace_scanning = trace_scanning;
m.trace_parsing = trace_parsing;
stringstream macro_output; stringstream macro_output;
m.parse(argv[1], macro_output); m.parse(argv[1], macro_output);
if (save_macro) if (save_macro)
@ -92,7 +86,7 @@ main(int argc, char** argv)
} }
// Do the rest // Do the rest
main2(macro_output, basename, trace_scanning, trace_parsing, clear_all); main2(macro_output, basename, debug, clear_all);
return 0; return 0;
} }

View File

@ -25,11 +25,9 @@ using namespace std;
#include "ModFile.hh" #include "ModFile.hh"
void void
main2(stringstream &in, string &basename, bool trace_scanning, bool trace_parsing, bool clear_all) main2(stringstream &in, string &basename, bool debug, bool clear_all)
{ {
ParsingDriver p; ParsingDriver p(debug);
p.trace_scanning = trace_scanning;
p.trace_parsing = trace_parsing;
// Do parsing and construct internal representation of mod file // Do parsing and construct internal representation of mod file
ModFile *mod_file = p.parse(in); ModFile *mod_file = p.parse(in);

View File

@ -23,7 +23,7 @@
#include "ParsingDriver.hh" #include "ParsingDriver.hh"
#include "Statement.hh" #include "Statement.hh"
ParsingDriver::ParsingDriver() : trace_scanning(false), trace_parsing(false) ParsingDriver::ParsingDriver(bool debug_arg) : debug(debug_arg)
{ {
} }
@ -70,9 +70,10 @@ ParsingDriver::parse(istream &in)
reset_data_tree(); reset_data_tree();
lexer = new DynareFlex(&in); lexer = new DynareFlex(&in);
lexer->set_debug(trace_scanning); lexer->set_debug(debug);
Dynare::parser parser(*this); Dynare::parser parser(*this);
parser.set_debug_level(debug);
parser.parse(); parser.parse();
delete lexer; delete lexer;

View File

@ -137,9 +137,12 @@ private:
//! The mod file representation constructed by this ParsingDriver //! The mod file representation constructed by this ParsingDriver
ModFile *mod_file; ModFile *mod_file;
//! Output debugging info during scanning and parsing ?
const bool debug;
public: public:
//! Constructor //! Constructor
ParsingDriver(); ParsingDriver(bool debug_arg);
//! Destructor //! Destructor
virtual ~ParsingDriver(); virtual ~ParsingDriver();
@ -153,15 +156,6 @@ public:
//! Copy of parsing location, maintained by YYLLOC_DEFAULT macro in DynareBison.yy //! Copy of parsing location, maintained by YYLLOC_DEFAULT macro in DynareBison.yy
Dynare::parser::location_type location; Dynare::parser::location_type location;
//! Trace scanning ?
/*! If set to true before calling parse(), the flex scanner will dump a lot of debugging information. Defaults to false.
*/
bool trace_scanning;
//! Trace parsing ?
/*! If set to true before calling parse(), the bison parser will dump debugging information. Defaults to false. */
bool trace_parsing;
//! Estimation parameters //! Estimation parameters
EstimationParams estim_params; EstimationParams estim_params;

View File

@ -22,7 +22,7 @@
#include "MacroDriver.hh" #include "MacroDriver.hh"
MacroDriver::MacroDriver() : trace_scanning(false), trace_parsing(false) MacroDriver::MacroDriver(bool debug_arg) : debug(debug_arg)
{ {
} }
@ -47,9 +47,10 @@ MacroDriver::parse(const string &f, ostream &out)
} }
lexer = new MacroFlex(&in, &out); lexer = new MacroFlex(&in, &out);
lexer->set_debug(trace_scanning); lexer->set_debug(debug);
Macro::parser parser(*this, out); Macro::parser parser(*this, out);
parser.set_debug_level(debug);
parser.parse(); parser.parse();
delete lexer; delete lexer;

View File

@ -138,6 +138,9 @@ class MacroDriver
{ {
friend class MacroValue; friend class MacroValue;
private: private:
//! Output debugging info during scanning and parsing ?
const bool debug;
//! Stores all created macro values //! Stores all created macro values
set<const MacroValue *> values; set<const MacroValue *> values;
@ -157,7 +160,7 @@ public:
}; };
//! Constructor //! Constructor
MacroDriver(); MacroDriver(bool debug_arg);
//! Destructor //! Destructor
virtual ~MacroDriver(); virtual ~MacroDriver();
@ -176,15 +179,6 @@ public:
//! Used to store the value of the last @if condition //! Used to store the value of the last @if condition
bool last_if; bool last_if;
//! Trace scanning ?
/*! If set to true before calling parse(), the flex scanner will dump a lot of debugging information. Defaults to false.
*/
bool trace_scanning;
//! Trace parsing ?
/*! If set to true before calling parse(), the bison parser will dump debugging information. Defaults to false. */
bool trace_parsing;
//! Error handler //! Error handler
void error(const Macro::parser::location_type &l, const string &m) const; void error(const Macro::parser::location_type &l, const string &m) const;