diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 35eaea639dc2697aedfbb02073f773d7721ac114..83fc079cd761ccd7015ed096e60563c511f59c9c 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -2131,3 +2131,107 @@ CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const lhs_field = "estimation_info." + lhs_field + "_corr(eifind)"; writeOptionsOutput(output, lhs_field, name1); } + +OptionsEqualStatement::OptionsEqualStatement(const string &to_declaration_type_arg, + const string &to_name1_arg, + const string &to_name2_arg, + const string &to_subsample_name_arg, + const string &from_declaration_type_arg, + const string &from_name1_arg, + const string &from_name2_arg, + const string &from_subsample_name_arg, + const SymbolTable &symbol_table_arg) : + to_declaration_type(to_declaration_type_arg), + to_name1(to_name1_arg), + to_name2(to_name2_arg), + to_subsample_name(to_subsample_name_arg), + from_declaration_type(from_declaration_type_arg), + from_name1(from_name1_arg), + from_name2(from_name2_arg), + from_subsample_name(from_subsample_name_arg), + symbol_table(symbol_table_arg) +{ +} + +void +OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) +{ + if ((to_declaration_type != "par" && to_declaration_type != "std" && to_declaration_type != "corr") || + (from_declaration_type != "par" && from_declaration_type != "std" && from_declaration_type != "corr")) + { + cerr << "Internal Dynare Error" << endl; + exit(EXIT_FAILURE); + } +} + +void +OptionsEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const +{ + if (symb_type == eExogenous || symb_type == eExogenousDet) + lhs_field = "structural_innovation"; + else + lhs_field = "measurement_error"; +} + +void +OptionsEqualStatement::writeOutput(ostream &output, const string &basename) const +{ + string lhs_field, rhs_field; + + if (to_declaration_type == "par") + lhs_field = "parameter"; + else + get_base_name(symbol_table.getType(to_name1), lhs_field); + + if (from_declaration_type == "par") + rhs_field = "parameter"; + else + get_base_name(symbol_table.getType(from_name1), rhs_field); + + + if (to_declaration_type == "corr") + lhs_field += "_corr"; + + if (from_declaration_type == "corr") + rhs_field += "_corr"; + + output << "ei_to_ind = get_new_or_existing_ei_index('" << lhs_field << "_options_index', '" + << to_name1 << "', '" << to_name2<< "');" << endl + << "ei_from_ind = get_new_or_existing_ei_index('" << rhs_field << "_options_index', '" + << from_name1 << "', '" << from_name2<< "');" << endl + << "estimation_info." << lhs_field << "_options_index(ei_to_ind) = {'" << to_name1; + + if (to_declaration_type == "corr") + output << ":" << to_name2; + output << "'};" << endl; + + if (to_declaration_type == "par") + lhs_field = "parameters"; + + if (from_declaration_type == "par") + rhs_field = "parameters"; + + lhs_field = "estimation_info." + lhs_field + "(ei_to_ind)"; + rhs_field = "estimation_info." + rhs_field + "(ei_from_ind)"; + + if (to_subsample_name.empty()) + lhs_field += ".options"; + else + { + output << "subsamples_to_indx = get_existing_subsamples_indx('" << to_name1 << "','" << to_name2 << "');" << endl + << lhs_field << ".range_index = estimation_info.subsamples(subsamples_to_indx).range_index;" << endl + << "ei_to_ss_ind = get_subsamples_range_indx(subsamples_to_indx, '" << to_subsample_name << "');" << endl; + lhs_field += ".subsample_options(ei_to_ss_ind)"; + } + + if (from_subsample_name.empty()) + rhs_field += ".options"; + else + { + output << "subsamples_from_indx = get_existing_subsamples_indx('" << from_name1 << "','" << from_name2 << "');" << endl + << "ei_from_ss_ind = get_subsamples_range_indx(subsamples_from_indx, '" << from_subsample_name << "');" << endl; + rhs_field += ".subsample_options(ei_from_ss_ind)"; + } + + output << lhs_field << " = " << rhs_field << ";" << endl; +} diff --git a/ComputingTasks.hh b/ComputingTasks.hh index fe93b4081edfd443b9cda56efe8f8fc3153a5250..3e048f7a0c15141979ce64b7ef91c6188e2fdacd 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -753,4 +753,31 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; }; +class OptionsEqualStatement : public Statement +{ +private: + const string to_declaration_type; + const string to_name1; + const string to_name2; + const string to_subsample_name; + const string from_declaration_type; + const string from_name1; + const string from_name2; + const string from_subsample_name; + const SymbolTable symbol_table; +public: + OptionsEqualStatement(const string &to_declaration_type_arg, + const string &to_name1_arg, + const string &to_name2_arg, + const string &to_subsample_name_arg, + const string &from_declaration_type_arg, + const string &from_name1_arg, + const string &from_name2_arg, + const string &from_subsample_name_arg, + const SymbolTable &symbol_table_arg); + void get_base_name(const SymbolType symb_type, string &lhs_field) const; + virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); + virtual void writeOutput(ostream &output, const string &basename) const; +}; + #endif diff --git a/DynareBison.yy b/DynareBison.yy index 3289badb9d9401c74fb6b199ecba13efc26b5f60..f4efacc1404e95a57c5c834d646e99f2e7f2e4b0 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -182,7 +182,7 @@ class ParsingDriver; %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 %type <symbol_type_val> change_type_arg -%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt +%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt %type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number %type <prior_distributions_val> prior_pdf prior_distribution %% @@ -224,6 +224,7 @@ statement : parameters | subsamples | subsamples_eq | options + | options_eq | varobs | observation_trends | unit_root_vars @@ -1362,6 +1363,65 @@ options_options : o_jscale | o_bounds ; +options_eq : options_eq_opt EQUAL options_eq_opt ';' + { + driver.copy_options($1->at(0), $1->at(1), $1->at(2), $1->at(3), + $3->at(0), $3->at(1), $3->at(2), $3->at(3)); + delete $1; + delete $3; + } + ; + +options_eq_opt : symbol '.' OPTIONS + { + $$ = new vector<string *>(); + $$->push_back(new string ("par")); + $$->push_back($1); + $$->push_back(new string ("")); + $$->push_back(new string ("")); + } + | symbol '.' symbol '.' OPTIONS + { + $$ = new vector<string *>(); + $$->push_back(new string ("par")); + $$->push_back($1); + $$->push_back(new string ("")); + $$->push_back($3); + } + | STD '(' symbol ')' '.' OPTIONS + { + $$ = new vector<string *>(); + $$->push_back(new string ("std")); + $$->push_back($3); + $$->push_back(new string ("")); + $$->push_back(new string ("")); + } + | STD '(' symbol ')' '.' symbol '.' OPTIONS + { + $$ = new vector<string *>(); + $$->push_back(new string ("std")); + $$->push_back($3); + $$->push_back(new string ("")); + $$->push_back($6); + } + | CORR '(' symbol COMMA symbol ')' '.' OPTIONS + { + $$ = new vector<string *>(); + $$->push_back(new string ("corr")); + $$->push_back($3); + $$->push_back($5); + $$->push_back(new string ("")); + } + | CORR '(' symbol COMMA symbol ')' '.' symbol '.' OPTIONS + { + $$ = new vector<string *>(); + $$->push_back(new string ("corr")); + $$->push_back($3); + $$->push_back($5); + $$->push_back($8); + } + ; + estimation : ESTIMATION ';' { driver.run_estimation(); } | ESTIMATION '(' estimation_options_list ')' ';' diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 8e3270850acba3a986f612456617e9e4493ce7f2..4f95a9c2b240a0b320cabd84c25b078d3d04a38b 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -1394,6 +1394,32 @@ ParsingDriver::set_options(string *name, string *subsample_name) delete subsample_name; } +void +ParsingDriver::copy_options(string *to_declaration_type, string *to_name1, string *to_name2, string *to_subsample_name, + string *from_declaration_type, string *from_name1, string *from_name2, string *from_subsample_name) +{ + check_symbol_existence(*to_name1); + check_symbol_existence(*from_name1); + + if (!to_name2->empty()) + check_symbol_existence(*to_name2); + + if (!from_name2->empty()) + check_symbol_existence(*from_name2); + + mod_file->addStatement(new OptionsEqualStatement(*to_declaration_type, *to_name1, *to_name2, *to_subsample_name, + *from_declaration_type, *from_name1, *from_name2, *from_subsample_name, + mod_file->symbol_table)); + delete to_declaration_type; + delete to_name1; + delete to_name2; + delete to_subsample_name; + delete from_declaration_type; + delete from_name1; + delete from_name2; + delete from_subsample_name; +} + void ParsingDriver::check_symbol_is_endogenous_or_exogenous(string *name) { diff --git a/ParsingDriver.hh b/ParsingDriver.hh index a1bbef815b588a2d5672f05c50c3d2916716274d..266283a7f8d3a772417dfd12446d5b364c85277a 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -397,6 +397,9 @@ public: string *from_declaration_type, string *from_name1, string *from_name2, string *from_subsample_name); //! Sets the options for a parameter void set_options(string *arg1, string *arg2); + //! Copies the options from_name to_name + void copy_options(string *to_declaration_type, string *to_name1, string *to_name2, string *to_subsample_name, + string *from_declaration_type, string *from_name1, string *from_name2, string *from_subsample_name); //! Sets the prior for estimated std dev void set_std_prior(string *arg1, string *arg2); //! Sets the options for estimated std dev