diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 500b8d14ed033cfd97cb7770795ffedaa53ded4a..aafe4022b5320ccc94ff1466dd9d6f7b5faabd7b 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -175,6 +175,7 @@ class ParsingDriver; %type <string_val> filename symbol vec_of_vec_value vec_value_list date_expr %type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf %type <string_val> range vec_value_w_inf vec_value_1_w_inf named_var +%type <string_val> integer_range signed_integer_range %type <symbol_type_val> change_type_arg %type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt calibration_range %type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number @@ -2367,6 +2368,8 @@ moment_calibration_item : symbol COMMA symbol COMMA calibration_range ';' { driver.add_moment_calibration_item($1, $3, new string("0"), $5); } | symbol COMMA symbol '(' signed_integer ')' COMMA calibration_range ';' { driver.add_moment_calibration_item($1, $3, $5, $8); } + | symbol COMMA symbol '(' signed_integer_range ')' COMMA calibration_range ';' + { driver.add_moment_calibration_item($1, $3, $5, $8); } ; irf_calibration : IRF_CALIBRATION ';' irf_calibration_list END ';' @@ -2381,6 +2384,8 @@ irf_calibration_item : symbol COMMA symbol COMMA calibration_range ';' { driver.add_irf_calibration_item($1, new string("1"), $3, $5); } | symbol '(' INT_NUMBER ')' COMMA symbol COMMA calibration_range ';' { driver.add_irf_calibration_item($1, $3, $6, $8); } + | symbol '(' integer_range ')' COMMA symbol COMMA calibration_range ';' + { driver.add_irf_calibration_item($1, $3, $6, $8); } ; o_dr_algo : DR_ALGO EQUAL INT_NUMBER { @@ -2842,6 +2847,31 @@ range : symbol ':' symbol $$ = $1; }; +integer_range : INT_NUMBER ':' INT_NUMBER + { + $1->append(":"); + $1->append(*$3); + delete $3; + $$ = $1; + }; + +signed_integer_range : signed_integer ':' signed_integer + { + $1->append(":"); + $1->append(*$3); + delete $3; + $$ = $1; + } + | MINUS '(' signed_integer ':' signed_integer ')' + { + $3->insert(0, "-("); + $3->append(":"); + $3->append(*$5); + delete $5; + $3->append(")"); + $$ = $3; + }; + vec_int_number : INT_NUMBER { $$ = new vector<int>(); $$->push_back(atoi((*$1).c_str())); delete $1; }; vec_int_elem : vec_int_number diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 3a46428f1f9c3d049044648197343ccf32173278..72e3c22c0aae658b56379211072f29c6a6f14a83 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -2606,7 +2606,7 @@ ParsingDriver::add_parallel_local_file(string *filename) } void -ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string *lag, vector<string *> *range) +ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string *lags, vector<string *> *range) { MomentCalibration::Constraint c; @@ -2622,8 +2622,8 @@ ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string error("Variable " + *endo2 + " is not an endogenous."); delete endo2; - c.lag = abs(atoi(lag->c_str())); - delete lag; + c.lags = *lags; + delete lags; assert(range->size() == 2); c.lower_bound = *((*range)[0]); @@ -2643,7 +2643,7 @@ void ParsingDriver::end_moment_calibration() } void -ParsingDriver::add_irf_calibration_item(string *endo, string *period, string *exo, vector<string *> *range) +ParsingDriver::add_irf_calibration_item(string *endo, string *periods, string *exo, vector<string *> *range) { IrfCalibration::Constraint c; @@ -2653,8 +2653,8 @@ ParsingDriver::add_irf_calibration_item(string *endo, string *period, string *ex error("Variable " + *endo + " is not an endogenous."); delete endo; - c.period = atoi(period->c_str()); - delete period; + c.periods = *periods; + delete periods; check_symbol_existence(*exo); c.exo = mod_file->symbol_table.getID(*exo); diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index 24b47ffce756d63ae36c2ecafdf977b5b87d5b6e..dec73dfe674d5f82c1d692705037e2db1afc2659 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -658,11 +658,11 @@ public: //! Processing the parallel_local_files option void add_parallel_local_file(string *filename); //! Add an item of a moment_calibration statement - void add_moment_calibration_item(string *endo1, string *endo2, string *lag, vector<string *> *range); + void add_moment_calibration_item(string *endo1, string *endo2, string *lags, vector<string *> *range); //! End a moment_calibration statement void end_moment_calibration(); //! Add an item of an irf_calibration statement - void add_irf_calibration_item(string *endo, string *period, string *exo, vector<string *> *range); + void add_irf_calibration_item(string *endo, string *periods, string *exo, vector<string *> *range); //! End a moment_calibration statement void end_irf_calibration(); }; diff --git a/preprocessor/Shocks.cc b/preprocessor/Shocks.cc index d9af2d0526a40f70ab80332b444838b8e802874f..c6b51ee47966dbb82814a66d626a822b6b26d7be 100644 --- a/preprocessor/Shocks.cc +++ b/preprocessor/Shocks.cc @@ -402,7 +402,7 @@ MomentCalibration::writeOutput(ostream &output, const string &basename) const const Constraint &c = constraints[i]; output << "'" << symbol_table.getName(c.endo1) << "', " << "'" << symbol_table.getName(c.endo2) << "', " - << c.lag << ", " + << c.lags << ", " << "[ " << c.lower_bound << ", " << c.upper_bound << " ];" << endl; } @@ -424,7 +424,7 @@ IrfCalibration::writeOutput(ostream &output, const string &basename) const const Constraint &c = constraints[i]; output << "'" << symbol_table.getName(c.endo) << "', " << "'" << symbol_table.getName(c.exo) << "', " - << c.period << ", " + << c.periods << ", " << "[ " << c.lower_bound << ", " << c.upper_bound << " ];" << endl; } diff --git a/preprocessor/Shocks.hh b/preprocessor/Shocks.hh index 17f6bb85702f6014b7e589e881faff79bbc3f20a..ef68b78e4739667b8b4ca84c32429677e1806aca 100644 --- a/preprocessor/Shocks.hh +++ b/preprocessor/Shocks.hh @@ -103,7 +103,7 @@ public: struct Constraint { int endo1, endo2; - int lag; + string lags; string lower_bound, upper_bound; }; typedef vector<Constraint> constraints_t; @@ -121,9 +121,9 @@ class IrfCalibration : public Statement public: struct Constraint { - int endo, period; + int endo; int exo; - string lower_bound, upper_bound; + string periods, lower_bound, upper_bound; }; typedef vector<Constraint> constraints_t; private: