From 3019c80f567f1a2605e4a4d1e732cb5c61ae6379 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 23 Sep 2013 14:27:43 +0200 Subject: [PATCH 01/16] front end for Geweke convergence diagnostics for single chains --- DynareBison.yy | 8 ++++++-- DynareFlex.ll | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/DynareBison.yy b/DynareBison.yy index 5207b3a0..dd2192a7 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 SOLVE_MAXIT %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 @@ -2388,6 +2390,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 e4045035..2024f625 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;} From cd50a2bcb3e22e5850d2cadad905eb776bcf34ee Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 24 Sep 2013 16:01:35 +0200 Subject: [PATCH 02/16] estim_params: remove short-circuit ops, #476 --- ComputingTasks.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 129bfff9..01be77d7 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; From aaa50d6a40eeab72385f65896a9f52b853a81f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 25 Sep 2013 14:44:49 +0200 Subject: [PATCH 03/16] Fix a bug similar to #476 in estimated_params_bounds --- ComputingTasks.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 01be77d7..458a1db2 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -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); From eeb0596831dbde308e1599adddb3178db19430f1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 2 Oct 2013 11:12:32 +0200 Subject: [PATCH 04/16] bug fix for date_number: don't permit weeks >= 53 --- DynareFlex.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index 2024f625..35616b1d 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -691,7 +691,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]))) { +([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-4][0-9])|([5][0-2]))) { yylval->string_val = new string(yytext); return token::DATE_NUMBER; } From 50d1a71aad2a8eedb4e92ce9de0142873a344716 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 2 Oct 2013 16:12:31 +0200 Subject: [PATCH 05/16] support negative dates --- DynareFlex.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index 35616b1d..9e3a9d55 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -691,7 +691,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-4][0-9])|([5][0-2]))) { +(-?[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-4][0-9])|([5][0-2]))) { yylval->string_val = new string(yytext); return token::DATE_NUMBER; } From 3e5f03fadcdbe0470b4653a70b566199a725f3de Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 2 Oct 2013 16:16:33 +0200 Subject: [PATCH 06/16] simplify regex --- DynareFlex.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index 9e3a9d55..2f2b89b4 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -691,7 +691,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-4][0-9])|([5][0-2]))) { +(-?[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-4][0-9])|(5[0-2]))) { yylval->string_val = new string(yytext); return token::DATE_NUMBER; } From afc73796d43134fb80ddf2384b8a721d7f0d668e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 2 Oct 2013 16:48:34 +0200 Subject: [PATCH 07/16] support unbounded years --- DynareFlex.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index 2f2b89b4..2193ff9d 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -691,7 +691,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-4][0-9])|(5[0-2]))) { +(-?[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; } From bba6318bdbd9fca95449402420da03c3248ced53 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 2 Oct 2013 16:56:38 +0200 Subject: [PATCH 08/16] remove unnecessary parenthesis --- DynareFlex.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index 2193ff9d..6d7f3ab6 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -691,7 +691,7 @@ string eofbuff; return token::INT_NUMBER; } -(-?[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]))) { +-?[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; } From b42790cd6e962db91eeac82842dda5f1c7a754b0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 2 Oct 2013 16:41:05 +0200 Subject: [PATCH 09/16] preprocessor: replace dates with dynDates --- ParsingDriver.cc | 3 ++- Statement.cc | 69 +++++++++++++++++++++++++++++++++++++++++++++++- Statement.hh | 6 +++-- 3 files changed, 74 insertions(+), 4 deletions(-) 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..242c73a8 100644 --- a/Statement.cc +++ b/Statement.cc @@ -18,6 +18,7 @@ */ #include "Statement.hh" +#include ModFileStructure::ModFileStructure() : check_present(false), @@ -65,11 +66,77 @@ 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( "\%.*" ); + 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); + + if (apostrophes.size() % 2) + { + cerr << native_statement << + " seems to be invalid Matlab syntax (an odd number of apostrophes was encountered)" << endl; + exit(EXIT_FAILURE); + } + + bool skip = false; + string newstr = ""; + int lastidx = 0; + sregex date_expr = sregex::compile( "-?[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])" ); + string format( "dynDate('$&')" ); + for (size_t i = 0; i < apostrophes.size(); i++) + if (apostrophes[i] == 0) + skip = true; + else + { + if (skip) + { + skip = false; + newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx)); + } + else + { + skip = true; + newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx), + date_expr, format)); + } + lastidx = apostrophes[i]; + } + + //Replace last (or only) element + if (apostrophes.empty()) + lastidx = 0; + newstr.append(regex_replace(native_statement.substr(lastidx, native_statement.size() - lastidx), + date_expr, format)); + 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 From a96d79a3f0efd06ab10adfd5a606ed2fd57c8084 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 3 Oct 2013 09:09:18 +0200 Subject: [PATCH 10/16] remove unnecessary test --- Statement.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Statement.cc b/Statement.cc index 242c73a8..0a449b85 100644 --- a/Statement.cc +++ b/Statement.cc @@ -123,10 +123,6 @@ NativeStatement::computingPass() } lastidx = apostrophes[i]; } - - //Replace last (or only) element - if (apostrophes.empty()) - lastidx = 0; newstr.append(regex_replace(native_statement.substr(lastidx, native_statement.size() - lastidx), date_expr, format)); native_statement = newstr; From bb4ce64add592e9270fe0889818592613fc59819 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 3 Oct 2013 10:48:29 +0200 Subject: [PATCH 11/16] catch leading space before comment --- Statement.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Statement.cc b/Statement.cc index 0a449b85..8ac208fe 100644 --- a/Statement.cc +++ b/Statement.cc @@ -76,7 +76,7 @@ NativeStatement::computingPass() { using namespace boost::xpressive; // Return if this is a comment - sregex comment_expr = sregex::compile( "\%.*" ); + sregex comment_expr = sregex::compile( "\\s*\%.*" ); match_results results; if (regex_match(native_statement, results, comment_expr)) return; From 50b2c9d45427aeaa895d986bc5abccc4d07c2c5d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 3 Oct 2013 15:43:38 +0200 Subject: [PATCH 12/16] clarify error message --- Statement.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Statement.cc b/Statement.cc index 8ac208fe..c60be843 100644 --- a/Statement.cc +++ b/Statement.cc @@ -95,8 +95,7 @@ NativeStatement::computingPass() if (apostrophes.size() % 2) { - cerr << native_statement << - " seems to be invalid Matlab syntax (an odd number of apostrophes was encountered)" << endl; + cerr << "ERROR: A Matlab Statement has an odd number of apostrophes: " << native_statement << endl; exit(EXIT_FAILURE); } From 1b527aa0043ebab1ed33f13a2dfdb914755714b1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 3 Oct 2013 16:19:35 +0200 Subject: [PATCH 13/16] fix regular expression --- Statement.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Statement.cc b/Statement.cc index c60be843..5e08c164 100644 --- a/Statement.cc +++ b/Statement.cc @@ -102,7 +102,7 @@ NativeStatement::computingPass() bool skip = false; string newstr = ""; int lastidx = 0; - sregex date_expr = sregex::compile( "-?[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])" ); + 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('$&')" ); for (size_t i = 0; i < apostrophes.size(); i++) if (apostrophes[i] == 0) From dea0cdbdf3954bb009ccc32bb27de821bf49714a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 3 Oct 2013 15:30:22 +0200 Subject: [PATCH 14/16] handle inline comments --- Statement.cc | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/Statement.cc b/Statement.cc index 5e08c164..649d99a5 100644 --- a/Statement.cc +++ b/Statement.cc @@ -101,10 +101,11 @@ NativeStatement::computingPass() bool skip = false; string newstr = ""; - int lastidx = 0; 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('$&')" ); - for (size_t i = 0; i < apostrophes.size(); i++) + size_t length, i, lastidx, commentidx; + length = lastidx = 0; + for (i = 0; i < apostrophes.size(); i++) if (apostrophes[i] == 0) skip = true; else @@ -116,14 +117,40 @@ NativeStatement::computingPass() } else { + length = apostrophes[i] - lastidx; + 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; + while (i++ < apostrophes.size()) + { + newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx)); + lastidx = apostrophes[i]; + } + native_statement = newstr; + return; + } skip = true; - newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx), - date_expr, format)); } lastidx = apostrophes[i]; } - newstr.append(regex_replace(native_statement.substr(lastidx, native_statement.size() - lastidx), - date_expr, format)); + length = native_statement.length() - lastidx; + 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; } From a29ed07ea56b6bf1d7f1d558e2410996d8201031 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 3 Oct 2013 16:34:51 +0200 Subject: [PATCH 15/16] remove unused portion of code, code cleanup --- Statement.cc | 51 +++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/Statement.cc b/Statement.cc index 649d99a5..4017d995 100644 --- a/Statement.cc +++ b/Statement.cc @@ -103,43 +103,26 @@ NativeStatement::computingPass() 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 length, i, lastidx, commentidx; - length = lastidx = 0; - for (i = 0; i < apostrophes.size(); i++) + size_t lastidx = 0; + for (size_t i = 0; i < apostrophes.size(); i++) if (apostrophes[i] == 0) skip = true; else - { - if (skip) - { - skip = false; - newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx)); - } - else - { - length = apostrophes[i] - lastidx; - 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; - while (i++ < apostrophes.size()) - { - newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx)); - lastidx = apostrophes[i]; - } - native_statement = newstr; - return; - } - skip = true; - } - lastidx = apostrophes[i]; - } - length = native_statement.length() - lastidx; - commentidx = native_statement.substr(lastidx, length).find("%", 0); + 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; From 7b523eccd0d31fc9f349bb2dac769fd6cbacca72 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 4 Oct 2013 16:17:29 +0200 Subject: [PATCH 16/16] remove error message because odd numbers of apostrophes are valid for transposing matrices in Matlab syntax --- Statement.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Statement.cc b/Statement.cc index 4017d995..38da6e36 100644 --- a/Statement.cc +++ b/Statement.cc @@ -93,12 +93,6 @@ NativeStatement::computingPass() else apostrophes.push_back(idx); - if (apostrophes.size() % 2) - { - cerr << "ERROR: A Matlab Statement has an odd number of apostrophes: " << native_statement << endl; - exit(EXIT_FAILURE); - } - 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])" );