1 /* 2 * Copyright © 2003-2019 Dynare Team 3 * 4 * This file is part of Dynare. 5 * 6 * Dynare is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Dynare is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Dynare. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef _PARSING_DRIVER_HH 21 #define _PARSING_DRIVER_HH 22 23 #ifdef _MACRO_DRIVER_HH 24 # error Impossible to include both ParsingDriver.hh and macro/Driver.hh 25 #endif 26 27 #include <string> 28 #include <vector> 29 #include <istream> 30 #include <stack> 31 32 #include "ModFile.hh" 33 #include "SymbolList.hh" 34 35 class ParsingDriver; 36 #include "ExprNode.hh" 37 #include "DynareBison.hh" 38 39 #include "ComputingTasks.hh" 40 #include "Shocks.hh" 41 #include "SigmaeInitialization.hh" 42 #include "NumericalInitialization.hh" 43 #include "DynamicModel.hh" 44 45 using namespace std; 46 47 // Declare DynareFlexLexer class 48 #ifndef __FLEX_LEXER_H 49 # define yyFlexLexer DynareFlexLexer 50 # include <FlexLexer.h> 51 # undef yyFlexLexer 52 #endif 53 54 //! The lexer class 55 /*! Actually it was necessary to subclass the DynareFlexLexer class generated by Flex, 56 since the prototype for DynareFlexLexer::yylex() was not convenient. 57 */ 58 class DynareFlex : public DynareFlexLexer 59 { 60 public: 61 DynareFlex(istream *in = nullptr, ostream *out = nullptr); 62 63 DynareFlex(const DynareFlex &) = delete; 64 DynareFlex(DynareFlex &&) = delete; 65 DynareFlex &operator=(const DynareFlex &) = delete; 66 DynareFlex &operator=(DynareFlex &&) = delete; 67 68 //! The main lexing function 69 Dynare::parser::token_type lex(Dynare::parser::semantic_type *yylval, 70 Dynare::parser::location_type *yylloc, 71 ParsingDriver &driver); 72 73 //! The filename being parsed 74 /*! The bison parser locations (begin and end) contain a pointer to that string */ 75 string filename; 76 77 //! Increment the location counter given a token 78 void location_increment(Dynare::parser::location_type *yylloc, const char *yytext); 79 80 //! Count parens in dates statement 81 int dates_parens_nb; 82 }; 83 84 //! Drives the scanning and parsing of the .mod file, and constructs its abstract representation 85 /*! It is built along the guidelines given in Bison 2.3 manual. */ 86 class ParsingDriver 87 { 88 private: 89 //! Checks that a given symbol exists, and stops with an error message if it doesn't 90 void check_symbol_existence(const string &name); 91 92 //! Checks that a given symbol exists and is a parameter, and stops with an error message if it isn't 93 void check_symbol_is_parameter(const string &name); 94 95 //! Checks that a given symbol was assigned within a Statement 96 void check_symbol_is_statement_variable(const string &name); 97 98 //! Checks that a given symbol exists and is a endogenous or exogenous, and stops with an error message if it isn't 99 void check_symbol_is_endogenous_or_exogenous(const string &name); 100 101 //! Checks that a given symbol exists and is a endogenous, and stops with an error message if it isn't 102 void check_symbol_is_endogenous(const string &name); 103 104 //! Checks that a given symbol exists and is a exogenous, and stops with an error message if it isn't 105 void check_symbol_is_exogenous(const string &name); 106 107 //! Checks for symbol existence in model block. If it doesn't exist, an error message is stored to be printed at 108 //! the end of the model block 109 void check_symbol_existence_in_model_block(const string &name); 110 111 //! Helper to add a symbol declaration 112 void declare_symbol(const string &name, SymbolType type, const string &tex_name, const vector<pair<string, string>> &partition_value); 113 114 //! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name 115 void optim_options_helper(const string &name); 116 void sampling_options_helper(const string &name); 117 118 //! Stores temporary symbol table 119 SymbolList symbol_list; 120 121 //! Temporary store for the planner objective 122 unique_ptr<StaticModel> planner_objective; 123 124 //! The data tree in which to add expressions currently parsed 125 /*! The object pointed to is not owned by the parsing driver. It is essentially a 126 reference. */ 127 DataTree *data_tree; 128 129 //! The model tree in which to add expressions currently parsed 130 /*! It is only a dynamic cast of data_tree pointer, and is therefore null if data_tree is not a ModelTree instance */ 131 ModelTree *model_tree; 132 133 //! The dynamic model tree in which to add expressions currently parsed 134 /*! It is only a dynamic cast of data_tree pointer, and is therefore null if data_tree is not a DynamicModel instance */ 135 DynamicModel *dynamic_model; 136 137 //! Sets data_tree and model_tree pointers 138 void set_current_data_tree(DataTree *data_tree_arg); 139 140 //! Stores options lists 141 OptionsList options_list; 142 //! Temporary storage for trend elements 143 ObservationTrendsStatement::trend_elements_t trend_elements; 144 //! Temporary storage for filename list of ModelComparison (contains weights) 145 ModelComparisonStatement::filename_list_t filename_list; 146 //! Temporary storage for list of EstimationParams (from estimated_params* statements) 147 vector<EstimationParams> estim_params_list; 148 //! Temporary storage for list of OsrParams (from osr_params_block statements) 149 vector<OsrParams> osr_params_list; 150 //! Temporary storage of variances from optim_weights 151 OptimWeightsStatement::var_weights_t var_weights; 152 //! Temporary storage of covariances from optim_weights 153 OptimWeightsStatement::covar_weights_t covar_weights; 154 //! Temporary storage for deterministic shocks 155 ShocksStatement::det_shocks_t det_shocks; 156 //! Temporary storage for periods of deterministic shocks 157 vector<pair<int, int>> det_shocks_periods; 158 //! Temporary storage for values of deterministic shocks 159 vector<expr_t> det_shocks_values; 160 //! Temporary storage for variances of shocks 161 ShocksStatement::var_and_std_shocks_t var_shocks; 162 //! Temporary storage for standard errors of shocks 163 ShocksStatement::var_and_std_shocks_t std_shocks; 164 //! Temporary storage for covariances of shocks 165 ShocksStatement::covar_and_corr_shocks_t covar_shocks; 166 //! Temporary storage for correlations of shocks 167 ShocksStatement::covar_and_corr_shocks_t corr_shocks; 168 //! Temporary storage for Sigma_e rows 169 SigmaeStatement::row_t sigmae_row; 170 //! Temporary storage for Sigma_e matrix 171 SigmaeStatement::matrix_t sigmae_matrix; 172 //! Temporary storage for initval/endval blocks 173 InitOrEndValStatement::init_values_t init_values; 174 //! Temporary storage for histval blocks 175 HistValStatement::hist_values_t hist_values; 176 //! Temporary storage for homotopy_setup blocks 177 HomotopyStatement::homotopy_values_t homotopy_values; 178 //! Temporary storage for moment_calibration 179 MomentCalibration::constraints_t moment_calibration_constraints; 180 //! Temporary storage for irf_calibration 181 IrfCalibration::constraints_t irf_calibration_constraints; 182 //! Temporary storage for ramsey_constraints 183 RamseyConstraintsStatement::constraints_t ramsey_constraints; 184 //! Temporary storage for svar_identification blocks 185 SvarIdentificationStatement::svar_identification_restrictions_t svar_ident_restrictions; 186 //! Temporary storage for mapping the equation number to the restrictions within an svar_identification block 187 map<int, vector<int>> svar_equation_restrictions; 188 //! Temporary storage for restrictions in an equation within an svar_identification block 189 vector<int> svar_restriction_symbols; 190 //! Temporary storage for constants exculsion within an svar_identification 191 bool svar_constants_exclusion; 192 //! Temporary storage for upper cholesky within an svar_identification block 193 bool svar_upper_cholesky; 194 //! Temporary storage for lower cholesky within an svar_identification block 195 bool svar_lower_cholesky; 196 //! Temporary storage for equation number for a restriction within an svar_identification block 197 int svar_equation_nbr; 198 //! Temporary storage for left/right handside of a restriction equation within an svar_identificaton block 199 bool svar_left_handside; 200 //! Temporary storage for current restriction number in svar_identification block 201 map<int, int> svar_Qi_restriction_nbr; 202 map<int, int> svar_Ri_restriction_nbr; 203 //! Stores undeclared model variables 204 set<string> undeclared_model_vars; 205 //! Temporary storage for restriction type 206 enum class SvarRestrictionType 207 { 208 NOT_SET, 209 Qi_TYPE, 210 Ri_TYPE 211 }; 212 SvarRestrictionType svar_restriction_type; 213 //! Temporary storage for generate_irfs 214 vector<string> generate_irf_names; 215 vector<map<string, double>> generate_irf_elements; 216 map<string, double> generate_irf_exos; 217 //! Temporary storage for argument list of external function 218 stack<vector<expr_t>> stack_external_function_args; 219 //! Temporary storage for parameters in joint prior statement 220 vector<string> joint_parameters; 221 //! Temporary storage for the symb_id associated with the "name" symbol of the current external_function statement 222 int current_external_function_id; 223 //! Temporary storage for option list provided to external_function() 224 ExternalFunctionsTable::external_function_options current_external_function_options; 225 //! Temporary storage for declaring trend variables 226 vector<int> declared_trend_vars; 227 //! Temporary storage for declaring nonstationary variables 228 vector<int> declared_nonstationary_vars; 229 //! Temporary storage for a variance declared in the prior statement 230 expr_t prior_variance; 231 SubsamplesStatement::subsample_declaration_map_t subsample_declaration_map; 232 //! Temporary storage for subsample statement: map<pair<var_name1, var_name2>>, subsample_declaration_map > 233 using subsample_declarations_t = map<pair<string, string >, SubsamplesStatement::subsample_declaration_map_t >; 234 subsample_declarations_t subsample_declarations; 235 //! Temporary storage for shock_groups 236 vector<string> shock_group; 237 vector<ShockGroupsStatement::Group> shock_groups; 238 //! Temporary storage for init2shocks 239 vector<pair<int, int>> init2shocks; 240 /* Temporary storage for planner_discount and planner_discount_latex_name 241 options of ramsey_model and ramsey_policy */ 242 expr_t planner_discount{nullptr}; 243 string planner_discount_latex_name; 244 //! reset the values for temporary storage 245 void reset_current_external_function_options(); 246 //! Adds a model lagged variable to ModelTree and VariableTable 247 expr_t add_model_variable(int symb_id, int lag); 248 //! For parsing the graph_format option 249 SymbolList graph_formats; 250 //! Temporary storage for equation tags 251 vector<pair<string, string>> eq_tags; 252 253 //! Map Var name to variables 254 map<string, vector<string>> var_map; 255 256 //! The mod file representation constructed by this ParsingDriver 257 unique_ptr<ModFile> mod_file; 258 259 WarningConsolidation &warnings; 260 261 //! Temporary storage for growth declared in pac_model 262 expr_t pac_growth; 263 double pac_steady_state_growth_rate_number = -1; 264 int pac_steady_state_growth_rate_symb_id = -1; 265 266 bool nostrict; 267 268 vector<pair<string, string>> model_errors; 269 vector<pair<string, string>> undeclared_model_variable_errors; 270 271 //! Used by VAR restrictions 272 void clear_VAR_storage(); 273 274 //! True when parsing the epilogue block 275 bool parsing_epilogue{false}; 276 277 //! True when parsing pac_model statement 278 bool parsing_pac_model{false}; 279 280 public: ParsingDriver(WarningConsolidation & warnings_arg,bool nostrict_arg)281 ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : 282 warnings{warnings_arg}, nostrict{nostrict_arg} 283 { 284 }; 285 286 ParsingDriver(const ParsingDriver &) = delete; 287 ParsingDriver(ParsingDriver &&) = delete; 288 ParsingDriver &operator=(const ParsingDriver &) = delete; 289 ParsingDriver &operator=(ParsingDriver &&) = delete; 290 291 //! Starts parsing, and constructs the MOD file representation 292 unique_ptr<ModFile> parse(istream &in, bool debug); 293 294 //! Reference to the lexer 295 unique_ptr<DynareFlex> lexer; 296 297 //! Copy of parsing location, maintained by YYLLOC_DEFAULT macro in DynareBison.yy 298 Dynare::parser::location_type location; 299 300 //! Estimation parameters 301 EstimationParams estim_params; 302 303 //! OSR parameters 304 OsrParams osr_params; 305 306 //! Temporary storage for the prior shape 307 PriorDistributions prior_shape; 308 309 //! VAR restrictions 310 //! > exclusion restrictions 311 map<int, SymbolList> exclusion_restriction; 312 map<int, map<int, SymbolList>> exclusion_restrictions; 313 //! > equation and crossequation restrictions 314 pair<int, pair<int, int>> var_restriction_coeff; 315 using var_restriction_eq_crosseq_t = pair<pair<int, pair<int, int>>, expr_t>; 316 vector<var_restriction_eq_crosseq_t> var_restriction_eq_or_crosseq; 317 pair<pair<var_restriction_eq_crosseq_t, var_restriction_eq_crosseq_t>, double> var_restriction_equation_or_crossequation; 318 map<int, pair<pair<var_restriction_eq_crosseq_t, var_restriction_eq_crosseq_t>, double>> equation_restrictions; 319 vector<pair<pair<var_restriction_eq_crosseq_t, var_restriction_eq_crosseq_t>, double>> crossequation_restrictions; 320 //! > covariance restrictions 321 map<pair<int, int>, double> covariance_number_restriction; 322 map<pair<int, int>, pair<int, int>> covariance_pair_restriction; 323 324 //! Temporary storage for "expression" option of VAR_EXPECTATION_MODEL 325 expr_t var_expectation_model_expression{nullptr}; 326 //! Temporary storage for discount option of VAR_EXPECTATION_MODEL 327 expr_t var_expectation_model_discount{nullptr}; 328 329 //! Error handler with explicit location 330 void error(const Dynare::parser::location_type &l, const string &m) __attribute__ ((noreturn)); 331 //! Error handler using saved location 332 void error(const string &m) __attribute__ ((noreturn)); 333 //! Warning handler using saved location 334 void warning(const string &m); 335 336 //! Error handler with explicit location (used in model block, accumulating error messages to be printed later) 337 void model_error(const string &m, const string &var); 338 void undeclared_model_variable_error(const string &m, const string &var); 339 340 //! Code shared between model_error() and error() 341 void create_error_string(const Dynare::parser::location_type &l, const string &m, const string &var); 342 void create_error_string(const Dynare::parser::location_type &l, const string &m, ostream &stream); 343 344 //! Check if a given symbol exists in the parsing context, and is not a mod file local variable 345 bool symbol_exists_and_is_not_modfile_local_or_external_function(const string &s); 346 //! Sets mode of ModelTree class to use C output 347 void use_dll(); 348 //! the modelis block decomposed 349 void block(); 350 //! the model is decomposed according to the linearity of its equations 351 void linear_decomposition(); 352 353 //! the model is stored in a binary file 354 void byte_code(); 355 //! the static model is not computed 356 void no_static(); 357 //! the differentiate_forward_vars option is enabled (for all vars) 358 void differentiate_forward_vars_all(); 359 //! the differentiate_forward_vars option is enabled (for a subset of vars) 360 void differentiate_forward_vars_some(); 361 //! cutoff option of model block 362 void cutoff(const string &value); 363 //! mfs option of model block 364 void mfs(const string &value); 365 //! the flags to substitute for the default compiler flags used by `use_dll` 366 void compilation_setup_substitute_flags(const string &flags); 367 //! the flags to add to the default compiler flags used by `use_dll` 368 void compilation_setup_add_flags(const string &flags); 369 //! the libs to substitute for the default compiler libs used by `use_dll` 370 void compilation_setup_substitute_libs(const string &libs); 371 //! the libs to add to the default compiler libs used by `use_dll` 372 void compilation_setup_add_libs(const string &libs); 373 //! the compiler to replace the default compiler used by `use_dll` 374 void compilation_setup_compiler(const string &path); 375 //! balanced_growth_test_tol option of model block 376 void balanced_growth_test_tol(const string &value); 377 //! Sets the FILENAME for the initial value in initval 378 void initval_file(const string &filename); 379 //! Declares an endogenous variable 380 void declare_endogenous(const string &name, const string &tex_name = "", const vector<pair<string, string>> &partition_value = {}); 381 //! Declares an exogenous variable 382 void declare_exogenous(const string &name, const string &tex_name = "", const vector<pair<string, string>> &partition_value = {}); 383 //! Declares an exogenous deterministic variable 384 void declare_exogenous_det(const string &name, const string &tex_name = "", const vector<pair<string, string>> &partition_value = {}); 385 //! Declares a parameter 386 void declare_parameter(const string &name, const string &tex_name = "", const vector<pair<string, string>> &partition_value = {}); 387 //! Declares a VAR variable and adds to symbol_list 388 void declare_var_endogenous(const string &name); 389 //! Declares a model local variable 390 void declare_model_local_variable(const string &name, const string &tex_name = ""); 391 //! Declares a statement local variable 392 void declare_statement_local_variable(const string &name); 393 //! Completes a subsample statement 394 void set_subsamples(string name1, string name2); 395 //! Declares a subsample, assigning the value to name 396 void set_subsample_name_equal_to_date_range(string name, string date1, string date2); 397 //! Checks that a subsample statement (and given name) were provided for the pair name1 & name2 398 void check_subsample_declaration_exists(const string &name1, const string &subsample_name); 399 void check_subsample_declaration_exists(const string &name1, const string &name2, const string &subsample_name); 400 //! Copies the set of subsamples from_name to_name 401 void copy_subsamples(string to_name1, string to_name2, string from_name1, string from_name2); 402 //! Sets the value of the planner_discount option of ramsey_{model,policy} 403 void set_planner_discount(expr_t value); 404 //! Sets the value of the planner_discount_latex_name option of ramsey_model 405 void set_planner_discount_latex_name(string tex_name); 406 //! Adds a predetermined_variable 407 void add_predetermined_variable(const string &name); 408 //! Declares and initializes a local parameter 409 void declare_and_init_model_local_variable(const string &name, expr_t rhs); 410 //! Changes type of a symbol 411 void change_type(SymbolType new_type, const vector<string> &var_list); 412 //! Adds a list of tags for the current equation 413 void add_equation_tags(string key, string value); 414 //! Adds a non-negative constant to DataTree 415 expr_t add_non_negative_constant(const string &constant); 416 //! Adds a NaN constant to DataTree 417 expr_t add_nan_constant(); 418 //! Adds an Inf constant to DataTree 419 expr_t add_inf_constant(); 420 //! Adds a model variable to ModelTree and VariableTable 421 expr_t add_model_variable(const string &name); 422 //! Declares a variable of type new_type OR changes a variable in the equations to type new_type 423 //! and removes any error messages that may have been issued in model_errors 424 expr_t declare_or_change_type(SymbolType new_type, const string &name); 425 //! Adds an Expression's variable 426 expr_t add_expression_variable(const string &name); 427 //! Adds a "periods" statement 428 void periods(const string &periods); 429 //! Adds a "dsample" statement 430 void dsample(const string &arg1); 431 //! Adds a "dsample" statement 432 void dsample(const string &arg1, const string &arg2); 433 //! Writes parameter intitialisation expression 434 void init_param(const string &name, expr_t rhs); 435 //! Writes an initval block 436 void init_val(const string &name, expr_t rhs); 437 //! Writes an histval block 438 void hist_val(const string &name, const string &lag, expr_t rhs); 439 //! Adds an entry in a homotopy_setup block 440 /*! Second argument "val1" can be NULL if no initial value provided */ 441 void homotopy_val(const string &name, expr_t val1, expr_t val2); 442 //! Writes end of an initval block 443 void end_initval(bool all_values_required); 444 //! Writes end of an endval block 445 void end_endval(bool all_values_required); 446 //! Writes end of an histval block 447 void end_histval(bool all_values_required); 448 //! Writes end of an homotopy_setup block 449 void end_homotopy(); 450 //! Begin epilogue block 451 void begin_epilogue(); 452 //! End epilogue block 453 void end_epilogue(); 454 //! Add epilogue variable 455 void add_epilogue_variable(const string &varname); 456 //! Add equation in epilogue block 457 void add_epilogue_equal(const string &varname, expr_t expr); 458 //! Begin a model block 459 void begin_model(); 460 //! End a model block, printing errors that were encountered in parsing 461 void end_model(); 462 //! Writes a shocks statement 463 void end_shocks(bool overwrite); 464 //! Writes a mshocks statement 465 void end_mshocks(bool overwrite); 466 //! Adds a deterministic shock or a path element inside a conditional_forecast_paths block 467 void add_det_shock(const string &var, bool conditional_forecast); 468 //! Adds a std error chock 469 void add_stderr_shock(const string &var, expr_t value); 470 //! Adds a variance chock 471 void add_var_shock(const string &var, expr_t value); 472 //! Adds a covariance chock 473 void add_covar_shock(const string &var1, const string &var2, expr_t value); 474 //! Adds a correlated chock 475 void add_correl_shock(const string &var1, const string &var2, expr_t value); 476 //! Adds a shock period range 477 void add_period(const string &p1, const string &p2); 478 //! Adds a shock period 479 void add_period(const string &p1); 480 //! Adds a deterministic shock value 481 void add_value(expr_t value); 482 //! Adds a deterministic shock value 483 /*! \param v a string containing a (possibly negative) numeric constant */ 484 void add_value(const string &v); 485 //! Writes a Sigma_e block 486 void do_sigma_e(); 487 //! Ends row of Sigma_e block 488 void end_of_row(); 489 //! Adds a constant element to current row of Sigma_e 490 void add_to_row_const(const string &v); 491 //! Adds an expression element to current row of Sigma_e 492 void add_to_row(expr_t v); 493 //! Write a steady command 494 void steady(); 495 //! Sets an option to a numerical value 496 void option_num(string name_option, string opt); 497 //! Sets an option to a numerical value 498 void option_num(string name_option, string opt1, string opt2); 499 //! Sets an option to a string value 500 void option_str(string name_option, string opt); 501 //! Sets an option to a date value 502 void option_date(string name_option, string opt); 503 //! Sets an option to a list of symbols (used in conjunction with add_in_symbol_list()) 504 void option_symbol_list(string name_option); 505 //! Sets an option to a vector of integers 506 void option_vec_int(string name_option, vector<int> opt); 507 //! Sets an option to a vector of strings 508 void option_vec_str(string name_option, vector<string> opt); 509 //! Indicates that the model is linear 510 void linear(); 511 //! Adds a variable to temporary symbol list 512 void add_in_symbol_list(const string &tmp_var); 513 //! Writes a rplot() command 514 void rplot(); 515 //! Writes a stock_simul command 516 void stoch_simul(); 517 //! Writes a trend component command 518 void trend_component_model(); 519 //! Writes a var (vector autoregression) command 520 void var_model(); 521 //! Writes a simul command 522 void simul(); 523 //! Writes check command 524 void check(); 525 //! Writes model_info command 526 void model_info(); 527 //! Writes estimated params command 528 void estimated_params(); 529 //! Writes estimated params init command 530 void estimated_params_init(bool use_calibration = false); 531 //! Writes estimated params bound command 532 void estimated_params_bounds(); 533 //! Adds a declaration for a user-defined external function 534 void external_function(); 535 //! Sets an external_function option to a string value 536 void external_function_option(const string &name_option, const string &opt); 537 //! Add a line in an estimated params block 538 void add_estimated_params_element(); 539 //! Writes osr params bounds command 540 void osr_params_bounds(); 541 //! Add a line in an osr params block 542 void add_osr_params_element(); 543 //! Sets the frequency of the data 544 void set_time(const string &arg); 545 //! Estimation Data 546 void estimation_data(); 547 //! Sets the prior for a parameter 548 void set_prior(const string &name, const string &subsample_name); 549 //! Sets the joint prior for a set of parameters 550 void set_joint_prior(const vector<string> &symbol_vec); 551 //! Adds a parameters to the list of joint parameters 552 void add_joint_parameter(string name); 553 //! Adds the variance option to its temporary holding place 554 void set_prior_variance(expr_t variance = nullptr); 555 //! Copies the prior from_name to_name 556 void copy_prior(const string &to_declaration_type, const string &to_name1, const string &to_name2, const string &to_subsample_name, 557 const string &from_declaration_type, const string &from_name1, const string &from_name2, const string &from_subsample_name); 558 //! Sets the options for a parameter 559 void set_options(const string &name, const string &subsample_name); 560 //! Copies the options from_name to_name 561 void copy_options(const string &to_declaration_type, const string &to_name1, const string &to_name2, const string &to_subsample_name, 562 const string &from_declaration_type, const string &from_name1, const string &from_name2, const string &from_subsample_name); 563 //! Sets the prior for estimated std dev 564 void set_std_prior(const string &name, const string &subsample_name); 565 //! Sets the options for estimated std dev 566 void set_std_options(const string &name, const string &subsample_name); 567 //! Sets the prior for estimated correlation 568 void set_corr_prior(const string &name1, const string &name2, const string &subsample_name); 569 //! Sets the options for estimated correlation 570 void set_corr_options(const string &name1, const string &name2, const string &subsample_name); 571 //! Runs estimation process 572 void run_estimation(); 573 //! Runs dynare_sensitivy() 574 void dynare_sensitivity(); 575 //! Adds an optimization option (string value) 576 void optim_options_string(const string &name, const string &value); 577 //! Adds an optimization option (numeric value) 578 void optim_options_num(const string &name, const string &value); 579 //! Adds an sampling option (string value) 580 void sampling_options_string(const string &name, const string &value); 581 //! Adds an sampling option (numeric value) 582 void sampling_options_num(const string &name, const string &value); 583 //! Adds an sampling option (vec_str value) 584 void sampling_options_vec_str(const string &name, vector<string> value); 585 //! Check that no observed variable has yet be defined 586 void check_varobs(); 587 //! Add a new observed variable 588 void add_varobs(const string &name); 589 //! Check that no observed exogenous variable has yet be defined 590 void check_varexobs(); 591 //! Add a new observed exogenous variable 592 void add_varexobs(const string &name); 593 //! Svar_Identification Statement 594 void begin_svar_identification(); 595 void end_svar_identification(); 596 //! Svar_Identification Statement: match list of restrictions and equation number with lag 597 void combine_lag_and_restriction(const string &lag); 598 //! Svar_Identification Statement: match list of restrictions with equation number 599 void add_restriction_in_equation(const string &equation); 600 //! Svar_Identification Statement: add list of restriction symbol ids 601 void add_in_svar_restriction_symbols(const string &tmp_var); 602 //! Svar_Identification Statement: add exclusions of constants 603 void add_constants_exclusion(); 604 //! Svar_Identification Statement: add equation number for following restriction equations 605 void add_restriction_equation_nbr(const string &eq_nbr); 606 //! Svar_Identification Statement: record presence of equal sign 607 void add_restriction_equal(); 608 //! Svar_Idenditification Statement: add coefficient of a linear restriction (positive value) 609 void add_positive_restriction_element(expr_t value, const string &variable, const string &lag); 610 //! Svar_Idenditification Statement: add unit coefficient of a linear restriction 611 void add_positive_restriction_element(const string &variable, const string &lag); 612 //! Svar_Idenditification Statement: add coefficient of a linear restriction (negative value) 613 void add_negative_restriction_element(expr_t value, const string &variable, const string &lag); 614 //! Svar_Idenditification Statement: add negative unit coefficient of a linear restriction 615 void add_negative_restriction_element(const string &variable, const string &lag); 616 //! Svar_Idenditification Statement: add restriction element 617 void add_restriction_element(expr_t value, const string &variable, const string &lag); 618 //! Svar_Identification Statement: check that restriction is homogenous 619 void check_restriction_expression_constant(expr_t value); 620 //! Svar_Identification Statement: restriction of form upper cholesky 621 void add_upper_cholesky(); 622 //! Svar_Identification Statement: restriction of form lower cholesky 623 void add_lower_cholesky(); 624 //! Svar_Global_Identification_Check Statement 625 void add_svar_global_identification_check(); 626 //! generate_irfs Block 627 void end_generate_irfs(); 628 void add_generate_irfs_element(string name); 629 void add_generate_irfs_exog_element(string exo, const string &value); 630 //! Forecast Statement 631 void forecast(); 632 void set_trends(); 633 void set_trend_element(string arg1, expr_t arg2); 634 void set_unit_root_vars(); 635 void optim_weights(); 636 void set_optim_weights(string name, expr_t value); 637 void set_optim_weights(const string &name1, const string &name2, expr_t value); 638 void set_osr_params(); 639 void run_osr(); 640 void run_dynasave(const string &filename); 641 void run_dynatype(const string &filename); 642 void run_load_params_and_steady_state(const string &filename); 643 void run_save_params_and_steady_state(const string &filename); 644 void run_identification(); 645 void add_mc_filename(string filename, string prior = "1"); 646 void run_model_comparison(); 647 //! Begin a planner_objective statement 648 void begin_planner_objective(); 649 //! End a planner objective statement 650 void end_planner_objective(expr_t expr); 651 //! Ramsey model statement 652 void ramsey_model(); 653 //! Ramsey constraints statement 654 void add_ramsey_constraints_statement(); 655 //! Ramsey less constraint 656 void ramsey_constraint_add_less(const string &name, const expr_t rhs); 657 //! Ramsey greater constraint 658 void ramsey_constraint_add_greater(const string &name, const expr_t rhs); 659 //! Ramsey less or equal constraint 660 void ramsey_constraint_add_less_equal(const string &name, const expr_t rhs); 661 //! Ramsey greater or equal constraint 662 void ramsey_constraint_add_greater_equal(const string &name, const expr_t rhs); 663 //! Ramsey constraint helper function 664 void add_ramsey_constraint(const string &name, BinaryOpcode op_code, const expr_t rhs); 665 //! Ramsey policy statement 666 void ramsey_policy(); 667 //! Evaluate Planner Objective 668 void evaluate_planner_objective(); 669 //! Discretionary policy statement 670 void discretionary_policy(); 671 //! Adds a write_latex_dynamic_model statement 672 void write_latex_dynamic_model(bool write_equation_tags); 673 //! Adds a write_latex_static_model statement 674 void write_latex_static_model(bool write_equation_tags); 675 //! Adds a write_latex_original_model statement 676 void write_latex_original_model(bool write_equation_tags); 677 //! Adds a write_latex_steady_state_model statement 678 void write_latex_steady_state_model(); 679 //! BVAR marginal density 680 void bvar_density(const string &maxnlags); 681 //! BVAR forecast 682 void bvar_forecast(const string &nlags); 683 //! SBVAR statement 684 void sbvar(); 685 //! Markov Switching Statement: Estimation 686 void ms_estimation(); 687 //! Markov Switching Statement: Simulation 688 void ms_simulation(); 689 //! Markov Switching Statement: MDD 690 void ms_compute_mdd(); 691 //! Markov Switching Statement: Probabilities 692 void ms_compute_probabilities(); 693 //! Markov Switching Statement: IRF 694 void ms_irf(); 695 //! Markov Switching Statement: Forecast 696 void ms_forecast(); 697 //! Markov Switching Statement: Variance Decomposition 698 void ms_variance_decomposition(); 699 //! Svar statement 700 void svar(); 701 //! MarkovSwitching statement 702 void markov_switching(); 703 //! Shock decomposition 704 void shock_decomposition(); 705 //! Realtime Shock decomposition 706 void realtime_shock_decomposition(); 707 //! Plot Shock decomposition 708 void plot_shock_decomposition(); 709 //! Initial Condition decomposition 710 void initial_condition_decomposition(); 711 //! squeeze_shock_decomposition statement 712 void squeeze_shock_decomposition(); 713 //! Conditional forecast statement 714 void conditional_forecast(); 715 //! Conditional forecast paths block 716 void conditional_forecast_paths(); 717 //! Plot conditional forecast statement 718 void plot_conditional_forecast(const string &periods = ""); 719 //! Smoother on calibrated models 720 void calib_smoother(); 721 //! Extended path 722 void extended_path(); 723 //! Writes token "arg1=arg2" to model tree 724 expr_t add_model_equal(expr_t arg1, expr_t arg2); 725 //! Writes token "arg=0" to model tree 726 expr_t add_model_equal_with_zero_rhs(expr_t arg); 727 //! Writes token "arg1+arg2" to model tree 728 expr_t add_plus(expr_t arg1, expr_t arg2); 729 //! Writes token "arg1-arg2" to model tree 730 expr_t add_minus(expr_t arg1, expr_t arg2); 731 //! Writes token "-arg1" to model tree 732 expr_t add_uminus(expr_t arg1); 733 //! Writes token "arg1*arg2" to model tree 734 expr_t add_times(expr_t arg1, expr_t arg2); 735 //! Writes token "arg1/arg2" to model tree 736 expr_t add_divide(expr_t arg1, expr_t arg2); 737 //! Writes token "arg1<arg2" to model tree 738 expr_t add_less(expr_t arg1, expr_t arg2); 739 //! Writes token "arg1>arg2" to model treeexpr_t 740 expr_t add_greater(expr_t arg1, expr_t arg2); 741 //! Writes token "arg1<=arg2" to model treeexpr_t 742 expr_t add_less_equal(expr_t arg1, expr_t arg2); 743 //! Writes token "arg1>=arg2" to model treeexpr_t 744 expr_t add_greater_equal(expr_t arg1, expr_t arg2); 745 //! Writes token "arg1==arg2" to model treeexpr_texpr_t 746 expr_t add_equal_equal(expr_t arg1, expr_t arg2); 747 //! Writes token "arg1!=arg2" to model treeexpr_texpr_t 748 expr_t add_different(expr_t arg1, expr_t arg2); 749 //! Writes token "arg1^arg2" to model tree 750 expr_t add_power(expr_t arg1, expr_t arg2); 751 //! Writes token "E(arg1)(arg2)" to model tree 752 expr_t add_expectation(const string &arg1, expr_t arg2); 753 //! Writes token "VAR_EXPECTATION(model_name)" to model tree 754 expr_t add_var_expectation(const string &model_name); 755 //! Writes token "PAC_EXPECTATION(model_name, discount, growth)" to model tree 756 expr_t add_pac_expectation(const string &var_model_name); 757 //! Creates pac_model statement 758 void begin_pac_growth(); 759 void begin_pac_model(); 760 void pac_model(); 761 //! Adds growth for pac 762 void set_pac_growth(expr_t pac_growth_arg); 763 //! Adds steady state growth for pac 764 void set_pac_steady_state_growth(const string &name_or_number); 765 //! Writes token "diff(arg1)" to model tree 766 expr_t add_diff(expr_t arg1); 767 //! Writes token "adl(arg1, lag)" to model tree 768 expr_t add_adl(expr_t arg1, const string &name, const string &lag); 769 expr_t add_adl(expr_t arg1, const string &name, const vector<int> &lags); 770 //! Writes token "exp(arg1)" to model tree 771 expr_t add_exp(expr_t arg1); 772 //! Writes token "log(arg1)" to model tree 773 expr_t add_log(expr_t arg1); 774 //! Writes token "log10(arg1)" to model tree 775 expr_t add_log10(expr_t arg1); 776 //! Writes token "cos(arg1)" to model tree 777 expr_t add_cos(expr_t arg1); 778 //! Writes token "sin(arg1)" to model tree 779 expr_t add_sin(expr_t arg1); 780 //! Writes token "tan(arg1)" to model tree 781 expr_t add_tan(expr_t arg1); 782 //! Writes token "acos(arg1)" to model tree 783 expr_t add_acos(expr_t arg1); 784 //! Writes token "asin(arg1)" to model tree 785 expr_t add_asin(expr_t arg1); 786 //! Writes token "atan(arg1)" to model tree 787 expr_t add_atan(expr_t arg1); 788 //! Writes token "cosh(arg1)" to model tree 789 expr_t add_cosh(expr_t arg1); 790 //! Writes token "sinh(arg1)" to model tree 791 expr_t add_sinh(expr_t arg1); 792 //! Writes token "tanh(arg1)" to model tree 793 expr_t add_tanh(expr_t arg1); 794 //! Writes token "acosh(arg1)" to model tree 795 expr_t add_acosh(expr_t arg1); 796 //! Writes token "asin(arg1)" to model tree 797 expr_t add_asinh(expr_t arg1); 798 //! Writes token "atanh(arg1)" to model tree 799 expr_t add_atanh(expr_t arg1); 800 //! Writes token "sqrt(arg1)" to model tree 801 expr_t add_sqrt(expr_t arg1); 802 //! Writes token "cbrt(arg1)" to model tree 803 expr_t add_cbrt(expr_t arg1); 804 //! Writes token "abs(arg1)" to model tree 805 expr_t add_abs(expr_t arg1); 806 //! Writes token "sign(arg1)" to model tree 807 expr_t add_sign(expr_t arg1); 808 //! Writes token "max(arg1,arg2)" to model tree 809 expr_t add_max(expr_t arg1, expr_t arg2); 810 //! Writes token "min(arg1,arg2)" to model tree 811 expr_t add_min(expr_t arg1, expr_t arg2); 812 //! Writes token "normcdf(arg1,arg2,arg3)" to model tree 813 expr_t add_normcdf(expr_t arg1, expr_t arg2, expr_t arg3); 814 //! Writes token "normcdf(arg,0,1)" to model tree 815 expr_t add_normcdf(expr_t arg); 816 //! Writes token "normpdf(arg1,arg2,arg3)" to model tree 817 expr_t add_normpdf(expr_t arg1, expr_t arg2, expr_t arg3); 818 //! Writes token "normpdf(arg,0,1)" to model tree 819 expr_t add_normpdf(expr_t arg); 820 //! Writes token "erf(arg)" to model tree 821 expr_t add_erf(expr_t arg); 822 //! Writes token "steadyState(arg1)" to model tree 823 expr_t add_steady_state(expr_t arg1); 824 //! Pushes empty vector onto stack when a symbol is encountered (mod_var or ext_fun) 825 void push_external_function_arg_vector_onto_stack(); 826 //! Adds an external function argument 827 void add_external_function_arg(expr_t arg); 828 //! Test to see if model/external function has exactly one integer argument 829 pair<bool, double> is_there_one_integer_argument() const; 830 //! Adds an external function call node 831 expr_t add_model_var_or_external_function(const string &function_name, bool in_model_block); 832 //! Adds a native statement 833 void add_native(const string &s); 834 //! Adds a native statement, first removing the set of characters passed in token (and everything after) 835 void add_native_remove_charset(string str, const string &token); 836 //! Adds a verbatim statement 837 void add_verbatim(const string &s); 838 //! Adds a verbatim statement, first removing the set of characters passed in token (and everything after) 839 void add_verbatim_remove_charset(string str, const string &token); 840 //! Resets data_tree and model_tree pointers to default (i.e. mod_file->expressions_tree) 841 void reset_data_tree(); 842 //! Begin a steady_state_model block 843 void begin_steady_state_model(); 844 //! Add an assignment equation in steady_state_model block 845 void add_steady_state_model_equal(const string &varname, expr_t expr); 846 //! Add a multiple assignment equation in steady_state_model block 847 void add_steady_state_model_equal_multiple(expr_t expr); 848 //! Switches datatree 849 void begin_trend(); 850 //! Declares a trend variable with its growth factor 851 void declare_trend_var(bool log_trend, const string &name, const string &tex_name = ""); 852 //! Ends declaration of trend variable 853 void end_trend_var(expr_t growth_factor); 854 //! Declares a nonstationary variable with its deflator 855 void declare_nonstationary_var(const string &name, const string &tex_name = "", const vector<pair<string, string>> &partition_value = {}); 856 //! Ends declaration of nonstationary variable 857 void end_nonstationary_var(bool log_deflator, expr_t deflator); 858 //! Add a graph format to the list of formats requested 859 void add_graph_format(const string &name); 860 //! Add the graph_format option to the OptionsList structure 861 void process_graph_format_option(); 862 //! Add the graph_format option to the initial_condition_decomp substructure of the OptionsList structure 863 void initial_condition_decomp_process_graph_format_option(); 864 //! Add the graph_format option to the plot_shock_decomp substructure of the OptionsList structure 865 void plot_shock_decomp_process_graph_format_option(); 866 //! Model diagnostics 867 void model_diagnostics(); 868 //! Processing the parallel_local_files option 869 void add_parallel_local_file(string filename); 870 //! Add an item of a moment_calibration statement 871 void add_moment_calibration_item(const string &endo1, const string &endo2, string lags, const pair<expr_t, expr_t> &range); 872 //! End a moment_calibration statement 873 void end_moment_calibration(); 874 //! Add an item of an irf_calibration statement 875 void add_irf_calibration_item(const string &endo, string periods, const string &exo, const pair<expr_t, expr_t> &range); 876 //! End a moment_calibration statement 877 void end_irf_calibration(); 878 //! Add a shock to a group 879 void add_shock_group_element(string name); 880 //! Add a set of shock groups 881 void add_shock_group(string name); 882 //! End shock groups declaration 883 void end_shock_groups(const string &name); 884 //! Add a set of init2shocks 885 void add_init2shocks(const string &endo_name, const string &exo_name); 886 //! End init2shocks declaration 887 void end_init2shocks(const string &name); 888 void smoother2histval(); 889 void histval_file(const string &filename); 890 void perfect_foresight_setup(); 891 void perfect_foresight_solver(); 892 void prior_posterior_function(bool prior_func); 893 //! VAR Restrictions 894 void begin_VAR_restrictions(); 895 void end_VAR_restrictions(const string &var_model_name); 896 void add_VAR_exclusion_restriction(const string &lagstr); 897 void add_VAR_restriction_exclusion_equation(const string &name); 898 void add_VAR_restriction_coeff(const string &name1, const string &name2, const string &lagstr); 899 void add_VAR_restriction_eq_or_crosseq(expr_t expr); 900 void add_VAR_restriction_equation_or_crossequation(const string &numberstr); 901 void multiply_arg2_by_neg_one(); 902 void add_VAR_restriction_equation_or_crossequation_final(const string &name); 903 void add_VAR_covariance_number_restriction(const string &name1, const string &name2, const string &valuestr); 904 void add_VAR_covariance_pair_restriction(const string &name11, const string &name12, const string &name21, const string &name22); 905 //! Runs VAR estimation process 906 void run_var_estimation(); 907 //! GMM Estimation statement 908 void gmm_estimation(); 909 //! SMM Estimation statement 910 void smm_estimation(); 911 //! Add a var_expectation_model statement 912 void var_expectation_model(); 913 }; 914 915 #endif // ! PARSING_DRIVER_HH 916