diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 81ce4cf9df28eecb4aded78a963cc7867d1a9536..c7a297880932eca46b24863186db1c38eed39a76 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -171,19 +171,20 @@ PriorPosteriorFunctionStatement::writeOutput(ostream &output, const string &base << "'" << type << "');" << endl; } -VARStatement::VARStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg, - const SymbolTable &symbol_table_arg) : +VarModelStatement::VarModelStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg, + const string &name_arg, + const SymbolTable &symbol_table_arg) : symbol_list(symbol_list_arg), options_list(options_list_arg), + name(name_arg), symbol_table(symbol_table_arg) { } void -VARStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) +VarModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - mod_file_struct.var_model_present = true; vector<string> symbols = symbol_list.get_symbols(); for (vector<string>::const_iterator it = symbols.begin(); it != symbols.end(); it++) if (symbol_table.getType(*it) != eEndogenous) @@ -192,27 +193,27 @@ VARStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation exit(EXIT_FAILURE); } - OptionsList::num_options_t::const_iterator it = options_list.num_options.find("var(varidx).order"); + OptionsList::num_options_t::const_iterator it = options_list.num_options.find("var.order"); if (it == options_list.num_options.end()) { - cerr << "ERROR: You must provide the order option to the var command." << endl; + cerr << "ERROR: You must provide the order option to the var_model statement." << endl; exit(EXIT_FAILURE); } - OptionsList::string_options_t::const_iterator it1 = options_list.string_options.find("var(varidx).name"); - if (it1 == options_list.string_options.end()) + if (name.empty()) { - cerr << "ERROR: You must provide the model_name option to the var command." << endl; + cerr << "ERROR: You must provide the model_name option to the var_model statement." << endl; exit(EXIT_FAILURE); } } void -VARStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +VarModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); - symbol_list.writeOutput("options_.var(varidx).var_list_", output); - output << "varidx = varidx + 1;" << endl; + symbol_list.writeOutput("options_.var.var_list_", output); + output << "M_.var." << name << " = options_.var;" << endl + << "clear options_.var;" << endl; } StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg, diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d9a0c536dce5a54f9147644f613ed53798182dec..bba0efbfb404d1374352dbc31449387c9232cee4 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -110,16 +110,18 @@ public: virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; -class VARStatement : public Statement +class VarModelStatement : public Statement { private: const SymbolList symbol_list; const OptionsList options_list; - const SymbolTable &symbol_table; + const string &name; + const SymbolTable &symbol_table; public: - VARStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg, - const SymbolTable &symbol_table_arg); + VarModelStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg, + const string &name_arg, + const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; diff --git a/DynareBison.yy b/DynareBison.yy index 3e23212b6180432e403c89a79a6b45362279610d..224a196589c4d8627a017dafe5228f5eb6d8d05a 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -347,7 +347,7 @@ var : VAR var_list ';' { driver.end_nonstationary_var(true, $6); } ; -var_model : VAR '(' var_model_options_list ')' symbol_list ';' { driver.var_model(); } ; +var_model : VAR_MODEL '(' var_model_options_list ')' symbol_list ';' { driver.var_model(); } ; var_model_options_list : var_model_options_list COMMA var_model_options | var_model_options @@ -2827,8 +2827,8 @@ o_simul_seed : SIMUL_SEED EQUAL INT_NUMBER { driver.error("'simul_seed' option i o_qz_criterium : QZ_CRITERIUM EQUAL non_negative_number { driver.option_num("qz_criterium", $3); }; o_qz_zero_threshold : QZ_ZERO_THRESHOLD EQUAL non_negative_number { driver.option_num("qz_zero_threshold", $3); }; o_file : FILE EQUAL filename { driver.option_str("file", $3); }; -o_var_name : MODEL_NAME EQUAL symbol { driver.option_str("var(varidx).name", $3); }; -o_var_order : ORDER EQUAL INT_NUMBER { driver.option_num("var(varidx).order", $3); }; +o_var_name : MODEL_NAME EQUAL symbol { driver.option_str("var.model_name", $3); }; +o_var_order : ORDER EQUAL INT_NUMBER { driver.option_num("var.order", $3); }; o_series : SERIES EQUAL symbol { driver.option_str("series", $3); }; o_datafile : DATAFILE EQUAL filename { driver.option_str("datafile", $3); }; o_dirname : DIRNAME EQUAL filename { driver.option_str("dirname", $3); }; diff --git a/ModFile.cc b/ModFile.cc index 1b114d1e07a4dfb34d8ed0f2f0b2afbc70cf4723..5719d0197fe9d8d27a65846b3a285f354c2be378 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -808,9 +808,6 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo static_model.writeOutput(mOutputFile, block); } - if (mod_file_struct.var_model_present) - mOutputFile << "varidx = 1;" << endl; - // Print statements for (vector<Statement *>::const_iterator it = statements.begin(); it != statements.end(); it++) diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 4fdf1396a8a139bc41829ec93d1caa25542e3369..d90f09332e42ca8f7d3a3e800f5e7162b35f087b 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -1282,7 +1282,11 @@ ParsingDriver::stoch_simul() void ParsingDriver::var_model() { - mod_file->addStatement(new VARStatement(symbol_list, options_list, mod_file->symbol_table)); + OptionsList::string_options_t::const_iterator it = options_list.string_options.find("var.model_name"); + if (it == options_list.string_options.end()) + error("You must pass the model_name option to the var_model statement."); + const string *name = new string(it->second); + mod_file->addStatement(new VarModelStatement(symbol_list, options_list, *name, mod_file->symbol_table)); symbol_list.clear(); options_list.clear(); } diff --git a/Statement.hh b/Statement.hh index 1676ff313804c417ab7b66c4586743027af39c23..ee7846ff4be0b5de66efcdc34c7063f454387b18 100644 --- a/Statement.hh +++ b/Statement.hh @@ -122,8 +122,6 @@ public: int orig_eq_nbr; //! Stores the number of equations added to the Ramsey model int ramsey_eq_nbr; - //! Whether a VAR statement is present - bool var_model_present; }; class Statement