diff --git a/ComputingTasks.cc b/ComputingTasks.cc index a5c6ffa7..18f3f092 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1210,6 +1210,7 @@ void SvarStatement::writeOutput(ostream &output, const string &basename) const { OptionsList::num_options_type::const_iterator it0, it1, it2; + OptionsList::vec_int_options_type::const_iterator itv; it0 = options_list.num_options.find("ms.chain"); if (it0 != options_list.num_options.end()) @@ -1223,11 +1224,17 @@ SvarStatement::writeOutput(ostream &output, const string &basename) const it0 = options_list.string_options.find("ms.coefficients"); it1 = options_list.string_options.find("ms.variances"); it2 = options_list.string_options.find("ms.constants"); - if (it0 != options_list.string_options.end() && it1 == options_list.string_options.end() && it2 == options_list.string_options.end()) + if (it0 != options_list.string_options.end() && + it1 == options_list.string_options.end() && + it2 == options_list.string_options.end()) output << "." << it0->second; - else if (it0 == options_list.string_options.end() && it1 != options_list.string_options.end() && it2 == options_list.string_options.end()) + else if (it0 == options_list.string_options.end() && + it1 != options_list.string_options.end() && + it2 == options_list.string_options.end()) output << "." << it1->second; - else if (it0 == options_list.string_options.end() && it1 == options_list.string_options.end() && it2 != options_list.string_options.end()) + else if (it0 == options_list.string_options.end() && + it1 == options_list.string_options.end() && + it2 != options_list.string_options.end()) output << "." << it2->second; else { @@ -1235,12 +1242,27 @@ SvarStatement::writeOutput(ostream &output, const string &basename) const exit(EXIT_FAILURE); } - it0 = options_list.num_options.find("ms.equations"); - if (it0 != options_list.num_options.end()) - if (it0->second.find("[")!=string::npos) - output << ".equations = " << it0->second << "';" << endl; - else - output << ".equations = " << it0->second << ";" << endl; + itv = options_list.vector_int_options.find("ms.equations"); + output << ".equations = "; + if (itv != options_list.vector_int_options.end()) + { + if (itv->second.size() > 1) + { + output << "["; + for (vector::const_iterator viit=itv->second.begin(); + viit!=itv->second.end(); viit++) + output << *viit << ";"; + output.seekp((long)output.tellp()-1); + output << "];" << endl; + } + else if (itv->second.size() == 1) + output << itv->second.front() << ";" << endl; + else + { + cerr << "SvarStatement::writeOutput() Should not arrive here (3). Please report this to the Dynare Team." << endl; + exit(EXIT_FAILURE); + } + } else - output << ".equations = 'ALL';" << endl; + output << "'ALL';" << endl; } diff --git a/DynareBison.yy b/DynareBison.yy index 912cd898..557197a7 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -74,6 +74,7 @@ class ParsingDriver; NodeID node_val; SymbolType symbol_type_val; vector *vector_string_val; + vector *vector_int_val; }; %{ @@ -167,6 +168,7 @@ class ParsingDriver; %type calib_arg2 range number %type change_type_arg %type change_type_var_list +%type vector_int_body vector_int %% @@ -1871,11 +1873,41 @@ o_number_of_states : NUMBER_OF_STATES EQUAL INT_NUMBER { driver.option_num("ms.n o_coefficients : COEFFICIENTS { driver.option_str("ms.coefficients","svar_coefficients"); }; o_variances : VARIANCES { driver.option_str("ms.variances","svar_variances"); }; o_constants : CONSTANTS { driver.option_str("ms.constants","svar_constants"); }; -o_equations : EQUATIONS EQUAL vec_int - { driver.option_num("ms.equations",$3); } +o_equations : EQUATIONS EQUAL vector_int + { driver.option_vec_int("ms.equations",$3); } | EQUATIONS EQUAL INT_NUMBER - { driver.option_num("ms.equations",$3); } + { + vector *oneInt = new vector(); + oneInt->push_back(atoi((*$3).c_str())); + driver.option_vec_int("ms.equations",oneInt); + delete oneInt; + } ; + +vector_int_body : INT_NUMBER + { $$ = new vector(); $$->push_back(atoi((*$1).c_str())); } + | vector_int_body INT_NUMBER + { $$ = $1; $1->push_back(atoi((*$2).c_str())); } + | vector_int_body COMMA INT_NUMBER + { $$ = $1; $1->push_back(atoi((*$3).c_str())); } + ; + +vector_int : '[' vector_int_body ']' + { $$ = $2; } + | '[' vector_int_body COMMA ']' + { $$ = $2; } + | '[' COMMA vector_int_body ']' + { $$ = $3; } + | '[' COMMA vector_int_body COMMA ']' + { $$ = $3; } + | '[' INT_NUMBER ':' INT_NUMBER ']' + { + $$ = new vector(); + for(int i=atoi((*$2).c_str()); i<=atoi((*$4).c_str()); i++) + $$->push_back(i); + } + ; + o_instruments : INSTRUMENTS EQUAL '(' symbol_list ')' {driver.option_symbol_list("instruments"); }; range : symbol ':' symbol diff --git a/ParsingDriver.cc b/ParsingDriver.cc index d379ec57..142fbc22 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -761,6 +761,16 @@ ParsingDriver::option_symbol_list(const string &name_option) symbol_list.clear(); } +void +ParsingDriver::option_vec_int(const string &name_option, const vector *opt) +{ + if (options_list.vector_int_options.find(name_option) + != options_list.vector_int_options.end()) + error("option " + name_option + " declared twice"); + + options_list.vector_int_options[name_option] = *opt; +} + void ParsingDriver::linear() { @@ -1198,6 +1208,7 @@ void ParsingDriver::svar() { OptionsList::num_options_type::const_iterator it0, it1, it2; + OptionsList::vec_int_options_type::const_iterator itv; it0 = options_list.string_options.find("ms.coefficients"); it1 = options_list.string_options.find("ms.variances"); @@ -1221,29 +1232,14 @@ ParsingDriver::svar() else if (atoi(it0->second.c_str()) <= 0) error("The value passed to the chain option must be greater than zero."); - it0 = options_list.num_options.find("ms.equations"); - if (it0 != options_list.num_options.end()) + itv = options_list.vector_int_options.find("ms.equations"); + if (itv != options_list.vector_int_options.end()) { - string strNextNumber; - for (string::const_iterator it=it0->second.begin(); itsecond.end(); it++) - { - if (*it == '[' || - *it == ',' || - *it == ' ' || - *it == ':' || - *it == ']') - { - if (!strNextNumber.empty()) - if (atoi(strNextNumber.c_str()) <= 0) - error("The value(s) passed to the equation option must be greater than zero."); - strNextNumber.clear(); - } - else - strNextNumber += *it; - } + if (itv->second.empty()) + error("There was an error in the integers passed to the equation option."); - if (!strNextNumber.empty()) - if (atoi(strNextNumber.c_str()) <= 0) + for (vector::const_iterator viit=itv->second.begin(); viit != itv->second.end(); viit++) + if (*viit <= 0) error("The value(s) passed to the equation option must be greater than zero."); } diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 4498aaee..6e004895 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -288,6 +288,8 @@ public: void option_str(const string &name_option, const string &opt); //! Sets an option to a list of symbols (used in conjunction with add_in_symbol_list()) void option_symbol_list(const string &name_option); + //! Sets an option to a vector of integers + void option_vec_int(const string &name_option, const vector *opt); //! Indicates that the model is linear void linear(); //! Adds a variable to temporary symbol list diff --git a/Statement.cc b/Statement.cc index 3f16dc1e..6f1e5680 100644 --- a/Statement.cc +++ b/Statement.cc @@ -80,6 +80,23 @@ OptionsList::writeOutput(ostream &output) const for(symbol_list_options_type::const_iterator it = symbol_list_options.begin(); it != symbol_list_options.end(); it++) it->second.writeOutput("options_." + it->first, output); + + for(vec_int_options_type::const_iterator it = vector_int_options.begin(); + it != vector_int_options.end(); it++) + { + output << "options_." << it->first << " = "; + if (it->second.size() > 1) + { + output << "["; + for (vector::const_iterator viit=it->second.begin(); + viit!=it->second.end(); viit++) + output << *viit << ";"; + output.seekp((long)output.tellp()-1); + output << "];" << endl; + } + else + output << it->second.front() << ";" << endl; + } } void @@ -103,6 +120,23 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const for(symbol_list_options_type::const_iterator it = symbol_list_options.begin(); it != symbol_list_options.end(); it++) it->second.writeOutput(option_group + "." + it->first, output); + + for(vec_int_options_type::const_iterator it = vector_int_options.begin(); + it != vector_int_options.end(); it++) + { + output << option_group << "." << it->first << " = "; + if (it->second.size() > 1) + { + output << "["; + for (vector::const_iterator viit=it->second.begin(); + viit!=it->second.end(); viit++) + output << *viit << ";"; + output.seekp((long)output.tellp()-1); + output << "];" << endl; + } + else + output << it->second.front() << ";" << endl; + } } void @@ -112,4 +146,5 @@ OptionsList::clear() paired_num_options.clear(); string_options.clear(); symbol_list_options.clear(); + vector_int_options.clear(); } diff --git a/Statement.hh b/Statement.hh index 277731ed..b745a16d 100644 --- a/Statement.hh +++ b/Statement.hh @@ -94,10 +94,12 @@ public: typedef map > paired_num_options_type; typedef map string_options_type; typedef map symbol_list_options_type; + typedef map > vec_int_options_type; num_options_type num_options; paired_num_options_type paired_num_options; string_options_type string_options; symbol_list_options_type symbol_list_options; + vec_int_options_type vector_int_options; void writeOutput(ostream &output) const; void writeOutput(ostream &output, const string &option_group) const; void clear();