diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index f492d6753..b8eceeaff 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2017 Dynare Team + * Copyright (C) 2003-2018 Dynare Team * * This file is part of Dynare. * @@ -50,7 +50,8 @@ class ParsingDriver; string *string_val; expr_t node_val; SymbolType symbol_type_val; - vector *vector_string_val; + vector *vector_string_val; + vector *vector_string_p_val; vector *vector_int_val; pair *string_pair_val; vector *> *vector_string_pair_val; @@ -176,10 +177,10 @@ class ParsingDriver; %token NUMBER_OF_POSTERIOR_DRAWS_AFTER_PERTURBATION MAX_NUMBER_OF_STAGES %token RANDOM_FUNCTION_CONVERGENCE_CRITERION RANDOM_PARAMETER_CONVERGENCE_CRITERION %token CENTERED_MOMENTS AUTOLAG RECURSIVE_ORDER_ESTIMATION BARTLETT_KERNEL_LAG WEIGHTING_MATRIX PENALIZED_ESTIMATOR VERBOSE -%token SIMULATION_MULTIPLE SEED BOUNDED_SHOCK_SUPPORT +%token SIMULATION_MULTIPLE SEED BOUNDED_SHOCK_SUPPORT EQTAGS %token ANALYTICAL_GIRF IRF_IN_PERCENT EMAS_GIRF EMAS_DROP EMAS_TOLF EMAS_MAX_ITER -%token SYMBOL_VEC +%token SYMBOL_VEC %type expression expression_or_empty %type equation hand_side @@ -191,7 +192,8 @@ class ParsingDriver; %type named_var_elem %type named_var named_var_1 %type change_type_arg -%type change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt calibration_range +%type vec_str vec_str_1 +%type change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt calibration_range %type vec_int_elem vec_int_1 vec_int vec_int_number %type prior_pdf prior_distribution %% @@ -376,6 +378,7 @@ var_model_options_list : var_model_options_list COMMA var_model_options var_model_options : o_var_name | o_var_order + | o_var_eq_tags ; restrictions : RESTRICTIONS '(' symbol ')' ';' { driver.begin_VAR_restrictions(); } @@ -3177,6 +3180,7 @@ o_series : SERIES EQUAL symbol { driver.option_str("series", $3); }; o_datafile : DATAFILE EQUAL filename { driver.option_str("datafile", $3); }; o_var_datafile : DATAFILE EQUAL filename { driver.option_str("var_estimation.datafile", $3); }; o_var_model_name : symbol { driver.option_str("var_estimation.model_name", $1); }; +o_var_eq_tags : EQTAGS EQUAL vec_str { driver.option_vec_str("var.eqtags", $3); } o_dirname : DIRNAME EQUAL filename { driver.option_str("dirname", $3); }; o_huge_number : HUGE_NUMBER EQUAL non_negative_number { driver.option_num("huge_number", $3); }; o_nobs : NOBS EQUAL vec_int @@ -3820,6 +3824,22 @@ vec_int : vec_int_1 ']' { $$ = $1; } ; +vec_str_1 : '[' QUOTED_STRING + { $$ = new vector(); $$->push_back(*$2); delete $2; } + | '[' COMMA QUOTED_STRING + { $$ = new vector(); $$->push_back(*$3); delete $3; } + | vec_str_1 QUOTED_STRING + { $$->push_back(*$2); delete $2; } + | vec_str_1 COMMA QUOTED_STRING + { $$->push_back(*$3); delete $3; } + ; + +vec_str : vec_str_1 ']' + { $$ = $1; } + | vec_str_1 COMMA ']' + { $$ = $1; } + ; + vec_value_1 : '[' signed_number { $2->insert(0,"["); $$ = $2; } | '[' COMMA signed_number { $3->insert(0,"["); $$ = $3; } | vec_value_1 signed_number diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 668db31e4..1ebe6a5c7 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2017 Dynare Team + * Copyright (C) 2003-2018 Dynare Team * * This file is part of Dynare. * @@ -481,6 +481,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 return token::ABAND; } write_equation_tags {return token::WRITE_EQUATION_TAGS;} +eqtags {return token::EQTAGS;} indxap {return token::INDXAP;} apband {return token::APBAND;} indximf {return token::INDXIMF;} @@ -960,19 +961,20 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 yytextcpy.erase(remove(yytextcpy.begin(), yytextcpy.end(), ' '), yytextcpy.end()); istringstream ss(yytextcpy); string token; - yylval->vector_string_val = new vector; + yylval->vector_string_val = new vector; + yylval->vector_string_p_val = new vector; bool dynare_statement = true; while(getline(ss, token, ',')) if (driver.symbol_exists_and_is_not_modfile_local_or_external_function(token.c_str())) - yylval->vector_string_val->push_back(new string(token)); + yylval->vector_string_p_val->push_back(new string(token)); else { - for (vector::iterator it=yylval->vector_string_val->begin(); - it != yylval->vector_string_val->end(); it++) + for (vector::iterator it=yylval->vector_string_p_val->begin(); + it != yylval->vector_string_p_val->end(); it++) delete *it; - delete yylval->vector_string_val; + delete yylval->vector_string_p_val; BEGIN NATIVE; yyless(0); dynare_statement = false; diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index b9e2a9b10..cf8760113 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2017 Dynare Team + * Copyright (C) 2003-2018 Dynare Team * * This file is part of Dynare. * @@ -1454,6 +1454,21 @@ ParsingDriver::option_vec_int(const string &name_option, const vector *opt) delete opt; } +void +ParsingDriver::option_vec_str(const string &name_option, const vector *opt) +{ + if (options_list.vector_str_options.find(name_option) + != options_list.vector_str_options.end()) + error("option " + name_option + " declared twice"); + + if ((*opt).empty()) + error("option " + name_option + " was passed an empty vector."); + + options_list.vector_str_options[name_option] = *opt; + + delete opt; +} + void ParsingDriver::linear() { diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index e7f54b0a9..872c39172 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2017 Dynare Team + * Copyright (C) 2003-2018 Dynare Team * * This file is part of Dynare. * @@ -444,6 +444,8 @@ public: void option_symbol_list(const string &name_option); //! Sets an option to a vector of integers void option_vec_int(const string &name_option, const vector *opt); + //! Sets an option to a vector of strings + void option_vec_str(const string &name_option, const vector *opt); //! Indicates that the model is linear void linear(); //! Adds a variable to temporary symbol list diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc index 8a86f75a9..c7b6dd487 100644 --- a/preprocessor/Statement.cc +++ b/preprocessor/Statement.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2017 Dynare Team + * Copyright (C) 2006-2018 Dynare Team * * This file is part of Dynare. * @@ -178,6 +178,22 @@ OptionsList::writeOutput(ostream &output) const else output << it->second.front() << ";" << endl; } + + for (vec_str_options_t::const_iterator it = vector_str_options.begin(); + it != vector_str_options.end(); it++) + { + output << "options_." << it->first << " = "; + if (it->second.size() > 1) + { + output << "["; + for (vector::const_iterator viit = it->second.begin(); + viit != it->second.end(); viit++) + output << "'" << *viit << "';"; + output << "];" << endl; + } + else + output << it->second.front() << ";" << endl; + } } void @@ -230,6 +246,22 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const else output << it->second.front() << ";" << endl; } + + for (vec_str_options_t::const_iterator it = vector_str_options.begin(); + it != vector_str_options.end(); it++) + { + output << option_group << "." << it->first << " = "; + if (it->second.size() > 1) + { + output << "["; + for (vector::const_iterator viit = it->second.begin(); + viit != it->second.end(); viit++) + output << "'" << *viit << "';"; + output << "];" << endl; + } + else + output << it->second.front() << ";" << endl; + } } void @@ -323,6 +355,30 @@ OptionsList::writeJsonOutput(ostream &output) const output << ", "; } + + for (vec_str_options_t::const_iterator it = vector_str_options.begin(); + it != vector_str_options.end();) + { + output << "\""<< it->first << "\": ["; + if (it->second.size() > 1) + { + for (vector::const_iterator viit = it->second.begin(); + viit != it->second.end();) + { + output << "\"" << *viit << "\""; + viit++; + if (viit != it->second.end()) + output << ", "; + } + } + else + output << it->second.front() << endl; + output << "]"; + it++; + if (it != vector_str_options.end()) + output << ", "; + } + output << "}"; } @@ -335,6 +391,7 @@ OptionsList::clear() date_options.clear(); symbol_list_options.clear(); vector_int_options.clear(); + vector_str_options.clear(); } int @@ -345,5 +402,6 @@ OptionsList::getNumberOfOptions() const + string_options.size() + date_options.size() + symbol_list_options.size() - + vector_int_options.size(); + + vector_int_options.size() + + vector_str_options.size(); } diff --git a/preprocessor/Statement.hh b/preprocessor/Statement.hh index a6a1d5c32..e9b0a96ee 100644 --- a/preprocessor/Statement.hh +++ b/preprocessor/Statement.hh @@ -179,12 +179,14 @@ public: typedef map date_options_t; typedef map symbol_list_options_t; typedef map > vec_int_options_t; + typedef map > vec_str_options_t; num_options_t num_options; paired_num_options_t paired_num_options; string_options_t string_options; date_options_t date_options; symbol_list_options_t symbol_list_options; vec_int_options_t vector_int_options; + vec_str_options_t vector_str_options; int getNumberOfOptions() const; void writeOutput(ostream &output) const; void writeOutput(ostream &output, const string &option_group) const;