Commit fe5de6d8 authored by sebastien's avatar sebastien
Browse files

trunk:

* added back model_comparison logic
* added QUOTED_STRING token in lexer
* added filename rule in parser (filename is NAME or QUOTED_STRING)


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2115 ac1d8469-bf42-47a9-8791-bf33cf982152
parent fe07f798
......@@ -827,16 +827,16 @@ ModelComparisonStatement::writeOutput(ostream &output, const string &basename) c
{
options_list.writeOutput(output);
output << "ModelNames_ = {};\n";
output << "ModelPriors_ = {};\n";
output << "ModelNames_ = {};" << endl;
output << "ModelPriors_ = [];" << endl;
for(filename_list_type::const_iterator it = filename_list.begin();
it != filename_list.end(); it++)
{
output << "ModelNames_ = { ModelNames_{:} '" << it->first << "};\n";
output << "ModelPriors_ = { ModelPriors_{:} '" << it->second << "};\n";
output << "ModelNames_ = { ModelNames_{:} '" << (*it).first << "'};" << endl;
output << "ModelPriors_ = [ ModelPriors_ ; " << (*it).second << "];" << endl;
}
output << "model_comparison(ModelNames_,ModelPriors_);\n";
output << "model_comparison(ModelNames_,ModelPriors_,oo_,options_,M_.fname);" << endl;
}
PlannerObjectiveStatement::PlannerObjectiveStatement(ModelTree *model_tree_arg) :
......
......@@ -96,16 +96,18 @@ class ParsingDriver;
%token <string_val> INT_NUMBER
%token INV_GAMMA1_PDF INV_GAMMA2_PDF IRF
%token KALMAN_ALGO KALMAN_TOL
%token LAPLACE LCC_COMPILER LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR LU MARKOWITZ MAX
%token LAPLACE LCC_COMPILER LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR LU
%token MARKOWITZ MARGINAL_DENSITY MAX
%token METHOD MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS
%token MODEL_COMPARISON_APPROXIMATION MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER
%token MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER
%token <string_val> NAME
%token NO_COMPILER NOBS NOCONSTANT NOCORR NODIAGNOSTIC NOFUNCTIONS
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS
%token PARAMETERS PERIODS PLANNER_OBJECTIVE PREFILTER PRESAMPLE
%token PRINT PRIOR_TRUNC PRIOR_ANALYSIS POSTERIOR_ANALYSIS
%token <string_val> QUOTED_STRING
%token QZ_CRITERIUM
%token RELATIVE_IRF REPLIC RPLOT
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO
......@@ -135,7 +137,8 @@ class ParsingDriver;
%type <node_val> expression
%type <node_val> equation hand_side model_var
%type <string_val> signed_float signed_integer prior
%type <string_val> value value1 filename filename_elem vec_int_elem vec_int_1 vec_int
%type <string_val> filename
%type <string_val> value value1 vec_int_elem vec_int_1 vec_int
%type <string_val> vec_value_1 vec_value
%type <string_val> calib_arg2 range number
......@@ -1117,44 +1120,31 @@ dynasave : DYNASAVE '(' NAME ')'';'
{ driver.run_dynasave($2, $4); }
;
model_comparison : MODEL_COMPARISON '(' model_comparison_options ')' filename_list ';'
{ driver.run_model_comparison(); };
model_comparison_options : model_comparison_options COMMA model_comparison_option
| model_comparison_option
;
model_comparison_option : o_model_comparison_approximation
| o_print
| o_noprint
;
filename_list : filename
{ driver.add_mc_filename($1); }
| filename_list COMMA filename
{ driver.add_mc_filename($3); }
| filename '(' value ')'
{ driver.add_mc_filename($1, $3); }
| filename_list COMMA filename '(' value ')'
{ driver.add_mc_filename($3, $5); }
;
model_comparison : MODEL_COMPARISON mc_filename_list ';'
{ driver.run_model_comparison(); }
| MODEL_COMPARISON '(' o_marginal_density ')' mc_filename_list ';'
{ driver.run_model_comparison(); }
;
filename : filename_elem
filename : NAME
{ $$ = $1; }
| QUOTED_STRING
{ $$ = $1; }
| filename filename_elem
{ $1->append(*$2); delete $2; $$ = $1; }
;
filename_elem : NAME
| '\\'
{ $$ = new string("\\"); }
| DIVIDE
{ $$ = new string("/"); }
| ':'
{ $$ = new string(":"); }
| '.'
{ $$ = new string("."); }
;
mc_filename_list : filename
{ driver.add_mc_filename($1); }
| filename '(' value ')'
{ driver.add_mc_filename($1, $3); }
| mc_filename_list filename
{ driver.add_mc_filename($2); }
| mc_filename_list filename '(' value ')'
{ driver.add_mc_filename($2, $4); }
| mc_filename_list COMMA filename
{ driver.add_mc_filename($3); }
| mc_filename_list COMMA filename '(' value ')'
{ driver.add_mc_filename($3, $5); }
;
planner_objective : PLANNER_OBJECTIVE { driver.begin_planner_objective(); }
hand_side { driver.end_planner_objective($3); } ';';
......@@ -1375,11 +1365,11 @@ o_filtered_vars : FILTERED_VARS { driver.option_num("filtered_vars", "1"); };
o_relative_irf : RELATIVE_IRF { driver.option_num("relative_irf", "1"); };
o_kalman_algo : KALMAN_ALGO EQUAL INT_NUMBER { driver.option_num("kalman_algo", $3); };
o_kalman_tol : KALMAN_TOL EQUAL INT_NUMBER { driver.option_num("kalman_tol", $3); };
o_model_comparison_approximation : MODEL_COMPARISON_APPROXIMATION EQUAL LAPLACE
{ driver.option_str("model_comparison_approximation", "Laplace"); }
| MODEL_COMPARISON_APPROXIMATION EQUAL MODIFIEDHARMONICMEAN
{ driver.option_str("model_comparison_approximation", "MODIFIEDHARMONICMEAN"); }
;
o_marginal_density : MARGINAL_DENSITY EQUAL LAPLACE
{ driver.option_str("mc_marginal_density", "laplace"); }
| MARGINAL_DENSITY EQUAL MODIFIEDHARMONICMEAN
{ driver.option_str("mc_marginal_density", "modifiedharmonicmean"); }
;
o_print : PRINT { driver.option_num("noprint", "0"); };
o_noprint : NOPRINT { driver.option_num("noprint", "1"); };
o_xls_sheet : XLS_SHEET EQUAL NAME { driver.option_str("xls_sheet", $3); };
......
......@@ -204,7 +204,7 @@ int sigma_e = 0;
<DYNARE_STATEMENT>periods {return token::PERIODS;}
<DYNARE_STATEMENT>cutoff {return token::CUTOFF;}
<DYNARE_STATEMENT>markowitz {return token::MARKOWITZ;}
<DYNARE_STATEMENT>model_comparison_approximation {return token::MODEL_COMPARISON;}
<DYNARE_STATEMENT>marginal_density {return token::MARGINAL_DENSITY;}
<DYNARE_STATEMENT>laplace {return token::LAPLACE;}
<DYNARE_STATEMENT>modifiedharmonicmean {return token::MODIFIEDHARMONICMEAN;}
<DYNARE_STATEMENT>constant {return token::CONSTANT;}
......@@ -380,6 +380,12 @@ int sigma_e = 0;
return token::INT_NUMBER;
}
<DYNARE_STATEMENT,DYNARE_BLOCK>\'[^\']+\' {
yylval->string_val = new string(yytext + 1);
yylval->string_val->resize(yylval->string_val->length() - 1);
return token::QUOTED_STRING;
}
/* an instruction starting with a recognized symbol (which is not a modfile local variable)
is passed as NAME,
otherwise it is a native statement until the end of the line
......
......@@ -1024,9 +1024,11 @@ ParsingDriver::run_dynasave(string *filename, string *ext)
void
ParsingDriver::add_mc_filename(string *filename, string *prior)
{
if (filename_list.find(*filename) != filename_list.end())
error("model_comparison: filename " + *filename + " declared twice");
filename_list[*filename] = *prior;
for(ModelComparisonStatement::filename_list_type::iterator it = filename_list.begin();
it != filename_list.end(); it++)
if ((*it).first == *filename)
error("model_comparison: filename " + *filename + " declared twice");
filename_list.push_back(make_pair(*filename, *prior));
delete filename;
delete prior;
}
......
......@@ -292,7 +292,7 @@ public:
class ModelComparisonStatement : public Statement
{
public:
typedef map<string, string, less<string> > filename_list_type;
typedef vector<pair<string, string> > filename_list_type;
private:
filename_list_type filename_list;
OptionsList options_list;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment