diff --git a/parser.src/ComputingTasks.cc b/parser.src/ComputingTasks.cc index 05efdbeb8a23c56ff004ec9701d68b4c5928eb3d..55f3078ce9a9f70e381f32d71b5edc6b41c689c2 100644 --- a/parser.src/ComputingTasks.cc +++ b/parser.src/ComputingTasks.cc @@ -59,12 +59,23 @@ void ComputingTasks::setOption(string name, string value) *output << "options_." << name << " = " << value << ";\n"; } //------------------------------------------------------------------------------ +void ComputingTasks::setOption(string name, string value1, string value2) +{ + *output << "options_." << name << " = [" << value1 << "; " << value2 << "];\n"; +} +//------------------------------------------------------------------------------ void ComputingTasks::runEstimation(string tmp1) { *output << tmp1; *output << "dynare_estimation(var_list_);\n"; } //------------------------------------------------------------------------------ +void ComputingTasks::runRplot(string tmp1) +{ + *output << tmp1; + *output << "rplot(var_list_,rplottype_);\n"; +} +//------------------------------------------------------------------------------ void ComputingTasks::setEstimationInit(void) { *output << "global estim_params_\n"; @@ -118,56 +129,54 @@ void ComputingTasks::setOptimOptions(string str1, string str2, int task) //------------------------------------------------------------------------------ void ComputingTasks::setEstimatedElements(void) { - if (!SymbolTable::Exist(EstimParams->name)) - { - string msg = "Unknown symbol : "+EstimParams->name; - error(msg.c_str()); - } - if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced) - { - return; - } - if ((EstimParams->init_val).size() == 0) - { - EstimParams->init_val = EstimParams->mean; - } - if (EstimParams->type == 2) - { - // Setting user parameter name - *output << "estim_params_.user_param_names = strvcat(estim_params_.user_param_names, "; - *output << "'" << EstimParams->name << "');\n"; - // Setting Dynare parameter name - *output << "estim_params_.param_names = strvcat(estim_params_.param_names, "; - *output << "'M_.params(" << SymbolTable::getID(EstimParams->name)+1 << ")');\n"; - } - if( SymbolTable::getType(EstimParams->name) == eExogenous) - { - *output << "estim_params_.var_exo = [estim_params_.var_exo; "; - } - else if ( SymbolTable::getType(EstimParams->name) == eEndogenous) + if (!SymbolTable::Exist(EstimParams->name)) + { + string msg = "Unknown symbol : "+EstimParams->name; + error(msg.c_str()); + } + if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced) + { + return; + } + if ((EstimParams->init_val).size() == 0) + { + EstimParams->init_val = EstimParams->mean; + } + switch(EstimParams->type) + { + case 1: + if( SymbolTable::getType(EstimParams->name) == eExogenous) { - *output << "estim_params_.var_endo = [estim_params_.var_endo; "; + *output << "estim_params_.var_exo = [estim_params_.var_exo; "; } - else if ( SymbolTable::getType(EstimParams->name) == eParameter) + else if ( SymbolTable::getType(EstimParams->name) == eEndogenous) { - *output << "estim_params_.param_vals = [estim_params_.param_vals; "; + *output << "estim_params_.var_endo = [estim_params_.var_endo; "; } - if (EstimParams->type == 1) + *output << SymbolTable::getID(EstimParams->name)+1; + break; + case 2: + *output << "estim_params_.param_vals = [estim_params_.param_vals; "; + *output << SymbolTable::getID(EstimParams->name)+1; + break; + case 3: + if( SymbolTable::getType(EstimParams->name) == eExogenous) { - *output << SymbolTable::getID(EstimParams->name)+1 << " " << - EstimParams->init_val << " " << EstimParams->low_bound << " " << - EstimParams->up_bound << " " << EstimParams->prior << " "; - *output << EstimParams->mean << " " << EstimParams->std << " " << - EstimParams->p3 << " " << EstimParams->p4 << " " << EstimParams->jscale << "];\n"; + *output << "estim_params_.corrx = [estim_params_.corrx; "; } - else if (EstimParams->type == 2) + else if ( SymbolTable::getType(EstimParams->name) == eEndogenous) { - *output << EstimParams->init_val << " " << EstimParams->low_bound << " " << - EstimParams->up_bound << " " << EstimParams->prior << " "; - *output << EstimParams->mean << " " << EstimParams->std << " " << - EstimParams->p3 << " " << EstimParams->p4 << " " << EstimParams->jscale << "];\n"; + *output << "estim_params_.corrn = [estim_params_.corrn; "; } - EstimParams->clear(); + *output << SymbolTable::getID(EstimParams->name)+1; + *output << " " << SymbolTable::getID(EstimParams->name2)+1; + break; + } + *output << " " << EstimParams->init_val << " " << EstimParams->low_bound << " " << + EstimParams->up_bound << " " << EstimParams->prior << " "; + *output << EstimParams->mean << " " << EstimParams->std << " " << + EstimParams->p3 << " " << EstimParams->p4 << " " << EstimParams->jscale << "];\n"; + EstimParams->clear(); } void ComputingTasks::set_trend_element (string name, string expression) { @@ -178,7 +187,7 @@ void ComputingTasks::set_trend_element (string name, string expression) (* error) (msg.c_str()); } Type type = SymbolTable::getType(name); - int id = SymbolTable::getID(name); + // int id = SymbolTable::getID(name); if (type == eEndogenous) { *output << "tmp1 = strmatch(" << name << ",options_.varobs,'exact');\n"; @@ -191,185 +200,217 @@ void ComputingTasks::set_trend_element (string name, string expression) } //------------------------------------------------------------------------------ -void ComputingTasks::setCalibInit(void) +void ComputingTasks::BeginCalibVar(void) { - *output << "%\n% CALIB_VAR \n%\n"; - for(int i=1;i<4;++i) - { - *output << "calib_var_index{" << i << "} = [];\n"; - *output << "calib_targets{" << i << "} = [];\n"; - *output << "calib_weights{" << i << "}=[];\n"; - } + *output << "%\n% CALIB_VAR \n%\n"; + for(int i=1;i<4;++i) + { + *output << "calib_var_index{" << i << "} = [];\n"; + *output << "calib_targets{" << i << "} = [];\n"; + *output << "calib_weights{" << i << "}=[];\n"; + } } //------------------------------------------------------------------------------ -void ComputingTasks::setCalibVariance(void) +void ComputingTasks::setCalibVar(string name, string weight, string expression) { -/* - char buffer[200]; - if (p_t->endo_exo == 1 || p_t->endo_exo == 3) + if (!SymbolTable::Exist(name)) { - sprintf(buffer,"calib_var_index{1} = [calib_var_index{1};%d];\n",p_t->nbr+1); - str_output(buffer); - str_output("calib_targets{1} =[calib_targets{1}; "); - p_expression(p_q); - str_output("];\n"); - sprintf(buffer,"calib_weights{1} = [calib_weights{1}; %s];\n",weight); - str_output(buffer); + string msg = "calib_var: " + name + " doesn't exist"; + error(msg.c_str()); } - else if (p_t->endo_exo == 0) + int id = SymbolTable::getID(name)+1; + if (SymbolTable::getType(name) == eEndogenous) { - sprintf(buffer,"calib_var_index{3} = [calib_var_index{3};%d %d];\n",p_t->nbr+1,p_t->nbr+1); - str_output(buffer); - str_output("calib_targets{3} =[calib_targets{3}; "); - p_expression(p_q); - str_output("];\n"); - sprintf(buffer,"calib_weights{3} = [calib_weights{3}; %s];\n",weight); - str_output(buffer); + *output << "calib_var_index{1} = [calib_var_index{1};" << id << "," << id << "];\n"; + *output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n"; + *output << "calib_targets{1} =[calib_targets{1}; " << expression << "];\n"; + } + else if (SymbolTable::getType(name) == eExogenous) + { + *output << "calib_var_index{3} = [calib_var_index{3};" << id << "," << id << "];\n"; + *output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n"; + *output << "calib_targets{3} =[calib_targets{3}; " << expression << "];\n"; } else { - printf("ERROR in CALIB: one of the targets isn't legitimate\n"); - } -*/ + string msg = "calib_var: " + name + "isn't a endogenous or an exogenous variable"; + error(msg.c_str()); + } } //------------------------------------------------------------------------------ -void ComputingTasks::setCalibCovariance(void) +void ComputingTasks::setCalibVar(string name1, string name2, string weight, string expression) { -/* -0 : exo -1 endo - char buffer[200]; - if ((p_t1->endo_exo == 0 && p_t2->endo_exo == 1)|| (p_t1->endo_exo == 1 && p_t2->endo_exo == 0)) + if (!SymbolTable::Exist(name1)) { - printf("ERROR in CALIB: can't target correlation between an Endogenousous and an Exogenousous variable\n"); - exit(1); + string msg = "calib_var: " + name1 + " doesn't exist"; + error(msg.c_str()); } - else if (p_t1->endo_exo == 1 || p_t1->endo_exo == 3) + if (!SymbolTable::Exist(name2)) { - sprintf(buffer,"calib_var_index{2} = [calib_var_index{2};%d %d];\n",p_t1->nbr+1,p_t2->nbr+1); - str_output(buffer); - str_output("calib_targets{2} =[calib_targets{2}; "); - p_expression(p_q); - str_output("];\n"); - sprintf(buffer,"calib_weights{2} = [calib_weights{2}; %s];\n",weight); - str_output(buffer); + string msg = "calib_var: " + name2 + " doesn't exist"; + error(msg.c_str()); } - else if (p_t1->endo_exo == 0) + if (SymbolTable::getType(name1) != SymbolTable::getType(name2)) { - sprintf(buffer,"calib_var_index{3} = [calib_var_index{2};%d %d];\n",p_t1->nbr+1,p_t2->nbr+1); - str_output(buffer); - str_output("calib_targets{3} =[calib_targets{3}; "); - p_expression(p_q); - str_output("];\n"); - sprintf(buffer,"calib_weights{3} = [calib_weights{3}; %s];\n",weight); - str_output(buffer); + string msg = "calib_var: " + name1 + " and " + name2 + " don't have the same type"; + error(msg.c_str()); + } + int id1 = SymbolTable::getID(name1)+1; + int id2 = SymbolTable::getID(name2)+1; + if (SymbolTable::getType(name1) == eEndogenous) + { + *output << "calib_var_index{1} = [calib_var_index{1};" << id1 << "," << id2 << "];\n"; + *output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n"; + *output << "calib_targets{1} =[calib_targets{1}; " << expression << "];\n"; + } + else if (SymbolTable::getType(name1) == eExogenous) + { + *output << "calib_var_index{3} = [calib_var_index{3};" << id1 << "," << id2 << "];\n"; + *output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n"; + *output << "calib_targets{3} =[calib_targets{3}; " << expression << "];\n"; } else { - printf("ERROR in CALIB: one of the targets isn''t legitimate\n"); - exit(1); + string msg = "calib_var: " + name1 + " and " + name2 + "aren't endogenous or exogenous variables"; + error(msg.c_str()); } -*/ } -//------------------------------------------------------------------------------ -void ComputingTasks::setCalibAutoCorrelation(void) +void ComputingTasks::setCalibAc(string name, string ar, string weight, string expression) { -/* - char buffer[200]; - int i, iar; - - iar = atoi(ar)+3; + static int max_iar = 3; + if (!SymbolTable::Exist(name)) + { + string msg = "calib_var: " + name + " doesn't exist"; + error(msg.c_str()); + } + int id = SymbolTable::getID(name)+1; + int iar = atoi(ar.c_str())+3; if (iar > max_iar) { - for(i=max_iar+1; i <= iar; ++i) + // creates new variables + for(int i=max_iar+1; i <= iar; ++i) { - sprintf(buffer,"calib_var_index{%d} = [];\ncalib_targets{%d} = [];\ncalib_weights{%d}=[];\n",i,i,i); - str_output(buffer); + *output << "calib_var_index{" << i << "} = [];\n"; + *output << "calib_targets{" << i << "} = [];\n"; + *output << "calib_weights{" << i << "}=[];\n"; } max_iar = iar; } - sprintf(buffer,"calib_var_index{%d} = [calib_var_index{%d};%d];\n",iar,iar,p_t->nbr+1); - str_output(buffer); - sprintf(buffer,"calib_targets{%d} =[calib_targets{%d}; ",iar,iar); - str_output(buffer); - p_expression(p_q); - str_output("];\n"); - sprintf(buffer,"calib_weights{%d} = [calib_weights{%d}; %s];\n",iar,iar,weight); - str_output(buffer); -*/ + if (SymbolTable::getType(name) == eEndogenous) + { + *output << "calib_var_index{" << iar << "} = [calib_var_index{" << iar << "};" << id << "];\n"; + *output << "calib_weights{" << iar << "} = [calib_weights{" << iar << "}; " << weight << "];\n"; + *output << "calib_targets{" << iar << "} =[calib_targets{" << iar << "}; " << expression << "];\n"; + } + else + { + string msg = "calib_var: " + name + "isn't a endogenous variable"; + error(msg.c_str()); + } } //------------------------------------------------------------------------------ -void ComputingTasks::setCalib(void) +void ComputingTasks::runCalib(int cova) { -/* - sprintf(buffer,"M_.Sigma_e=calib(calib_var_index,calib_targets,calib_weights,%d,%d,Sigma_e_);\n",max_iar-3,cova); - str_output(buffer); -*/ + *output << "M_.Sigma_e=calib(calib_var_index,calib_targets,calib_weights," << cova << ",Sigma_e_);\n"; } //------------------------------------------------------------------------------ -void ComputingTasks::setOsr(string tmp1) +void ComputingTasks::setOsrParams(string tmp) { - *output << tmp1; - *output << "osr(var1_list_,osr_params_,optim_weights_);\n"; + *output << tmp; +} +//------------------------------------------------------------------------------ +void ComputingTasks::runOsr(string tmp1) +{ + *output << tmp1; + *output << "osr(var1_list_,osr_params_,optim_weights_);\n"; } //------------------------------------------------------------------------------ -void ComputingTasks::setOlr(string tmp1, string tmp2) +void ComputingTasks::setOlrInst(string tmp) { - *output << tmp1 << tmp2; - *output << "olr(var_list_,olr_inst_,obj_var_,optim_weights_);\n"; - + *output << tmp; } //------------------------------------------------------------------------------ -void ComputingTasks::setOptimWeightsInit(void) +void ComputingTasks::runOlr(string tmp1) { - *output << "% OPTIM_WEIGHTS\n\n"; - *output << "optim_weights_ = sparse(endo_nbr,endo_nbr);\n"; - *output << "obj_var_ = [];\n\n"; + *output << tmp1; + *output << "options_.olr = 1;\n"; + *output << "options_.olr_w = optim_weights_;\n"; + *output << "options_.olr_inst = olr_inst_;\n"; + *output << "info = stoch_simul(var_list_);\n"; } //------------------------------------------------------------------------------ -void ComputingTasks::setOptimWeights1(void) +void ComputingTasks::BeginOptimWeights(void) { -/* - char buffer[200]; - - if (p_t->endo_exo != 1 && p_t->endo_exo != 3) + *output << "% OPTIM_WEIGHTS\n\n"; + *output << "optim_weights_ = sparse(endo_nbr,endo_nbr);\n"; + *output << "obj_var_ = [];\n\n"; +} +//------------------------------------------------------------------------------ +void ComputingTasks::setOptimWeights(string name, string exp) +{ + if (!SymbolTable::Exist(name) || SymbolTable::getType(name) != eEndogenous) { - fprintf(stdout,"OPTIM_WEIGHTS ERROR: only Endogenousous variables can have weights" ); - exit(1); + string msg = "optim_weights: " + name + " isn't an endogenous variable"; + error(msg.c_str()); } - - sprintf(buffer,"optim_weights_(%d,%d) = ",p_t->nbr+1,p_t->nbr+1); - str_output(buffer); - p_expression(p_q); - str_output(";\n"); - sprintf(buffer,"obj_var_ = [obj_var_; %d];\n",p_t->nbr+1); - str_output(buffer); -*/ + int id = SymbolTable::getID(name)+1; + *output << "optim_weights_(" << id << "," << id << ") = " << exp << ";\n"; + *output << "obj_var_ = [obj_var_; " << id << "];\n"; } //------------------------------------------------------------------------------ -void ComputingTasks::setOptimWeights2(void) +void ComputingTasks::setOptimWeights(string name1, string name2, string exp) { -/* - char buffer[200]; - - if ((p_t1->endo_exo != 1 && p_t1->endo_exo != 3) || (p_t2->endo_exo != 1 && p_t2->endo_exo != 3)) + if (!SymbolTable::Exist(name1) || SymbolTable::getType(name1) != eEndogenous) { - fprintf(stdout,"OPTIM_WEIGHTS ERROR: only Endogenousous variables can have weights" ); - exit(1); + string msg = "optim_weights: " + name1 + " isn't an endogenous variable"; + error(msg.c_str()); } - - sprintf(buffer,"optim_weights_(%d,%d) = ",p_t1->nbr+1,p_t2->nbr+1); - str_output(buffer); - p_expression(p_q); - str_output(";\n"); - sprintf(buffer,"optim_weights_(%d,%d) = optim_weights_(%d,%d);\n",p_t2->nbr+1,p_t1->nbr+1,p_t1->nbr+1,p_t2->nbr+1); - str_output(buffer); - sprintf(buffer,"obj_var_ = [obj_var_; %d];\n",p_t1->nbr+1); - sprintf(buffer,"obj_var_ = [obj_var_; %d];\n",p_t2->nbr+1); -*/ + if (!SymbolTable::Exist(name2) || SymbolTable::getType(name2) != eEndogenous) + { + string msg = "optim_weights: " + name2 + " isn't an endogenous variable"; + error(msg.c_str()); + } + int id1 = SymbolTable::getID(name1)+1; + int id2 = SymbolTable::getID(name2)+1; + *output << "optim_weights_(" << id1 << "," << id2 << ") = " << exp << ";\n"; + *output << "obj_var_ = [obj_var_; " << id1 << " " << id2 << "];\n"; } //------------------------------------------------------------------------------ +void ComputingTasks::runDynasave(string filename, string ext, string varlist) +{ + *output << varlist; + *output << "dynasave(" << filename; + if (ext.size() > 0) + { + *output << "," << ext; + } + *output << ",varlist_);\n"; +} +void ComputingTasks::runDynatype(string filename, string ext, string varlist) +{ + *output << varlist; + *output << "dynatype(" << filename; + if (ext.size() > 0) + { + *output << "," << ext; + } + *output << ",varlist_);\n"; +} +void ComputingTasks::beginModelComparison(void) +{ + *output << "ModelNames_ = {};\n"; + *output << "ModelPriors_ = {};\n"; +} +void ComputingTasks::addMcFilename(string filename, string prior) +{ + *output << "ModelNames_ = { ModelNames_{:} '" << filename << "};\n"; + *output << "ModelPriors_ = { ModelPriors_{:} '" << prior << "};\n"; +} +void ComputingTasks::runModelComparison(void) +{ + *output << "model_comparison(ModelNames_,ModelPriors_);\n"; +} /* string ComputingTasks::get(void) { diff --git a/parser.src/DataTree.cc b/parser.src/DataTree.cc index f5ec2f06c26695b9da47b8a45ebf8df624199990..567ebd0f63572f01b2ea3b547459992638816464 100644 --- a/parser.src/DataTree.cc +++ b/parser.src/DataTree.cc @@ -15,8 +15,8 @@ using namespace std; #include <time.h> //------------------------------------------------------------------------------ +#include "DynareBison.h" #include "VariableTable.h" -#include "d_tab.h" #include "NumericalConstants.h" #include "DataTree.h" //------------------------------------------------------------------------------ diff --git a/parser.src/DynareBison.yy b/parser.src/DynareBison.yy index 6c5899530f1a9a86de706c3fa7ec76018649c9f2..fefc53a9f36d8a5e56cc5d493449e64100c9a7bd 100644 --- a/parser.src/DynareBison.yy +++ b/parser.src/DynareBison.yy @@ -13,7 +13,7 @@ #define YYERROR_VERBOSE #define YLMM_PARSER_CLASS dynare::parser #define YLMM_LEX_STATIC -#include "yaccmm.h" +#include "ylmm/yaccmm.hh" #ifdef yyerror #undef yyerror #define yyerror _parser->error @@ -21,22 +21,29 @@ %} /* %pure_parser */ -%token SIGMA_E INITVAL ENDVAL HISTVAL SHOCKS VALUES STDERR CORR MODEL END -%token VAR VAREXO VAREXO_DET PARAMETER PERIODS -%token NAME TEX_NAME INT_NUMBER FLOAT_NUMBER EQUAL -%token DR_ALGO SOLVE_ALGO STOCH_SIMUL STEADY SIMUL CHECK -%token ORDER NOFUNCTIONS REPLIC DROP IRF AR LINEAR HP_FILTER NOCORR SIMUL_SEED USE_DLL -%token HP_NGRID HP_NGRIDDR_ALGO SIMUL_ALGO QZ_CRITERIUM NOMOMENTS -%token VAROBS ESTIMATION OBSERVATION_TRENDS UNIT_ROOT_VARS -%token PERC DATAFILE NOBS FIRST_OBS -%token MH_REPLIC MH_DROP -%token MH_JSCALE OPTIM MH_INIT_SCALE MODE_FILE MODE_COMPUTE MODE_CHECK -%token PRIOR_TRUNC MH_MODE MH_NBLOCKS LOAD_MH_FILE LOGLINEAR -%token NODIAGNOSTIC NOGRAPH PRESAMPLE CONF_SIG LIK_INIT PREFILTER LIK_ALGO -%token ESTIMATED_PARAMS GAMMA_PDF BETA_PDF NORMAL_PDF INV_GAMMA_PDF UNIFORM_PDF -%token INV_GAMMA1_PDF INV_GAMMA2_PDF -%token KALMAN_ALGO KALMAN_TOL FORECAST SMOOTHER BAYESIAN_IRF MOMENTS_VARENDO -%token FILTERED_VARS RELATIVE_IRF TEX +%token AR AUTOCORR +%token BAYESIAN_IRF BETA_PDF +%token CALIB CALIB_VAR CHECK CONF_SIG CORR COVAR +%token DATAFILE DIAGNOSTIC DIFFUSE_D DOLLAR DR_ALGO DROP DSAMPLE DYN2VEC DYNASAVE DYNATYPE +%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT +%token FILTERED_VARS FIRST_OBS FLOAT_NUMBER FORECAST FUNCTIONS +%token GAMMA_PDF GRAPH +%token HISTVAL HP_FILTER HP_NGRID +%token INITVAL INITVALF INT_NUMBER INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF +%token KALMAN_ALGO KALMAN_TOL +%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR +%token MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_COMPARISON_APPROXIMATION MODIFIEDHARMONICMEAN MOMENTS MOMENTS_VARENDO MSHOCKS +%token NAME NK NOBS NOCORR NODIAGNOSTIC NOFUNCTIONS NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF +%token OBSERVATION_TRENDS OLR OLR_INST OLR_BETA OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS +%token PARAMETERS PERIODS PREFILTER PRESAMPLE PRINT PRIOR_TRUNC +%token QZ_CRITERIUM +%token RELATIVE_IRF REPLIC RESOL RPLOT +%token SHOCKS SHOCK_SIZE SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO STDERR STEADY STOCH_SIMUL +%token TEX TEX_NAME +%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL +%token VALUES VAR VAREXO VAREXO_DET VAROBS +%token XTICK XTICKLABEL +%left COMMA %left PLUS MINUS %left TIMES DIVIDE %left UMINUS @@ -47,8 +54,8 @@ statement_list : statement - | statement_list statement - ; + | statement_list statement + ; statement : declaration @@ -66,10 +73,11 @@ | stoch_simul | estimation | estimated_params + | estimated_params_bounds + | estimated_params_init | varobs | observation_trends | unit_root_vars - /* | dsample | rplot | optim_weights @@ -81,7 +89,7 @@ | dynasave | olr | olr_inst - */ + | model_comparison ; @@ -93,6 +101,12 @@ ; + dsample : DSAMPLE INT_NUMBER ';' {_parser->option_num("dsample",$2);} + | DSAMPLE INT_NUMBER INT_NUMBER ';' {_parser->option_num("dsample",$2,$3);} + ; + + rplot : RPLOT tmp_var_list ';' {_parser->rplot();} + ; var : VAR var_list ';' ; @@ -106,19 +120,19 @@ ; parameters - : PARAMETER parameter_list ';' + : PARAMETERS parameter_list ';' ; var_list : var_list NAME {$$ = _parser->add_endogenous($2);} - | var_list ',' NAME + | var_list COMMA NAME {$$ = _parser->add_endogenous($3);} | NAME {$$ = _parser->add_endogenous($1);} | var_list NAME TEX_NAME {$$ = _parser->add_endogenous($2,$3);} - | var_list ',' NAME TEX_NAME + | var_list COMMA NAME TEX_NAME {$$ = _parser->add_endogenous($3,$4);} | NAME TEX_NAME {$$ = _parser->add_endogenous($1,$2);} @@ -127,13 +141,13 @@ varexo_list : varexo_list NAME {$$ = _parser->add_exogenous($2);} - | varexo_list ',' NAME + | varexo_list COMMA NAME {$$ = _parser->add_exogenous($3);} | NAME {$$ = _parser->add_exogenous($1);} | varexo_list NAME TEX_NAME {$$ = _parser->add_exogenous($2, $3);} - | varexo_list ',' NAME TEX_NAME + | varexo_list COMMA NAME TEX_NAME {$$ = _parser->add_exogenous($3, $4);} | NAME TEX_NAME {$$ = _parser->add_exogenous($1, $2);} @@ -142,13 +156,13 @@ varexo_det_list : varexo_det_list NAME {$$ = _parser->add_exogenous_det($2);} - | varexo_det_list ',' NAME + | varexo_det_list COMMA NAME {$$ = _parser->add_exogenous_det($3);} | NAME {$$ = _parser->add_exogenous_det($1);} | varexo_det_list NAME TEX_NAME {$$ = _parser->add_exogenous_det($2, $3);} - | varexo_det_list ',' NAME TEX_NAME + | varexo_det_list COMMA NAME TEX_NAME {$$ = _parser->add_exogenous_det($3, $4);} | NAME TEX_NAME {$$ = _parser->add_exogenous_det($1, $2);} @@ -157,13 +171,13 @@ parameter_list : parameter_list NAME {$$ = _parser->add_parameter($2);} - | parameter_list ',' NAME + | parameter_list COMMA NAME {$$ = _parser->add_parameter($3);} | NAME {$$ = _parser->add_parameter($1);} | parameter_list NAME TEX_NAME {$$ = _parser->add_parameter($2, $3);} - | parameter_list ',' NAME TEX_NAME + | parameter_list COMMA NAME TEX_NAME {$$ = _parser->add_parameter($3,$4);} | NAME TEX_NAME {$$ = _parser->add_parameter($1, $2);} @@ -233,8 +247,15 @@ {$$ = _parser->add_expression_token($3, $1);} | SQRT '(' expression ')' {$$ = _parser->add_expression_token($3, $1);} + | NAME '(' expression ')' + {$$ = _parser->add_expression_token($3, $1);} + | NAME '(' comma_expression ')' + {$$ = _parser->add_expression_token($3, $1);} ; - + + comma_expression : expression COMMA expression {$$ = _parser->add_expression_token($1,$3,$2);} + | comma_expression COMMA expression {$$ = _parser->add_expression_token($1,$3,$2);} + initval : INITVAL ';' {_parser->begin_initval();} initval_list END ';' {_parser->end_initval();} @@ -357,9 +378,9 @@ {_parser->add_stderr_shock($2, $6);} | VAR NAME EQUAL expression {$$ = _parser->get_expression($4);} ';' {_parser->add_var_shock($2, $5);} - | VAR NAME ',' NAME EQUAL expression {$$ = _parser->get_expression($6);} ';' + | VAR NAME COMMA NAME EQUAL expression {$$ = _parser->get_expression($6);} ';' {_parser->add_covar_shock($2, $4, $7);} - | CORR NAME ',' NAME EQUAL expression {$$ = _parser->get_expression($6);} ';' + | CORR NAME COMMA NAME EQUAL expression {$$ = _parser->get_expression($6);} ';' {_parser->add_correl_shock($2, $4, $7);} ; @@ -368,9 +389,9 @@ {_parser->add_period($2);} | period_list INT_NUMBER ':' INT_NUMBER {_parser->add_period($2,$4);} - | period_list ',' INT_NUMBER + | period_list COMMA INT_NUMBER {_parser->add_period($3);} - | period_list ',' INT_NUMBER ':' INT_NUMBER + | period_list COMMA INT_NUMBER ':' INT_NUMBER {_parser->add_period($3,$5);} | INT_NUMBER ':' INT_NUMBER {_parser->add_period($1,$3);} @@ -411,11 +432,11 @@ ; triangular_row - : triangular_row ',' '(' expression {$$ = _parser->get_expression($4);} ')' + : triangular_row COMMA '(' expression {$$ = _parser->get_expression($4);} ')' {_parser->add_to_row($5);} - | triangular_row ',' FLOAT_NUMBER + | triangular_row COMMA FLOAT_NUMBER {_parser->add_to_row($3);} - | triangular_row ',' INT_NUMBER + | triangular_row COMMA INT_NUMBER {_parser->add_to_row($3);} | triangular_row '(' expression {$$ = _parser->get_expression($3);} ')' {_parser->add_to_row($4);} @@ -441,7 +462,7 @@ {_parser->steady();} ; - steady_options_list : steady_options_list ',' steady_options + steady_options_list : steady_options_list COMMA steady_options | steady_options ; @@ -455,7 +476,7 @@ {_parser->check();} ; - check_options_list : check_options_list ',' check_options + check_options_list : check_options_list COMMA check_options | check_options ; @@ -469,7 +490,7 @@ {_parser->simul();} ; - simul_options_list: simul_options_list ',' simul_options + simul_options_list: simul_options_list COMMA simul_options | simul_options ; @@ -487,7 +508,7 @@ {_parser->stoch_simul();} ; - stoch_simul_options_list: stoch_simul_options_list ',' stoch_simul_options + stoch_simul_options_list: stoch_simul_options_list COMMA stoch_simul_options | stoch_simul_options ; @@ -517,9 +538,9 @@ {_parser->add_tmp_var($2);} | tmp_var_list NAME EQUAL NAME {_parser->add_tmp_var($2,$4);} - | tmp_var_list ',' NAME + | tmp_var_list COMMA NAME {_parser->add_tmp_var($3);} - | tmp_var_list ',' NAME EQUAL NAME + | tmp_var_list COMMA NAME EQUAL NAME {_parser->add_tmp_var($3,$5);} | NAME {_parser->add_tmp_var($1);} @@ -557,7 +578,7 @@ ; estimated_elem - : estimated_elem1 ',' estimated_elem2 ';' + : estimated_elem1 COMMA estimated_elem2 ';' ; estimated_elem1 @@ -569,16 +590,21 @@ {_parser->estim_params.type = 2; _parser->estim_params.name = *$1; } + | CORR NAME COMMA NAME + {_parser->estim_params.type = 3; + _parser->estim_params.name = *$2; + _parser->estim_params.name2 = *$4; + } ; estimated_elem2 - : prior ',' estimated_elem3 + : prior COMMA estimated_elem3 {_parser->estim_params.prior=*$1;} - | value ',' prior ',' estimated_elem3 + | value COMMA prior COMMA estimated_elem3 {_parser->estim_params.init_val=*$1; _parser->estim_params.prior=*$3; } - | value ',' value ',' value ',' prior ',' estimated_elem3 + | value COMMA value COMMA value COMMA prior COMMA estimated_elem3 {_parser->estim_params.init_val=*$1; _parser->estim_params.low_bound=*$3; _parser->estim_params.up_bound=*$5; @@ -586,7 +612,7 @@ } | value {_parser->estim_params.init_val=*$1;} - | value ',' value ',' value + | value COMMA value COMMA value {_parser->estim_params.init_val=*$1; _parser->estim_params.low_bound=*$3; _parser->estim_params.up_bound=*$5; @@ -594,17 +620,17 @@ ; estimated_elem3 - : value ',' value + : value COMMA value {_parser->estim_params.mean=*$1; _parser->estim_params.std=*$3; } - | value ',' value ',' value ',' value + | value COMMA value COMMA value COMMA value {_parser->estim_params.mean=*$1; _parser->estim_params.std=*$3; _parser->estim_params.p3=*$5; _parser->estim_params.p4=*$7; } - | value ',' value ',' value ',' value ',' value + | value COMMA value COMMA value COMMA value COMMA value {_parser->estim_params.mean=*$1; _parser->estim_params.std=*$3; _parser->estim_params.p3=*$5; @@ -613,6 +639,59 @@ } ; + estimated_params_init: ESTIMATED_PARAMS_INIT ';' estimated_init_list END + ; + + estimated_init_list : estimated_init_list estimated_init_elem + | estimated_init_elem + ; + + estimated_init_elem : STDERR NAME COMMA value ';' + {_parser->estim_params.type = 1; + _parser->estim_params.name = *$2; + _parser->estim_params.init_val=*$4; + } + | CORR NAME COMMA NAME COMMA value ';' + {_parser->estim_params.type = 3; + _parser->estim_params.name = *$2; + _parser->estim_params.name2 = *$4; + _parser->estim_params.init_val=*$6; + } + | NAME COMMA value ';' + {_parser->estim_params.type = 2; + _parser->estim_params.name = *$1; + _parser->estim_params.init_val=*$3; + } + ; + + estimated_params_bounds: ESTIMATED_PARAMS_BOUNDS ';' estimated_bounds_list END + ; + + estimated_bounds_list : estimated_bounds_list estimated_bounds_elem + | estimated_bounds_elem + ; + + estimated_bounds_elem : STDERR NAME COMMA value COMMA value ';' + {_parser->estim_params.type = 1; + _parser->estim_params.name = *$2; + _parser->estim_params.low_bound=*$4; + _parser->estim_params.up_bound=*$6; + } + | CORR NAME COMMA NAME COMMA value COMMA value ';' + {_parser->estim_params.type = 3; + _parser->estim_params.name = *$2; + _parser->estim_params.name2 = *$4; + _parser->estim_params.low_bound=*$6; + _parser->estim_params.up_bound=*$8; + } + | NAME COMMA value COMMA value ';' + {_parser->estim_params.type = 2; + _parser->estim_params.name = *$1; + _parser->estim_params.low_bound=*$3; + _parser->estim_params.up_bound=*$5; + } + ; + prior : BETA_PDF {$$ = new dynare::Objects("1");} @@ -650,7 +729,7 @@ ; estimation_options_list - : estimation_options_list ',' estimation_options + : estimation_options_list COMMA estimation_options | estimation_options ; @@ -688,13 +767,13 @@ ; list_optim_option - : '\'' NAME '\'' ',' '\'' NAME '\'' {_parser->optim_options($2,$6,2);} - | '\'' NAME '\'' ',' value {_parser->optim_options($2,$5,2);} + : '\'' NAME '\'' COMMA '\'' NAME '\'' {_parser->optim_options($2,$6,2);} + | '\'' NAME '\'' COMMA value {_parser->optim_options($2,$5,2);} ; optim_options : list_optim_option - | optim_options ',' list_optim_option; + | optim_options COMMA list_optim_option; ; varobs @@ -717,6 +796,106 @@ unit_root_vars : UNIT_ROOT_VARS tmp_var_list ';' {_parser->set_unit_root_vars();} ; + optim_weights : OPTIM_WEIGHTS ';' {_parser->begin_optim_weights();} optim_weights_list END + ; + + optim_weights_list : optim_weights_list NAME expression {$$=_parser->get_expression($3);} ';' {_parser->set_optim_weights($2, $4);} + | optim_weights_list NAME COMMA NAME expression {$$=_parser->get_expression($3);} ';' {_parser->set_optim_weights($2, $4, $6);} + | NAME expression {$$=_parser->get_expression($2);} ';' {_parser->set_optim_weights($1, $3);} + | NAME COMMA NAME expression {$$=_parser->get_expression($3);} ';' {_parser->set_optim_weights($1, $3, $5);} + ; + + osr_params : OSR_PARAMS tmp_var_list ';' {_parser->set_osr_params();} + ; + + osr : OSR ';' {_parser->run_osr();} + | OSR '(' olr_options ')' ';' {_parser->run_osr();} + | OSR tmp_var_list ';' {_parser->run_osr();} + | OSR '(' olr_options ')' tmp_var_list ';' {_parser->run_osr();} + ; + + olr : OLR ';' {_parser->run_olr();} + | OLR '(' olr_options ')' ';' {_parser->run_olr();} + | OLR tmp_var_list ';' {_parser->run_olr();} + | OLR '(' olr_options ')' tmp_var_list ';' {_parser->run_olr();} + ; + + olr_option : o_olr_beta + | stoch_simul_options_list + ; + + olr_options : olr_option + | olr_options COMMA olr_option + ; + + olr_inst : OLR_INST tmp_var_list ';' {_parser->set_olr_inst();} + ; + + calib_var : CALIB_VAR ';' {_parser->begin_calib_var();} calib_var_list END + ; + + calib_var_list : calib_var_list calib_arg1 + | calib_arg1 + ; + + calib_arg1 : NAME calib_arg2 EQUAL expression ';' {_parser->set_calib_var($1,$2,$4);} + | NAME COMMA NAME calib_arg2 EQUAL expression ';' {_parser->set_calib_var($1,$3,$4,$6);} + | AUTOCORR NAME '(' INT_NUMBER ')' calib_arg2 EQUAL expression ';' {_parser->set_calib_ac($2,$4,$6,$8);} + ; + + calib_arg2 : {$$ = new dynare::Objects("1");} + | '(' INT_NUMBER ')' {$$ = $2;} + | '(' FLOAT_NUMBER ')' {$$ = $2;} + ; + + calib : CALIB ';' {_parser->run_calib(0);} + | CALIB '(' COVAR ')' ';' {_parser->run_calib(1);} + ; + + dynatype : DYNATYPE '(' NAME ')'';' {_parser->run_dynatype($3);} + | DYNATYPE '(' NAME ')' tmp_var_list ';' {_parser->run_dynatype($3);} + | DYNATYPE NAME ';' {_parser->run_dynatype($2);} + | DYNATYPE '(' NAME '.' NAME ')'';' {_parser->run_dynatype($3,$5);} + | DYNATYPE '(' NAME '.' NAME ')' tmp_var_list ';' {_parser->run_dynatype($3,$5);} + | DYNATYPE NAME '.' NAME ';' {_parser->run_dynatype($2,$4);}; + + dynasave : DYNASAVE '(' NAME ')'';' {_parser->run_dynasave($3);} + | DYNASAVE '(' NAME ')' tmp_var_list ';' {_parser->run_dynasave($3);} + | DYNASAVE NAME ';' {_parser->run_dynasave($2);} + | DYNASAVE '(' NAME '.' NAME ')'';' {_parser->run_dynasave($3,$5);} + | DYNASAVE '(' NAME '.' NAME ')' tmp_var_list ';' {_parser->run_dynasave($3,$5);} + | DYNASAVE NAME '.' NAME ';' {_parser->run_dynasave($2,$4);}; + + model_comparison : MODEL_COMPARISON '(' model_comparison_options ')' {_parser->begin_model_comparison();} + filename_list ';' {_parser->run_model_comparison();} + ; + + model_comparison_options: model_comparison_options ',' model_comparison_option + | model_comparison_option + ; + + model_comparison_option : o_model_comparison_approximation + | o_print + | o_noprint + ; + + filename_list : filename {_parser->add_mc_filename($1);} + | filename_list ',' filename {_parser->add_mc_filename($3);} + | filename '(' value ')' {_parser->add_mc_filename($1,$3);} + | filename_list ',' filename '(' value ')' {_parser->add_mc_filename($3,$5);} + ; + + filename : filename_elem {$$=$1;} + | filename filename_elem {$$ = _parser->cat($1,$2);} + ; + + filename_elem : NAME + | '\\' {$$ = new dynare::Objects("\\");} + | '/' {$$ = new dynare::Objects("/");} + | ':' {$$ = new dynare::Objects(":");} + | '.' {$$ = new dynare::Objects(".");} + ; + o_dr_algo: DR_ALGO EQUAL INT_NUMBER {_parser->option_num("dr_algo",$3);}; o_solve_algo: SOLVE_ALGO EQUAL INT_NUMBER {_parser->option_num("solve_algo",$3);}; o_simul_algo: SIMUL_ALGO EQUAL INT_NUMBER {_parser->option_num("simul_algo",$3);}; @@ -770,5 +949,12 @@ o_relative_irf : RELATIVE_IRF {_parser->option_num("relative_irf","1");}; o_kalman_algo : KALMAN_ALGO EQUAL INT_NUMBER {_parser->option_num("kalman_algo",$3);}; o_kalman_tol : KALMAN_TOL EQUAL INT_NUMBER {_parser->option_num("kalman_tol",$3);}; + o_olr_beta: OLR_BETA EQUAL value {_parser->option_num("olr_beta",$3);}; + o_model_comparison_approximation: MODEL_COMPARISON_APPROXIMATION EQUAL LAPLACE {dynare::Objects* tmp = new dynare::Objects("Laplace");_parser->option_str("model_comparison_approximation",tmp);} + | MODEL_COMPARISON_APPROXIMATION EQUAL MODIFIEDHARMONICMEAN {dynare::Objects* tmp = new dynare::Objects("MODIFIEDHARMONICMEAN");_parser->option_str("model_comparison_approximation",tmp);} + ; + o_print : PRINT {_parser->option_num("noprint","0");}; + o_noprint : NOPRINT {_parser->option_num("noprint","1");}; + o_nograph : GRAPH {_parser->option_num("nograph","0");}; + %% - diff --git a/parser.src/DynareFlex.ll b/parser.src/DynareFlex.ll index 1c435df4d1efb5307bf295f74b9c24663c3e7e09..903081fd328a2f2f708356d152cb4cf6f6c647cd 100644 --- a/parser.src/DynareFlex.ll +++ b/parser.src/DynareFlex.ll @@ -1,4 +1,5 @@ %{ +#define YY_BUF_SIZE 1000000 #include <unistd.h> #include <string.h> #include "DynareScanner.h" @@ -8,7 +9,8 @@ #define YLMM_SCANNER_CLASS dynare::scanner #define LEXDEBUG 1 #define FINISH 0 -#include "lexmm.h" +#define YY_READ_BUF_SIZE 1000000 +#include "ylmm/lexmm.hh" int lineno = 1; int comment_caller; /* Particular value : when sigma_e command is found @@ -43,16 +45,28 @@ int sigma_e = 0; <INITIAL>var {BEGIN DYNARE_STATEMENT; return VAR;} <INITIAL>varexo {BEGIN DYNARE_STATEMENT; return VAREXO;} <INITIAL>varexo_det {BEGIN DYNARE_STATEMENT; return VAREXO_DET;} -<INITIAL>parameters {BEGIN DYNARE_STATEMENT; return PARAMETER;} +<INITIAL>parameters {BEGIN DYNARE_STATEMENT; return PARAMETERS;} <INITIAL>periods {BEGIN DYNARE_STATEMENT; return PERIODS;} +<INITIAL>initvalf {BEGIN DYNARE_STATEMENT; return INITVALF;} <INITIAL>estimation {BEGIN DYNARE_STATEMENT; return ESTIMATION;} <INITIAL>varobs {BEGIN DYNARE_STATEMENT; return VAROBS;} <INITIAL>unit_root_vars {BEGIN DYNARE_STATEMENT; return UNIT_ROOT_VARS;} +<INITIAL>dyn2vec {BEGIN DYNARE_STATEMENT; return DYN2VEC;} +<INITIAL>rplot {BEGIN DYNARE_STATEMENT; return RPLOT;} +<INITIAL>osr_params {BEGIN DYNARE_STATEMENT; return OSR_PARAMS;} +<INITIAL>osr {BEGIN DYNARE_STATEMENT; return OSR;} +<INITIAL>calib_var {BEGIN DYNARE_STATEMENT; return CALIB_VAR;} +<INITIAL>dynatype {BEGIN DYNARE_STATEMENT; return DYNATYPE;} +<INITIAL>dynasave {BEGIN DYNARE_STATEMENT; return DYNASAVE;} +<INITIAL>olr {BEGIN DYNARE_STATEMENT; return OLR;} +<INITIAL>olr_inst {BEGIN DYNARE_STATEMENT; return OLR_INST;} +<INITIAL>model_comparison {BEGIN DYNARE_STATEMENT; return MODEL_COMPARISON;} <INITIAL>steady {BEGIN DYNARE_STATEMENT; return STEADY;} <INITIAL>check {BEGIN DYNARE_STATEMENT; return CHECK;} <INITIAL>simul {BEGIN DYNARE_STATEMENT; return SIMUL;} <INITIAL>stoch_simul {BEGIN DYNARE_STATEMENT; return STOCH_SIMUL;} +<INITIAL>dsample {BEGIN DYNARE_STATEMENT; return DSAMPLE;} <INITIAL>Sigma_e {BEGIN DYNARE_STATEMENT;sigma_e = 1; return SIGMA_E;} /* End of a Dynare statement */ @@ -66,7 +80,10 @@ int sigma_e = 0; <INITIAL>histval {BEGIN DYNARE_BLOCK;return HISTVAL;} <INITIAL>shocks {BEGIN DYNARE_BLOCK;return SHOCKS;} <INITIAL>estimated_params {BEGIN DYNARE_BLOCK;return ESTIMATED_PARAMS;} +<INITIAL>estimated_params_init {BEGIN DYNARE_BLOCK;return ESTIMATED_PARAMS_INIT;} +<INITIAL>estimated_params_bounds {BEGIN DYNARE_BLOCK;return ESTIMATED_PARAMS_BOUNDS;} <INITIAL>observation_trends {BEGIN DYNARE_BLOCK;return OBSERVATION_TRENDS;} +<INITIAL>optim_weights {BEGIN DYNARE_BLOCK;return OPTIM_WEIGHTS;} /* End of a Dynare block */ <DYNARE_BLOCK>end {BEGIN INITIAL;return END;} @@ -79,11 +96,14 @@ int sigma_e = 0; <DYNARE_STATEMENT>presample {return PRESAMPLE;} <DYNARE_STATEMENT>lik_algo {return LIK_ALGO;} <DYNARE_STATEMENT>lik_init {return LIK_INIT;} +<DYNARE_STATEMENT>graph {return GRAPH;} <DYNARE_STATEMENT>nograph {return NOGRAPH;} +<DYNARE_STATEMENT>print {return PRINT;} +<DYNARE_STATEMENT>noprint {return NOPRINT;} <DYNARE_STATEMENT>conf_sig {return CONF_SIG;} <DYNARE_STATEMENT>mh_replic {return MH_REPLIC;} <DYNARE_STATEMENT>mh_drop {return MH_DROP;} -<DYNARE_STATEMENT>mh_jscale {return MH_JSCALE;} +<DYNARE_STATEMENT>mh_jscale {return MH_JSCALE;} <DYNARE_STATEMENT>mh_init_scale {return MH_INIT_SCALE;} <DYNARE_STATEMENT>mode_file {return MODE_FILE;} <DYNARE_STATEMENT>mode_compute {return MODE_COMPUTE;} @@ -103,6 +123,17 @@ int sigma_e = 0; <DYNARE_STATEMENT>filtered_vars {return FILTERED_VARS;} <DYNARE_STATEMENT>relative_irf {return RELATIVE_IRF;} <DYNARE_STATEMENT>tex {return TEX;} +<DYNARE_STATEMENT>shock_size {return SHOCK_SIZE;} +<DYNARE_STATEMENT>moments {return MOMENTS;} +<DYNARE_STATEMENT>nomoments {return NOMOMENTS;} +<DYNARE_STATEMENT>corr {return CORR;} +<DYNARE_STATEMENT>nocorr {return NOCORR;} +<DYNARE_STATEMENT>optim {return OPTIM;} +<DYNARE_STATEMENT>diffuse_d {return DIFFUSE_D;} +<DYNARE_STATEMENT>nk {return NK;} +<DYNARE_STATEMENT>model_comparison_approximation {return MODEL_COMPARISON;} +<DYNARE_STATEMENT>laplace {return LAPLACE;} +<DYNARE_STATEMENT>modifiedharmonicmean {return MODIFIEDHARMONICMEAN;} <DYNARE_STATEMENT>[\$][^$]*[\$] { strtok(yytext+1,"$"); @@ -122,34 +153,38 @@ int sigma_e = 0; <DYNARE_BLOCK>inv_gamma_pdf {return INV_GAMMA_PDF;} <DYNARE_BLOCK>inv_gamma1_pdf {return INV_GAMMA_PDF;} <DYNARE_BLOCK>inv_gamma2_pdf {return INV_GAMMA_PDF;} -<DYNARE_BLOCK>unif_pdf {return UNIFORM_PDF;} +<DYNARE_BLOCK>uniform_pdf {return UNIFORM_PDF;} <DYNARE_BLOCK>corr {return CORR;} <DYNARE_BLOCK>; {return yytext[0];} - /* Inside Dynare block or statement */ -<DYNARE_STATEMENT,DYNARE_BLOCK>solve_algo {return SOLVE_ALGO;} -<DYNARE_STATEMENT,DYNARE_BLOCK>dr_algo {return DR_ALGO;} -<DYNARE_STATEMENT,DYNARE_BLOCK>simul_algo {return SIMUL_ALGO;} -<DYNARE_STATEMENT,DYNARE_BLOCK>solve_algo {return SOLVE_ALGO;} -<DYNARE_STATEMENT,DYNARE_BLOCK>drop {return DROP;} -<DYNARE_STATEMENT,DYNARE_BLOCK>order {return ORDER;} -<DYNARE_STATEMENT,DYNARE_BLOCK>replic {return REPLIC;} -<DYNARE_STATEMENT,DYNARE_BLOCK>nomoments {return NOMOMENTS;} -<DYNARE_STATEMENT,DYNARE_BLOCK>nocorr {return NOCORR;} -<DYNARE_STATEMENT,DYNARE_BLOCK>ar {return AR;} -<DYNARE_STATEMENT,DYNARE_BLOCK>nofunctions {return NOFUNCTIONS;} -<DYNARE_STATEMENT,DYNARE_BLOCK>irf {return IRF;} -<DYNARE_STATEMENT,DYNARE_BLOCK>hp_filter {return HP_FILTER;} -<DYNARE_STATEMENT,DYNARE_BLOCK>hp_ngrid {return HP_NGRID;} -<DYNARE_STATEMENT,DYNARE_BLOCK>simul_seed {return SIMUL_SEED;} -<DYNARE_STATEMENT,DYNARE_BLOCK>qz_criterium {return QZ_CRITERIUM;} + /* Inside Dynare statement */ +<DYNARE_STATEMENT>solve_algo {return SOLVE_ALGO;} +<DYNARE_STATEMENT>dr_algo {return DR_ALGO;} +<DYNARE_STATEMENT>simul_algo {return SIMUL_ALGO;} +<DYNARE_STATEMENT>solve_algo {return SOLVE_ALGO;} +<DYNARE_STATEMENT>drop {return DROP;} +<DYNARE_STATEMENT>order {return ORDER;} +<DYNARE_STATEMENT>replic {return REPLIC;} +<DYNARE_STATEMENT>nomoments {return NOMOMENTS;} +<DYNARE_STATEMENT>nocorr {return NOCORR;} +<DYNARE_STATEMENT>ar {return AR;} +<DYNARE_STATEMENT>nofunctions {return NOFUNCTIONS;} +<DYNARE_STATEMENT>irf {return IRF;} +<DYNARE_STATEMENT>hp_filter {return HP_FILTER;} +<DYNARE_STATEMENT>hp_ngrid {return HP_NGRID;} +<DYNARE_STATEMENT>simul_seed {return SIMUL_SEED;} +<DYNARE_STATEMENT>qz_criterium {return QZ_CRITERIUM;} +<DYNARE_STATEMENT>simul {return SIMUL;} +<DYNARE_STATEMENT>autocorr {return AUTOCORR;} +<DYNARE_STATEMENT>olr_beta {return OLR_BETA;} +<DYNARE_STATEMENT>xtick {return XTICK;} +<DYNARE_STATEMENT>xticklabel {return XTICKLABEL;} + <DYNARE_STATEMENT,DYNARE_BLOCK>use_dll {return USE_DLL;} <DYNARE_STATEMENT,DYNARE_BLOCK>linear {return LINEAR;} -<DYNARE_STATEMENT,DYNARE_BLOCK>simul {return SIMUL;} - -<DYNARE_STATEMENT,DYNARE_BLOCK>[,] {return yytext[0];} +<DYNARE_STATEMENT,DYNARE_BLOCK>[,] {_scanner->do_operator(COMMA); return COMMA;} <DYNARE_STATEMENT,DYNARE_BLOCK>[\(\)] {return yytext[0];} <DYNARE_STATEMENT,DYNARE_BLOCK>[\[] {return yytext[0];} <DYNARE_STATEMENT,DYNARE_BLOCK>[\]] {if (sigma_e) sigma_e=0; return yytext[0];} diff --git a/parser.src/DynareParser.cc b/parser.src/DynareParser.cc index f134c63215faaebd51d95e7c95ca99a946da5f41..4264a9c9b6e2199a811090586139509c8cdbc2e0 100644 --- a/parser.src/DynareParser.cc +++ b/parser.src/DynareParser.cc @@ -33,28 +33,29 @@ void dynare::parser::setoutput(ostringstream* ostr) dynare::Objects* dynare::parser::add_endogenous(Objects* obj, Objects* tex_name) { - //cout << "add_endogenous \n"; - obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eEndogenous, tex_name->symbol); - obj->type = eEndogenous; - return (obj); + //cout << "add_endogenous \n"; + + obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eEndogenous, tex_name->symbol); + obj->type = eEndogenous; + return (obj); } dynare::Objects* dynare::parser::add_exogenous(Objects* obj, Objects* tex_name) { - obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eExogenous, tex_name->symbol); - obj->type = eExogenous; - return (obj); + obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eExogenous, tex_name->symbol); + obj->type = eExogenous; + return (obj); } dynare::Objects* dynare::parser::add_exogenous_det(Objects* obj, Objects* tex_name) { - obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eExogenousDet, tex_name->symbol); - obj->type = eExogenousDet; - return (obj); + obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eExogenousDet, tex_name->symbol); + obj->type = eExogenousDet; + return (obj); } dynare::Objects* dynare::parser::add_parameter(Objects* obj, Objects* tex_name) { - obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eParameter, tex_name->symbol); - obj->type = eParameter; - return (obj); + obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eParameter, tex_name->symbol); + obj->type = eParameter; + return (obj); } dynare::Objects* dynare::parser::add_constant(Objects* obj) { @@ -146,11 +147,20 @@ dynare::Objects* dynare::parser::add_expression_token( Objects* arg1, Objects* } dynare::Objects* dynare::parser::add_expression_token( Objects* arg1, Objects* op) { - - int id = expression.AddToken((int) arg1->ID,arg1->type, + int id; + if (op->opcode != NAME) + { + id = expression.AddToken((int) arg1->ID,arg1->type, op->opcode); - //cout << "after add_expression_token\n"; - return new Objects("", (NodeID) id, eTempResult); + } + else + { + id = expression.AddToken((int) arg1->ID,arg1->type, + op->symbol); + } + + //cout << "after add_expression_token\n"; + return new Objects("", (NodeID) id, eTempResult); } dynare::Objects* dynare::parser::get_expression(Objects* exp) { @@ -164,6 +174,12 @@ dynare::Objects* dynare::parser::get_expression(Objects* exp) else return exp; } +dynare::Objects* dynare::parser::cat(Objects* string1, Objects* string2) +{ + dynare::Objects* result = new dynare::Objects; + result->symbol = string1->symbol+string2->symbol; + return result; +} void dynare::parser::init_param(Objects* lhs, Objects* rhs) { numerical_initialization.SetConstant(lhs->symbol, rhs->symbol); @@ -203,67 +219,47 @@ void dynare::parser::check_model(void) void dynare::parser::finish(void) { - string model_file_name(file_name); + string model_file_name(file_name); - // Setting flags to compute what is necessary - if (order == 1 || linear == 1) - { - model_tree.computeJacobianExo = true; - model_tree.computeJacobian = false; - } - else if (order != -1 && linear != -1) - { - model_tree.computeHessian = true; - model_tree.computeJacobianExo = true; - } - // Removing extension chars - model_file_name.erase(model_file_name.size()-4,4); - model_tree.ModelInitialization(); + // Setting flags to compute what is necessary + if (order == 1 || linear == 1) + { + model_tree.computeJacobianExo = true; + model_tree.computeJacobian = false; + } + else if (order != -1 && linear != -1) + { + model_tree.computeHessian = true; + model_tree.computeJacobianExo = true; + } + // Removing extension chars + model_file_name.erase(model_file_name.size()-4,4); + model_tree.ModelInitialization(); - - if ((model_tree.computeJacobian || model_tree.computeJacobianExo) && - !model_tree.computeHessian) - { - model_tree.derive(1); - cout << "Processing outputs ...\n"; - if (model_tree.offset == 0) - { - model_tree.setStaticModelC(); - } - else - { - model_tree.setStaticModelM(); - } - } - else if (model_tree.computeHessian) - { - model_tree.derive(2); - cout << "Processing outputs ...\n"; - if (model_tree.offset == 0) - { - model_tree.setStaticModelC(); - } - else - { - model_tree.setStaticModelM(); - } - } + if ( model_tree.computeHessian ) + { + model_tree.derive(2); + } + else + { + model_tree.derive(1); + } - if (model_tree.computeJacobian || model_tree.computeJacobianExo || model_tree.computeHessian) - { - if (model_tree.offset == 0) - { - model_tree.setDynamicModelC(); - model_tree.OpenCFiles(model_file_name+"_static", model_file_name+"_dynamic"); - model_tree.SaveCFiles(); - } - else - { - model_tree.setDynamicModelM(); - model_tree.OpenMFiles(model_file_name+"_static", model_file_name+"_dynamic"); - model_tree.SaveMFiles(); - } - } + cout << "Processing outputs ...\n"; + model_tree.setStaticModel(); + model_tree.setDynamicModel(); + + if (model_tree.offset == 0) + { + model_tree.OpenCFiles(model_file_name+"_static", model_file_name+"_dynamic"); + model_tree.SaveCFiles(); + } + else + { + model_tree.OpenMFiles(model_file_name+"_static", model_file_name+"_dynamic"); + model_tree.SaveMFiles(); + } + } void dynare::parser::begin_initval(void) @@ -389,6 +385,10 @@ void dynare::parser::option_num(string name_option, Objects* opt) else if (name_option == "linear") linear = atoi((opt->symbol).c_str()); } +void dynare::parser::option_num(string name_option, Objects* opt1, Objects* opt2) +{ + computing_tasks.setOption(name_option, opt1->symbol, opt2->symbol); +} void dynare::parser::option_num(string name_option, string opt) { computing_tasks.setOption(name_option, opt); @@ -417,9 +417,15 @@ void dynare::parser::add_tmp_var(Objects* tmp_var) { tmp_symbol_table.AddTempSymbol(tmp_var->symbol); } -dynare::Objects* get_tmp_var(string) +// dynare::Objects* get_tmp_var(string) +// { +// //string str = tmp_symbol_table.get +// } +void dynare::parser::rplot() { - //string str = tmp_symbol_table.get + tmp_symbol_table.set("var_list_"); + string tmp = tmp_symbol_table.get(); + computing_tasks.runRplot(tmp); } void dynare::parser::stoch_simul() { @@ -489,6 +495,89 @@ void dynare::parser::set_trend_element(Objects* arg1, Objects* arg2) { computing_tasks.set_trend_element(arg1->symbol, arg2->symbol); } +void dynare::parser::begin_optim_weights(void) +{ + computing_tasks.BeginOptimWeights(); +} +void dynare::parser::set_optim_weights(Objects* arg1, Objects* arg2) +{ + computing_tasks.setOptimWeights(arg1->symbol, arg2->symbol); +} +void dynare::parser::set_optim_weights(Objects* arg1, Objects* arg2, Objects* arg3) +{ + computing_tasks.setOptimWeights(arg1->symbol, arg2->symbol, arg3->symbol); +} +void dynare::parser::set_osr_params(void) +{ + tmp_symbol_table.set("osr_params_"); + string tmp = tmp_symbol_table.get(); + computing_tasks.setOsrParams(tmp); +} +void dynare::parser::run_osr(void) +{ + tmp_symbol_table.set("var_list_"); + string tmp = tmp_symbol_table.get(); + computing_tasks.runOsr(tmp); +} +void dynare::parser::set_olr_inst(void) +{ + tmp_symbol_table.set("options_.olr_inst"); + string tmp = tmp_symbol_table.get(); + computing_tasks.setOlrInst(tmp); +} +void dynare::parser::run_olr(void) +{ + tmp_symbol_table.set("var_list_"); + string tmp = tmp_symbol_table.get(); + computing_tasks.runOlr(tmp); +} +void dynare::parser::begin_calib_var(void) +{ + computing_tasks.BeginCalibVar(); +} +void dynare::parser::set_calib_var(Objects* name, Objects* weight, Objects* expression) +{ + Objects* exp = get_expression(expression); + computing_tasks.setCalibVar(name->symbol,weight->symbol,exp->symbol); +} +void dynare::parser::set_calib_var(Objects* name1, Objects* name2, Objects* weight, Objects* expression) +{ + Objects* exp = get_expression(expression); + computing_tasks.setCalibVar(name1->symbol,name2->symbol,weight->symbol,exp->symbol); +} +void dynare::parser::set_calib_ac(Objects* name, Objects* ar, Objects* weight, Objects* expression) +{ + Objects* exp = get_expression(expression); + computing_tasks.setCalibAc(name->symbol,ar->symbol,weight->symbol,exp->symbol); +} +void dynare::parser::run_calib(int flag) +{ + computing_tasks.runCalib(flag); +} +void dynare::parser::run_dynatype(Objects* filename, Objects* ext) +{ + tmp_symbol_table.set("var_list_"); + string tmp = tmp_symbol_table.get(); + computing_tasks.runDynatype(filename->symbol,ext->symbol,tmp); +} +void dynare::parser::run_dynasave(Objects* filename, Objects* ext) +{ + tmp_symbol_table.set("var_list_"); + string tmp = tmp_symbol_table.get(); + computing_tasks.runDynasave(filename->symbol,ext->symbol,tmp); +} +void dynare::parser::begin_model_comparison(void) +{ + computing_tasks.beginModelComparison(); +} +void dynare::parser::add_mc_filename(Objects* filename, Objects* prior) +{ + computing_tasks.addMcFilename(filename->symbol, prior->symbol); +} +void dynare::parser::run_model_comparison(void) +{ + computing_tasks.runModelComparison(); +} dynare::Objects* dynare::parser::add_equal(Objects* arg1, Objects* arg2) { NodeID id = model_tree.AddEqual(arg1->ID, arg2->ID); diff --git a/parser.src/ModelTree.cc b/parser.src/ModelTree.cc index aa632e29a934d569245eddcdcb32da383dd32fff..c8ab9d0d831936cb4c92bf070c6289e5b48aae1d 100644 --- a/parser.src/ModelTree.cc +++ b/parser.src/ModelTree.cc @@ -15,7 +15,7 @@ using namespace std; //------------------------------------------------------------------------------ #include "VariableTable.h" -#include "d_tab.h" +#include "DynareBison.h" #include "NumericalConstants.h" #include "ModelTree.h" //------------------------------------------------------------------------------ @@ -261,344 +261,342 @@ void ModelTree::SaveCFiles() void ModelTree::derive(int iOrder) { - NodeID lToken; // To store current working token - NodeID lD1, lD2; // To store derivative arguments of - // current argument - NodeID lArg1, lArg2; // To store current arguments - Type lType1; // Type of first argument - NodeID t1,t11,t12,t13, - t14, t15; // To store temoporary result arguments - TreeIterator BeginIT; // Iterator of the 1st token to derive - TreeIterator EndIT; // Iterator of the last token to derive - TreeIterator currentIT; // Iterator (counter) for model tree loop - - vector<NodeID> EqualTokenIDs; // IDs of "equal token" in model Tree - // Capturing equation IDs - for (currentIT = BeginModel; currentIT != mModelTree.end(); currentIT++) - { - if ((*currentIT)->op_code == EQUAL) - { - EqualTokenIDs.push_back(*currentIT); - // Equation is forced to be in Model Tree as refferenced - // This is usfull to remove symetric elements - (*currentIT)->reference_count[0]++; - } - } - mDerivativeIndex.resize(iOrder); - // Uncomment this to print model tree data - /* - //cout << "ModelTree==================================\n"; - for (currentIT = mModelTree.begin(); currentIT != mModelTree.end(); currentIT++) - { - lToken = *currentIT; - int ID = lToken->idx; - cout << ID << ":" << lToken << "->" << lToken->id1 << " " << lToken->type1 << " " << - lToken->id2 << " " << lToken->op_code << "\n"; - } - */ - // initialize derivatives of variables - int nbr_deriv_var = 0; - - EndIT = mModelTree.begin(); - EndIT--; - cout << "Processing derivation ...\n"; - // loop on order of derivation - for(int Order = 1; Order <= iOrder; Order++) + NodeID lToken; // To store current working token + NodeID lD1, lD2; // To store derivative arguments of + // current argument + NodeID lArg1, lArg2; // To store current arguments + Type lType1; // Type of first argument + NodeID t1,t11,t12,t13, + t14, t15; // To store temoporary result arguments + TreeIterator BeginIT; // Iterator of the 1st token to derive + TreeIterator EndIT; // Iterator of the last token to derive + TreeIterator currentIT; // Iterator (counter) for model tree loop + + vector<NodeID> EqualTokenIDs; // IDs of "equal token" in model Tree + // Capturing equation IDs + for (currentIT = BeginModel; currentIT != mModelTree.end(); currentIT++) + { + if ((*currentIT)->op_code == EQUAL) + { + EqualTokenIDs.push_back(*currentIT); + // Equation is forced to be in Model Tree as refferenced + // This is usfull to remove symetric elements + (*currentIT)->reference_count[0]++; + } + } + mDerivativeIndex.resize(iOrder); + // Uncomment this to print model tree data + /* + //cout << "ModelTree==================================\n"; + for (currentIT = mModelTree.begin(); currentIT != mModelTree.end(); currentIT++) + { + lToken = *currentIT; + int ID = lToken->idx; + cout << ID << ":" << lToken << "->" << lToken->id1 << " " << lToken->type1 << " " << + lToken->id2 << " " << lToken->op_code << "\n"; + } + */ + + EndIT = mModelTree.begin(); + EndIT--; + cout << "Processing derivation ...\n"; + // loop on order of derivation + for(int Order = 1; Order <= iOrder; Order++) { - cout << "\tProcessing Order " << Order << "... "; - current_order = Order; - BeginIT = EndIT; - BeginIT++; - EndIT = mModelTree.end(); - EndIT--; - // Adding a reference counter for current order to tokens in mModelTree - // and updating them - - for (TreeIterator it = mModelTree.begin(); it != mModelTree.end(); it++) - { - int s = (*it)->reference_count.size(); - for (int i = s; i <= current_order; i++) - { - int rc = (*it)->reference_count[i-1]; - (*it)->reference_count.push_back(rc); - } - } - // Loop on variables of derivation - for (int var = 0; var < VariableTable::size(); var++) - { + cout << "\tProcessing Order " << Order << "... "; + current_order = Order; + BeginIT = EndIT; + BeginIT++; + EndIT = mModelTree.end(); + EndIT--; + // Adding a reference counter for current order to tokens in mModelTree + // and updating them + + for (TreeIterator it = mModelTree.begin(); it != mModelTree.end(); it++) + { + int s = (*it)->reference_count.size(); + for (int i = s; i <= current_order; i++) + { + int rc = (*it)->reference_count[i-1]; + (*it)->reference_count.push_back(rc); + } + } + // Loop on variables of derivation + for (int var = 0; var < VariableTable::size(); var++) + { - // Loop on tokens - for (currentIT = BeginIT;; currentIT++) - { - //cout << "Token " << (*currentIT)->idx << endl; - if (accumulate((*currentIT)->reference_count.begin(), (*currentIT)->reference_count.end(),0) > 0) - { - lToken = *currentIT;//mModelTree[TokenCount]; - - lArg1 = lToken->id1; - lArg2 = lToken->id2; - lType1 = lToken->type1; - lD1 = DeriveArgument(lArg1, lType1, var); - if (lArg2 != NullID) - lD2 = DeriveArgument(lArg2, eTempResult, var); - // Case where token is a final argument - if (lToken->op_code == NoOpCode) - { - setDerivativeAdress(*currentIT, lD1, var); - } - else - { - - switch (lToken->op_code) - { - case UMINUS: - t1 = AddUMinus(lD1); - setDerivativeAdress(*currentIT, t1, var); - break; - case PLUS: - t1 = AddPlus(lD1, lD2); - setDerivativeAdress(*currentIT, t1, var); - break; - case MINUS: - t1 = AddMinus(lD1, lD2); - setDerivativeAdress(*currentIT, t1, var); - break; - case TIMES: - t11 = AddTimes(lD1, lArg2); - t12 = AddTimes(lD2, lArg1); - t1 = AddPlus(t11, t12); - setDerivativeAdress(*currentIT, t1, var); - break; - case DIVIDE: - t11 = AddTimes(lD1, lArg2); - t12 = AddTimes(lD2, lArg1); - t13 = AddMinus(t11, t12); - t14 = AddTimes(lArg2, lArg2); - t1 = AddDivide(t13, t14); - setDerivativeAdress(*currentIT, t1, var); - break; - case SQRT: - t11 = AddPlus(*currentIT, *currentIT); - t1 = AddDivide(lD1, t11); - setDerivativeAdress(*currentIT, t1,var); - break; - case POWER: - if (lD2 == Zero) - { - if (lD1 == Zero) - t1 = Zero; - else - { - t11 = AddMinus(lArg2, One); - t12 = AddPower(lArg1, t11); - t13 = AddTimes(lArg2, t12); - t1 = AddTimes(lD1, t13); - } - } - else - { - t11 = AddLog(lArg1); - t12 = AddTimes(lD2, t11); - t13 = AddTimes(lD1, lArg2); - t14 = AddDivide(t13, lArg1); - t15 = AddPlus(t12, t14); - t1 = AddTimes(t15, *currentIT); - } - setDerivativeAdress(*currentIT, t1, var); - break; - case EXP: - t1 = AddTimes(lD1, *currentIT); - setDerivativeAdress(*currentIT, t1, var); - break; - case LOG: - t1 = AddDivide(lD1, lArg1); - setDerivativeAdress(*currentIT, t1, var); - break; - case LOG10: - t11 = AddExp(One); - t12 = AddLog10(t11); - t13 = AddDivide(lD1, lArg1); - t1 = AddTimes(t12, t13); - setDerivativeAdress(*currentIT, t1, var); - break; - case COS: - t11 = AddSin(lArg1); - t12 = AddUMinus(t11); - t1 = AddTimes( lD1, t12); - setDerivativeAdress(*currentIT, t1, var); - break; - case SIN: - t11 = AddCos(lArg1); - t1 = AddTimes(lD1,t11); - setDerivativeAdress(*currentIT, t1, var); - break; - case TAN: - t11 = AddTimes(*currentIT, *currentIT); - t12 = AddPlus(t11, One); - t1 = AddTimes(lD1, t12); - setDerivativeAdress(*currentIT, t1, var); - break; - case ACOS: - t11 = AddSin(*currentIT); - t12 = AddDivide(lD1, t11); - t1 = AddUMinus(t12); - setDerivativeAdress(*currentIT, t1, var); - break; - case ASIN: - t11 = AddCos(*currentIT); - t1 = AddDivide(lD1, t11); - setDerivativeAdress(*currentIT, t1, var); - break; - case ATAN: - t11 = AddTimes(lArg1, lArg1); - t12 = AddPlus(One, t11); - t1 = AddDivide(lD1, t12); - setDerivativeAdress(*currentIT, t1,var); - break; - case COSH: - t11 = AddSinH(lArg1); - t1 = AddTimes( lD1,t11); - setDerivativeAdress(*currentIT, t1, var); - break; - case SINH: - t11 = AddCosH(lArg1); - t1 = AddTimes( lD1, t11); - setDerivativeAdress(*currentIT, t1, var); - break; - case TANH: - t11 = AddTimes(*currentIT, *currentIT); - t12 = AddMinus(One, t11); - t1 = AddTimes(lD1, t12); - setDerivativeAdress(*currentIT, t1,var); - break; - case ACOSH: - t11 = AddSinH(*currentIT); - t1 = AddDivide(lD1, t11); - setDerivativeAdress(*currentIT, t1,var); - break; - case ASINH: - t11 = AddCosH(*currentIT); - t1 = AddDivide(lD1, t11); - setDerivativeAdress(*currentIT, t1,var); - break; - case ATANH: - t11 = AddTimes(lArg1, lArg1); - t12 = AddMinus(One, t11); - t1 = AddTimes(lD1, t12); - setDerivativeAdress(*currentIT, t1,var); - break; - } - } - } - if (currentIT == EndIT) break; - } - - // Treating equal tokens - // Skeeping symetric elements - //vector<MetaToken>::iterator tree_it2 = mModelTree.begin(); - //int id = 0; - int starti = var*Order*(Order-1)*ModelParameters::eq_nbr/2; - for (int i = starti; i < EqualTokenIDs.size() ; i++ ) + // Loop on tokens + for (currentIT = BeginIT;; currentIT++) + { + //cout << "Token " << (*currentIT)->idx << endl; + if (accumulate((*currentIT)->reference_count.begin(), (*currentIT)->reference_count.end(),0) > 0) + { + lToken = *currentIT;//mModelTree[TokenCount]; + + lArg1 = lToken->id1; + lArg2 = lToken->id2; + lType1 = lToken->type1; + lD1 = DeriveArgument(lArg1, lType1, var); + if (lArg2 != NullID) + lD2 = DeriveArgument(lArg2, eTempResult, var); + // Case where token is a final argument + if (lToken->op_code == NoOpCode) + { + setDerivativeAdress(*currentIT, lD1, var); + } + else + { + + switch (lToken->op_code) { - lToken = EqualTokenIDs[i]; - lArg1 = lToken->id1; - lArg2 = lToken->id2; - lType1 = lToken->type1; - lD1 = DeriveArgument(lArg1, lType1, var); - lD2 = DeriveArgument(lArg2, eTempResult, var); - // If one hand sid is null, take the other - if (lD1 == Zero && lD2 != Zero) - { - t11 = AddUMinus(lD2); - t1 = AddEqual(t11, Zero); - } - else if (lD1 != Zero && lD2 == Zero) - { - t1 = AddEqual(lD1, Zero); - } - else - { - t11 = AddMinus(lD1, lD2); - t1 = AddEqual(t11, Zero); - } - // The derivative is forced to be in Model Tree as refferenced - // This is usfull to remove symetric elements - IncrementReferenceCount(t1); - setDerivativeAdress(EqualTokenIDs[i], t1, var); - if (Order == 1) - { - mDerivativeIndex[0].push_back(DerivativeIndex(t1, i-starti, var)); - } - else if (Order == 2) + case UMINUS: + t1 = AddUMinus(lD1); + setDerivativeAdress(*currentIT, t1, var); + break; + case PLUS: + t1 = AddPlus(lD1, lD2); + setDerivativeAdress(*currentIT, t1, var); + break; + case MINUS: + t1 = AddMinus(lD1, lD2); + setDerivativeAdress(*currentIT, t1, var); + break; + case TIMES: + t11 = AddTimes(lD1, lArg2); + t12 = AddTimes(lD2, lArg1); + t1 = AddPlus(t11, t12); + setDerivativeAdress(*currentIT, t1, var); + break; + case DIVIDE: + t11 = AddTimes(lD1, lArg2); + t12 = AddTimes(lD2, lArg1); + t13 = AddMinus(t11, t12); + t14 = AddTimes(lArg2, lArg2); + t1 = AddDivide(t13, t14); + setDerivativeAdress(*currentIT, t1, var); + break; + case SQRT: + t11 = AddPlus(*currentIT, *currentIT); + t1 = AddDivide(lD1, t11); + setDerivativeAdress(*currentIT, t1,var); + break; + case POWER: + if (lD2 == Zero) + { + if (lD1 == Zero) + t1 = Zero; + else { - int var1 = VariableTable::getSortID(i/ModelParameters::eq_nbr); - int var2 = VariableTable::getSortID(var); - mDerivativeIndex[1].push_back(DerivativeIndex( - t1, - i-ModelParameters::eq_nbr*(i/ModelParameters::eq_nbr), - var1*VariableTable::size()+var2)); + t11 = AddMinus(lArg2, One); + t12 = AddPower(lArg1, t11); + t13 = AddTimes(lArg2, t12); + t1 = AddTimes(lD1, t13); } + } + else + { + t11 = AddLog(lArg1); + t12 = AddTimes(lD2, t11); + t13 = AddTimes(lD1, lArg2); + t14 = AddDivide(t13, lArg1); + t15 = AddPlus(t12, t14); + t1 = AddTimes(t15, *currentIT); + } + setDerivativeAdress(*currentIT, t1, var); + break; + case EXP: + t1 = AddTimes(lD1, *currentIT); + setDerivativeAdress(*currentIT, t1, var); + break; + case LOG: + t1 = AddDivide(lD1, lArg1); + setDerivativeAdress(*currentIT, t1, var); + break; + case LOG10: + t11 = AddExp(One); + t12 = AddLog10(t11); + t13 = AddDivide(lD1, lArg1); + t1 = AddTimes(t12, t13); + setDerivativeAdress(*currentIT, t1, var); + break; + case COS: + t11 = AddSin(lArg1); + t12 = AddUMinus(t11); + t1 = AddTimes( lD1, t12); + setDerivativeAdress(*currentIT, t1, var); + break; + case SIN: + t11 = AddCos(lArg1); + t1 = AddTimes(lD1,t11); + setDerivativeAdress(*currentIT, t1, var); + break; + case TAN: + t11 = AddTimes(*currentIT, *currentIT); + t12 = AddPlus(t11, One); + t1 = AddTimes(lD1, t12); + setDerivativeAdress(*currentIT, t1, var); + break; + case ACOS: + t11 = AddSin(*currentIT); + t12 = AddDivide(lD1, t11); + t1 = AddUMinus(t12); + setDerivativeAdress(*currentIT, t1, var); + break; + case ASIN: + t11 = AddCos(*currentIT); + t1 = AddDivide(lD1, t11); + setDerivativeAdress(*currentIT, t1, var); + break; + case ATAN: + t11 = AddTimes(lArg1, lArg1); + t12 = AddPlus(One, t11); + t1 = AddDivide(lD1, t12); + setDerivativeAdress(*currentIT, t1,var); + break; + case COSH: + t11 = AddSinH(lArg1); + t1 = AddTimes( lD1,t11); + setDerivativeAdress(*currentIT, t1, var); + break; + case SINH: + t11 = AddCosH(lArg1); + t1 = AddTimes( lD1, t11); + setDerivativeAdress(*currentIT, t1, var); + break; + case TANH: + t11 = AddTimes(*currentIT, *currentIT); + t12 = AddMinus(One, t11); + t1 = AddTimes(lD1, t12); + setDerivativeAdress(*currentIT, t1,var); + break; + case ACOSH: + t11 = AddSinH(*currentIT); + t1 = AddDivide(lD1, t11); + setDerivativeAdress(*currentIT, t1,var); + break; + case ASINH: + t11 = AddCosH(*currentIT); + t1 = AddDivide(lD1, t11); + setDerivativeAdress(*currentIT, t1,var); + break; + case ATANH: + t11 = AddTimes(lArg1, lArg1); + t12 = AddMinus(One, t11); + t1 = AddTimes(lD1, t12); + setDerivativeAdress(*currentIT, t1,var); + break; } - + } } - // Uncomment to debug : prints unreferenced tokens - /* - cout << "Order : " << Order << "\n"; - for (TokenCount = BeginModel; TokenCount < mModelTree.size() ; TokenCount++ ) + if (currentIT == EndIT) break; + } + + // Treating equal tokens + // Skeeping symetric elements + //vector<MetaToken>::iterator tree_it2 = mModelTree.begin(); + //int id = 0; + int starti = var*Order*(Order-1)*ModelParameters::eq_nbr/2; + for (unsigned int i = starti; i < EqualTokenIDs.size() ; i++ ) + { + lToken = EqualTokenIDs[i]; + lArg1 = lToken->id1; + lArg2 = lToken->id2; + lType1 = lToken->type1; + lD1 = DeriveArgument(lArg1, lType1, var); + lD2 = DeriveArgument(lArg2, eTempResult, var); + // If one hand sid is null, take the other + if (lD1 == Zero && lD2 != Zero) { - if (accumulate(mModelTree[TokenCount].reference_count.begin(),mModelTree[TokenCount].reference_count.end(),0) == 0) - cout << "\tNot referenced : token ID :" << TokenCount << endl; + t11 = AddUMinus(lD2); + t1 = AddEqual(t11, Zero); } - */ - // Uncomment this to debug : mDerivative(1and2)Index data - // before removing unreferenced tokens - /* - cout << "Contenence of mDerivative1Index\n"; - for (int i=0; i< mDerivativeIndex[0].size();i++) - //if (mDerivativeIndex[0][i].token_id != 3) - cout << "\t" << mDerivativeIndex[0][i].token_id << endl; - cout << "Contenence of mDerivative2Index\n"; - for (int i=0; i< mDerivativeIndex[1].size();i++) - //if (mDerivativeIndex[1][i].token_id != 3) - cout << "\t" << mDerivativeIndex[1][i].token_id << endl; - */ - //cout << "Removing unreferenced tokens range ids :" << CurrentID << " - " << mModelTree.size()-1 << endl; - // Removing unreferenced tokens in last derivative - // RemoveUnref(CurrentID, mModelTree.size()-1, Order); - // Decrementing reference couter of unreferenced tokens in last derivative - //DecrementUnref(CurrentID, mModelTree.size()-1, Order); - /* - cout << "Order : " << Order << "\n"; - for (TokenCount = BeginModel; TokenCount < mModelTree.size() ; TokenCount++ ) + else if (lD1 != Zero && lD2 == Zero) + { + t1 = AddEqual(lD1, Zero); + } + else { - if (accumulate(mModelTree[TokenCount].reference_count.begin(),mModelTree[TokenCount].reference_count.end(),0) == 0) - cout << "\tNot referenced : token ID :" << TokenCount << endl; + t11 = AddMinus(lD1, lD2); + t1 = AddEqual(t11, Zero); } - */ - EqualTokenIDs.clear(); - // Updating EqualTokenIDs - for (int i=0; i< mDerivativeIndex[Order-1].size();i++) + // The derivative is forced to be in Model Tree as refferenced + // This is usfull to remove symetric elements + IncrementReferenceCount(t1); + setDerivativeAdress(EqualTokenIDs[i], t1, var); + if (Order == 1) { - EqualTokenIDs.push_back(mDerivativeIndex[Order-1][i].token_id); + mDerivativeIndex[0].push_back(DerivativeIndex(t1, i-starti, var)); } + else if (Order == 2) + { + int var1 = VariableTable::getSortID(i/ModelParameters::eq_nbr); + int var2 = VariableTable::getSortID(var); + mDerivativeIndex[1].push_back(DerivativeIndex( + t1, + i-ModelParameters::eq_nbr*(i/ModelParameters::eq_nbr), + var1*VariableTable::size()+var2)); + } + } + + } + // Uncomment to debug : prints unreferenced tokens + /* + cout << "Order : " << Order << "\n"; + for (TokenCount = BeginModel; TokenCount < mModelTree.size() ; TokenCount++ ) + { + if (accumulate(mModelTree[TokenCount].reference_count.begin(),mModelTree[TokenCount].reference_count.end(),0) == 0) + cout << "\tNot referenced : token ID :" << TokenCount << endl; + } + */ + // Uncomment this to debug : mDerivative(1and2)Index data + // before removing unreferenced tokens + /* + cout << "Contenence of mDerivative1Index\n"; + for (int i=0; i< mDerivativeIndex[0].size();i++) + //if (mDerivativeIndex[0][i].token_id != 3) + cout << "\t" << mDerivativeIndex[0][i].token_id << endl; + cout << "Contenence of mDerivative2Index\n"; + for (int i=0; i< mDerivativeIndex[1].size();i++) + //if (mDerivativeIndex[1][i].token_id != 3) + cout << "\t" << mDerivativeIndex[1][i].token_id << endl; + */ + //cout << "Removing unreferenced tokens range ids :" << CurrentID << " - " << mModelTree.size()-1 << endl; + // Removing unreferenced tokens in last derivative + // RemoveUnref(CurrentID, mModelTree.size()-1, Order); + // Decrementing reference couter of unreferenced tokens in last derivative + //DecrementUnref(CurrentID, mModelTree.size()-1, Order); + /* + cout << "Order : " << Order << "\n"; + for (TokenCount = BeginModel; TokenCount < mModelTree.size() ; TokenCount++ ) + { + if (accumulate(mModelTree[TokenCount].reference_count.begin(),mModelTree[TokenCount].reference_count.end(),0) == 0) + cout << "\tNot referenced : token ID :" << TokenCount << endl; + } + */ + EqualTokenIDs.clear(); + // Updating EqualTokenIDs + for (unsigned int i=0; i< mDerivativeIndex[Order-1].size();i++) + { + EqualTokenIDs.push_back(mDerivativeIndex[Order-1][i].token_id); + } - // Uncomment this to debug : mDerivative(1and2)Index data - // after removing unreferenced tokens - /* - cout << "Contenence of mDerivative1Index after removing\n"; - for (int i=0; i< mDerivativeIndex[0].size();i++) - if (mDerivativeIndex[0][i].token_id != 3) - cout << "\t" << mDerivativeIndex[0][i].token_id << endl; - cout << "Contenence of mDerivative2Index after removing\n"; - for (int i=0; i< mDerivativeIndex[1].size();i++) - //if (mDerivativeIndex[1][i].token_id != 3) - cout << "\t" << mDerivativeIndex[1][i].token_id << endl; - */ - cout << "done \n"; + // Uncomment this to debug : mDerivative(1and2)Index data + // after removing unreferenced tokens + /* + cout << "Contenence of mDerivative1Index after removing\n"; + for (int i=0; i< mDerivativeIndex[0].size();i++) + if (mDerivativeIndex[0][i].token_id != 3) + cout << "\t" << mDerivativeIndex[0][i].token_id << endl; + cout << "Contenence of mDerivative2Index after removing\n"; + for (int i=0; i< mDerivativeIndex[1].size();i++) + //if (mDerivativeIndex[1][i].token_id != 3) + cout << "\t" << mDerivativeIndex[1][i].token_id << endl; + */ + cout << "done \n"; - } + } } //------------------------------------------------------------------------------ inline bool ModelTree::writeAsTemp(NodeID id) @@ -668,7 +666,7 @@ inline void ModelTree::setDerivativeAdress(NodeID iTokenID, NodeID iDerivative,i //mModelTree[iDerivative].p1[iVarID] = iTokenID; } //------------------------------------------------------------------------------ -string ModelTree::setStaticModelM(void) +string ModelTree::setStaticModel(void) { TreeIterator tree_it; int lEquationNBR = 0; @@ -679,7 +677,6 @@ string ModelTree::setStaticModelM(void) int d = current_order; // Minimum number of times a temparary expression apears in equations int EquationNBR; // Number of model equations - int col = 1; // Colomn index of Jacobian EquationNBR = ModelParameters::eq_nbr; // Reference count of token "0=0" is set to 0 @@ -699,7 +696,7 @@ string ModelTree::setStaticModelM(void) model_output << getExpression(((*tree_it)->id1), eStaticEquations, lEquationNBR) << ";" << endl; model_output << "rhs ="; model_output << getExpression(((*tree_it)->id2), eStaticEquations, lEquationNBR) << ";" << endl; - model_output << "residual(" << lEquationNBR+1 << ")= lhs-rhs;" << endl; + model_output << "residual" << lpar << lEquationNBR+1 << rpar << "= lhs-rhs;" << endl; lEquationNBR++; } else break; @@ -736,7 +733,7 @@ string ModelTree::setStaticModelM(void) } lEquationNBR = 0; - for (int i = 0; i < mDerivativeIndex[0].size(); i++) + for (unsigned int i = 0; i < mDerivativeIndex[0].size(); i++) { if (VariableTable::getType(mDerivativeIndex[0][i].derivators) == eEndogenous) { @@ -745,38 +742,60 @@ string ModelTree::setStaticModelM(void) { string exp = getExpression(startJacobian->id1, eStaticDerivatives); ostringstream g1; - g1 << " g1(" << mDerivativeIndex[0][i].equation_id+1 << ", " << - VariableTable::getSymbolID(mDerivativeIndex[0][i].derivators)+1 << ')'; + g1 << " g1" << lpar << mDerivativeIndex[0][i].equation_id+1 << ", " << + VariableTable::getSymbolID(mDerivativeIndex[0][i].derivators)+1 << rpar; jacobian_output << g1.str() << "=" << g1.str() << "+" << exp << ";\n"; } } } // Writing ouputs - StaticOutput << "global M_ \n"; - StaticOutput << "params = M_.params;\n"; - - StaticOutput << " residual = zeros( " << ModelParameters::eq_nbr << ", 1);\n"; - StaticOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; - StaticOutput << model_output.str(); - StaticOutput << "if ~isreal(residual)\n"; - StaticOutput << " residual = real(residual)+imag(residual).^2;\n"; - StaticOutput << "end\n"; - StaticOutput << "if nargout >= 2,\n"; - StaticOutput << " g1 = " << - "zeros(" << ModelParameters::eq_nbr << ", " << - ModelParameters::endo_nbr << ");\n" ; - StaticOutput << "\n\t%\n\t% Jacobian matrix\n\t%\n\n"; - StaticOutput << jacobian_output.str(); - StaticOutput << " if ~isreal(g1)\n"; - StaticOutput << " g1 = real(g1)+2*imag(g1);\n"; - StaticOutput << " end\n"; - StaticOutput << "end\n"; + if (offset == 1) + { + StaticOutput << "global M_ \n"; + StaticOutput << "params = M_.params;\n"; + + StaticOutput << " residual = zeros( " << ModelParameters::eq_nbr << ", 1);\n"; + StaticOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; + StaticOutput << model_output.str(); + StaticOutput << "if ~isreal(residual)\n"; + StaticOutput << " residual = real(residual)+imag(residual).^2;\n"; + StaticOutput << "end\n"; + StaticOutput << "if nargout >= 2,\n"; + StaticOutput << " g1 = " << + "zeros(" << ModelParameters::eq_nbr << ", " << + ModelParameters::endo_nbr << ");\n" ; + StaticOutput << "\n\t%\n\t% Jacobian matrix\n\t%\n\n"; + StaticOutput << jacobian_output.str(); + StaticOutput << " if ~isreal(g1)\n"; + StaticOutput << " g1 = real(g1)+2*imag(g1);\n"; + StaticOutput << " end\n"; + StaticOutput << "end\n"; + } + else + { + StaticOutput << "void Static(double *y, double *x, double *residual, double *g1)\n"; + StaticOutput << "{\n"; + StaticOutput << " double lhs, rhs;\n\n"; + // Writing residual equations + StaticOutput << " /* Residual equations */\n"; + StaticOutput << " if (residual == NULL) return;\n"; + StaticOutput << " {\n"; + StaticOutput << model_output.str(); + // Writing Jacobian + StaticOutput << " /* Jacobian for endogenous variables without lag */\n"; + StaticOutput << " if (g1 == NULL) return;\n"; + StaticOutput << " {\n"; + StaticOutput << jacobian_output.str(); + StaticOutput << " }\n"; + StaticOutput << " }\n"; + StaticOutput << "}\n\n"; + } current_order = d; return StaticOutput.str(); } //------------------------------------------------------------------------------ -string ModelTree::setDynamicModelM(void) +string ModelTree::setDynamicModel(void) { TreeIterator tree_it; int lEquationNBR = 0; @@ -796,8 +815,6 @@ string ModelTree::setDynamicModelM(void) // Not to be printed as a temp expression fill(ZeroEqZero->reference_count.begin(), ZeroEqZero->reference_count.end(),0); - DynamicOutput << "global M_ it_\n"; - DynamicOutput << "params = M_.params;\n"; // Clearing output string model_output.str(""); @@ -819,7 +836,7 @@ string ModelTree::setDynamicModelM(void) model_output << getExpression(((*tree_it)->id1), eDynamicEquations, lEquationNBR) << ";" << endl; model_output << "rhs ="; model_output << getExpression(((*tree_it)->id2), eDynamicEquations, lEquationNBR) << ";" << endl; - model_output << "residual(" << lEquationNBR+1 << ")= lhs-rhs;" << endl; + model_output << "residual" << lpar << lEquationNBR+1 << rpar << "= lhs-rhs;" << endl; lEquationNBR++; } else break; @@ -875,7 +892,7 @@ string ModelTree::setDynamicModelM(void) } lEquationNBR = 0; - for (int i = 0; i < mDerivativeIndex[0].size(); i++) + for (unsigned int i = 0; i < mDerivativeIndex[0].size(); i++) { if (computeJacobianExo || VariableTable::getType(mDerivativeIndex[0][i].derivators) == eEndogenous) { @@ -884,8 +901,8 @@ string ModelTree::setDynamicModelM(void) { string exp = getExpression(startJacobian->id1, eDynamicDerivatives); ostringstream g1; - g1 << " g1(" << mDerivativeIndex[0][i].equation_id+1 << ", " << - VariableTable::getSortID(mDerivativeIndex[0][i].derivators)+1 << ')'; + g1 << " g1" << lpar << mDerivativeIndex[0][i].equation_id+1 << ", " << + VariableTable::getSortID(mDerivativeIndex[0][i].derivators)+1 << rpar; jacobian_output << g1.str() << "=" << g1.str() << "+" << exp << ";\n"; } } @@ -900,7 +917,7 @@ string ModelTree::setDynamicModelM(void) // Searching for the next '=' operator, lEquationNBR = 0; cout << "\tHessian .. "; - for (int i = 0; i < mDerivativeIndex[1].size(); i++) + for (unsigned int i = 0; i < mDerivativeIndex[1].size(); i++) { NodeID startHessian = mDerivativeIndex[1][i].token_id; //cout << "ID = " << startHessian << " exp = " << exp << "\n"; @@ -910,694 +927,79 @@ string ModelTree::setDynamicModelM(void) int varID1 = mDerivativeIndex[1][i].derivators/VariableTable::size(); int varID2 = mDerivativeIndex[1][i].derivators-varID1*VariableTable::size(); - hessian_output << " g2(" << mDerivativeIndex[1][i].equation_id+1 << ", " << - mDerivativeIndex[1][i].derivators+1 << ") = " << exp << ";\n"; + hessian_output << " g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " << + mDerivativeIndex[1][i].derivators+1 << rpar << " = " << exp << ";\n"; // Treating symetric elements if (varID1 != varID2) - lsymetric << " g2(" << mDerivativeIndex[1][i].equation_id+1 << ", " << - varID2*VariableTable::size()+varID1+1 << ") = " << - "g2(" << mDerivativeIndex[1][i].equation_id+1 << ", " << - mDerivativeIndex[1][i].derivators+1 << ");\n"; + lsymetric << " g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " << + varID2*VariableTable::size()+varID1+1 << rpar << " = " << + "g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " << + mDerivativeIndex[1][i].derivators+1 << rpar << ";\n"; } } cout << "done \n"; } int nrows = ModelParameters::eq_nbr; - DynamicOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; - DynamicOutput << "residual = zeros(" << nrows << ", 1);\n"; - - DynamicOutput << model_output.str(); - - if (computeJacobian || computeJacobianExo) + if (offset == 1) { - DynamicOutput << "if nargout >= 2,\n"; - // Writing initialization instruction for matrix g1 - DynamicOutput << " g1 = " << - "zeros(" << nrows << ", " << VariableTable::size() << ");\n" ; - DynamicOutput << "\n\t%\n\t% Jacobian matrix\n\t%\n\n"; - DynamicOutput << jacobian_output.str(); - DynamicOutput << "end\n"; - } - if (computeHessian) - { - DynamicOutput << "if nargout >= 3,\n"; - // Writing initialization instruction for matrix g2 - int ncols = VariableTable::size()*VariableTable::size(); - DynamicOutput << " g2 = " << - "sparse([],[],[]," << nrows << ", " << ncols << ", " << - 5*ncols << ");\n"; - DynamicOutput << "\n\t%\n\t% Hessian matrix\n\t%\n\n"; - DynamicOutput << hessian_output.str() << lsymetric.str(); - DynamicOutput << "end;\n"; - } -current_order = d; -return DynamicOutput.str(); -} - -// DynamicOutput << "\n%\n% Computting residuals and Jacobian with respect\n"; -// DynamicOutput << "% to endogenous variables\n%\n"; -// DynamicOutput << " residual = zeros( " << ModelParameters::eq_nbr << ", 1);\n"; -// DynamicOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; -// DynamicOutput << model_output.str(); -// DynamicOutput << "if nargout >= 2,\n"; -// DynamicOutput << "\n\t%\n\t% Jacobian matrix\n\t%\n\n"; -// DynamicOutput << " g1 = " << -// "zeros(" << ModelParameters::eq_nbr << ", " << -// ModelParameters::var_endo_nbr << ");\n" ; - -// DynamicOutput << jacobian_output.str(); -// DynamicOutput << jacobian_tmp_output.str() << "\n"; -// DynamicOutput << "end\n"; -// } -// // Case where residuals and Jacobian with respect to endogenous and exogenous -// // variables are computed -// else if (computeJacobianExo && !computeHessian) -// { -// // Clearing output string -// model_output.str(""); -// jacobian_output.str(""); -// model_tmp_output.str(""); -// jacobian_tmp_output.str(""); -// current_order = 1; -// lEquationNBR = 0; -// // Getting equations from model tree -// // Starting from the end of equation -// // Searching for the next '=' operator, - -// cout << "\tequations .. "; -// for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// { -// if ((*tree_it)->op_code == EQUAL) -// { -// if (lEquationNBR < ModelParameters::eq_nbr) -// { -// model_output << getExpression(*tree_it, eDynamicEquations, lEquationNBR) << endl; -// lEquationNBR++; -// } -// else break; -// } -// } -// // for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// // { -// // if (((*tree_it)->tmp_status == 1) && -// // writeAsTemp(*tree_it)) -// // { -// // (*tree_it)->tmp_status = -1; -// // model_tmp_output << " T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// // } -// // } -// cout << "done \n"; - -// // Getting Jacobian from model tree -// // Starting from the end of equation -// // Searching for the next '=' operator, - -// cout << "\tJacobian .. "; -// for (int i = 0; i < mDerivativeIndex[0].size(); i++) -// { -// NodeID startJacobian = mDerivativeIndex[0][i].token_id; -// string exp = getExpression(startJacobian, eDynamicDerivatives); -// if (startJacobian != ZeroEqZero) -// jacobian_output << " g1(" << mDerivativeIndex[0][i].equation_id+1 << ", " << -// VariableTable::getSortID(mDerivativeIndex[0][i].derivators)+1 << ") = " << exp << ";\n"; -// } -// // for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// // { -// // if (((*tree_it)->tmp_status == 1) && -// // writeAsTemp(*tree_it)) -// // { -// // (*tree_it)->tmp_status = -1; -// // jacobian_tmp_output << " T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// // } -// // } -// cout << "done \n"; - -// DynamicOutput << "\n%\n% Computting residuals and Jacobian with respect\n"; -// DynamicOutput << "% to endogenous and exogenous variables\n%\n"; -// DynamicOutput << "if nargout >= 1,\n"; -// DynamicOutput << " residual = zeros( " << ModelParameters::eq_nbr << ", 1);\n"; -// DynamicOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; -// DynamicOutput << model_tmp_output.str() << "\n"; -// DynamicOutput << model_output.str(); -// DynamicOutput << "end\n"; -// DynamicOutput << "if nargout >= 2,\n"; -// // Writing initialization instruction for matrix g1 -// DynamicOutput << " g1 = " << -// "zeros(" << ModelParameters::eq_nbr << ", " << -// VariableTable::size() << ");\n" ; -// DynamicOutput << "\n\t%\n\t% Jacobian matrix\n\t%\n\n"; -// DynamicOutput << jacobian_tmp_output.str() << "\n"; -// DynamicOutput << jacobian_output.str(); -// DynamicOutput << "end\n"; -// } -// // Case where residuals, Jacobian and Hessian with respect to endogenous and exogenous -// // variables are computed -// else if (computeHessian && computeJacobianExo) -// { -// // Clearing output string -// model_output.str(""); -// jacobian_output.str(""); -// hessian_output.str(""); -// model_tmp_output.str(""); -// jacobian_tmp_output.str(""); -// hessian_tmp_output.str(""); -// lsymetric.str(""); - -// current_order = 2; -// lEquationNBR = 0; -// // Getting equations from model tree -// // Starting from the end of equation -// // Searching for the next '=' operator, - -// cout << "\tequations .. "; -// for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// { -// if ((*tree_it)->op_code == EQUAL) -// { -// if (lEquationNBR < ModelParameters::eq_nbr) -// { -// model_output << getExpression(*tree_it, eDynamicEquations, lEquationNBR) << endl; -// lEquationNBR++; -// } -// else break; -// } -// } -// // for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// // { -// // if (((*tree_it)->tmp_status == 1) && -// // writeAsTemp(*tree_it)) -// // { -// // (*tree_it)->tmp_status = -1; -// // model_tmp_output << " T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// // } -// // } -// cout << "done \n"; - -// // Getting Jacobian from model tree -// // Starting from the end of equation -// // Searching for the next '=' operator, - -// cout << "\tJacobian .. "; -// for (int i = 0; i < mDerivativeIndex[0].size(); i++) -// { -// NodeID startJacobian = mDerivativeIndex[0][i].token_id; -// string exp = getExpression(startJacobian, eDynamicDerivatives); -// if (startJacobian != ZeroEqZero) -// jacobian_output << " g1(" << mDerivativeIndex[0][i].equation_id+1 << ", " << -// VariableTable::getSortID(mDerivativeIndex[0][i].derivators)+1 << ") = " << exp << ";\n"; -// } -// // for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// // { -// // if (((*tree_it)->tmp_status == 1) && -// // writeAsTemp(*tree_it)) -// // { -// // (*tree_it)->tmp_status = -1; -// // jacobian_tmp_output << " T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// // } -// // } -// cout << "done \n"; - -// // Getting Hessian from model tree -// // Starting from the end of equation -// // Searching for the next '=' operator, -// lEquationNBR = 0; -// cout << "\tHessian .. "; -// for (int i = 0; i < mDerivativeIndex[1].size(); i++) -// { -// NodeID startHessian = mDerivativeIndex[1][i].token_id; -// string exp = getExpression(startHessian, eDynamicDerivatives); - -// int varID1 = mDerivativeIndex[1][i].derivators/VariableTable::size(); -// int varID2 = mDerivativeIndex[1][i].derivators-varID1*VariableTable::size(); -// //cout << "ID = " << startHessian << " exp = " << exp << "\n"; -// if (startHessian != ZeroEqZero) -// { -// hessian_output << " g2(" << mDerivativeIndex[1][i].equation_id+1 << ", " << -// mDerivativeIndex[1][i].derivators+1 << ") = " << exp << ";\n"; -// // Treating symetric elements -// if (varID1 != varID2) -// lsymetric << " g2(" << mDerivativeIndex[1][i].equation_id+1 << ", " << -// varID2*VariableTable::size()+varID1+1 << ") = " << -// "g2(" << mDerivativeIndex[1][i].equation_id+1 << ", " << -// mDerivativeIndex[1][i].derivators+1 << ");\n"; -// } + DynamicOutput << "global M_ it_\n"; + DynamicOutput << "params = M_.params;\n"; + DynamicOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; + DynamicOutput << "residual = zeros(" << nrows << ", 1);\n"; -// } -// // for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// // { -// // if (((*tree_it)->tmp_status == 1) && -// // writeAsTemp(*tree_it)) -// // { -// // (*tree_it)->tmp_status = -1; -// // hessian_tmp_output << " T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// // } -// // } -// cout << "done \n"; + DynamicOutput << model_output.str(); -// DynamicOutput << "\n% Computting residuals, Jacobian and Hessian with respect\n"; -// DynamicOutput << "% to endogenous and exogenous variables are computed\n"; -// DynamicOutput << "if nargout >= 1,\n"; -// DynamicOutput << " residual = zeros( " << ModelParameters::eq_nbr << ", 1);\n"; -// DynamicOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; -// DynamicOutput << model_tmp_output.str() << "\n"; -// DynamicOutput << model_output.str(); -// DynamicOutput << "end\n"; -// DynamicOutput << "if nargout >= 2,\n"; -// // Writing initialization instruction for matrix g2 -// DynamicOutput << " g1 = " << -// "zeros(" << ModelParameters::eq_nbr << ", " << -// VariableTable::size() << ");\n" ; -// DynamicOutput << "\n\t%\n\t% Jacobian matrix\n\t%\n\n"; -// DynamicOutput << jacobian_tmp_output.str() << "\n"; -// DynamicOutput << jacobian_output.str(); -// DynamicOutput << "end\n"; -// DynamicOutput << "if nargout >= 3,\n"; -// // Writing initialization instruction for matrix g2 -// DynamicOutput << " g2 = " << -// "zeros(" << ModelParameters::eq_nbr << ", " << -// VariableTable::size()*VariableTable::size()<< ");\n"; -// DynamicOutput << "\n\t%\n\t% Hessian matrix\n\t%\n\n"; -// DynamicOutput << hessian_tmp_output.str() << "\n"; -// DynamicOutput << hessian_output.str() << lsymetric.str(); -// DynamicOutput << "end;\n"; -// } -// current_order = d; -// return DynamicOutput.str(); -// } -//------------------------------------------------------------------------------ -string ModelTree::setStaticModelC(void) -{ - TreeIterator tree_it; - int lEquationNBR = 0; - ostringstream model_output;; // Used for storing model equations - ostringstream jacobian_output; // Used for storing jacobian equations - ostringstream model_tmp_output;; // Used for storing tmp expressions formodel equations - ostringstream jacobian_tmp_output; // Used for storing tmp expressions for jacobian equations - int d = current_order; // Minimum number of times a temparary expression apears in equations - int EquationNBR; // Number of model equations - int col = 1; // Colomn index of Jacobian - - EquationNBR = ModelParameters::eq_nbr; - // Reference count of token "0=0" is set to 0 - // Not to be printed as a temp expression - fill(ZeroEqZero->reference_count.begin(), - ZeroEqZero->reference_count.end(),0); - // Setting tmp_status to 0, -// for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// { -// (*tree_it)->tmp_status = 0; - -// } - // Writing model Equations - current_order = 1; - for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) + if (computeJacobian || computeJacobianExo) { - if ((*tree_it)->op_code == EQUAL) - { - if (lEquationNBR < ModelParameters::eq_nbr) - { - model_output << getExpression(*tree_it, eStaticEquations, lEquationNBR) << endl;; - lEquationNBR++; - } - else break; - } + DynamicOutput << "if nargout >= 2,\n"; + // Writing initialization instruction for matrix g1 + DynamicOutput << " g1 = " << + "zeros(" << nrows << ", " << VariableTable::size() << ");\n" ; + DynamicOutput << "\n\t%\n\t% Jacobian matrix\n\t%\n\n"; + DynamicOutput << jacobian_output.str(); + DynamicOutput << "end\n"; } -// for (tree_it = BeginModel; tree_it != mModelTree.end();tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// model_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[0] << ";\n"; -// } -// } - // Writing Jacobian for endogenous variables without lag - lEquationNBR = 0; - for (int i = 0; i < mDerivativeIndex[0].size(); i++) + if (computeHessian) { - if (VariableTable::getType(mDerivativeIndex[0][i].derivators) == eEndogenous) - { - NodeID startJacobian = mDerivativeIndex[0][i].token_id; - string exp = getExpression(startJacobian, eStaticDerivatives); - if (startJacobian != ZeroEqZero) - { - ostringstream g1; - g1 << " g1[" << mDerivativeIndex[0][i].equation_id+ - (VariableTable::getSymbolID(mDerivativeIndex[0][i].derivators))*ModelParameters::eq_nbr << "]"; - jacobian_output << g1.str() << "=" << g1.str() << "+" << exp << ";\n"; - } - } + DynamicOutput << "if nargout >= 3,\n"; + // Writing initialization instruction for matrix g2 + int ncols = VariableTable::size()*VariableTable::size(); + DynamicOutput << " g2 = " << + "sparse([],[],[]," << nrows << ", " << ncols << ", " << + 5*ncols << ");\n"; + DynamicOutput << "\n\t%\n\t% Hessian matrix\n\t%\n\n"; + DynamicOutput << hessian_output.str() << lsymetric.str(); + DynamicOutput << "end;\n"; } -// for (tree_it = BeginModel; tree_it != mModelTree.end();tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// jacobian_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[0] << ";\n"; -// } -// } - - // Writing C function Static - StaticOutput << "void Static(double *y, double *x, double *residual, double *g1)\n"; - StaticOutput << "{\n"; - StaticOutput << " double lhs, rhs;\n\n"; - // Writing residual equations - StaticOutput << " /* Residual equations */\n"; - StaticOutput << " if (residual == NULL) return;\n"; - StaticOutput << " {\n"; - StaticOutput << model_tmp_output.str() << "\n"; - StaticOutput << model_output.str(); - // Writing Jacobian - StaticOutput << " /* Jacobian for endogenous variables without lag */\n"; - StaticOutput << " if (g1 == NULL) return;\n"; - StaticOutput << " {\n"; - StaticOutput << jacobian_tmp_output.str() << "\n"; - StaticOutput << jacobian_output.str(); - StaticOutput << " }\n"; - StaticOutput << " }\n"; - StaticOutput << "}\n\n"; - current_order = d; - return StaticOutput.str(); -} -//------------------------------------------------------------------------------ -string ModelTree::setDynamicModelC(void) -{ - TreeIterator tree_it; - int lEquationNBR = 0; - ostringstream lsymetric; // Used when writing symetric elements - ostringstream model_output;; // Used for storing model equations - ostringstream jacobian_output; // Used for storing jacobian equations - ostringstream model_tmp_output;; // Used for storing tmp expressions for model equations - ostringstream jacobian_tmp_output; // Used for storing tmp expressions for jacobian equations - ostringstream hessian_output; // Used for storing Hessian equations - ostringstream hessian_tmp_output; // Used for storing tmp expressions for Hessian equations - int d = current_order; - - - - // Reference count of token "0=0" is set to 0 - // Not to be printed as a temp expression - fill(ZeroEqZero->reference_count.begin(), - ZeroEqZero->reference_count.end(),0); - // Setting tmp_status to 0, -// for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) -// { -// (*tree_it)->tmp_status = 0; - -// } - // Case where residuals and Jacobian with respect to endogenous variables - // are computed - if (computeJacobian && !computeJacobianExo && !computeHessian) - { - // Clearing output string - model_output.str(""); - // Getting equations from model tree - // Starting from the end of equation - // Searching for the next '=' operator, - current_order = 1; - lEquationNBR = 0; - cout << "\tequations .. "; - for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) - { - if ((*tree_it)->op_code == EQUAL) - { - if (lEquationNBR < ModelParameters::eq_nbr) - { - model_output << getExpression(*tree_it, eDynamicEquations, lEquationNBR) << endl;; - lEquationNBR++; - } - else break; - } - } -// for (tree_it = BeginModel;tree_it != mModelTree.end(); tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// model_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// } -// } - - cout << "done \n"; - // Getting Jacobian from model tree - cout << "\tJacobian .. "; - lEquationNBR = 0; - for (int i = 0; i < mDerivativeIndex[0].size(); i++) + } + else + { + DynamicOutput << "void Dynamic(double *y, double *x, double *residual, double *g1, double *g2)\n"; + DynamicOutput << "{\n"; + DynamicOutput << " double lhs, rhs;\n\n"; + DynamicOutput << " /* Residual equations */\n"; + DynamicOutput << model_output.str(); + if (computeJacobian || computeJacobianExo) { - if (VariableTable::getType(mDerivativeIndex[0][i].derivators) == eEndogenous) - { - NodeID startJacobian = mDerivativeIndex[0][i].token_id; - string exp = getExpression(startJacobian, eDynamicDerivatives); - if (startJacobian != ZeroEqZero) - jacobian_output << " g1[" << mDerivativeIndex[0][i].equation_id+ - (VariableTable::getPrintIndex(mDerivativeIndex[0][i].derivators))* - ModelParameters::eq_nbr << "] = " << exp << ";\n"; - } + DynamicOutput << " /* Jacobian */\n"; + DynamicOutput << " if (g1 == NULL) return;\n"; + DynamicOutput << " {\n"; + DynamicOutput << jacobian_output.str(); + DynamicOutput << " }\n"; } -// for (tree_it = BeginModel;tree_it != mModelTree.end(); tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// jacobian_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// } -// } - cout << "done \n"; - - // Writing C function Dynamic - DynamicOutput << "void Dynamic(double *y, double *x, double *residual, double *g1, double *g2)\n"; - DynamicOutput << "{\n"; - DynamicOutput << " double lhs, rhs;\n\n"; - DynamicOutput << " /* Residual equations */\n"; - DynamicOutput << " if (residual == NULL) return;\n"; - DynamicOutput << " {\n"; - DynamicOutput << model_output.str() << "\n"; - DynamicOutput << model_output.str(); - DynamicOutput << " /* Jacobian for for endogenous variables */\n"; - DynamicOutput << " if (g1 == NULL) return;\n"; - DynamicOutput << " {\n"; - DynamicOutput << jacobian_tmp_output.str() << "\n"; - DynamicOutput << jacobian_output.str(); - DynamicOutput << " }\n"; - DynamicOutput << " }\n"; - DynamicOutput << "}\n\n"; - } - // Case where residuals and Jacobian with respect to endogenous and exogenous - // variables are computed - else if (computeJacobianExo && !computeHessian) - { - // Clearing output string - model_output.str(""); - jacobian_output.str(""); - current_order = 1; - lEquationNBR = 0; - // Getting equations from model tree - // Starting from the end of equation - // Searching for the next '=' operator, - - cout << "\tequations .. "; - for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) + if (computeHessian) { - if ((*tree_it)->op_code == EQUAL) - { - if (lEquationNBR < ModelParameters::eq_nbr) - { - model_output << getExpression(*tree_it, eDynamicEquations, lEquationNBR) << endl; - lEquationNBR++; - } - else break; - } + DynamicOutput << " /* Hessian for endogenous and exogenous variables */\n"; + DynamicOutput << " if (g2 == NULL) return;\n"; + DynamicOutput << " {\n"; + DynamicOutput << hessian_output.str() << lsymetric.str(); + DynamicOutput << " }\n"; } -// for (tree_it = BeginModel;tree_it != mModelTree.end(); tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// model_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// } -// } - cout << "done \n"; - - // Getting Jacobian from model tree - // Starting from the end of equation - // Searching for the next '=' operator, - - cout << "\tJacobian .. "; - for (int i = 0; i < mDerivativeIndex[0].size(); i++) - { - NodeID startJacobian = mDerivativeIndex[0][i].token_id; - string exp = getExpression(startJacobian, eDynamicDerivatives); - if (startJacobian != ZeroEqZero) - jacobian_output << " g1[" << mDerivativeIndex[0][i].equation_id + - (VariableTable::getSortID(mDerivativeIndex[0][i].derivators))* - ModelParameters::eq_nbr << "] = " << exp << ";\n"; - } -// for (tree_it = BeginModel;tree_it != mModelTree.end(); tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// jacobian_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// } -// } - cout << "done \n"; - - // Writing C function Dynamic - DynamicOutput << "void Dynamic(double *y, double *x, double *residual, double *g1, double *g2)\n"; - DynamicOutput << "{\n"; - DynamicOutput << " double lhs, rhs;\n\n"; - DynamicOutput << " /* Residual equations */\n"; - DynamicOutput << " if (residual == NULL) return;\n"; - DynamicOutput << " {\n"; - DynamicOutput << model_tmp_output.str() << "\n"; - DynamicOutput << model_output.str(); - DynamicOutput << " /* Jacobian for endogenous and exogenous variables */\n"; - DynamicOutput << " if (g1 == NULL) return;\n"; - DynamicOutput << " {\n"; - DynamicOutput << jacobian_tmp_output.str() << "\n"; - DynamicOutput << jacobian_output.str(); - DynamicOutput << " }\n"; - DynamicOutput << " }\n"; - DynamicOutput << "}\n\n"; - } - // Case where residuals, Jacobian and Hessian with respect to endogenous and exogenous - // variables are computed - else if (computeHessian && computeJacobianExo) - { - // Clearing output string - model_output.str(""); - jacobian_output.str(""); - hessian_output.str(""); - lsymetric.str(""); - - current_order = 2; - lEquationNBR = 0; - // Getting equations from model tree - // Starting from the end of equation - // Searching for the next '=' operator, - - cout << "\tequations .. "; - - for (tree_it = BeginModel; tree_it != mModelTree.end(); tree_it++) - { - if ((*tree_it)->op_code == EQUAL) - { - if (lEquationNBR < ModelParameters::eq_nbr) - { - model_output << getExpression(*tree_it, eDynamicEquations, lEquationNBR) << endl; - lEquationNBR++; - } - else break; - } - } -// for (tree_it = BeginModel;tree_it != mModelTree.end(); tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// model_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// } -// } - cout << "done \n"; - - // Getting Jacobian from model tree - // Starting from the end of equation - // Searching for the next '=' operator, - - cout << "\tJacobian .. "; - for (int i = 0; i < mDerivativeIndex[0].size(); i++) - { - NodeID startJacobian = mDerivativeIndex[0][i].token_id; - string exp = getExpression(startJacobian, eDynamicDerivatives); - if (startJacobian != ZeroEqZero) - jacobian_output << " g1[" << mDerivativeIndex[0][i].equation_id+ - (VariableTable::getSortID(mDerivativeIndex[0][i].derivators)) - *ModelParameters::eq_nbr << "] = " << exp << ";\n"; - } -// for (tree_it = BeginModel;tree_it != mModelTree.end(); tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// jacobian_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// } -// } - cout << "done \n"; - - // Getting Hessian from model tree - // Starting from the end of equation - // Searching for the next '=' operator, - lEquationNBR = 0; - cout << "\tHessian .. "; - for (int i = 0; i < mDerivativeIndex[1].size(); i++) - { - NodeID startHessian = mDerivativeIndex[1][i].token_id; - string exp = getExpression(startHessian, eDynamicDerivatives); - - int varID1 = mDerivativeIndex[1][i].derivators/VariableTable::size(); - int varID2 = mDerivativeIndex[1][i].derivators-varID1*VariableTable::size(); - //cout << "ID = " << startHessian << " exp = " << exp << "\n"; - if (startHessian != ZeroEqZero) - { - hessian_output << " g2[" << mDerivativeIndex[1][i].equation_id+ - mDerivativeIndex[1][i].derivators* - ModelParameters::eq_nbr << "] = " << exp << ";\n"; - // Treating symetric elements - if (varID1 != varID2) - lsymetric << " g2[" << mDerivativeIndex[1][i].equation_id+ - (varID2*VariableTable::size()+varID1)* - ModelParameters::eq_nbr << "] = " << - "g2[" << mDerivativeIndex[1][i].equation_id+ - (mDerivativeIndex[1][i].derivators)* - ModelParameters::eq_nbr << "];\n"; - } - - } -// for (tree_it = BeginModel;tree_it != mModelTree.end(); tree_it++) -// { -// if (((*tree_it)->tmp_status == 1) && -// writeAsTemp(*tree_it)) -// { -// (*tree_it)->tmp_status = -1; -// hessian_tmp_output << " double T" << (*tree_it)->idx << " = " << (*tree_it)->exp[1] << ";\n"; -// } -// } - cout << "done \n"; - - // Writing C function Dynamic - DynamicOutput << "void Dynamic(double *y, double *x, double *residual, double *g1, double *g2)\n"; - DynamicOutput << "{\n"; - DynamicOutput << " double lhs, rhs;\n\n"; - DynamicOutput << " /* Residual equations */\n"; - DynamicOutput << " if (residual == NULL) return;\n"; - DynamicOutput << " {\n"; - DynamicOutput << model_tmp_output.str() << "\n"; - DynamicOutput << model_output.str(); - DynamicOutput << " /* Jacobian for endogenous and exogenous variables */\n"; - DynamicOutput << " if (g1 == NULL) return;\n"; - DynamicOutput << " {\n"; - DynamicOutput << jacobian_tmp_output.str() << "\n"; - DynamicOutput << jacobian_output.str(); - DynamicOutput << " /* Hessian for endogenous and exogenous variables */\n"; - DynamicOutput << " if (g2 == NULL) return;\n"; - DynamicOutput << " {\n"; - DynamicOutput << hessian_tmp_output.str() << "\n"; - DynamicOutput << hessian_output.str() << lsymetric.str(); - DynamicOutput << " }\n"; - DynamicOutput << " }\n"; - DynamicOutput << " }\n"; - DynamicOutput << "}\n\n"; - } - current_order = d; - return DynamicOutput.str(); + DynamicOutput << "}\n\n"; + } +current_order = d; +return DynamicOutput.str(); } //------------------------------------------------------------------------------ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationType, int iEquationID) @@ -1704,307 +1106,6 @@ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationTy } return exp.str(); } -// - -// // Stack of temporary tokens -// stack <int, vector<NodeID> > stack_token; -// // Stack of temporary expressions -// stack <int, vector<string> > stack_expression; -// // Temporary output -// ostringstream exp; -// // temporary variables for saving arguments and name oparator -// string argument1, argument2, op_name; -// // Current token ID -// NodeID currentTokenID; -// int current_op, last_op; - -// // Initialization of "followed" flags -// StartID->followed1 = false; -// StartID->followed2 = false; -// // Setting equation type for exp field -// int eq_type; -// switch (iEquationType) -// { -// case eStaticEquations: -// case eStaticDerivatives: -// eq_type = 0; -// break; -// default : -// eq_type = 1; -// } - - -// stack_token.push(StartID); -// current_op = last_op = stack_token.top()->op_code; -// currentTokenID = StartID; - -// // Main loop : -// // Repeat for last token from the stack -// // (1) if argument is temporary result, and not yet followed, -// // set it as followed (flag) and push corresponding token -// // on the token stack -// // (2) argument followed, or final argument -// // (2.1) if argument is followed -// // - set argument1 (or argument2) by last expression on -// // expression tack -// // - pop last expression from expression stack -// // (2.2) if final argument -// // set argument1 (or argument2) by final argument -// // (3) set op_name by last token from the token stack -// // (3) pop last token from the token stack -// // (4) write temporary expression (using argument1, argument2 -// // and op_name) and push it on the expression stack -// // (5) - -// while (stack_token.size() > 0) -// { - -// currentTokenID = stack_token.top(); - -// //currentTokenID = mIndexOfTokens[Key((MToken) stack_token.top())]; -// // Testing if expression has been writen as temp result -// if ( currentTokenID->exp[eq_type].size() == 0 ) -// { -// //if (currentTokenID != 0 && currentTokenID != 3) -// // cout << "currentTokenID = " << currentTokenID << endl; -// // First argument is a temporary result, -// // pushing token on token stack and setting that argument to be followed -// if ((currentTokenID->followed1 == false) && -// (currentTokenID->type1 == eTempResult)) -// { -// currentTokenID->followed1 = true; -// // Initialization of "followed" flags -// currentTokenID->id1->followed1 = false; -// currentTokenID->id1->followed2 = false; -// stack_token.push(currentTokenID->id1); -// } -// // Second argument has id >=0 (temporary result), -// // pushing token on stack and setting that argument to be followed -// else if ((currentTokenID->followed2 == false) && -// (currentTokenID->id2 != NullID)) -// { -// currentTokenID->followed2 = true; -// // Initialization of "followed" flags -// currentTokenID->id2->followed1 = false; -// currentTokenID->id2->followed2 = false; -// stack_token.push(currentTokenID->id2); -// } -// // Writing expression -// else -// { -// //cout << "currentTokenID = " << currentTokenID << endl; -// // Final token -// if (currentTokenID->op_code == NoOpCode) -// { -// argument1 = getArgument(currentTokenID->id1, currentTokenID->type1, iEquationType); -// //cout << "Test 1 : argument1 = " << argument1 << endl; -// current_op = last_op; -// op_name = currentTokenID->op_name; -// exp.str(""); -// stack_token.pop(); -// // Saving last operator for the followed argument -// if (stack_token.size() > 0) -// { -// last_op = stack_token.top()->op_code; -// } -// else -// { -// last_op = current_op; -// } -// exp << argument1; -// currentTokenID->tmp_status = 0; -// } -// // Testing if unary or binary token -// // Binary operator -// else if (currentTokenID->id2 != NullID) -// { -// argument2 = stack_expression.top(); -// //cout << "Test 2 : argument2 = " << argument2 << endl; -// stack_expression.pop(); -// argument1 = stack_expression.top(); -// //cout << "Test 2 : argument1 = " << argument1 << endl; -// current_op = currentTokenID->op_code; -// if (argument1 == "y(54)" && current_op == DIVIDE) -// { -// cout << "y(54)/" << argument2 << "\n"; -// } -// stack_expression.pop(); -// op_name = currentTokenID->op_name; -// exp.str(""); -// stack_token.pop(); -// // Saving last operator for the followed argument -// if (stack_token.size() > 0) -// { -// last_op = stack_token.top()->op_code; -// } -// else -// { -// last_op = current_op; -// } -// if (operator_table.precedence(current_op) < operator_table.precedence(last_op)) -// { -// // Comma operator, no parentheses -// // parentheses are writing with function operator -// if (current_op == COMMA) -// { -// exp << argument1 << op_name << argument2 ; -// } -// else if ((offset == 1) || (current_op != POWER)) -// { -// exp << '(' << argument1 << op_name << argument2 << ')'; -// } -// else -// { -// exp << '(' << "pow(" << argument1 << ", " << argument2 << "))"; -// } -// currentTokenID->tmp_status = 1; -// } -// else -// { -// if (current_op == EQUAL) -// { -// //Writing model equations -// switch(iEquationType) -// { -// case eDynamicDerivatives : -// case eStaticDerivatives : -// { -// exp << argument1; -// NodeID id1 = currentTokenID->id1; -// if (currentTokenID->idx == 2305) -// { -// cout << "tmp_status " << currentTokenID->tmp_status << " id1 " << id1->tmp_status <<"\n"; -// } -// currentTokenID->tmp_status = id1->tmp_status; -// currentTokenID->tmp_status = 1; -// //cout << "current_order = " << current_order << " : " << -// //mModelTree[currentTokenID].reference_count[current_order] << " : " << exp.str() << endl; -// } -// break; -// case eDynamicEquations : -// exp << " lhs = " << argument1 << ";\n"; -// exp << " rhs = " << argument2 << ";\n"; -// exp << " residual" << lpar << iEquationID+offset << rpar << " = lhs - rhs;\n"; -// currentTokenID->tmp_status = 0; -// //cout << "current_order = " << current_order << " : " -// //<< mModelTree[currentTokenID].reference_count[current_order] << " : " << exp.str(); -// break; -// case eStaticEquations : -// exp << " lhs = " << argument1 << ";\n"; -// exp << " rhs = " << argument2 << ";\n"; -// exp << " residual" << lpar << iEquationID+offset << rpar << " = lhs - rhs;\n"; -// currentTokenID->tmp_status = 0; -// break; -// } -// } -// else -// { // Matlab format -// if (offset == 1) -// exp << argument1 << op_name << argument2; -// // C format -// else -// if (current_op == POWER) -// exp << "pow(" << argument1 << "," << argument2 << ')'; -// // In C language --X is not allowed -// else if (last_op == MINUS) -// exp << '(' << argument1 << op_name << argument2 << ')'; -// else -// exp << argument1 << op_name << argument2; - -// currentTokenID->tmp_status = 1; -// } -// } -// } -// // Unary operator -// else -// { -// argument1 = stack_expression.top(); -// //cout << "Test 2 : argument1 = " << argument1 << endl; -// current_op = currentTokenID->op_code; -// stack_expression.pop(); -// op_name = stack_token.top()->op_name; -// exp.str(""); -// stack_token.pop(); -// // Saving last operator for the followed argument -// if (stack_token.size() > 0) -// { -// last_op = stack_token.top()->op_code; -// } -// else -// { -// last_op = current_op; -// } -// /* -// if (operator_table.precedence(current_op) < operator_table.precedence(last_op)) -// { -// exp << '(' << op_name << argument1 << ')'; -// currentTokenID->tmp_status = 1; -// // Exclude "-cte" from temprary expressions -// if (currentTokenID->op_code == UMINUS) -// { -// NodeID id1 = currentTokenID->id1; -// if (id1->type1 == eNumericalConstant) -// currentTokenID->tmp_status = 0; -// } - -// } -// else -// { -// */ -// currentTokenID->tmp_status = 1; -// // Case of functions -// if (operator_table.isfunction(current_op) == true) -// { -// exp << op_name << '(' << argument1 << ')'; -// } -// else -// { -// exp << op_name << '(' << argument1 << ')'; -// // Exclude "-cte" from temprary expressions -// NodeID id1 = currentTokenID->id1; -// if (id1->type1 != eTempResult) -// currentTokenID->tmp_status = 0; -// } -// //} -// } -// if (currentTokenID->tmp_status && -// writeAsTemp(currentTokenID)) -// { -// currentTokenID->exp[eq_type] = exp.str(); -// exp.str(""); -// exp << "T" << currentTokenID->idx; -// stack_expression.push(exp.str()); -// } -// else -// { -// stack_expression.push(exp.str()); -// currentTokenID->exp[eq_type] = exp.str(); - -// } -// } -// } -// // Expression is in data member exp[] -// else -// { -// if (currentTokenID->tmp_status && -// writeAsTemp(currentTokenID)) -// { -// exp.str(""); -// stack_token.pop(); -// exp << "T" << currentTokenID->idx; -// stack_expression.push(exp.str()); -// } -// else -// { -// stack_token.pop(); -// stack_expression.push(currentTokenID->exp[eq_type]); -// } -// last_op = current_op; -// } - -// } -// return stack_expression.top(); -// } //------------------------------------------------------------------------------ /* void ModelTree::RemoveUnref(int iBeginID, int iEndID, int iOrder) @@ -2133,193 +1234,193 @@ void ModelTree::DecrementUnref(int iBeginID, int iEndID, int iOrder) inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquationType) { - stringstream argument; + stringstream argument; - if (type == eParameter) - { - argument << param_name << lpar << (int)id+offset << rpar; - } - else if (type == eNumericalConstant) - { - argument << NumericalConstants::get((int) id); - } - else if (type == eEndogenous || type == eExogenous || type == eExogenousDet) - if (iEquationType == eStaticEquations || iEquationType == eStaticDerivatives) - { - int idx = VariableTable::getSymbolID((int) id)+offset; - if (type == eEndogenous) - { - argument << "y" << lpar << idx << rpar; - } - else if (type == eExogenous) - { - argument << "x" << lpar << idx << rpar; - } - else if (type == eExogenousDet) - { - argument << "exedet_" << lpar << idx << rpar; - } + if (type == eParameter) + { + argument << param_name << lpar << (int)id+offset << rpar; + } + else if (type == eNumericalConstant) + { + argument << NumericalConstants::get((int) id); + } + else if (type == eEndogenous || type == eExogenous || type == eExogenousDet) + if (iEquationType == eStaticEquations || iEquationType == eStaticDerivatives) + { + int idx = VariableTable::getSymbolID((int) id)+offset; + if (type == eEndogenous) + { + argument << "y" << lpar << idx << rpar; } - else + else if (type == eExogenous) + { + argument << "x" << lpar << idx << rpar; + } + else if (type == eExogenousDet) { - if (type == eEndogenous) - { - int idx = VariableTable::getPrintIndex((int) id)+offset; - argument << "y" << lpar << idx << rpar; - } - else if (type == eExogenous) - { - int idx = VariableTable::getSymbolID((int) id)+offset; - int lag = VariableTable::getLag((int) id); - if (offset == 1) - { - if ( lag != 0) - { - argument << "x" << lpar << "it_ + " << lag - << ", " << idx << rpar; - } - else - { - argument << "x" << lpar << "it_, " << idx << rpar; - } - } - else - { - if ( lag != 0) - { - argument << "x" << lpar << "it_+" << lag - << "+" << idx << "*nb_row_x" << rpar; - } - else - { - argument << "x" << lpar << "it_+" << idx << "*nb_row_x" << rpar; - } - } - } - else if (type == eExogenousDet) - { - int idx = VariableTable::getSymbolID((int) id)+offset; - int lag = VariableTable::getLag((int) id); - if (offset == 1) - { - if (lag != 0) - { - argument << "exdet_" << lpar << "it_ + " << lag - << ", " << idx << rpar; - } - else - { - argument << "exdet_" << lpar << "it_, " << idx << rpar; - } - } - else - { - if (lag != 0) - { - argument << "exdet_" << lpar << "it_ + " << lag - << "+" << idx << "*nb_row_xd" << rpar; - } - else - { - argument << "exdet_" << lpar << "it_+" << idx << "*nb_row_xd" << rpar; - } - } + argument << "exedet_" << lpar << idx << rpar; + } + } + else + { + if (type == eEndogenous) + { + int idx = VariableTable::getPrintIndex((int) id)+offset; + argument << "y" << lpar << idx << rpar; + } + else if (type == eExogenous) + { + int idx = VariableTable::getSymbolID((int) id)+offset; + int lag = VariableTable::getLag((int) id); + if (offset == 1) + { + if ( lag != 0) + { + argument << "x" << lpar << "it_ + " << lag + << ", " << idx << rpar; + } + else + { + argument << "x" << lpar << "it_, " << idx << rpar; + } + } + else + { + if ( lag != 0) + { + argument << "x" << lpar << "it_+" << lag + << "+" << idx << "*nb_row_x" << rpar; + } + else + { + argument << "x" << lpar << "it_+" << idx << "*nb_row_x" << rpar; + } + } + } + else if (type == eExogenousDet) + { + int idx = VariableTable::getSymbolID((int) id)+offset; + int lag = VariableTable::getLag((int) id); + if (offset == 1) + { + if (lag != 0) + { + argument << "exdet_" << lpar << "it_ + " << lag + << ", " << idx << rpar; + } + else + { + argument << "exdet_" << lpar << "it_, " << idx << rpar; + } + } + else + { + if (lag != 0) + { + argument << "exdet_" << lpar << "it_ + " << lag + << "+" << idx << "*nb_row_xd" << rpar; + } + else + { + argument << "exdet_" << lpar << "it_+" << idx << "*nb_row_xd" << rpar; + } + } - } } - return argument.str(); + } + return argument.str(); } //------------------------------------------------------------------------------ void ModelTree::ModelInitialization(void) { - // Exit if there is no equation in model file*/ - if (ModelParameters::eq_nbr == 0) - { - (* error) ("no equations found in model file"); - } - cout << ModelParameters::eq_nbr << " equation(s) found \n"; - // Sorting variable table - VariableTable::Sort(); - - // Setting number of equations in ModelParameters class - // Here no derivative are computed - BeginModel++; - min_cost = 40*operator_table.cost(PLUS,offset); - // Setting format of parentheses - if (offset == 1) - { - lpar = '('; - rpar = ')'; - param_name = "params"; - } - else - { - lpar = '['; - rpar = ']'; - param_name = "params"; - } - /* Writing initialisation for M_.lead_lag_incidence matrix - M_.lead_lag_incidence is a matrix with as many columns as there are - endogenous variables and as many rows as there are periods in the - models (nbr of rows = M_.max_lag+M_.max_lead+1) - - The matrix elements are equal to zero if a variable isn't present in the - model at a given period. - */ - // Initializing matrix to zero - output << "M_.lead_lag_incidence = ["; - /* - zeros(" << - ModelParameters::max_lag+ModelParameters::max_lead+1 << ", " << - ModelParameters::endo_nbr << ");\n"; - */ - // Loop on endogenous variables - for (int endoID = 0; endoID < ModelParameters::endo_nbr; endoID++) + // Exit if there is no equation in model file*/ + if (ModelParameters::eq_nbr == 0) + { + (* error) ("no equations found in model file"); + } + cout << ModelParameters::eq_nbr << " equation(s) found \n"; + // Sorting variable table + VariableTable::Sort(); + + // Setting number of equations in ModelParameters class + // Here no derivative are computed + BeginModel++; + min_cost = 40*operator_table.cost(PLUS,offset); + // Setting format of parentheses + if (offset == 1) + { + lpar = '('; + rpar = ')'; + param_name = "params"; + } + else + { + lpar = '['; + rpar = ']'; + param_name = "params"; + } + /* Writing initialisation for M_.lead_lag_incidence matrix + M_.lead_lag_incidence is a matrix with as many columns as there are + endogenous variables and as many rows as there are periods in the + models (nbr of rows = M_.max_lag+M_.max_lead+1) + + The matrix elements are equal to zero if a variable isn't present in the + model at a given period. + */ + // Initializing matrix to zero + output << "M_.lead_lag_incidence = ["; + /* + zeros(" << + ModelParameters::max_lag+ModelParameters::max_lead+1 << ", " << + ModelParameters::endo_nbr << ");\n"; + */ + // Loop on endogenous variables + for (int endoID = 0; endoID < ModelParameters::endo_nbr; endoID++) + { + output << "\n\t"; + // Loop on periods + for (int lag = -ModelParameters::max_lag; lag <= ModelParameters::max_lead; lag++) { - output << "\n\t"; - // Loop on periods - for (int lag = -ModelParameters::max_lag; lag <= ModelParameters::max_lead; lag++) - { - // Getting name of symbol - string name = SymbolTable::getNameByID(eEndogenous, endoID); - // and its variableID if exists with current period - int varID = VariableTable::getID(name, lag); - //cout << name << " " << varID << " " << lag << " " << VariableTable::getPrintIndex(varID)+1 << " " << VariableTable::getSortID(varID)+1 << endl; + // Getting name of symbol + string name = SymbolTable::getNameByID(eEndogenous, endoID); + // and its variableID if exists with current period + int varID = VariableTable::getID(name, lag); + //cout << name << " " << varID << " " << lag << " " << VariableTable::getPrintIndex(varID)+1 << " " << VariableTable::getSortID(varID)+1 << endl; - if (varID >=0) - { - output << " " << VariableTable::getPrintIndex(varID)+1; - } - else - { - output << " 0"; - } - } - output << ";"; + if (varID >=0) + { + output << " " << VariableTable::getPrintIndex(varID)+1; + } + else + { + output << " 0"; + } } - output << "]';\n"; + output << ";"; + } + output << "]';\n"; - // Writing initialization for some other variables - output << "M_.exo_name_orig_ord = [1:" << ModelParameters::exo_nbr << "];\n"; - output << "M_.maximum_lag = " << ModelParameters::max_lag << ";\n"; - output << "M_.maximum_lead = " << ModelParameters::max_lead<< ";\n"; - if (ModelParameters::endo_nbr) - output << "oo_.steady_state = zeros(" << ModelParameters::endo_nbr << ", 1);\n"; - if (ModelParameters::exo_nbr) - output << "oo_.exo_steady_state = zeros(" << ModelParameters::exo_nbr << ", 1);\n"; - if (ModelParameters::parameter_nbr) - output << "M_.params = zeros(" << ModelParameters::parameter_nbr << ", 1);\n"; - if (ModelParameters::exo_det_nbr) - output << "oo_exdet_ = zeros(" << ModelParameters::exo_det_nbr << ", 1);\n"; - if (ModelParameters::exo_det_nbr) - output << "oo_exedet_ = zeros(" << ModelParameters::exo_det_nbr << ", 1);\n"; + // Writing initialization for some other variables + output << "M_.exo_names_orig_ord = [1:" << ModelParameters::exo_nbr << "];\n"; + output << "M_.maximum_lag = " << ModelParameters::max_lag << ";\n"; + output << "M_.maximum_lead = " << ModelParameters::max_lead<< ";\n"; + if (ModelParameters::endo_nbr) + output << "oo_.steady_state = zeros(" << ModelParameters::endo_nbr << ", 1);\n"; + if (ModelParameters::exo_nbr) + output << "oo_.exo_steady_state = zeros(" << ModelParameters::exo_nbr << ", 1);\n"; + if (ModelParameters::parameter_nbr) + output << "M_.params = zeros(" << ModelParameters::parameter_nbr << ", 1);\n"; + if (ModelParameters::exo_det_nbr) + output << "oo_exdet_ = zeros(" << ModelParameters::exo_det_nbr << ", 1);\n"; + if (ModelParameters::exo_det_nbr) + output << "oo_exedet_ = zeros(" << ModelParameters::exo_det_nbr << ", 1);\n"; } //------------------------------------------------------------------------------ string ModelTree::get() { - return output.str(); + return output.str(); } //------------------------------------------------------------------------------ inline int ModelTree::optimize(NodeID node) @@ -2357,87 +1458,87 @@ inline int ModelTree::optimize(NodeID node) #ifdef TEST_MODELTREE int main(void) { - SymbolTable st; - VariableTable vt; - NumericalConstants nc; - ModelTree model; - vector<int> t(20); + SymbolTable st; + VariableTable vt; + NumericalConstants nc; + ModelTree model; + vector<int> t(20); - //Adding 2 different symbols with AddSymbolDeclar - SymbolTable::AddSymbolDeclar("c",eExogenous); - //SymbolTable::PrintSymbolTable(); - SymbolTable::AddSymbolDeclar("k",eEndogenous); - //SymbolTable::PrintSymbolTable(); - SymbolTable::AddSymbolDeclar("aa",eParameter); - //SymbolTable::PrintSymbolTable(); - SymbolTable::AddSymbolDeclar("x",eExogenous); - SymbolTable::AddSymbolDeclar("alph",eParameter); - SymbolTable::AddSymbolDeclar("delt",eParameter); - - VariableTable::AddVariable("k",0); - VariableTable::AddVariable("x",-1); - VariableTable::AddVariable("c",-1); + //Adding 2 different symbols with AddSymbolDeclar + SymbolTable::AddSymbolDeclar("c",eExogenous); + //SymbolTable::PrintSymbolTable(); + SymbolTable::AddSymbolDeclar("k",eEndogenous); + //SymbolTable::PrintSymbolTable(); + SymbolTable::AddSymbolDeclar("aa",eParameter); + //SymbolTable::PrintSymbolTable(); + SymbolTable::AddSymbolDeclar("x",eExogenous); + SymbolTable::AddSymbolDeclar("alph",eParameter); + SymbolTable::AddSymbolDeclar("delt",eParameter); + + VariableTable::AddVariable("k",0); + VariableTable::AddVariable("x",-1); + VariableTable::AddVariable("c",-1); - SymbolTable::AddSymbolDeclar("x1",eEndogenous); - SymbolTable::AddSymbolDeclar("x2",eExogenousDet); - //SymbolTable::AddSymbolDeclar("x3",eExogenous); - - VariableTable::AddVariable("x1",-1); - VariableTable::AddVariable("x2",1); - //VariableTable::AddVariable("x3",-1); - //VariableTable::AddVariable("k",1); - //VariableTable::AddVariable("y",0); - - - t[0] = model.AddToken("aa"); - t[1] = model.AddToken("x",-1); - t[2] = model.AddToken("k",0); - t[3] = model.AddToken(Argument(t[0], eTempResult), - Argument(t[1], eTempResult), TIMES); - t[4] = model.AddToken("alph"); - t[5] = model.AddToken(Argument(t[2], eTempResult), - Argument(t[4], eTempResult), POWER); - t[6] = model.AddToken(Argument(t[3], eTempResult), - Argument(t[5], eTempResult), TIMES); + SymbolTable::AddSymbolDeclar("x1",eEndogenous); + SymbolTable::AddSymbolDeclar("x2",eExogenousDet); + //SymbolTable::AddSymbolDeclar("x3",eExogenous); + + VariableTable::AddVariable("x1",-1); + VariableTable::AddVariable("x2",1); + //VariableTable::AddVariable("x3",-1); + //VariableTable::AddVariable("k",1); + //VariableTable::AddVariable("y",0); + + + t[0] = model.AddToken("aa"); + t[1] = model.AddToken("x",-1); + t[2] = model.AddToken("k",0); + t[3] = model.AddToken(Argument(t[0], eTempResult), + Argument(t[1], eTempResult), TIMES); + t[4] = model.AddToken("alph"); + t[5] = model.AddToken(Argument(t[2], eTempResult), + Argument(t[4], eTempResult), POWER); + t[6] = model.AddToken(Argument(t[3], eTempResult), + Argument(t[5], eTempResult), TIMES); - t[7] = model.AddToken("delt"); - //t[8] = model.AddToken("1"); - t[9] = model.AddToken(Argument(1, eTempResult), - Argument(t[7], eTempResult), MINUS); - t[10] = model.AddToken(Argument(t[9], eTempResult), - Argument(t[2], eTempResult), TIMES); + t[7] = model.AddToken("delt"); + //t[8] = model.AddToken("1"); + t[9] = model.AddToken(Argument(1, eTempResult), + Argument(t[7], eTempResult), MINUS); + t[10] = model.AddToken(Argument(t[9], eTempResult), + Argument(t[2], eTempResult), TIMES); - t[11] = model.AddToken(Argument(t[2], eTempResult), - UMINUS); - - t[12] = model.AddToken(Argument(t[11], eTempResult), - Argument(t[6], eTempResult), PLUS); - t[13] = model.AddToken(Argument(t[12], eTempResult), - Argument(t[10], eTempResult), PLUS); - t[14] = model.AddToken(Argument(t[13], eTempResult), - Argument(t[10], eTempResult), PLUS); - t[15] = model.AddToken("c",-1); - t[16] = model.AddToken(Argument(t[15], eTempResult), - Argument(t[14], eTempResult), EQUAL); - //try - //{ - model.derive(2); - model.setStaticModel(); - model.setDynamicStochasticModel(); - model.Open("static_model.m", "dynamic_model.m"); - model.Save(); - //cout << model.getStaticModel(); - //} - //catch(Error err) - //{ - // cout << "error---------------------\n"; - // exit(-1); - //} - //cout << model.getDynamicDeterministicModel() << endl; - //cout << model.getDynamicStochasticModel() << endl; - //VariableTable::Sort(); + t[11] = model.AddToken(Argument(t[2], eTempResult), + UMINUS); + + t[12] = model.AddToken(Argument(t[11], eTempResult), + Argument(t[6], eTempResult), PLUS); + t[13] = model.AddToken(Argument(t[12], eTempResult), + Argument(t[10], eTempResult), PLUS); + t[14] = model.AddToken(Argument(t[13], eTempResult), + Argument(t[10], eTempResult), PLUS); + t[15] = model.AddToken("c",-1); + t[16] = model.AddToken(Argument(t[15], eTempResult), + Argument(t[14], eTempResult), EQUAL); + //try + //{ + model.derive(2); + model.setStaticModel(); + model.setDynamicStochasticModel(); + model.Open("static_model.m", "dynamic_model.m"); + model.Save(); + //cout << model.getStaticModel(); + //} + //catch(Error err) + //{ + // cout << "error---------------------\n"; + // exit(-1); + //} + //cout << model.getDynamicDeterministicModel() << endl; + //cout << model.getDynamicStochasticModel() << endl; + //VariableTable::Sort(); } #endif //------------------------------------------------------------------------------ diff --git a/parser.src/NumericalConstants.cc b/parser.src/NumericalConstants.cc index d8a73221afb5b3fb6cd1884cef03576c04f06547..1a3d6ee76409106a8435365afab2ec86f0fa56ec 100644 --- a/parser.src/NumericalConstants.cc +++ b/parser.src/NumericalConstants.cc @@ -35,7 +35,7 @@ int NumericalConstants::AddConstant(string iConst) //------------------------------------------------------------------------------ string NumericalConstants::get(int ID) { - if (ID < mNumericalConstants.size()) + if (ID < (int)mNumericalConstants.size()) { return mNumericalConstants[ID]; } diff --git a/parser.src/OperatorTable.cc b/parser.src/OperatorTable.cc index fd04fb4137a22fb3022e93491a8017e32e158509..005207c75cbbfcd756af9933ace89f21fa2fe42a 100644 --- a/parser.src/OperatorTable.cc +++ b/parser.src/OperatorTable.cc @@ -65,6 +65,7 @@ OperatorTable::OperatorTable() operator_table[SQRT].precedence = operator_table[NAME].precedence = 6; + // Operator costs for M files operator_table[COMMA].cost[1] = 0; operator_table[EQUAL].cost[1] = 0; @@ -126,7 +127,7 @@ OperatorTable::OperatorTable() operator_table[TIMES].isfunction = false; operator_table[DIVIDE].isfunction = false; operator_table[UMINUS].isfunction = false; - operator_table[POWER].isfunction = true; + operator_table[POWER].isfunction = false; operator_table[EXP].isfunction = true; operator_table[LOG].isfunction = true; operator_table[LOG10].isfunction = true; diff --git a/parser.src/Shocks.cc b/parser.src/Shocks.cc index 049cecce1b7b2bbc110828b1d74ee613eacb0d2f..b320257d2dc8af599455a0ceccb2b5e353411efb 100644 --- a/parser.src/Shocks.cc +++ b/parser.src/Shocks.cc @@ -48,7 +48,7 @@ void Shocks::AddShock(shocktype type, int id1, int id2, string value) string msg = "in shocks statement, number of periods and values dont agree"; (* error) (msg.c_str()); } - for (int i = 0; i < mPeriod1.size(); i++) + for (unsigned int i = 0; i < mPeriod1.size(); i++) { string period1 = mPeriod1[i]; string period2 = mPeriod2[i]; diff --git a/parser.src/SigmaeInitialization.cc b/parser.src/SigmaeInitialization.cc index 00fd36a5110ef420c189658b3d78f8705695af1c..d2424662313ffefb86e8b0c7a42f3ecbeb792ae0 100644 --- a/parser.src/SigmaeInitialization.cc +++ b/parser.src/SigmaeInitialization.cc @@ -39,8 +39,9 @@ void SigmaeInitialization::EndOfRow() //------------------------------------------------------------------------------ void SigmaeInitialization::CheckMatrix(void) { - vector<vector<string> >::iterator ir, irend; - int inc, nbe; + vector<vector<string> >::iterator ir; + unsigned int nbe; + int inc; // Checking if first or last row has one element. if (matrix.front().size() == 1) { @@ -72,10 +73,10 @@ void SigmaeInitialization::CheckMatrix(void) //------------------------------------------------------------------------------ void SigmaeInitialization::SetMatrix(void) { - int ic, ic1; - int ir, ir1; + unsigned int ic, ic1; + unsigned int ir, ir1; - *output << "M_.Sigma_e = [...\n"; + *output << "M_.Sigma_e = [...\n"; for (ir = 0; ir < matrix.size(); ir++) { *output << "\t"; diff --git a/parser.src/SymbolTable.cc b/parser.src/SymbolTable.cc index 268fa1fffee801d9ab7d438742014d385545f4c0..ba66daaf2dc954e7577dbdacf658c0bb5404a218 100644 --- a/parser.src/SymbolTable.cc +++ b/parser.src/SymbolTable.cc @@ -35,36 +35,32 @@ int SymbolTable::AddSymbol(string name,Type type, string tex_name) name_table[(int) type].push_back(name); tex_name_table[(int) type].push_back(tex_name); - if (type == eExogenous) - { + switch (type) + { + case eExogenous: symboltable[name].id = ModelParameters::exo_nbr; - ModelParameters::exo_nbr++; - return ModelParameters::exo_nbr-1; - } - else if (type == eExogenousDet) - { + ModelParameters::exo_nbr++; + return ModelParameters::exo_nbr-1; + case eExogenousDet: symboltable[name].id = ModelParameters::exo_det_nbr; ModelParameters::exo_det_nbr++; return ModelParameters::exo_det_nbr-1; - } - else if (type == eEndogenous) - { + case eEndogenous: symboltable[name].id = ModelParameters::endo_nbr; ModelParameters::endo_nbr++; return ModelParameters::endo_nbr-1; - } - else if (type == eParameter) - { + case eParameter: symboltable[name].id = ModelParameters::parameter_nbr; ModelParameters::parameter_nbr++; return ModelParameters::parameter_nbr-1; - } - else if (type == eRecursiveVariable) - { + case eRecursiveVariable: symboltable[name].id = ModelParameters::recur_nbr; ModelParameters::recur_nbr++; return ModelParameters::recur_nbr-1; - } + default: + // should never happen + return -1; + } } //------------------------------------------------------------------------------ @@ -83,6 +79,7 @@ int SymbolTable::AddSymbolDeclar(string name,Type type, string tex_name) else{ string msg = "symbol " + name + " declared more than once with different types."; (* error) (msg.c_str()); + return -1; } } @@ -159,11 +156,12 @@ void SymbolTable::clean() nb_type[t]--; unused += "fprintf(1,'%-30s"; switch(types[t]) - { - case eEndogenous : unused += "Endogenous variable\\n','";break; - case eExogenous : unused += "Exogenous variable\\n','";break; - case eExogenousDet : unused += "Exogenous deterministic variable\\n','";break; - } + { + case eEndogenous : unused += "Endogenous variable\\n','";break; + case eExogenous : unused += "Exogenous variable\\n','";break; + case eExogenousDet : unused += "Exogenous deterministic variable\\n','";break; + default : ; + } unused += name; unused += "');\n"; warning = true; diff --git a/parser.src/VariableTable.cc b/parser.src/VariableTable.cc index 499d98574f1bd4d3e40fe9be57a40e36965b04a5..f798dfdb475460a9a2c1036e3e8c5568ba8d0ead 100644 --- a/parser.src/VariableTable.cc +++ b/parser.src/VariableTable.cc @@ -107,7 +107,7 @@ void VariableTable::Sort(void) return; } // First putting types into TypesToSort - for (int id=0; id < mVariableIndex.size(); id++) + for (unsigned int id=0; id < mVariableIndex.size(); id++) { key = mVariableIndex[id]; variable = mVariableTable[key]; @@ -146,7 +146,7 @@ void VariableTable::Sort(void) mPrintFormatIndex.resize(VarToSort.size()); Type type = Types[VarToSort[0].second]; int index = 0; - for (int id = 0; id < VarToSort.size(); id++) + for (unsigned int id = 0; id < VarToSort.size(); id++) { int id2 = VarToSort[id].second; mSortedVariableID[id2] = id; diff --git a/parser.src/bin/makefile b/parser.src/bin/makefile index c539971dc6265cf90cb9ac48c2353c8b0a13986b..90350bf4d4c23bda3760d4ea66bd94829c685a1e 100644 --- a/parser.src/bin/makefile +++ b/parser.src/bin/makefile @@ -1,150 +1,312 @@ -CPP = c++ -ifeq ($(DEBUG),yes) - CPPFLAGS = -mno-cygwin -ggdb -Wall - CPPFLAGS = -ggdb -Wall -else - CPPFLAGS = -mno-cygwin -O1 -endif -OBJ=\ - ComputingTasks.o\ - DynareBison.o\ - DynareFlex.o\ - DynareMain.o\ - Expression.o\ - ModelParameters.o\ - ModelTree.o\ - NumericalConstants.o\ - NumericalInitialization.o\ - OperatorTable.o\ - OutputFile.o\ - Shocks.o\ - SigmaeInitialization.o\ - SymbolTable.o\ - TmpSymbolTable.o\ - VariableTable.o\ - DynareParser.o\ - DataTree.o - - -SRC=../DynareFlex.cc ../DynareBison.cc ../include/DynareBison.h - - -################################################################################ -### Build ###################################################################### -################################################################################ - -all: dynare.exe - -dynare.exe: $(SRC) $(OBJ) - pwd;\ - $(CPP) $(CPPFLAGS) -o dynare.exe $(OBJ);\ - cp dynare.exe ../../matlab/dynare_m.exe;\ - - - -################################################################################ -### Compile #################################################################### -################################################################################ - -ComputingTasks.o: ../ComputingTasks.cc ModelTree.o ../include/ComputingTasks.h - $(CPP) $(CPPFLAGS) -c -I../include -o ComputingTasks.o ../ComputingTasks.cc - - -DynareFlex.o: ../DynareFlex.cc - $(CPP) $(CPPFLAGS) -c -I../include -o DynareFlex.o ../DynareFlex.cc - - -DynareMain.o: ../DynareMain.cc ../include/DynareParser.h ../include/DynareScanner.h ../include/OutputFile.h - $(CPP) $(CPPFLAGS) -c -I../include -o DynareMain.o ../DynareMain.cc - - -Expression.o: ../Expression.cc - $(CPP) $(CPPFLAGS) -c -I../include -o Expression.o ../Expression.cc - - -ModelParameters.o: ../ModelParameters.cc - $(CPP) $(CPPFLAGS) -c -I../include -o ModelParameters.o ../ModelParameters.cc - - -ModelTree.o: ../ModelTree.cc ../include/ModelTree.h ../include/ModelTypes.h ../include/DataTree.h - $(CPP) $(CPPFLAGS) -c -I../include -o ModelTree.o ../ModelTree.cc - -DataTree.o: ../DataTree.cc ../include/DataTree.h ../include/ModelTypes.h - $(CPP) $(CPPFLAGS) -c -I../include -o DataTree.o ../DataTree.cc - -NumericalConstants.o: ../NumericalConstants.cc - $(CPP) $(CPPFLAGS) -c -I../include -o NumericalConstants.o ../NumericalConstants.cc - - -NumericalInitialization.o: ../NumericalInitialization.cc - $(CPP) $(CPPFLAGS) -c -I../include -o NumericalInitialization.o ../NumericalInitialization.cc - - -OperatorTable.o: ../OperatorTable.cc - $(CPP) $(CPPFLAGS) -c -I../include -o OperatorTable.o ../OperatorTable.cc - - -OutputFile.o: ../OutputFile.cc - $(CPP) $(CPPFLAGS) -c -I../include -o OutputFile.o ../OutputFile.cc - - -Shocks.o: ../Shocks.cc - $(CPP) $(CPPFLAGS) -c -I../include -o Shocks.o ../Shocks.cc - - -SigmaeInitialization.o: ../SigmaeInitialization.cc - $(CPP) $(CPPFLAGS) -c -I../include -o SigmaeInitialization.o ../SigmaeInitialization.cc - - -SymbolTable.o: ../SymbolTable.cc - $(CPP) $(CPPFLAGS) -c -I../include -o SymbolTable.o ../SymbolTable.cc - - -TmpSymbolTable.o: ../TmpSymbolTable.cc - $(CPP) $(CPPFLAGS) -c -I../include -o TmpSymbolTable.o ../TmpSymbolTable.cc - - -VariableTable.o: ../VariableTable.cc - $(CPP) $(CPPFLAGS) -c -I../include -o VariableTable.o ../VariableTable.cc - -DynareParser.o: ../include/DynareParser.h ../DynareParser.cc - $(CPP) $(CPPFLAGS) -c -I../include -o DynareParser.o ../DynareParser.cc - -DynareBison.o: ../DynareBison.cc - $(CPP) $(CPPFLAGS) -c -I../include -o DynareBison.o ../DynareBison.cc - -../DynareFlex.cc: ../DynareFlex.ll ../include/DynareScanner.h - flex -i -o../DynareFlex.cc ../DynareFlex.ll - -../DynareBison.cc ../include/DynareBison.h: ../DynareBison.yy ../include/DynareParser.h - (bison -v -d -b --verbose -o../DynareBison.cc ../DynareBison.yy; mv ../DynareBison.hh ../include/DynareBison.h) - - -################################################################################ -### Clean ###################################################################### -################################################################################ - -clean: - rm "ComputingTasks.o" \ - "DynareParser.o" \ - "DynareBison.o" \ - "DynareFlex.o" \ - "DynareMain.o" \ - "Expression.o" \ - "ModelParameters.o" \ - "ModelTree.o" \ - "NumericalConstants.o" \ - "NumericalInitialization.o" \ - "OperatorTable.o" \ - "OutputFile.o" \ - "Shocks.o" \ - "SigmaeInitialization.o" \ - "SymbolTable.o" \ - "TmpSymbolTable.o" \ - "VariableTable.o" \ - "DataTree.o" \ - "dynare.exe" \ - "../DynareBison.cc" \ - "../include/DynareBison.h" \ - "../DynareFlex.cc" - +CPP = c++ +ifeq ($(DEBUG),yes) + CPPFLAGS = -mno-cygwin -ggdb -pg -Wall + FLEXFLAGS = -i +else +ifeq ($(MINGW),yes) + CPPFLAGS = -O2 + FLEXFLAGS = -i -d +else + CPPFLAGS = -mno-cygwin -O2 + FLEXFLAGS = -i +endif +endif +OBJ=\ + ComputingTasks.o\ + DynareBison.o\ + DynareFlex.o\ + DynareMain.o\ + Expression.o\ + ModelParameters.o\ + ModelTree.o\ + NumericalConstants.o\ + NumericalInitialization.o\ + OperatorTable.o\ + OutputFile.o\ + Shocks.o\ + SigmaeInitialization.o\ + SymbolTable.o\ + TmpSymbolTable.o\ + VariableTable.o\ + DynareParser.o\ + DataTree.o + + +SRC=../DynareFlex.cc ../DynareBison.cc ../include/DynareBison.h + + +################################################################################ +### Build ###################################################################### +################################################################################ + +all: dynare.exe + +dynare.exe: $(SRC) $(OBJ) + pwd;\ + $(CPP) $(CPPFLAGS) -o dynare.exe $(OBJ);\ + cp dynare.exe ../../matlab/dynare_m.exe;\ + + + +################################################################################ +### Compile #################################################################### +################################################################################ + +ComputingTasks.o: ../ComputingTasks.cc ModelTree.o ../include/ComputingTasks.h + $(CPP) $(CPPFLAGS) -c -I../include -o ComputingTasks.o ../ComputingTasks.cc + + +DynareFlex.o: ../DynareFlex.cc + $(CPP) $(CPPFLAGS) -c -I../include -o DynareFlex.o ../DynareFlex.cc + + +DynareMain.o: ../DynareMain.cc ../include/DynareParser.h ../include/DynareScanner.h ../include/OutputFile.h + $(CPP) $(CPPFLAGS) -c -I../include -o DynareMain.o ../DynareMain.cc + + +Expression.o: ../Expression.cc + $(CPP) $(CPPFLAGS) -c -I../include -o Expression.o ../Expression.cc + + +ModelParameters.o: ../ModelParameters.cc + $(CPP) $(CPPFLAGS) -c -I../include -o ModelParameters.o ../ModelParameters.cc + + +ModelTree.o: ../ModelTree.cc ../include/ModelTree.h ../include/ModelTypes.h ../include/DataTree.h + $(CPP) $(CPPFLAGS) -c -I../include -o ModelTree.o ../ModelTree.cc + +DataTree.o: ../DataTree.cc ../include/DataTree.h ../include/ModelTypes.h + $(CPP) $(CPPFLAGS) -c -I../include -o DataTree.o ../DataTree.cc + +NumericalConstants.o: ../NumericalConstants.cc + $(CPP) $(CPPFLAGS) -c -I../include -o NumericalConstants.o ../NumericalConstants.cc + + +NumericalInitialization.o: ../NumericalInitialization.cc + $(CPP) $(CPPFLAGS) -c -I../include -o NumericalInitialization.o ../NumericalInitialization.cc + + +OperatorTable.o: ../OperatorTable.cc + $(CPP) $(CPPFLAGS) -c -I../include -o OperatorTable.o ../OperatorTable.cc + + +OutputFile.o: ../OutputFile.cc + $(CPP) $(CPPFLAGS) -c -I../include -o OutputFile.o ../OutputFile.cc + + +Shocks.o: ../Shocks.cc + $(CPP) $(CPPFLAGS) -c -I../include -o Shocks.o ../Shocks.cc + + +SigmaeInitialization.o: ../SigmaeInitialization.cc + $(CPP) $(CPPFLAGS) -c -I../include -o SigmaeInitialization.o ../SigmaeInitialization.cc + + +SymbolTable.o: ../SymbolTable.cc + $(CPP) $(CPPFLAGS) -c -I../include -o SymbolTable.o ../SymbolTable.cc + + +TmpSymbolTable.o: ../TmpSymbolTable.cc + $(CPP) $(CPPFLAGS) -c -I../include -o TmpSymbolTable.o ../TmpSymbolTable.cc + + +VariableTable.o: ../VariableTable.cc + $(CPP) $(CPPFLAGS) -c -I../include -o VariableTable.o ../VariableTable.cc + +DynareParser.o: ../include/DynareParser.h ../DynareParser.cc + $(CPP) $(CPPFLAGS) -c -I../include -o DynareParser.o ../DynareParser.cc + +DynareBison.o: ../DynareBison.cc + $(CPP) $(CPPFLAGS) -c -I../include -o DynareBison.o ../DynareBison.cc + +../DynareFlex.cc: ../DynareFlex.ll ../include/DynareScanner.h + flex $(FLEXFLAGS) -o../DynareFlex.cc ../DynareFlex.ll + +../DynareBison.cc ../include/DynareBison.h: ../DynareBison.yy ../include/DynareParser.h + (bison -v -d -b --verbose -o../DynareBison.cc ../DynareBison.yy; mv ../DynareBison.hh ../include/DynareBison.h) + + +################################################################################ +### Clean ###################################################################### +################################################################################ + +clean: + rm "ComputingTasks.o" \ + "DynareParser.o" \ + "DynareBison.o" \ + "DynareFlex.o" \ + "DynareMain.o" \ + "Expression.o" \ + "ModelParameters.o" \ + "ModelTree.o" \ + "NumericalConstants.o" \ + "NumericalInitialization.o" \ + "OperatorTable.o" \ + "OutputFile.o" \ + "Shocks.o" \ + "SigmaeInitialization.o" \ + "SymbolTable.o" \ + "TmpSymbolTable.o" \ + "VariableTable.o" \ + "DataTree.o" \ + "dynare.exe" \ + "../DynareBison.cc" \ + "../include/DynareBison.h" \ + "../DynareFlex.cc" + +# DO NOT DELETE + +ComputingTasks.o: ../include/ComputingTasks.h ../include/TmpSymbolTable.h +ComputingTasks.o: ../include/SymbolTable.h ../include/ModelParameters.h +ComputingTasks.o: ../include/SymbolTableTypes.h +DataTree.o: /usr/include/time.h /usr/include/_ansi.h /usr/include/newlib.h +DataTree.o: /usr/include/sys/config.h /usr/include/machine/ieeefp.h +DataTree.o: /usr/include/sys/reent.h /usr/include/sys/_types.h +DataTree.o: /usr/include/sys/lock.h /usr/include/machine/time.h +DataTree.o: /usr/include/sys/types.h /usr/include/machine/_types.h +DataTree.o: /usr/include/limits.h /usr/include/features.h +DataTree.o: /usr/include/sys/cdefs.h /usr/include/sys/features.h +DataTree.o: /usr/include/machine/types.h ../include/DynareBison.h +DataTree.o: ../include/VariableTable.h ../include/SymbolTable.h +DataTree.o: ../include/ModelParameters.h ../include/SymbolTableTypes.h +DataTree.o: ../include/NumericalConstants.h ../include/DataTree.h +DataTree.o: /usr/include/stdio.h /usr/include/sys/stdio.h +DataTree.o: ../include/OperatorTable.h ../include/ModelTypes.h +DynareBison.o: ../include/DynareParser.h ../include/ModelParameters.h +DynareBison.o: ../include/SymbolTable.h ../include/SymbolTableTypes.h +DynareBison.o: ../include/Expression.h ../include/OperatorTable.h +DynareBison.o: ../include/DynareBison.h ../include/NumericalConstants.h +DynareBison.o: ../include/NumericalInitialization.h ../include/ModelTree.h +DynareBison.o: ../include/ModelTypes.h ../include/DataTree.h +DynareBison.o: /usr/include/stdio.h /usr/include/_ansi.h +DynareBison.o: /usr/include/newlib.h /usr/include/sys/config.h +DynareBison.o: /usr/include/machine/ieeefp.h /usr/include/sys/reent.h +DynareBison.o: /usr/include/sys/_types.h /usr/include/sys/lock.h +DynareBison.o: /usr/include/sys/types.h /usr/include/machine/_types.h +DynareBison.o: /usr/include/limits.h /usr/include/features.h +DynareBison.o: /usr/include/sys/cdefs.h /usr/include/sys/features.h +DynareBison.o: /usr/include/machine/types.h /usr/include/sys/stdio.h +DynareBison.o: ../include/VariableTable.h ../include/Shocks.h +DynareBison.o: ../include/SigmaeInitialization.h +DynareBison.o: ../include/ComputingTasks.h ../include/TmpSymbolTable.h +DynareBison.o: ../include/Objects.h ../include/ylmm/basic_parser.hh +DynareBison.o: ../include/ylmm/basic_messenger.hh +DynareBison.o: ../include/ylmm/basic_location.hh +DynareBison.o: ../include/ylmm/basic_scanner.hh +DynareBison.o: ../include/ylmm/basic_buffer.hh ../include/ylmm/yaccmm.hh +DynareFlex.o: /usr/include/stdio.h /usr/include/_ansi.h +DynareFlex.o: /usr/include/newlib.h /usr/include/sys/config.h +DynareFlex.o: /usr/include/machine/ieeefp.h /usr/include/sys/reent.h +DynareFlex.o: /usr/include/sys/_types.h /usr/include/sys/lock.h +DynareFlex.o: /usr/include/sys/types.h /usr/include/machine/_types.h +DynareFlex.o: /usr/include/limits.h /usr/include/features.h +DynareFlex.o: /usr/include/sys/cdefs.h /usr/include/sys/features.h +DynareFlex.o: /usr/include/machine/types.h /usr/include/sys/stdio.h +DynareFlex.o: /usr/include/errno.h /usr/include/sys/errno.h +DynareFlex.o: /usr/include/unistd.h /usr/include/sys/unistd.h +DynareFlex.o: /usr/include/string.h /usr/include/sys/string.h +DynareFlex.o: ../include/DynareScanner.h ../include/DynareBison.h +DynareFlex.o: ../include/ylmm/basic_scanner.hh +DynareFlex.o: ../include/ylmm/basic_buffer.hh ../include/Objects.h +DynareFlex.o: ../include/SymbolTable.h ../include/ModelParameters.h +DynareFlex.o: ../include/SymbolTableTypes.h ../include/ModelTypes.h +DynareFlex.o: ../include/ylmm/lexmm.hh /usr/include/stdlib.h +DynareFlex.o: /usr/include/machine/stdlib.h /usr/include/alloca.h +DynareMain.o: /usr/include/stdio.h /usr/include/_ansi.h +DynareMain.o: /usr/include/newlib.h /usr/include/sys/config.h +DynareMain.o: /usr/include/machine/ieeefp.h /usr/include/sys/reent.h +DynareMain.o: /usr/include/sys/_types.h /usr/include/sys/lock.h +DynareMain.o: /usr/include/sys/types.h /usr/include/machine/_types.h +DynareMain.o: /usr/include/limits.h /usr/include/features.h +DynareMain.o: /usr/include/sys/cdefs.h /usr/include/sys/features.h +DynareMain.o: /usr/include/machine/types.h /usr/include/sys/stdio.h +DynareMain.o: ../include/DynareParser.h ../include/ModelParameters.h +DynareMain.o: ../include/SymbolTable.h ../include/SymbolTableTypes.h +DynareMain.o: ../include/Expression.h ../include/OperatorTable.h +DynareMain.o: ../include/DynareBison.h ../include/NumericalConstants.h +DynareMain.o: ../include/NumericalInitialization.h ../include/ModelTree.h +DynareMain.o: ../include/ModelTypes.h ../include/DataTree.h +DynareMain.o: ../include/VariableTable.h ../include/Shocks.h +DynareMain.o: ../include/SigmaeInitialization.h +DynareMain.o: ../include/ComputingTasks.h ../include/TmpSymbolTable.h +DynareMain.o: ../include/Objects.h ../include/ylmm/basic_parser.hh +DynareMain.o: ../include/ylmm/basic_messenger.hh +DynareMain.o: ../include/ylmm/basic_location.hh +DynareMain.o: ../include/ylmm/basic_scanner.hh +DynareMain.o: ../include/ylmm/basic_buffer.hh ../include/DynareScanner.h +DynareMain.o: ../include/OutputFile.h +DynareParser.o: ../include/ModelParameters.h ../include/SymbolTable.h +DynareParser.o: ../include/SymbolTableTypes.h ../include/Expression.h +DynareParser.o: ../include/OperatorTable.h ../include/DynareBison.h +DynareParser.o: ../include/NumericalConstants.h +DynareParser.o: ../include/NumericalInitialization.h +DynareParser.o: ../include/ModelTree.h ../include/ModelTypes.h +DynareParser.o: ../include/DataTree.h /usr/include/stdio.h +DynareParser.o: /usr/include/_ansi.h /usr/include/newlib.h +DynareParser.o: /usr/include/sys/config.h /usr/include/machine/ieeefp.h +DynareParser.o: /usr/include/sys/reent.h /usr/include/sys/_types.h +DynareParser.o: /usr/include/sys/lock.h /usr/include/sys/types.h +DynareParser.o: /usr/include/machine/_types.h /usr/include/limits.h +DynareParser.o: /usr/include/features.h /usr/include/sys/cdefs.h +DynareParser.o: /usr/include/sys/features.h /usr/include/machine/types.h +DynareParser.o: /usr/include/sys/stdio.h ../include/VariableTable.h +DynareParser.o: ../include/Shocks.h ../include/SigmaeInitialization.h +DynareParser.o: ../include/ComputingTasks.h ../include/TmpSymbolTable.h +DynareParser.o: ../include/DynareParser.h ../include/Objects.h +DynareParser.o: ../include/ylmm/basic_parser.hh +DynareParser.o: ../include/ylmm/basic_messenger.hh +DynareParser.o: ../include/ylmm/basic_location.hh +DynareParser.o: ../include/ylmm/basic_scanner.hh +DynareParser.o: ../include/ylmm/basic_buffer.hh +Expression.o: ../include/Expression.h ../include/SymbolTable.h +Expression.o: ../include/ModelParameters.h ../include/SymbolTableTypes.h +Expression.o: ../include/OperatorTable.h ../include/DynareBison.h +Expression.o: ../include/NumericalConstants.h +ModelParameters.o: ../include/ModelParameters.h /usr/include/limits.h +ModelParameters.o: /usr/include/features.h /usr/include/sys/cdefs.h +ModelParameters.o: /usr/include/sys/features.h +ModelTree.o: /usr/include/stdio.h /usr/include/_ansi.h +ModelTree.o: /usr/include/newlib.h /usr/include/sys/config.h +ModelTree.o: /usr/include/machine/ieeefp.h /usr/include/sys/reent.h +ModelTree.o: /usr/include/sys/_types.h /usr/include/sys/lock.h +ModelTree.o: /usr/include/sys/types.h /usr/include/machine/_types.h +ModelTree.o: /usr/include/limits.h /usr/include/features.h +ModelTree.o: /usr/include/sys/cdefs.h /usr/include/sys/features.h +ModelTree.o: /usr/include/machine/types.h /usr/include/sys/stdio.h +ModelTree.o: /usr/include/time.h /usr/include/machine/time.h +ModelTree.o: ../include/VariableTable.h ../include/SymbolTable.h +ModelTree.o: ../include/ModelParameters.h ../include/SymbolTableTypes.h +ModelTree.o: ../include/d_tab.h ../include/DynareBison.h +ModelTree.o: ../include/NumericalConstants.h ../include/ModelTree.h +ModelTree.o: ../include/OperatorTable.h ../include/ModelTypes.h +ModelTree.o: ../include/DataTree.h +NumericalConstants.o: ../include/NumericalConstants.h +NumericalInitialization.o: ../include/NumericalInitialization.h +NumericalInitialization.o: ../include/SymbolTable.h +NumericalInitialization.o: ../include/ModelParameters.h +NumericalInitialization.o: ../include/SymbolTableTypes.h +OperatorTable.o: ../include/OperatorTable.h ../include/DynareBison.h +OutputFile.o: ../include/OutputFile.h ../include/SymbolTable.h +OutputFile.o: ../include/ModelParameters.h ../include/SymbolTableTypes.h +OutputFile.o: ../include/ModelTree.h ../include/OperatorTable.h +OutputFile.o: ../include/DynareBison.h ../include/NumericalConstants.h +OutputFile.o: ../include/ModelTypes.h ../include/DataTree.h +OutputFile.o: /usr/include/stdio.h /usr/include/_ansi.h +OutputFile.o: /usr/include/newlib.h /usr/include/sys/config.h +OutputFile.o: /usr/include/machine/ieeefp.h /usr/include/sys/reent.h +OutputFile.o: /usr/include/sys/_types.h /usr/include/sys/lock.h +OutputFile.o: /usr/include/sys/types.h /usr/include/machine/_types.h +OutputFile.o: /usr/include/limits.h /usr/include/features.h +OutputFile.o: /usr/include/sys/cdefs.h /usr/include/sys/features.h +OutputFile.o: /usr/include/machine/types.h /usr/include/sys/stdio.h +OutputFile.o: ../include/VariableTable.h +Shocks.o: ../include/Shocks.h ../include/ModelParameters.h +SigmaeInitialization.o: ../include/SigmaeInitialization.h +SymbolTable.o: ../include/SymbolTable.h ../include/ModelParameters.h +SymbolTable.o: ../include/SymbolTableTypes.h +TmpSymbolTable.o: ../include/SymbolTable.h ../include/ModelParameters.h +TmpSymbolTable.o: ../include/SymbolTableTypes.h +TmpSymbolTable.o: ../include/TmpSymbolTable.h +VariableTable.o: ../include/VariableTable.h ../include/SymbolTable.h +VariableTable.o: ../include/ModelParameters.h +VariableTable.o: ../include/SymbolTableTypes.h diff --git a/parser.src/include/ComputingTasks.h b/parser.src/include/ComputingTasks.h index c0172c6f9ef3e1fadca28e44312fb5670ef7e6eb..45b5059b9851a4a3716037f79f800180b5874d05 100644 --- a/parser.src/include/ComputingTasks.h +++ b/parser.src/include/ComputingTasks.h @@ -19,6 +19,7 @@ struct EstimationParams{ int type; std::string name; + std::string name2; std::string init_val; std::string prior; std::string low_bound; @@ -37,6 +38,7 @@ struct EstimationParams{ { type = 0; name = ""; + name2 = ""; init_val = "NaN"; prior = "NaN"; low_bound = "-Inf"; @@ -86,8 +88,10 @@ class ComputingTasks option_.<iName> = <iValue> */ void setOption(std::string iName, std::string iValue); + void setOption(std::string iName, std::string iValue1, std::string iValue2); /*! Prints "dynare_estimation;" */ - void runEstimation(std::string); + void runEstimation(std::string); + void runRplot(std::string); /*! Prints some estimation initialisation */ void setEstimationInit(void); //! Prints optimization options */ @@ -97,26 +101,40 @@ class ComputingTasks void setEstimationStandardError(void); void set_trend_element(std::string, std::string); - void setCalibInit(void); + void BeginCalibVar(void); - void setCalibVariance(void); - - void setCalibCovariance(void); + void setCalibVar(std::string, std::string, std::string); + + void setCalibVar(std::string, std::string, std::string, std::string); - void setCalibAutoCorrelation(void); + void setCalibAc(std::string, std::string, std::string, std::string); - void setCalib(void); + void runCalib(int); // write "osr(var_list_,osr_params_,optim_weights_);" - void setOsr(std::string tmp1); + void setOsrParams(std::string); + + void runOsr(std::string); // writes "olr(var_list_,olr_inst_,obj_var_,optim_weights_);" - void setOlr(std::string tmp1, std::string tmp2); - - void setOptimWeightsInit(void); + void setOlrInst(std::string); + + void runOlr(std::string); - void setOptimWeights1(void); + void BeginOptimWeights(void); - void setOptimWeights2(void); + void setOptimWeights(std::string, std::string); + void setOptimWeights(std::string, std::string, std::string); + + void runDynasave(std::string,std::string,std::string); + + void runDynatype(std::string,std::string,std::string); + + void beginModelComparison(void); + + void addMcFilename(std::string,std::string); + + void runModelComparison(void); + void set(void); static std::string get(void); diff --git a/parser.src/include/DataTree.h b/parser.src/include/DataTree.h index cc483073253c75d19253949d57266ec016f21cb0..f6ab09463760e3b63e39ecb47836b92125f26647 100644 --- a/parser.src/include/DataTree.h +++ b/parser.src/include/DataTree.h @@ -187,7 +187,7 @@ inline std::string DataTree::Key(MToken iToken) char key[100]; //ostringstream key; //key << iToken.id1 << " " << iToken.id2 << " " << iToken.type1 << " " << iToken.op_code; - sprintf(key,"%X %X %d %d", iToken.id1, iToken.id2, + sprintf(key,"%X %X %d %d", (int)iToken.id1, (int)iToken.id2, iToken.type1, iToken.op_code); //std::cout << key << endl; return std::string(key); diff --git a/parser.src/include/DataTreeDef.h b/parser.src/include/DataTreeDef.h index 4e6021358cc2d80fb9f2517f929a741be564b5e7..4448ed2e4be24b0275d1d14ae763ac765e347d3e 100644 --- a/parser.src/include/DataTreeDef.h +++ b/parser.src/include/DataTreeDef.h @@ -6,7 +6,7 @@ using namespace std; //------------------------------------------------------------------------------ #include "VariableTable.h" -#include "d_tab.h" +#include "DynareBison.h" #include "NumericalConstants.h" #include "DataTree.h" //------------------------------------------------------------------------------ diff --git a/parser.src/include/DynareParser.h b/parser.src/include/DynareParser.h index 449a6180d603326771188322a2ed44e5ef4d753d..6b4b961312d2ac690a96b7b1143ae5127f18826e 100644 --- a/parser.src/include/DynareParser.h +++ b/parser.src/include/DynareParser.h @@ -20,10 +20,10 @@ #include "TmpSymbolTable.h" #include "Objects.h" #ifndef YLMM_basic_parser -#include "basic_parser.h" +#include "ylmm/basic_parser.hh" #endif #ifndef YLMM_basic_scanner -#include "basic_scanner.h" +#include "ylmm/basic_scanner.hh" #endif #ifndef __IOSTREAM__ #include <iostream> @@ -145,9 +145,11 @@ namespace dynare /*! Adds a binary token to an expression */ Objects* add_expression_token( Objects* arg1, Objects* arg2, Objects* op); /*! Adds an unary token to an expression */ - Objects* add_expression_token( Objects* arg1, Objects* op); + Objects* add_expression_token( Objects* arg1, Objects* op); /*! Gets literal expression string */ - Objects* get_expression(Objects* exp); + Objects* get_expression(Objects* exp); + /* Concatenates two string objects */ + Objects* cat(Objects* string1, Objects* string2); /*! Writes parameter intitialisation expression */ void init_param(Objects* lhs, Objects* rhs); /*! Writes parameter intitialisation expression */ @@ -196,6 +198,7 @@ namespace dynare void steady(void); /*! Sets an option to a numerical value */ void option_num(string name_option, Objects* opt); + void option_num(string name_option, Objects* opt1, Objects* opt2); /*! Sets an option to a string value */ void option_str(string name_option, Objects* opt); /*! Sets an option to a numerical value */ @@ -208,7 +211,9 @@ namespace dynare void add_tmp_var(Objects* tmp_var); /*! Gets temp symbol table output */ Objects* get_tmp_var(void); - /*! Writes a stock_simul command */ + /*! Writes a rplot() command */ + void rplot(void); + /*! Writes a stock_simul command */ void stoch_simul(void); /*! Writes a simul command */ void simul(void); @@ -228,6 +233,23 @@ namespace dynare void set_trend_init(void); void set_trend_element(Objects*, Objects*); void set_unit_root_vars(void); + void begin_optim_weights(void); + void set_optim_weights(Objects*,Objects*); + void set_optim_weights(Objects*,Objects*,Objects*); + void set_osr_params(void); + void run_osr(void); + void set_olr_inst(void); + void run_olr(void); + void begin_calib_var(void); + void set_calib_var(Objects*,Objects*,Objects*); + void set_calib_var(Objects*,Objects*,Objects*,Objects*); + void set_calib_ac(Objects*,Objects*,Objects*,Objects*); + void run_calib(int); + void run_dynasave(Objects* arg1,Objects* arg2 = new Objects("")); + void run_dynatype(Objects* arg1,Objects* arg2 = new Objects("")); + void begin_model_comparison(void); + void add_mc_filename(Objects* filename, Objects* prior = new Objects("1")); + void run_model_comparison(); /*! Writes token "arg1=arg2" to model tree */ Objects* add_equal(Objects* arg1, Objects* arg2 = new Objects("0.0",ModelTree::Zero, eTempResult)); /*! Writes token "arg1+arg2" to model tree */ diff --git a/parser.src/include/DynareScanner.h b/parser.src/include/DynareScanner.h index 68bf55b4b583529fcce14f484d59b03269b18492..b6f95f68d785f39222236b7cb5751a87ec233cd3 100644 --- a/parser.src/include/DynareScanner.h +++ b/parser.src/include/DynareScanner.h @@ -6,12 +6,13 @@ \date 04/27/2004 \par This file defines the scanner class. */ -//------------------------------------------------------------------------------#include <iostream> +//------------------------------------------------------------------------------ +#include <iostream> #include <sstream> #include <string> #include "DynareBison.h" #ifndef YLMM_basic_scanner -#include "basic_scanner.h" +#include "ylmm/basic_scanner.hh" #endif #include "Objects.h" #include "SymbolTable.h" diff --git a/parser.src/include/ModelTree.h b/parser.src/include/ModelTree.h index d5a6184b75d558c0ce563d5ffcdbe932d0f3285a..f530080b7a5d936eedb8e4e8cf4b86eae0382008 100644 --- a/parser.src/include/ModelTree.h +++ b/parser.src/include/ModelTree.h @@ -56,6 +56,7 @@ class ModelTree : public DataTree char lpar, rpar; /*! Name of parameter variables ("params" for C output, and M_.params for Matlab) */ std::string param_name; + private : /*! Computes argument derivative */ inline NodeID DeriveArgument(NodeID iArg, Type iType, int iVarID); @@ -74,7 +75,7 @@ class ModelTree : public DataTree //void RemoveUnref(int iBeginID, int iEndID, int iOrder); /*! Decrementing reference couter of unreferenced tokens in last derivative */ void DecrementUnref(int iBeginID, int iEndID, int iOrder); - + inline int optimize(NodeID id); public : /*! When Jacobian (vs endogenous) is writen this flag is set to true */ bool computeJacobian; @@ -97,29 +98,17 @@ class ModelTree : public DataTree /*! Computes derivatives of ModelTree */ void derive(int iOrder); /*! - Writes M output file for static model : - - equations - - 1st order derivatives with respect to endogenous variables (without lags) - */ - std::string setStaticModelM(void); - /*! - Writes M output file for dynamic stochastic model : - - equations - - 1st order and 2nd order derivatives with respect to endogenous, exogenous, exogenous_det (in specific order) - */ - std::string setDynamicModelM(void); - /*! - Writes C output file for static model : + Writes output file for static model : - equations - 1st order derivatives with respect to endogenous variables (without lags) */ - std::string setStaticModelC(void); + std::string setStaticModel(void); /*! - Writes C output file for dynamic stochastic model : + Writes output file for dynamic stochastic model : - equations - 1st order and 2nd order derivatives with respect to endogenous, exogenous, exogenous_det (in specific order) */ - std::string setDynamicModelC(void); + std::string setDynamicModel(void); /*! Writes initialization of various Matlab variables */ void ModelInitialization(void); /*! Returns string output for main file */ diff --git a/parser.src/include/ModelTypes.h b/parser.src/include/ModelTypes.h index 4b29e32e71fa11a3e2f5aa6810e434004dd29054..00292cb8862d24e06272f2ce26028eae6cd090b1 100644 --- a/parser.src/include/ModelTypes.h +++ b/parser.src/include/ModelTypes.h @@ -140,6 +140,11 @@ struct MetaToken : public MToken /*! Operator name */ std::string op_name; /*! Cast MetaToken -> MToken */ + // set to one when left node has been treated + int left_done; + // set to one when right node has been treated + int right_done; + inline operator MToken() const { MToken lToken(id1,type1,id2, op_code); @@ -163,6 +168,8 @@ struct MetaToken : public MToken exp[1] = exp[1]; idx = t1.idx; tmp_status = t1.tmp_status; + left_done = t1.left_done; + right_done = t1.right_done; //cout << "Creation by equality\n"; return *this; } @@ -173,6 +180,8 @@ struct MetaToken : public MToken cost = 0; followed1 = followed2 = false; tmp_status = 0; + left_done = 0; + right_done = 0; } /* Copy constructor */ inline MetaToken(const MetaToken& mt) @@ -189,7 +198,8 @@ struct MetaToken : public MToken exp[1] = mt.exp[1]; idx = mt.idx; tmp_status = mt.tmp_status; - + left_done = mt.left_done; + right_done = mt.right_done; } /* Destructor */ ~MetaToken() diff --git a/parser.src/include/Objects.h b/parser.src/include/Objects.h index 78fecd5079789dc8e9fac3adead5e2adf447162e..fcdb78395389b626a9e0041ea2b14d2595e527f8 100644 --- a/parser.src/include/Objects.h +++ b/parser.src/include/Objects.h @@ -39,14 +39,16 @@ namespace dynare /*! Constrcutor of object with known symbol name */ Objects(string name) { - symbol = name; + opcode = NAME; + symbol = name; } /*! Constrcutor of object with known symbol name */ Objects(const char* name, NodeID id = NULL, Type t = eUNDEF) { - symbol = name; - type = t; - ID = id; + opcode = NAME; + symbol = name; + type = t; + ID = id; } /*! Constrcutor of object with known symbol name, ID and type */ Objects(string name,NodeID id, Type t) diff --git a/parser.src/include/OperatorTable.h b/parser.src/include/OperatorTable.h index cec649a690ca620338707890beaa510098742e62..f04da7ce223b2fe068da640f49ecbf0c20b1f2f9 100644 --- a/parser.src/include/OperatorTable.h +++ b/parser.src/include/OperatorTable.h @@ -11,7 +11,7 @@ #include <string> #include <vector> //------------------------------------------------------------------------------ -#include "d_tab.h" +#include "DynareBison.h" //------------------------------------------------------------------------------ /*! \class OperatorTable diff --git a/parser.src/include/SymbolTable.h b/parser.src/include/SymbolTable.h index 61e1253727dc048e432fea1e7f80462605623ec1..a1e8334667dabbfaff5c40cc324a7995f8a0dfb3 100644 --- a/parser.src/include/SymbolTable.h +++ b/parser.src/include/SymbolTable.h @@ -99,14 +99,14 @@ inline bool SymbolTable::Exist(std::string name) //------------------------------------------------------------------------------ inline std::string SymbolTable::getNameByID(Type type,int id) { - if (id >= 0 && name_table[type].size() > id) + if (id >= 0 && (int)name_table[type].size() > id) return(name_table[type][id]); else return ""; } //------------------------------------------------------------------------------ inline std::string SymbolTable::getTexNameByID(Type type,int id) { - if (id >= 0 && tex_name_table[type].size() > id) + if (id >= 0 && (int)tex_name_table[type].size() > id) return(tex_name_table[type][id]); else return ""; }