diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 129bfff9..458a1db2 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -625,16 +625,16 @@ EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basenam { if (symb_type == eExogenous) { - output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << " && estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") || " - << "(estim_params_.corrx(:,2)==" << symb_id << " && estim_params_.corrx(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; + output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << " & estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " + << "(estim_params_.corrx(:,2)==" << symb_id << " & estim_params_.corrx(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; output << "estim_params_.corrx(tmp1,3) = "; it->init_val->writeOutput(output); output << ";" << endl; } else if (symb_type == eEndogenous) { - output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << " && estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") || " - << "(estim_params_.corrn(:,2)==" << symb_id << " && estim_params_.corrn(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; + output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << " & estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " + << "(estim_params_.corrn(:,2)==" << symb_id << " & estim_params_.corrn(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; output << "estim_params_.corrn(tmp1,3) = "; it->init_val->writeOutput(output); output << ";" << endl; @@ -703,7 +703,8 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen { if (symb_type == eExogenous) { - output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << ")) & (estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ");" << endl; + output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << " & estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " + << "(estim_params_.corrx(:,2)==" << symb_id << " & estim_params_.corrx(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; output << "estim_params_.corrx(tmp1,4) = "; it->low_bound->writeOutput(output); @@ -715,7 +716,8 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen } else if (symb_type == eEndogenous) { - output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << ")) & (estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ";" << endl; + output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << " & estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " + << "(estim_params_.corrn(:,2)==" << symb_id << " & estim_params_.corrn(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; output << "estim_params_.corrn(tmp1,4) = "; it->low_bound->writeOutput(output); diff --git a/DynareBison.yy b/DynareBison.yy index 621a092b..85663273 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -113,7 +113,7 @@ class ParsingDriver; %token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT %token MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN MINIMAL_SOLVING_PERIODS %token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN -%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS +%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL %token NAME %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS %token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF @@ -1555,7 +1555,9 @@ estimation_options : o_datafile | o_ar | o_endogenous_prior | o_use_univariate_filters_if_singularity_is_detected - | o_qz_zero_threshold + | o_qz_zero_threshold + | o_taper_steps + | o_geweke_interval ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -2389,6 +2391,8 @@ 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_vec_int("filter_step_ahead", $3); }; +o_taper_steps : TAPER_STEPS EQUAL vec_int { driver.option_vec_int("taper_steps", $3); }; +o_geweke_interval : GEWEKE_INTERVAL EQUAL vec_value { driver.option_num("geweke_interval",$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"); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index b045719c..19829085 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -222,6 +222,8 @@ string eofbuff; presample {return token::PRESAMPLE;} lik_algo {return token::LIK_ALGO;} lik_init {return token::LIK_INIT;} +taper_steps {return token::TAPER_STEPS;} +geweke_interval {return token::GEWEKE_INTERVAL;} graph {return token::GRAPH;} nograph {return token::NOGRAPH;} nodisplay {return token::NODISPLAY;} @@ -688,7 +690,7 @@ string eofbuff; return token::INT_NUMBER; } -([1-2][0-9]{3}[Mm](([1-9])|(1[0-2])))|([1-2][0-9]{3}[Qq][1-4])|([1-2][0-9]{3}[Ww](([1-9]{1})|([1-5][0-9]))) { +-?[0-9]+[Mm]([1-9]|1[0-2])|-?[0-9]+[Qq][1-4]|-?[0-9]+[Ww]([1-9]{1}|[1-4][0-9]|5[0-2]) { yylval->string_val = new string(yytext); return token::DATE_NUMBER; } diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 38bf5a78..37029fdc 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -2449,7 +2449,8 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in void ParsingDriver::add_native(const string &s) { - mod_file->addStatement(new NativeStatement(s)); + string ss = string(s); + mod_file->addStatement(new NativeStatement(ss)); } void diff --git a/Statement.cc b/Statement.cc index 59021287..38da6e36 100644 --- a/Statement.cc +++ b/Statement.cc @@ -18,6 +18,7 @@ */ #include "Statement.hh" +#include ModFileStructure::ModFileStructure() : check_present(false), @@ -65,11 +66,76 @@ Statement::computingPass() { } -NativeStatement::NativeStatement(const string &native_statement_arg) : +NativeStatement::NativeStatement(string &native_statement_arg) : native_statement(native_statement_arg) { } +void +NativeStatement::computingPass() +{ + using namespace boost::xpressive; + // Return if this is a comment + sregex comment_expr = sregex::compile( "\\s*\%.*" ); + match_results results; + if (regex_match(native_statement, results, comment_expr)) + return; + + // Otherwise, look at the line and consider substituting date + size_t idx = -1; + vector apostrophes; + while((idx = native_statement.find("'", idx + 1)) != string::npos) + if (apostrophes.size() < 2) + apostrophes.push_back(idx); + else + if (idx == apostrophes.back() + 1) + apostrophes.pop_back(); + else + apostrophes.push_back(idx); + + bool skip = false; + string newstr = ""; + sregex date_expr = sregex::compile( "-?[0-9]+[Mm](1[0-2]|[1-9])|-?[0-9]+[Qq][1-4]|-?[0-9]+[Ww]([1-4][0-9]|5[0-2]|[1-9])" ); + string format( "dynDate('$&')" ); + size_t lastidx = 0; + for (size_t i = 0; i < apostrophes.size(); i++) + if (apostrophes[i] == 0) + skip = true; + else + if (skip) + { + newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx)); + lastidx = apostrophes[i]; + skip = false; + } + else + { + newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx), + date_expr, format)); + lastidx = apostrophes[i]; + skip = true; + } + size_t length = native_statement.length() - lastidx; + size_t commentidx = native_statement.substr(lastidx, length).find("%", 0); + if (commentidx != string::npos) + length = commentidx; + + newstr.append(regex_replace(native_statement.substr(lastidx, length), date_expr, format)); + + if (commentidx != string::npos) + { + lastidx += commentidx; + newstr.append(native_statement.substr(lastidx, native_statement.length() - lastidx)); + } + + native_statement = newstr; +} + +void +regexReplace() +{ +} + void NativeStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/Statement.hh b/Statement.hh index cd3fd5cf..82f64fa7 100644 --- a/Statement.hh +++ b/Statement.hh @@ -121,10 +121,12 @@ public: class NativeStatement : public Statement { private: - const string native_statement; + string native_statement; public: - NativeStatement(const string &native_statement_arg); + NativeStatement(string &native_statement_arg); + virtual void computingPass(); virtual void writeOutput(ostream &output, const string &basename) const; + void regexReplace(); }; class OptionsList