diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 18f3f092ed9bce0a3cb0dad9e1d11e3a84b251eb..dc109d5cb0f5eb60dff999a96a4e043e21690edc 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1126,7 +1126,7 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename { for (unsigned int h = 0; h < it->second.size(); h++) { - int j = symbol_table.getTypeSpecificID(it->second.at(h)) + 1; + int j = it->second.at(h) + 1; int i = it->first.second; if (j < 1 || j > n || (int)h+1 > n || i < 1) { @@ -1252,7 +1252,6 @@ SvarStatement::writeOutput(ostream &output, const string &basename) const for (vector<int>::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) diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d7ee489aea6247dcef19b108fcf0b2ac84221d70..5d0a0aea79e1ba88096402d42c189a50aaeb5674 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -492,7 +492,7 @@ public: class SvarIdentificationStatement : public Statement { public: - typedef map<pair<int, int>, vector<string> > svar_identification_exclusion_type; + typedef map<pair<int, int>, vector<int> > svar_identification_exclusion_type; private: const svar_identification_exclusion_type exclusion; const bool upper_cholesky_present; diff --git a/DynareBison.yy b/DynareBison.yy index 557197a705e3bb67f1bbf7d548c1a628ff85d99b..2549b6bf0f0476beff8fc4890a6beaf293280ae4 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -163,12 +163,12 @@ class ParsingDriver; %type <node_val> equation hand_side model_var %type <string_val> signed_float signed_integer prior %type <string_val> filename symbol -%type <string_val> value value1 vec_int_elem vec_int_1 vec_int +%type <string_val> value value1 %type <string_val> vec_value_1 vec_value %type <string_val> calib_arg2 range number %type <symbol_type_val> change_type_arg %type <vector_string_val> change_type_var_list -%type <vector_int_val> vector_int_body vector_int +%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number %% @@ -1667,15 +1667,15 @@ o_simul_seed : SIMUL_SEED EQUAL INT_NUMBER { driver.option_num("simul_seed", $3) o_qz_criterium : QZ_CRITERIUM EQUAL number { driver.option_num("qz_criterium", $3); }; o_datafile : DATAFILE EQUAL filename { driver.option_str("datafile", $3); }; o_nobs : NOBS EQUAL vec_int - { driver.option_num("nobs", $3); } - | NOBS EQUAL INT_NUMBER - { driver.option_num("nobs", $3); } + { driver.option_vec_int("nobs", $3); } + | NOBS EQUAL vec_int_number + { driver.option_vec_int("nobs", $3); } ; o_conditional_variance_decomposition : CONDITIONAL_VARIANCE_DECOMPOSITION EQUAL vec_int - { driver.option_num("conditional_variance_decomposition", $3); } - | CONDITIONAL_VARIANCE_DECOMPOSITION EQUAL INT_NUMBER - { driver.option_num("conditional_variance_decomposition", $3); } - ; + { driver.option_vec_int("conditional_variance_decomposition", $3); } + | CONDITIONAL_VARIANCE_DECOMPOSITION EQUAL vec_int_number + { driver.option_vec_int("conditional_variance_decomposition", $3); } + ; o_first_obs : FIRST_OBS EQUAL INT_NUMBER { driver.option_num("first_obs", $3); }; o_prefilter : PREFILTER EQUAL INT_NUMBER { driver.option_num("prefilter", $3); }; o_presample : PRESAMPLE EQUAL INT_NUMBER { driver.option_num("presample", $3); }; @@ -1720,7 +1720,7 @@ o_print : PRINT { driver.option_num("noprint", "0"); }; o_noprint : NOPRINT { driver.option_num("noprint", "1"); }; o_xls_sheet : XLS_SHEET EQUAL symbol { driver.option_str("xls_sheet", $3); }; o_xls_range : XLS_RANGE EQUAL range { driver.option_str("xls_range", $3); }; -o_filter_step_ahead : FILTER_STEP_AHEAD EQUAL vec_int { driver.option_num("filter_step_ahead", $3); }; +o_filter_step_ahead : FILTER_STEP_AHEAD EQUAL vec_int { driver.option_vec_int("filter_step_ahead", $3); }; o_constant : CONSTANT { driver.option_num("noconstant", "0"); }; o_noconstant : NOCONSTANT { driver.option_num("noconstant", "1"); }; o_mh_recover : MH_RECOVER { driver.option_num("mh_recover", "1"); }; @@ -1873,41 +1873,12 @@ 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 vector_int +o_equations : EQUATIONS EQUAL vec_int + { driver.option_vec_int("ms.equations",$3); } + | EQUATIONS EQUAL vec_int_number { driver.option_vec_int("ms.equations",$3); } - | EQUATIONS EQUAL INT_NUMBER - { - vector<int> *oneInt = new vector<int>(); - oneInt->push_back(atoi((*$3).c_str())); - driver.option_vec_int("ms.equations",oneInt); - delete oneInt; - } ; -vector_int_body : INT_NUMBER - { $$ = new vector<int>(); $$->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<int>(); - 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 @@ -1918,38 +1889,45 @@ range : symbol ':' symbol $$ = $1; }; -vec_int_elem : INT_NUMBER +vec_int_number : INT_NUMBER { $$ = new vector<int>(); $$->push_back(atoi((*$1).c_str())); delete $1; }; + +vec_int_elem : vec_int_number | INT_NUMBER ':' INT_NUMBER { - $1->append(":"); - $1->append(*$3); + $$ = new vector<int>(); + for(int i=atoi((*$1).c_str()); i<=atoi((*$3).c_str()); i++) + $$->push_back(i); + delete $1; delete $3; - $$ = $1; } ; vec_int_1 : '[' vec_int_elem - { $2->insert(0, "["); $$ = $2;} + { $$ = $2;} + | '[' COMMA vec_int_elem + { $$ = $3;} | vec_int_1 vec_int_elem { - $1->append(" "); - $1->append(*$2); - delete $2; $$ = $1; + for (vector<int>::const_iterator it=$2->begin(); + it!=$2->end(); it++) + $1->push_back(*it); + delete $2; } | vec_int_1 COMMA vec_int_elem { - $1->append(","); - $1->append(*$3); - delete $3; $$ = $1; + for (vector<int>::const_iterator it=$3->begin(); + it!=$3->end(); it++) + $1->push_back(*it); + delete $3; } ; vec_int : vec_int_1 ']' - { $1->append("]"); $$ = $1; } + { $$ = $1; } | vec_int_1 COMMA ']' - { $1->append(",]"); $$ = $1; } + { $$ = $1; } ; vec_value_1 : '[' value1 diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 142fbc224e5e24eac6fb1567c4f95a92da586848..95641aef3353062d1d8b5a3d7a019db7d2404b58 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -608,7 +608,7 @@ ParsingDriver::combine_lag_and_restriction(string *lag) if (it->first.first == current_lag) error("lag " + *lag + " used more than once."); - for(map<int, vector<string> >::const_iterator it = svar_equation_restrictions.begin(); + for(map<int, vector<int> >::const_iterator it = svar_equation_restrictions.begin(); it != svar_equation_restrictions.end(); it++ ) svar_ident_exclusion_values[make_pair(current_lag, it->first)] = it->second; @@ -638,14 +638,18 @@ void ParsingDriver::add_in_svar_restriction_symbols(string *tmp_var) { check_symbol_existence(*tmp_var); - for (unsigned int i=0; i<svar_restriction_symbols.size(); i++) - if (*tmp_var==svar_restriction_symbols.at(i)) + int symb_id = mod_file->symbol_table.getID(*tmp_var); + + for (vector<int>::const_iterator viit=svar_restriction_symbols.begin(); + viit!=svar_restriction_symbols.end(); viit++) + if (symb_id==*viit) error(*tmp_var + " restriction added twice."); - svar_restriction_symbols.push_back(*tmp_var); + svar_restriction_symbols.push_back(symb_id); delete tmp_var; } + void ParsingDriver::add_upper_cholesky() { @@ -768,7 +772,11 @@ ParsingDriver::option_vec_int(const string &name_option, const vector<int> *opt) != options_list.vector_int_options.end()) error("option " + name_option + " declared twice"); + if ((*opt).empty()) + error("option " + name_option + " was passed an empty vector."); + options_list.vector_int_options[name_option] = *opt; + delete opt; } void @@ -1234,14 +1242,9 @@ ParsingDriver::svar() itv = options_list.vector_int_options.find("ms.equations"); if (itv != options_list.vector_int_options.end()) - { - if (itv->second.empty()) - error("There was an error in the integers passed to the equation option."); - - for (vector<int>::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."); - } + for (vector<int>::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."); mod_file->addStatement(new SvarStatement(options_list)); options_list.clear(); diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 6e004895785322d691fe40ab755455284d31e79c..bd9fe763c341374b59afaaf9949ec63a301a4cbb 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -145,9 +145,13 @@ private: HomotopyStatement::homotopy_values_type homotopy_values; //! Temporary storage for svar_identification blocks SvarIdentificationStatement::svar_identification_exclusion_type svar_ident_exclusion_values; - map<int, vector<string> > svar_equation_restrictions; - vector<string> svar_restriction_symbols; + //! Temporary storage for mapping the equation number to the restrictions within an svar_identification bock + map<int, vector<int> > svar_equation_restrictions; + //! Temporary storage for restrictions in an equation within an svar_identification bock + vector<int> svar_restriction_symbols; + //! Temporary storage for upper cholesky within an svar_identification bock bool svar_upper_cholesky; + //! Temporary storage for lower cholesky within an svar_identification bock bool svar_lower_cholesky; //! Temporary storage for argument list of unknown function @@ -328,10 +332,15 @@ public: void set_varobs(); //! Svar_Identification Statement void end_svar_identification(); + //! Svar_Identification Statement: match list of restrictions and equation number with lag void combine_lag_and_restriction(string *lag); + //! Svar_Identification Statement: match list of restrictions with equation number void add_restriction_in_equation(string *equation); + //! Svar_Identification Statement: add list of restriction symbol ids void add_in_svar_restriction_symbols(string *name); + //! Svar_Identification Statement: restriction of form upper cholesky void add_upper_cholesky(); + //! Svar_Identification Statement: restriction of form lower cholesky void add_lower_cholesky(); //! Forecast Statement void forecast(); diff --git a/Statement.cc b/Statement.cc index 6f1e56805e65e905d594a0d4d9846d4fa0ee934e..1e48a4daf4ae6bbcafa87a0320ab1f12f72fad52 100644 --- a/Statement.cc +++ b/Statement.cc @@ -91,7 +91,6 @@ OptionsList::writeOutput(ostream &output) const for (vector<int>::const_iterator viit=it->second.begin(); viit!=it->second.end(); viit++) output << *viit << ";"; - output.seekp((long)output.tellp()-1); output << "];" << endl; } else @@ -131,7 +130,6 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const for (vector<int>::const_iterator viit=it->second.begin(); viit!=it->second.end(); viit++) output << *viit << ";"; - output.seekp((long)output.tellp()-1); output << "];" << endl; } else