diff --git a/DynareBison.yy b/DynareBison.yy index f492d6753c2abbd1bbf370a949aac3e6083ac495..b8eceeaff89f1e801d3b07e37bf94ac9d4cee3ad 100644 --- a/DynareBison.yy +++ b/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<string *> *vector_string_val; + vector<string> *vector_string_val; + vector<string *> *vector_string_p_val; vector<int> *vector_int_val; pair<string *, string *> *string_pair_val; vector<pair<string *, string *> *> *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 <vector_string_val> SYMBOL_VEC +%token <vector_string_p_val> SYMBOL_VEC %type <node_val> expression expression_or_empty %type <node_val> equation hand_side @@ -191,7 +192,8 @@ class ParsingDriver; %type <string_pair_val> named_var_elem %type <vector_string_pair_val> named_var named_var_1 %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_string_val> vec_str vec_str_1 +%type <vector_string_p_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 %type <prior_distributions_val> 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<string>(); $$->push_back(*$2); delete $2; } + | '[' COMMA QUOTED_STRING + { $$ = new vector<string>(); $$->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/DynareFlex.ll b/DynareFlex.ll index 668db31e45fe1b61a4f20dcfd106ee5d575b7387..1ebe6a5c74884bd1e4b0700589fdbd2d0d7a78bb 100644 --- a/DynareFlex.ll +++ b/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; } <DYNARE_STATEMENT>write_equation_tags {return token::WRITE_EQUATION_TAGS;} +<DYNARE_STATEMENT>eqtags {return token::EQTAGS;} <DYNARE_STATEMENT>indxap {return token::INDXAP;} <DYNARE_STATEMENT>apband {return token::APBAND;} <DYNARE_STATEMENT>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<string *>; + yylval->vector_string_val = new vector<string>; + yylval->vector_string_p_val = new vector<string *>; 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<string *>::iterator it=yylval->vector_string_val->begin(); - it != yylval->vector_string_val->end(); it++) + for (vector<string *>::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/ParsingDriver.cc b/ParsingDriver.cc index b9e2a9b10ba2cc76b3bb178d367490dfd7492679..cf8760113268d06665ffd2fd40efc8bb965b63af 100644 --- a/ParsingDriver.cc +++ b/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<int> *opt) delete opt; } +void +ParsingDriver::option_vec_str(const string &name_option, const vector<string> *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/ParsingDriver.hh b/ParsingDriver.hh index e7f54b0a9a21cccee2c82071c6262b99ddfec1cb..872c391728f85ac41962731727f7eb353af02772 100644 --- a/ParsingDriver.hh +++ b/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<int> *opt); + //! Sets an option to a vector of strings + void option_vec_str(const string &name_option, const vector<string> *opt); //! Indicates that the model is linear void linear(); //! Adds a variable to temporary symbol list diff --git a/Statement.cc b/Statement.cc index 8a86f75a96b34ee234a195e99831bdda6d35c701..c7b6dd48717da69d66bf4027167aa442f16c4d04 100644 --- a/Statement.cc +++ b/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<string>::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<string>::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<string>::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/Statement.hh b/Statement.hh index a6a1d5c32c58f5777ff716d0a41decc75fd9c7f9..e9b0a96eef88c6bdec289af45d78fc6740d3a175 100644 --- a/Statement.hh +++ b/Statement.hh @@ -179,12 +179,14 @@ public: typedef map<string, string> date_options_t; typedef map<string, SymbolList> symbol_list_options_t; typedef map<string, vector<int> > vec_int_options_t; + typedef map<string, vector<string > > 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;