v4 parser:
* removed Expression class; the "ExprNode" class is therefore now used everywhere * removed interprete class, and replaced it by a method in ExprNode and an global evaluation context in ModFile * fixed breakage of SparseDLL / Block decomposition code introduced in previous revision git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1204 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
30c70a35e3
commit
573227a044
|
@ -60,8 +60,10 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
output << "simul(oo_.dr);\n";
|
output << "simul(oo_.dr);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
SimulSparseStatement::SimulSparseStatement(const OptionsList &options_list_arg) :
|
SimulSparseStatement::SimulSparseStatement(const OptionsList &options_list_arg,
|
||||||
options_list(options_list_arg)
|
int compiler_arg) :
|
||||||
|
options_list(options_list_arg),
|
||||||
|
compiler(compiler_arg)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,10 +83,10 @@ SimulSparseStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
output << "end\n";
|
output << "end\n";
|
||||||
output << "disp('compiling...');\n";
|
output << "disp('compiling...');\n";
|
||||||
if (compiler == 0)
|
if (compiler == 0)
|
||||||
output << "mex " << filename << "_dynamic.c;\n";
|
output << "mex " << basename << "_dynamic.c;\n";
|
||||||
else
|
else
|
||||||
output << "mex " << filename << "_dynamic.cc;\n";
|
output << "mex " << basename << "_dynamic.cc;\n";
|
||||||
output << "oo_.endo_simul=" << filename << "_dynamic;\n";
|
output << "oo_.endo_simul=" << basename << "_dynamic;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
StochSimulStatement::StochSimulStatement(const TmpSymbolTable &tmp_symbol_table_arg,
|
StochSimulStatement::StochSimulStatement(const TmpSymbolTable &tmp_symbol_table_arg,
|
||||||
|
@ -452,7 +454,9 @@ ObservationTrendsStatement::writeOutput(ostream &output, const string &basename)
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
{
|
{
|
||||||
output << "tmp1 = strmatch('" << it->first << "',options_.varobs,'exact');\n";
|
output << "tmp1 = strmatch('" << it->first << "',options_.varobs,'exact');\n";
|
||||||
output << "options_.trend_coeffs{tmp1} = '" << it->second << "';\n";
|
output << "options_.trend_coeffs{tmp1} = '";
|
||||||
|
it->second->writeOutput(output);
|
||||||
|
output << "';" << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cout << "Error : Non-variable symbol used in TREND_COEFF: " << it->first << endl;
|
cout << "Error : Non-variable symbol used in TREND_COEFF: " << it->first << endl;
|
||||||
|
@ -490,20 +494,24 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
{
|
{
|
||||||
const string &name = it->first;
|
const string &name = it->first;
|
||||||
const string &weight = it->second.first;
|
const string &weight = it->second.first;
|
||||||
const string &expression = it->second.second;
|
const NodeID expression = it->second.second;
|
||||||
|
|
||||||
int id = symbol_table.getID(name) + 1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
if (symbol_table.getType(name) == eEndogenous)
|
if (symbol_table.getType(name) == eEndogenous)
|
||||||
{
|
{
|
||||||
output << "calib_var_index{1} = [calib_var_index{1};" << id << "," << id << "];\n";
|
output << "calib_var_index{1} = [calib_var_index{1};" << id << "," << id << "];\n";
|
||||||
output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n";
|
output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n";
|
||||||
output << "calib_targets{1} =[calib_targets{1}; " << expression << "];\n";
|
output << "calib_targets{1} =[calib_targets{1}; ";
|
||||||
|
expression->writeOutput(output);
|
||||||
|
output << "];\n";
|
||||||
}
|
}
|
||||||
else if (symbol_table.getType(name) == eExogenous)
|
else if (symbol_table.getType(name) == eExogenous)
|
||||||
{
|
{
|
||||||
output << "calib_var_index{3} = [calib_var_index{3};" << id << "," << id << "];\n";
|
output << "calib_var_index{3} = [calib_var_index{3};" << id << "," << id << "];\n";
|
||||||
output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n";
|
output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n";
|
||||||
output << "calib_targets{3} =[calib_targets{3}; " << expression << "];\n";
|
output << "calib_targets{3} =[calib_targets{3}; ";
|
||||||
|
expression->writeOutput(output);
|
||||||
|
output << "];\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +522,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
const string &name1 = it->first.first;
|
const string &name1 = it->first.first;
|
||||||
const string &name2 = it->first.second;
|
const string &name2 = it->first.second;
|
||||||
const string &weight = it->second.first;
|
const string &weight = it->second.first;
|
||||||
const string &expression = it->second.second;
|
const NodeID expression = it->second.second;
|
||||||
|
|
||||||
int id1 = symbol_table.getID(name1) + 1;
|
int id1 = symbol_table.getID(name1) + 1;
|
||||||
int id2 = symbol_table.getID(name2) + 1;
|
int id2 = symbol_table.getID(name2) + 1;
|
||||||
|
@ -522,13 +530,17 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
{
|
{
|
||||||
output << "calib_var_index{1} = [calib_var_index{1};" << id1 << "," << id2 << "];\n";
|
output << "calib_var_index{1} = [calib_var_index{1};" << id1 << "," << id2 << "];\n";
|
||||||
output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n";
|
output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n";
|
||||||
output << "calib_targets{1} =[calib_targets{1}; " << expression << "];\n";
|
output << "calib_targets{1} =[calib_targets{1}; ";
|
||||||
|
expression->writeOutput(output);
|
||||||
|
output << "];\n";
|
||||||
}
|
}
|
||||||
else if (symbol_table.getType(name1) == eExogenous)
|
else if (symbol_table.getType(name1) == eExogenous)
|
||||||
{
|
{
|
||||||
output << "calib_var_index{3} = [calib_var_index{3};" << id1 << "," << id2 << "];\n";
|
output << "calib_var_index{3} = [calib_var_index{3};" << id1 << "," << id2 << "];\n";
|
||||||
output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n";
|
output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n";
|
||||||
output << "calib_targets{3} =[calib_targets{3}; " << expression << "];\n";
|
output << "calib_targets{3} =[calib_targets{3}; ";
|
||||||
|
expression->writeOutput(output);
|
||||||
|
output << "];\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +553,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
const string &name = it->first.first;
|
const string &name = it->first.first;
|
||||||
int iar = it->first.second + 3;
|
int iar = it->first.second + 3;
|
||||||
const string &weight = it->second.first;
|
const string &weight = it->second.first;
|
||||||
const string &expression = it->second.second;
|
const NodeID expression = it->second.second;
|
||||||
|
|
||||||
int id = symbol_table.getID(name) + 1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
|
|
||||||
|
@ -559,7 +571,9 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
|
|
||||||
output << "calib_var_index{" << iar << "} = [calib_var_index{" << iar << "};" << id << "];\n";
|
output << "calib_var_index{" << iar << "} = [calib_var_index{" << iar << "};" << id << "];\n";
|
||||||
output << "calib_weights{" << iar << "} = [calib_weights{" << iar << "}; " << weight << "];\n";
|
output << "calib_weights{" << iar << "} = [calib_weights{" << iar << "}; " << weight << "];\n";
|
||||||
output << "calib_targets{" << iar << "} =[calib_targets{" << iar << "}; " << expression << "];\n";
|
output << "calib_targets{" << iar << "} =[calib_targets{" << iar << "}; ";
|
||||||
|
expression->writeOutput(output);
|
||||||
|
output << "];\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,9 +685,11 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
|
||||||
it != var_weights.end(); it++)
|
it != var_weights.end(); it++)
|
||||||
{
|
{
|
||||||
const string &name = it->first;
|
const string &name = it->first;
|
||||||
const string &value = it->second;
|
const NodeID value = it->second;
|
||||||
int id = symbol_table.getID(name) + 1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
output << "optim_weights_(" << id << "," << id << ") = " << value << ";\n";
|
output << "optim_weights_(" << id << "," << id << ") = ";
|
||||||
|
value->writeOutput(output);
|
||||||
|
output << ";" << endl;
|
||||||
output << "obj_var_ = [obj_var_; " << id << "];\n";
|
output << "obj_var_ = [obj_var_; " << id << "];\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,10 +698,12 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
|
||||||
{
|
{
|
||||||
const string &name1 = it->first.first;
|
const string &name1 = it->first.first;
|
||||||
const string &name2 = it->first.second;
|
const string &name2 = it->first.second;
|
||||||
const string &value = it->second;
|
const NodeID value = it->second;
|
||||||
int id1 = symbol_table.getID(name1) + 1;
|
int id1 = symbol_table.getID(name1) + 1;
|
||||||
int id2 = symbol_table.getID(name2) + 1;
|
int id2 = symbol_table.getID(name2) + 1;
|
||||||
output << "optim_weights_(" << id1 << "," << id2 << ") = " << value << ";\n";
|
output << "optim_weights_(" << id1 << "," << id2 << ") = ";
|
||||||
|
value->writeOutput(output);
|
||||||
|
output << ";" << endl;
|
||||||
output << "obj_var_ = [obj_var_; " << id1 << " " << id2 << "];\n";
|
output << "obj_var_ = [obj_var_; " << id1 << " " << id2 << "];\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -770,7 +788,7 @@ void
|
||||||
PlannerObjectiveStatement::computingPass()
|
PlannerObjectiveStatement::computingPass()
|
||||||
{
|
{
|
||||||
model_tree->computeStaticHessian = true;
|
model_tree->computeStaticHessian = true;
|
||||||
model_tree->computingPass();
|
model_tree->computingPass(eval_context_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -43,21 +43,14 @@ DataTree::AddVariable(const string &name, int lag)
|
||||||
|
|
||||||
symbol_table.SetReferenced(name);
|
symbol_table.SetReferenced(name);
|
||||||
|
|
||||||
|
int symb_id = symbol_table.getID(name);
|
||||||
Type type = symbol_table.getType(name);
|
Type type = symbol_table.getType(name);
|
||||||
int id;
|
|
||||||
if (type == eEndogenous
|
|
||||||
|| type == eExogenousDet
|
|
||||||
|| type == eExogenous
|
|
||||||
|| type == eRecursiveVariable)
|
|
||||||
id = variable_table.AddVariable(name, lag);
|
|
||||||
else
|
|
||||||
id = symbol_table.getID(name);
|
|
||||||
|
|
||||||
variable_node_map_type::iterator it = variable_node_map.find(make_pair(id, type));
|
variable_node_map_type::iterator it = variable_node_map.find(make_pair(make_pair(symb_id, type), lag));
|
||||||
if (it != variable_node_map.end())
|
if (it != variable_node_map.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
else
|
else
|
||||||
return new VariableNode(*this, id, type);
|
return new VariableNode(*this, symb_id, type, lag);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
|
@ -346,3 +339,9 @@ DataTree::AddLocalParameter(const string &name, NodeID value) throw (LocalParame
|
||||||
|
|
||||||
local_parameters_table[id] = value;
|
local_parameters_table[id] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeID
|
||||||
|
DataTree::AddUnknownFunction(const string &function_name, const vector<NodeID> &arguments)
|
||||||
|
{
|
||||||
|
return new UnknownFunctionNode(*this, function_name, arguments);
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -7,11 +7,7 @@ using namespace std;
|
||||||
|
|
||||||
class ParsingDriver;
|
class ParsingDriver;
|
||||||
|
|
||||||
#include "SymbolTableTypes.hh"
|
|
||||||
#include "ExprNode.hh"
|
#include "ExprNode.hh"
|
||||||
|
|
||||||
//! Type for semantic value of non-derivable expressions
|
|
||||||
typedef pair<int, Type> ExpObj;
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%parse-param { ParsingDriver &driver }
|
%parse-param { ParsingDriver &driver }
|
||||||
|
@ -30,8 +26,7 @@ typedef pair<int, Type> ExpObj;
|
||||||
%union
|
%union
|
||||||
{
|
{
|
||||||
string *string_val;
|
string *string_val;
|
||||||
ExpObj *exp_val;
|
NodeID node_val;
|
||||||
NodeID model_val;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
@ -75,8 +70,8 @@ typedef pair<int, Type> ExpObj;
|
||||||
%nonassoc POWER
|
%nonassoc POWER
|
||||||
%token EXP LOG LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH ASINH ACOSH ATANH SQRT
|
%token EXP LOG LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH ASINH ACOSH ATANH SQRT
|
||||||
|
|
||||||
%type <exp_val> expression comma_expression
|
%type <node_val> expression
|
||||||
%type <model_val> equation hand_side model_var
|
%type <node_val> equation hand_side model_var
|
||||||
%type <string_val> signed_float signed_integer prior
|
%type <string_val> signed_float signed_integer prior
|
||||||
%type <string_val> value filename filename_elem vec_int_elem vec_int_1 vec_int
|
%type <string_val> value filename filename_elem vec_int_elem vec_int_1 vec_int
|
||||||
%type <string_val> calib_arg2 range
|
%type <string_val> calib_arg2 range
|
||||||
|
@ -255,54 +250,52 @@ cutoff
|
||||||
| NAME
|
| NAME
|
||||||
{$$ = driver.add_expression_variable($1);}
|
{$$ = driver.add_expression_variable($1);}
|
||||||
| FLOAT_NUMBER
|
| FLOAT_NUMBER
|
||||||
{$$ = driver.add_expression_constant($1);}
|
{$$ = driver.add_constant($1);}
|
||||||
| INT_NUMBER
|
| INT_NUMBER
|
||||||
{$$ = driver.add_expression_constant($1);}
|
{$$ = driver.add_constant($1);}
|
||||||
| expression PLUS expression
|
| expression PLUS expression
|
||||||
{$$ = driver.add_expression_token($1, $3, token::PLUS);}
|
{$$ = driver.add_plus($1, $3);}
|
||||||
| expression MINUS expression
|
| expression MINUS expression
|
||||||
{$$ = driver.add_expression_token($1, $3, token::MINUS);}
|
{$$ = driver.add_minus($1, $3);}
|
||||||
| expression DIVIDE expression
|
| expression DIVIDE expression
|
||||||
{$$ = driver.add_expression_token($1, $3, token::DIVIDE);}
|
{$$ = driver.add_divide($1, $3);}
|
||||||
| expression TIMES expression
|
| expression TIMES expression
|
||||||
{$$ = driver.add_expression_token($1, $3, token::TIMES);}
|
{$$ = driver.add_times($1, $3);}
|
||||||
| expression POWER expression
|
| expression POWER expression
|
||||||
{$$ = driver.add_expression_token($1, $3, token::POWER);}
|
{$$ = driver.add_power($1, $3);}
|
||||||
| MINUS expression %prec UMINUS
|
| MINUS expression %prec UMINUS
|
||||||
{$$ = driver.add_expression_token($2, token::UMINUS);}
|
{$$ = driver.add_uminus($2);}
|
||||||
| PLUS expression
|
| PLUS expression
|
||||||
{$$ = $2;}
|
{$$ = $2;}
|
||||||
| EXP '(' expression ')'
|
| EXP '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::EXP);}
|
{$$ = driver.add_exp($3);}
|
||||||
| LOG '(' expression ')'
|
| LOG '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::LOG);}
|
{$$ = driver.add_log($3);}
|
||||||
| LOG10 '(' expression ')'
|
| LOG10 '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::LOG10);}
|
{$$ = driver.add_log10($3);}
|
||||||
| SIN '(' expression ')'
|
| SIN '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::SIN);}
|
{$$ = driver.add_sin($3);}
|
||||||
| COS '(' expression ')'
|
| COS '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::COS);}
|
{$$ = driver.add_cos($3);}
|
||||||
| TAN '(' expression ')'
|
| TAN '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::TAN);}
|
{$$ = driver.add_tan($3);}
|
||||||
| ASIN '(' expression ')'
|
| ASIN '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::ASIN);}
|
{$$ = driver.add_asin($3);}
|
||||||
| ACOS '(' expression ')'
|
| ACOS '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::ACOS);}
|
{$$ = driver.add_acos($3);}
|
||||||
| ATAN '(' expression ')'
|
| ATAN '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::ATAN);}
|
{$$ = driver.add_atan($3);}
|
||||||
| SQRT '(' expression ')'
|
| SQRT '(' expression ')'
|
||||||
{$$ = driver.add_expression_token($3, token::SQRT);}
|
{$$ = driver.add_sqrt($3);}
|
||||||
| NAME '(' expression ')'
|
|
||||||
{$$ = driver.add_expression_token($3, $1);}
|
|
||||||
| NAME '(' comma_expression ')'
|
| NAME '(' comma_expression ')'
|
||||||
{$$ = driver.add_expression_token($3, $1);}
|
{$$ = driver.add_unknown_function($1);}
|
||||||
;
|
;
|
||||||
|
|
||||||
comma_expression :
|
comma_expression :
|
||||||
expression COMMA expression
|
expression
|
||||||
{$$ = driver.add_expression_token($1, $3, token::COMMA);}
|
{ driver.add_unknown_function_arg($1); }
|
||||||
| comma_expression COMMA expression
|
| comma_expression COMMA expression
|
||||||
{$$ = driver.add_expression_token($1, $3, token::COMMA);}
|
{ driver.add_unknown_function_arg($3); }
|
||||||
|
|
||||||
initval
|
initval
|
||||||
: INITVAL ';' initval_list END
|
: INITVAL ';' initval_list END
|
||||||
|
@ -356,15 +349,15 @@ cutoff
|
||||||
;
|
;
|
||||||
|
|
||||||
model
|
model
|
||||||
: MODEL ';' { driver.begin_model(); } equation_list END
|
: MODEL ';' { driver.begin_model(); } equation_list END { driver.reset_data_tree(); }
|
||||||
| MODEL '(' o_linear ')' ';' { driver.begin_model(); }
|
| MODEL '(' o_linear ')' ';' { driver.begin_model(); }
|
||||||
equation_list END
|
equation_list END { driver.reset_data_tree(); }
|
||||||
| MODEL '(' USE_DLL ')' ';' { driver.begin_model(); driver.use_dll(); }
|
| MODEL '(' USE_DLL ')' ';' { driver.begin_model(); driver.use_dll(); }
|
||||||
equation_list END
|
equation_list END { driver.reset_data_tree(); }
|
||||||
| MODEL '(' SPARSE_DLL COMMA model_sparse_options_list ')' { driver.sparse_dll(); driver.begin_model(); } ';'
|
| MODEL '(' SPARSE_DLL COMMA model_sparse_options_list ')' { driver.begin_model(); driver.sparse_dll(); } ';'
|
||||||
equation_list END
|
equation_list END { driver.reset_data_tree(); }
|
||||||
| MODEL '(' SPARSE_DLL ')' { driver.sparse_dll(); driver.begin_model(); } ';'
|
| MODEL '(' SPARSE_DLL ')' { driver.begin_model(); driver.sparse_dll(); } ';'
|
||||||
equation_list END
|
equation_list END { driver.reset_data_tree(); }
|
||||||
;
|
;
|
||||||
|
|
||||||
equation_list
|
equation_list
|
||||||
|
@ -385,43 +378,43 @@ cutoff
|
||||||
: '(' hand_side ')' {$$ = $2;}
|
: '(' hand_side ')' {$$ = $2;}
|
||||||
| model_var
|
| model_var
|
||||||
| FLOAT_NUMBER
|
| FLOAT_NUMBER
|
||||||
{$$ = driver.add_model_constant($1);}
|
{$$ = driver.add_constant($1);}
|
||||||
| INT_NUMBER
|
| INT_NUMBER
|
||||||
{$1->append(".0"); $$ = driver.add_model_constant($1);}
|
{$1->append(".0"); $$ = driver.add_constant($1);}
|
||||||
| hand_side PLUS hand_side
|
| hand_side PLUS hand_side
|
||||||
{$$ = driver.add_model_plus($1, $3);}
|
{$$ = driver.add_plus($1, $3);}
|
||||||
| hand_side MINUS hand_side
|
| hand_side MINUS hand_side
|
||||||
{$$ = driver.add_model_minus($1, $3);}
|
{$$ = driver.add_minus($1, $3);}
|
||||||
| hand_side DIVIDE hand_side
|
| hand_side DIVIDE hand_side
|
||||||
{$$ = driver.add_model_divide($1, $3);}
|
{$$ = driver.add_divide($1, $3);}
|
||||||
| hand_side TIMES hand_side
|
| hand_side TIMES hand_side
|
||||||
{$$ = driver.add_model_times($1, $3);}
|
{$$ = driver.add_times($1, $3);}
|
||||||
| hand_side POWER hand_side
|
| hand_side POWER hand_side
|
||||||
{$$ = driver.add_model_power($1, $3);}
|
{$$ = driver.add_power($1, $3);}
|
||||||
| MINUS hand_side %prec UMINUS
|
| MINUS hand_side %prec UMINUS
|
||||||
{ $$ = driver.add_model_uminus($2);}
|
{ $$ = driver.add_uminus($2);}
|
||||||
| PLUS hand_side
|
| PLUS hand_side
|
||||||
{$$ = $2;}
|
{$$ = $2;}
|
||||||
| EXP '(' hand_side ')'
|
| EXP '(' hand_side ')'
|
||||||
{$$ = driver.add_model_exp($3);}
|
{$$ = driver.add_exp($3);}
|
||||||
| LOG '(' hand_side ')'
|
| LOG '(' hand_side ')'
|
||||||
{$$ = driver.add_model_log($3);}
|
{$$ = driver.add_log($3);}
|
||||||
| LOG10 '(' hand_side ')'
|
| LOG10 '(' hand_side ')'
|
||||||
{$$ = driver.add_model_log10($3);}
|
{$$ = driver.add_log10($3);}
|
||||||
| SIN '(' hand_side ')'
|
| SIN '(' hand_side ')'
|
||||||
{$$ = driver.add_model_sin($3);}
|
{$$ = driver.add_sin($3);}
|
||||||
| COS '(' hand_side ')'
|
| COS '(' hand_side ')'
|
||||||
{$$ = driver.add_model_cos($3);}
|
{$$ = driver.add_cos($3);}
|
||||||
| TAN '(' hand_side ')'
|
| TAN '(' hand_side ')'
|
||||||
{$$ = driver.add_model_tan($3);}
|
{$$ = driver.add_tan($3);}
|
||||||
| ASIN '(' hand_side ')'
|
| ASIN '(' hand_side ')'
|
||||||
{$$ = driver.add_model_asin($3);}
|
{$$ = driver.add_asin($3);}
|
||||||
| ACOS '(' hand_side ')'
|
| ACOS '(' hand_side ')'
|
||||||
{$$ = driver.add_model_acos($3);}
|
{$$ = driver.add_acos($3);}
|
||||||
| ATAN '(' hand_side ')'
|
| ATAN '(' hand_side ')'
|
||||||
{$$ = driver.add_model_atan($3);}
|
{$$ = driver.add_atan($3);}
|
||||||
| SQRT '(' hand_side ')'
|
| SQRT '(' hand_side ')'
|
||||||
{$$ = driver.add_model_sqrt($3);}
|
{$$ = driver.add_sqrt($3);}
|
||||||
;
|
;
|
||||||
|
|
||||||
pound_expression: '#' NAME EQUAL hand_side ';'
|
pound_expression: '#' NAME EQUAL hand_side ';'
|
||||||
|
@ -478,17 +471,17 @@ cutoff
|
||||||
|
|
||||||
value_list
|
value_list
|
||||||
: value_list signed_float
|
: value_list signed_float
|
||||||
{driver.add_value($2);}
|
{driver.add_value_const($2);}
|
||||||
| value_list signed_integer
|
| value_list signed_integer
|
||||||
{driver.add_value($2);}
|
{driver.add_value_const($2);}
|
||||||
| value_list NAME
|
| value_list NAME
|
||||||
{driver.add_value($2);}
|
{driver.add_value_var($2);}
|
||||||
| signed_float
|
| signed_float
|
||||||
{driver.add_value($1);}
|
{driver.add_value_const($1);}
|
||||||
| signed_integer
|
| signed_integer
|
||||||
{driver.add_value($1);}
|
{driver.add_value_const($1);}
|
||||||
| NAME
|
| NAME
|
||||||
{driver.add_value($1);}
|
{driver.add_value_var($1);}
|
||||||
| value_list '(' expression ')'
|
| value_list '(' expression ')'
|
||||||
{driver.add_value($3);}
|
{driver.add_value($3);}
|
||||||
| '(' expression ')'
|
| '(' expression ')'
|
||||||
|
@ -511,21 +504,21 @@ cutoff
|
||||||
: triangular_row COMMA '(' expression ')'
|
: triangular_row COMMA '(' expression ')'
|
||||||
{driver.add_to_row($4);}
|
{driver.add_to_row($4);}
|
||||||
| triangular_row COMMA FLOAT_NUMBER
|
| triangular_row COMMA FLOAT_NUMBER
|
||||||
{driver.add_to_row($3);}
|
{driver.add_to_row_const($3);}
|
||||||
| triangular_row COMMA INT_NUMBER
|
| triangular_row COMMA INT_NUMBER
|
||||||
{driver.add_to_row($3);}
|
{driver.add_to_row_const($3);}
|
||||||
| triangular_row '(' expression ')'
|
| triangular_row '(' expression ')'
|
||||||
{driver.add_to_row($3);}
|
{driver.add_to_row($3);}
|
||||||
| triangular_row FLOAT_NUMBER
|
| triangular_row FLOAT_NUMBER
|
||||||
{driver.add_to_row($2);}
|
{driver.add_to_row_const($2);}
|
||||||
| triangular_row INT_NUMBER
|
| triangular_row INT_NUMBER
|
||||||
{driver.add_to_row($2);}
|
{driver.add_to_row_const($2);}
|
||||||
| '(' expression ')'
|
| '(' expression ')'
|
||||||
{driver.add_to_row($2);}
|
{driver.add_to_row($2);}
|
||||||
| FLOAT_NUMBER
|
| FLOAT_NUMBER
|
||||||
{driver.add_to_row($1);}
|
{driver.add_to_row_const($1);}
|
||||||
| INT_NUMBER
|
| INT_NUMBER
|
||||||
{driver.add_to_row($1);}
|
{driver.add_to_row_const($1);}
|
||||||
;
|
;
|
||||||
|
|
||||||
steady
|
steady
|
||||||
|
|
|
@ -84,6 +84,12 @@ ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
// Nothing to do for a terminal node
|
// Nothing to do for a terminal node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ExprNode::writeOutput(ostream &output)
|
||||||
|
{
|
||||||
|
writeOutput(output, oMatlabOutsideModel, temporary_terms_type());
|
||||||
|
}
|
||||||
|
|
||||||
NumConstNode::NumConstNode(DataTree &datatree_arg, int id_arg) :
|
NumConstNode::NumConstNode(DataTree &datatree_arg, int id_arg) :
|
||||||
ExprNode(datatree_arg),
|
ExprNode(datatree_arg),
|
||||||
id(id_arg)
|
id(id_arg)
|
||||||
|
@ -114,10 +120,10 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
output << datatree.num_constants.get(id);
|
output << datatree.num_constants.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
double
|
||||||
NumConstNode::Evaluate() const
|
NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalException)
|
||||||
{
|
{
|
||||||
datatree.interprete_.Stack.push(atof(datatree.num_constants.get(id).c_str()));
|
return(atof(datatree.num_constants.get(id).c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -125,13 +131,23 @@ NumConstNode::collectEndogenous(NodeID &Id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableNode::VariableNode(DataTree &datatree_arg, int id_arg, Type type_arg) :
|
VariableNode::VariableNode(DataTree &datatree_arg, int symb_id_arg, Type type_arg, int lag_arg) :
|
||||||
ExprNode(datatree_arg),
|
ExprNode(datatree_arg),
|
||||||
id(id_arg),
|
symb_id(symb_id_arg),
|
||||||
type(type_arg)
|
type(type_arg),
|
||||||
|
lag(lag_arg)
|
||||||
{
|
{
|
||||||
// Add myself to the variable map
|
// Add myself to the variable map
|
||||||
datatree.variable_node_map[make_pair(id, type)] = this;
|
datatree.variable_node_map[make_pair(make_pair(symb_id, type), lag)] = this;
|
||||||
|
|
||||||
|
// Add myself to the variable table if necessary and initialize var_id
|
||||||
|
if (type == eEndogenous
|
||||||
|
|| type == eExogenousDet
|
||||||
|
|| type == eExogenous
|
||||||
|
|| type == eRecursiveVariable)
|
||||||
|
var_id = datatree.variable_table.AddVariable(datatree.symbol_table.getNameByID(type, symb_id), lag);
|
||||||
|
else
|
||||||
|
var_id = -1;
|
||||||
|
|
||||||
// Fill in non_null_derivatives
|
// Fill in non_null_derivatives
|
||||||
switch(type)
|
switch(type)
|
||||||
|
@ -141,21 +157,15 @@ VariableNode::VariableNode(DataTree &datatree_arg, int id_arg, Type type_arg) :
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
case eRecursiveVariable:
|
case eRecursiveVariable:
|
||||||
// For a variable, the only non-null derivative is with respect to itself
|
// For a variable, the only non-null derivative is with respect to itself
|
||||||
non_null_derivatives.insert(id);
|
non_null_derivatives.insert(var_id);
|
||||||
break;
|
break;
|
||||||
case eParameter:
|
case eParameter:
|
||||||
// All derivatives are null, do nothing
|
// All derivatives are null, do nothing
|
||||||
break;
|
break;
|
||||||
case eLocalParameter:
|
case eLocalParameter:
|
||||||
// Non null derivatives are those of the value of the local parameter
|
// Non null derivatives are those of the value of the local parameter
|
||||||
non_null_derivatives = datatree.local_parameters_table[id]->non_null_derivatives;
|
non_null_derivatives = datatree.local_parameters_table[symb_id]->non_null_derivatives;
|
||||||
break;
|
break;
|
||||||
case eNumericalConstant:
|
|
||||||
case eUNDEF:
|
|
||||||
case eTempResult:
|
|
||||||
// Impossible cases
|
|
||||||
cerr << "Incorrect symbol type used in VariableNode" << endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,20 +178,14 @@ VariableNode::computeDerivative(int varID)
|
||||||
case eExogenous:
|
case eExogenous:
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
case eRecursiveVariable:
|
case eRecursiveVariable:
|
||||||
if (varID == id)
|
if (varID == var_id)
|
||||||
return datatree.One;
|
return datatree.One;
|
||||||
else
|
else
|
||||||
return datatree.Zero;
|
return datatree.Zero;
|
||||||
case eParameter:
|
case eParameter:
|
||||||
return datatree.Zero;
|
return datatree.Zero;
|
||||||
case eLocalParameter:
|
case eLocalParameter:
|
||||||
return datatree.local_parameters_table[id]->getDerivative(varID);
|
return datatree.local_parameters_table[symb_id]->getDerivative(varID);
|
||||||
case eNumericalConstant:
|
|
||||||
case eUNDEF:
|
|
||||||
case eTempResult:
|
|
||||||
// Impossible cases
|
|
||||||
cerr << "Incorrect symbol type used in VariableNode" << endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
cerr << "Impossible case!" << endl;
|
cerr << "Impossible case!" << endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
@ -201,18 +205,19 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
output << "T" << idx << "[it_]";
|
output << "T" << idx << "[it_]";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int idx, lag;
|
|
||||||
|
int i;
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case eParameter:
|
case eParameter:
|
||||||
if (output_type == oMatlabOutsideModel)
|
if (output_type == oMatlabOutsideModel)
|
||||||
output << "M_.params" << "(" << id + 1 << ")";
|
output << "M_.params" << "(" << symb_id + 1 << ")";
|
||||||
else
|
else
|
||||||
output << "params" << LPAR(output_type) << id + OFFSET(output_type) << RPAR(output_type);
|
output << "params" << LPAR(output_type) << symb_id + OFFSET(output_type) << RPAR(output_type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case eLocalParameter:
|
case eLocalParameter:
|
||||||
output << datatree.symbol_table.getNameByID(eLocalParameter, id);
|
output << datatree.symbol_table.getNameByID(eLocalParameter, symb_id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case eEndogenous:
|
case eEndogenous:
|
||||||
|
@ -220,55 +225,52 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
{
|
{
|
||||||
case oMatlabDynamicModel:
|
case oMatlabDynamicModel:
|
||||||
case oCDynamicModel:
|
case oCDynamicModel:
|
||||||
idx = datatree.variable_table.getPrintIndex(id) + OFFSET(output_type);
|
i = datatree.variable_table.getPrintIndex(var_id) + OFFSET(output_type);
|
||||||
output << "y" << LPAR(output_type) << idx << RPAR(output_type);
|
output << "y" << LPAR(output_type) << i << RPAR(output_type);
|
||||||
break;
|
break;
|
||||||
case oMatlabStaticModel:
|
case oMatlabStaticModel:
|
||||||
case oCStaticModel:
|
case oCStaticModel:
|
||||||
idx = datatree.variable_table.getSymbolID(id) + OFFSET(output_type);
|
i = symb_id + OFFSET(output_type);
|
||||||
output << "y" << LPAR(output_type) << idx << RPAR(output_type);
|
output << "y" << LPAR(output_type) << i << RPAR(output_type);
|
||||||
break;
|
break;
|
||||||
case oCDynamicModelSparseDLL:
|
case oCDynamicModelSparseDLL:
|
||||||
idx = datatree.variable_table.getSymbolID(id);
|
|
||||||
lag = datatree.variable_table.getLag((long int) id);
|
|
||||||
if (lag > 0)
|
if (lag > 0)
|
||||||
output << "y" << LPAR(output_type) << "(it_+" << lag << ")*y_size+" << idx << RPAR(output_type);
|
output << "y" << LPAR(output_type) << "(it_+" << lag << ")*y_size+" << symb_id << RPAR(output_type);
|
||||||
else if (lag < 0)
|
else if (lag < 0)
|
||||||
output << "y" << LPAR(output_type) << "(it_" << lag << ")*y_size+" << idx << RPAR(output_type);
|
output << "y" << LPAR(output_type) << "(it_" << lag << ")*y_size+" << symb_id << RPAR(output_type);
|
||||||
else
|
else
|
||||||
output << "y" << LPAR(output_type) << "Per_y_+" << idx << RPAR(output_type);
|
output << "y" << LPAR(output_type) << "Per_y_+" << symb_id << RPAR(output_type);
|
||||||
break;
|
break;
|
||||||
case oMatlabOutsideModel:
|
case oMatlabOutsideModel:
|
||||||
output << "oo_.steady_state" << "(" << id + 1 << ")";
|
output << "oo_.steady_state" << "(" << symb_id + 1 << ")";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case eExogenous:
|
case eExogenous:
|
||||||
idx = datatree.variable_table.getSymbolID(id) + OFFSET(output_type);
|
i = symb_id + OFFSET(output_type);
|
||||||
lag = datatree.variable_table.getLag(id);
|
|
||||||
switch(output_type)
|
switch(output_type)
|
||||||
{
|
{
|
||||||
case oMatlabDynamicModel:
|
case oMatlabDynamicModel:
|
||||||
if (lag > 0)
|
if (lag > 0)
|
||||||
output << "x(it_+" << lag << ", " << idx << ")";
|
output << "x(it_+" << lag << ", " << i << ")";
|
||||||
else if (lag < 0)
|
else if (lag < 0)
|
||||||
output << "x(it_" << lag << ", " << idx << ")";
|
output << "x(it_" << lag << ", " << i << ")";
|
||||||
else
|
else
|
||||||
output << "x(it_, " << idx << ")";
|
output << "x(it_, " << i << ")";
|
||||||
break;
|
break;
|
||||||
case oCDynamicModel:
|
case oCDynamicModel:
|
||||||
|
case oCDynamicModelSparseDLL:
|
||||||
if (lag == 0)
|
if (lag == 0)
|
||||||
output << "x[it_+" << idx << "*nb_row_x]";
|
output << "x[it_+" << i << "*nb_row_x]";
|
||||||
else if (lag > 0)
|
else if (lag > 0)
|
||||||
output << "x[it_+" << lag << "+" << idx << "*nb_row_x]";
|
output << "x[it_+" << lag << "+" << i << "*nb_row_x]";
|
||||||
else
|
else
|
||||||
output << "x[it_" << lag << "+" << idx << "*nb_row_x]";
|
output << "x[it_" << lag << "+" << i << "*nb_row_x]";
|
||||||
break;
|
break;
|
||||||
case oMatlabStaticModel:
|
case oMatlabStaticModel:
|
||||||
case oCStaticModel:
|
case oCStaticModel:
|
||||||
case oCDynamicModelSparseDLL:
|
output << "x" << LPAR(output_type) << i << RPAR(output_type);
|
||||||
output << "x" << LPAR(output_type) << idx << RPAR(output_type);
|
|
||||||
break;
|
break;
|
||||||
case oMatlabOutsideModel:
|
case oMatlabOutsideModel:
|
||||||
if (lag != 0)
|
if (lag != 0)
|
||||||
|
@ -276,36 +278,35 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
cerr << "VariableNode::writeOutput: lag != 0 for exogenous variable outside model scope!" << endl;
|
cerr << "VariableNode::writeOutput: lag != 0 for exogenous variable outside model scope!" << endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
output << "oo_.exo_steady_state" << "(" << idx << ")";
|
output << "oo_.exo_steady_state" << "(" << i << ")";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
idx = datatree.variable_table.getSymbolID(id) + datatree.symbol_table.exo_nbr + OFFSET(output_type);
|
i = symb_id + datatree.symbol_table.exo_nbr + OFFSET(output_type);
|
||||||
lag = datatree.variable_table.getLag(id);
|
|
||||||
switch(output_type)
|
switch(output_type)
|
||||||
{
|
{
|
||||||
case oMatlabDynamicModel:
|
case oMatlabDynamicModel:
|
||||||
if (lag > 0)
|
if (lag > 0)
|
||||||
output << "x(it_+" << lag << ", " << idx << ")";
|
output << "x(it_+" << lag << ", " << i << ")";
|
||||||
else if (lag < 0)
|
else if (lag < 0)
|
||||||
output << "x(it_" << lag << ", " << idx << ")";
|
output << "x(it_" << lag << ", " << i << ")";
|
||||||
else
|
else
|
||||||
output << "x(it_, " << idx << ")";
|
output << "x(it_, " << i << ")";
|
||||||
break;
|
break;
|
||||||
case oCDynamicModel:
|
case oCDynamicModel:
|
||||||
|
case oCDynamicModelSparseDLL:
|
||||||
if (lag == 0)
|
if (lag == 0)
|
||||||
output << "x[it_+" << idx << "*nb_row_xd]";
|
output << "x[it_+" << i << "*nb_row_xd]";
|
||||||
else if (lag > 0)
|
else if (lag > 0)
|
||||||
output << "x[it_+" << lag << "+" << idx << "*nb_row_xd]";
|
output << "x[it_+" << lag << "+" << i << "*nb_row_xd]";
|
||||||
else
|
else
|
||||||
output << "x[it_" << lag << "+" << idx << "*nb_row_xd]";
|
output << "x[it_" << lag << "+" << i << "*nb_row_xd]";
|
||||||
break;
|
break;
|
||||||
case oMatlabStaticModel:
|
case oMatlabStaticModel:
|
||||||
case oCStaticModel:
|
case oCStaticModel:
|
||||||
case oCDynamicModelSparseDLL:
|
output << "x" << LPAR(output_type) << i << RPAR(output_type);
|
||||||
output << "x" << LPAR(output_type) << idx << RPAR(output_type);
|
|
||||||
break;
|
break;
|
||||||
case oMatlabOutsideModel:
|
case oMatlabOutsideModel:
|
||||||
if (lag != 0)
|
if (lag != 0)
|
||||||
|
@ -313,7 +314,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
cerr << "VariableNode::writeOutput: lag != 0 for exogenous determistic variable outside model scope!" << endl;
|
cerr << "VariableNode::writeOutput: lag != 0 for exogenous determistic variable outside model scope!" << endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
output << "oo_.exo_det_steady_state" << "(" << datatree.variable_table.getSymbolID(id) + 1 << ")";
|
output << "oo_.exo_det_steady_state" << "(" << symb_id + 1 << ")";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -321,33 +322,27 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
case eRecursiveVariable:
|
case eRecursiveVariable:
|
||||||
cerr << "Recursive variable not implemented" << endl;
|
cerr << "Recursive variable not implemented" << endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
case eTempResult:
|
|
||||||
case eNumericalConstant:
|
|
||||||
case eUNDEF:
|
|
||||||
// Impossible cases
|
|
||||||
cerr << "Incorrect symbol type used in VariableNode" << endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
double
|
||||||
VariableNode::Evaluate() const
|
VariableNode::eval(const eval_context_type &eval_context) const throw (EvalException)
|
||||||
{
|
{
|
||||||
if (type == eParameter)
|
if (lag != 0)
|
||||||
datatree.interprete_.Stack.push(datatree.interprete_.GetDataValue(id, type));
|
throw EvalException();
|
||||||
else
|
|
||||||
datatree.interprete_.Stack.push(datatree.interprete_.GetDataValue(datatree.variable_table.getSymbolID(id), type));
|
eval_context_type::const_iterator it = eval_context.find(make_pair(symb_id, type));
|
||||||
|
if (it == eval_context.end())
|
||||||
|
throw EvalException();
|
||||||
|
|
||||||
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VariableNode::collectEndogenous(NodeID &Id)
|
VariableNode::collectEndogenous(NodeID &Id)
|
||||||
{
|
{
|
||||||
int idx;
|
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
{
|
Id->present_endogenous.insert(make_pair(symb_id, lag));
|
||||||
idx = datatree.variable_table.getSymbolID(id);
|
|
||||||
Id->present_endogenous.insert(make_pair(idx, datatree.variable_table.getLag((long int) id)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg) :
|
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg) :
|
||||||
|
@ -663,67 +658,50 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
output << ")";
|
output << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
double
|
||||||
UnaryOpNode::Evaluate() const
|
UnaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalException)
|
||||||
{
|
{
|
||||||
this->arg->Evaluate();
|
double v = arg->eval(eval_context);
|
||||||
datatree.interprete_.u2 = datatree.interprete_.Stack.top();
|
|
||||||
datatree.interprete_.Stack.pop();
|
|
||||||
switch(op_code)
|
switch(op_code)
|
||||||
{
|
{
|
||||||
case oUminus:
|
case oUminus:
|
||||||
datatree.interprete_.u1=-datatree.interprete_.u2;
|
return(-v);
|
||||||
break;
|
|
||||||
case oExp:
|
case oExp:
|
||||||
datatree.interprete_.u1=exp(datatree.interprete_.u2);
|
return(exp(v));
|
||||||
break;
|
|
||||||
case oLog:
|
case oLog:
|
||||||
datatree.interprete_.u1=log(datatree.interprete_.u2);
|
return(log(v));
|
||||||
break;
|
|
||||||
case oLog10:
|
case oLog10:
|
||||||
datatree.interprete_.u1=log10(datatree.interprete_.u2);
|
return(log10(v));
|
||||||
break;
|
|
||||||
case oCos:
|
case oCos:
|
||||||
datatree.interprete_.u1=cos(datatree.interprete_.u2);
|
return(cos(v));
|
||||||
break;
|
|
||||||
case oSin:
|
case oSin:
|
||||||
datatree.interprete_.u1=sin(datatree.interprete_.u2);
|
return(sin(v));
|
||||||
break;
|
|
||||||
case oTan:
|
case oTan:
|
||||||
datatree.interprete_.u1=tan(datatree.interprete_.u2);
|
return(tan(v));
|
||||||
break;
|
|
||||||
case oAcos:
|
case oAcos:
|
||||||
datatree.interprete_.u1=acos(datatree.interprete_.u2);
|
return(acos(v));
|
||||||
break;
|
|
||||||
case oAsin:
|
case oAsin:
|
||||||
datatree.interprete_.u1=asin(datatree.interprete_.u2);
|
return(asin(v));
|
||||||
break;
|
|
||||||
case oAtan:
|
case oAtan:
|
||||||
datatree.interprete_.u1=atan(datatree.interprete_.u2);
|
return(atan(v));
|
||||||
break;
|
|
||||||
case oCosh:
|
case oCosh:
|
||||||
datatree.interprete_.u1=cosh(datatree.interprete_.u2);
|
return(cosh(v));
|
||||||
break;
|
|
||||||
case oSinh:
|
case oSinh:
|
||||||
datatree.interprete_.u1=sinh(datatree.interprete_.u2);
|
return(sinh(v));
|
||||||
break;
|
|
||||||
case oTanh:
|
case oTanh:
|
||||||
datatree.interprete_.u1=tanh(datatree.interprete_.u2);
|
return(tanh(v));
|
||||||
break;
|
|
||||||
case oAcosh:
|
case oAcosh:
|
||||||
datatree.interprete_.u1=acosh(datatree.interprete_.u2);
|
return(acosh(v));
|
||||||
break;
|
|
||||||
case oAsinh:
|
case oAsinh:
|
||||||
datatree.interprete_.u1=asinh(datatree.interprete_.u2);
|
return(asinh(v));
|
||||||
break;
|
|
||||||
case oAtanh:
|
case oAtanh:
|
||||||
datatree.interprete_.u1=atanh(datatree.interprete_.u2);
|
return(atanh(v));
|
||||||
break;
|
|
||||||
case oSqrt:
|
case oSqrt:
|
||||||
datatree.interprete_.u1=sqrt(datatree.interprete_.u2);
|
return(sqrt(v));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
datatree.interprete_.Stack.push(datatree.interprete_.u1);
|
// Impossible
|
||||||
|
throw EvalException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -928,37 +906,28 @@ BinaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
double
|
||||||
BinaryOpNode::Evaluate() const
|
BinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalException)
|
||||||
{
|
{
|
||||||
// Write current operator symbol
|
double v1 = arg1->eval(eval_context);
|
||||||
this->arg1->Evaluate();
|
double v2 = arg2->eval(eval_context);
|
||||||
this->arg2->Evaluate();
|
|
||||||
datatree.interprete_.u2 = datatree.interprete_.Stack.top();
|
|
||||||
datatree.interprete_.Stack.pop();
|
|
||||||
datatree.interprete_.u1 = datatree.interprete_.Stack.top();
|
|
||||||
datatree.interprete_.Stack.pop();
|
|
||||||
switch(op_code)
|
switch(op_code)
|
||||||
{
|
{
|
||||||
case oPlus:
|
case oPlus:
|
||||||
datatree.interprete_.u1+=datatree.interprete_.u2;
|
return(v1 + v2);
|
||||||
break;
|
|
||||||
case oMinus:
|
case oMinus:
|
||||||
datatree.interprete_.u1-=datatree.interprete_.u2;
|
return(v1 - v2);
|
||||||
break;
|
|
||||||
case oTimes:
|
case oTimes:
|
||||||
datatree.interprete_.u1*=datatree.interprete_.u2;
|
return(v1 * v2);
|
||||||
break;
|
|
||||||
case oDivide:
|
case oDivide:
|
||||||
datatree.interprete_.u1/=datatree.interprete_.u2;
|
return(v1 / v2);
|
||||||
break;
|
|
||||||
case oPower:
|
case oPower:
|
||||||
datatree.interprete_.u1=pow(datatree.interprete_.u1,datatree.interprete_.u2);
|
return(pow(v1, v2));
|
||||||
break;
|
|
||||||
case oEqual:
|
case oEqual:
|
||||||
break;
|
default:
|
||||||
|
throw EvalException();
|
||||||
}
|
}
|
||||||
datatree.interprete_.Stack.push(datatree.interprete_.u1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1060,3 +1029,67 @@ BinaryOpNode::collectEndogenous(NodeID &Id)
|
||||||
arg1->collectEndogenous(Id);
|
arg1->collectEndogenous(Id);
|
||||||
arg2->collectEndogenous(Id);
|
arg2->collectEndogenous(Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UnknownFunctionNode::UnknownFunctionNode(DataTree &datatree_arg,
|
||||||
|
const string &function_name_arg,
|
||||||
|
const vector<NodeID> &arguments_arg) :
|
||||||
|
ExprNode(datatree_arg),
|
||||||
|
function_name(function_name_arg),
|
||||||
|
arguments(arguments_arg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeID
|
||||||
|
UnknownFunctionNode::computeDerivative(int varID)
|
||||||
|
{
|
||||||
|
cerr << "UnknownFunctionNode::computeDerivative: operation impossible!" << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UnknownFunctionNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
|
temporary_terms_type &temporary_terms,
|
||||||
|
bool is_matlab) const
|
||||||
|
{
|
||||||
|
cerr << "UnknownFunctionNode::computeTemporaryTerms: operation impossible!" << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnknownFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
|
const temporary_terms_type &temporary_terms) const
|
||||||
|
{
|
||||||
|
output << function_name << "(";
|
||||||
|
for(vector<NodeID>::const_iterator it = arguments.begin();
|
||||||
|
it != arguments.end(); it++)
|
||||||
|
{
|
||||||
|
if (it != arguments.begin())
|
||||||
|
output << ",";
|
||||||
|
|
||||||
|
(*it)->writeOutput(output, output_type, temporary_terms);
|
||||||
|
}
|
||||||
|
output << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UnknownFunctionNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
|
temporary_terms_type &temporary_terms,
|
||||||
|
map<NodeID, int> &first_occurence,
|
||||||
|
int Curr_block,
|
||||||
|
Model_Block *ModelBlock) const
|
||||||
|
{
|
||||||
|
cerr << "UnknownFunctionNode::computeTemporaryTerms: not implemented" << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UnknownFunctionNode::collectEndogenous(NodeID &Id)
|
||||||
|
{
|
||||||
|
cerr << "UnknownFunctionNode::collectEndogenous: not implemented" << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (EvalException)
|
||||||
|
{
|
||||||
|
throw EvalException();
|
||||||
|
}
|
||||||
|
|
|
@ -1,285 +0,0 @@
|
||||||
/*! \file
|
|
||||||
\version 1.0
|
|
||||||
\date 04/09/2004
|
|
||||||
\par This file implements the Expression class methodes.
|
|
||||||
*/
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <stack>
|
|
||||||
using namespace std;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include "Expression.hh"
|
|
||||||
#include "OperatorTable.hh"
|
|
||||||
|
|
||||||
Expression::Expression()
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
Expression::~Expression()
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Expression::setNumericalConstants(NumericalConstants *num_constants_arg)
|
|
||||||
{
|
|
||||||
num_constants = num_constants_arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Expression::AddToken(int id1,Type type1,int id2,Type type2,int op_code)
|
|
||||||
{
|
|
||||||
Token token;
|
|
||||||
// Making token structure
|
|
||||||
token.id1 = id1;
|
|
||||||
token.type1 = type1;
|
|
||||||
token.id2 = id2;
|
|
||||||
token.type2 = type2;
|
|
||||||
token.op_code = op_code;
|
|
||||||
token.op_name = OperatorTable::str(op_code);
|
|
||||||
// Inserting token into expression_list
|
|
||||||
expression_list.push_back(token);
|
|
||||||
return expression_list.size() -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int Expression::AddToken(int id1,Type type1,int op_code)
|
|
||||||
{
|
|
||||||
Token token;
|
|
||||||
// Making token structure
|
|
||||||
token.id1 = id1;
|
|
||||||
token.type1 = type1;
|
|
||||||
token.id2 = -1;
|
|
||||||
token.type2 = eUNDEF;
|
|
||||||
token.op_code = op_code;
|
|
||||||
token.op_name = OperatorTable::str(op_code);;
|
|
||||||
// Inserting token into expression_list
|
|
||||||
expression_list.push_back(token);
|
|
||||||
return expression_list.size() -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int Expression::AddToken(int id1,Type type1, string ufunction)
|
|
||||||
{
|
|
||||||
Token token;
|
|
||||||
// Making token structure
|
|
||||||
token.id1 = id1;
|
|
||||||
token.type1 = type1;
|
|
||||||
token.id2 = -1;
|
|
||||||
token.type2 = eUNDEF;
|
|
||||||
token.op_code = token::NAME;
|
|
||||||
token.op_name = ufunction;
|
|
||||||
// Inserting token into expression_list
|
|
||||||
expression_list.push_back(token);
|
|
||||||
return expression_list.size() -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void Expression::set(void)
|
|
||||||
{
|
|
||||||
// Stack of temporary tokens
|
|
||||||
stack <int, vector<Token> > stack_token;
|
|
||||||
// Dtack 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;
|
|
||||||
// Define type for type operator (binary or unary)
|
|
||||||
enum OperatorType
|
|
||||||
{
|
|
||||||
unary,
|
|
||||||
binary
|
|
||||||
};
|
|
||||||
OperatorType op_type;
|
|
||||||
int current_op, last_op;
|
|
||||||
|
|
||||||
// Clearing output string
|
|
||||||
output.str("");
|
|
||||||
// Starting from the end of list
|
|
||||||
stack_token.push(expression_list.back());
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
// First argument is a temporary result,
|
|
||||||
// pushing token on token stack and setting that argument to be followed
|
|
||||||
if ((stack_token.top().type1 == eTempResult) &&
|
|
||||||
(stack_token.top().followed1 == false))
|
|
||||||
{
|
|
||||||
stack_token.top().followed1 = true;
|
|
||||||
stack_token.push(expression_list[stack_token.top().id1]);
|
|
||||||
}
|
|
||||||
// Second argument is a temporary result,
|
|
||||||
// pushing token on stack and setting that argument to be followed
|
|
||||||
else if ((stack_token.top().type2 == eTempResult) &&
|
|
||||||
(stack_token.top().followed2 == false))
|
|
||||||
{
|
|
||||||
stack_token.top().followed2 = true;
|
|
||||||
stack_token.push(expression_list[stack_token.top().id2]);
|
|
||||||
}
|
|
||||||
// Writing expression
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Final token, no argment followed
|
|
||||||
if ((stack_token.top().followed1 == false) &&
|
|
||||||
(stack_token.top().followed2 == false))
|
|
||||||
{
|
|
||||||
argument1 = getArgument(stack_token.top().type1,stack_token.top().id1);
|
|
||||||
current_op = stack_token.top().op_code;
|
|
||||||
// Testing if unary or binary token
|
|
||||||
if (stack_token.top().id2 >= 0)
|
|
||||||
{
|
|
||||||
argument2 = getArgument(stack_token.top().type2,stack_token.top().id2);
|
|
||||||
op_type = binary;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
op_type = unary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Both arguments are followed, writing stacked expressions
|
|
||||||
else if ((stack_token.top().followed1 == true) &&
|
|
||||||
(stack_token.top().followed2 == true))
|
|
||||||
{
|
|
||||||
// Testing if unary or binary token
|
|
||||||
if (stack_token.top().id2 >= 0)
|
|
||||||
{
|
|
||||||
argument2 = stack_expression.top();
|
|
||||||
stack_expression.pop();
|
|
||||||
op_type = binary;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
op_type = unary;
|
|
||||||
}
|
|
||||||
argument1 = stack_expression.top();
|
|
||||||
current_op = stack_token.top().op_code;
|
|
||||||
stack_expression.pop();
|
|
||||||
|
|
||||||
}
|
|
||||||
// Only argument 1 is followed, combining expressions
|
|
||||||
else if (stack_token.top().followed1 == true)
|
|
||||||
{
|
|
||||||
argument1 = stack_expression.top();
|
|
||||||
current_op = stack_token.top().op_code;
|
|
||||||
stack_expression.pop();
|
|
||||||
// Testing if unary or binary token
|
|
||||||
if (stack_token.top().id2 >= 0)
|
|
||||||
{
|
|
||||||
argument2 = getArgument(stack_token.top().type2,stack_token.top().id2);
|
|
||||||
op_type = binary;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
op_type = unary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Only argument 2 is followed, combining experssions
|
|
||||||
else if (stack_token.top().followed2 == true)
|
|
||||||
{
|
|
||||||
argument1 = getArgument(stack_token.top().type1,stack_token.top().id1);
|
|
||||||
argument2 = stack_expression.top();
|
|
||||||
stack_expression.pop();
|
|
||||||
current_op = stack_token.top().op_code;
|
|
||||||
op_type = binary;
|
|
||||||
}
|
|
||||||
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 (op_type == binary)
|
|
||||||
{
|
|
||||||
// Comma operator, no parentheses
|
|
||||||
// parentheses are writing with function operator
|
|
||||||
if (current_op == token::COMMA)
|
|
||||||
{
|
|
||||||
exp << argument1 << op_name << argument2 ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
exp << "(" << argument1 << op_name << argument2 << ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Case of functions
|
|
||||||
if (OperatorTable::isfunction(current_op) == true)
|
|
||||||
exp << op_name << "(" << argument1 << ")";
|
|
||||||
else
|
|
||||||
exp << "(" << op_name << argument1 << ")";
|
|
||||||
}
|
|
||||||
stack_expression.push(exp.str());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output << stack_expression.top();
|
|
||||||
expression_list.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
string Expression::getArgument(Type type,int id)
|
|
||||||
{
|
|
||||||
ostringstream argument;
|
|
||||||
|
|
||||||
if (type == eExogenous)
|
|
||||||
{
|
|
||||||
argument << "oo_.exo_steady_state"<< "(" << id+1 << ")";
|
|
||||||
}
|
|
||||||
else if (type == eExogenousDet)
|
|
||||||
{
|
|
||||||
argument << "oo_.exo_det_steady_state" << "(" << id+1 << ")";
|
|
||||||
}
|
|
||||||
else if (type == eEndogenous)
|
|
||||||
{
|
|
||||||
argument << "oo_.steady_state" << "(" << id+1 << ")";
|
|
||||||
}
|
|
||||||
else if (type == eParameter)
|
|
||||||
{
|
|
||||||
argument << "M_.params" << "(" << id+1 << ")";
|
|
||||||
}
|
|
||||||
else if (type == eNumericalConstant)
|
|
||||||
{
|
|
||||||
argument << num_constants->get(id);
|
|
||||||
}
|
|
||||||
return argument.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
string Expression::get()
|
|
||||||
{
|
|
||||||
return output.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void Expression::clear(void)
|
|
||||||
{
|
|
||||||
expression_list.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
|
@ -37,7 +37,6 @@ COMMON_OBJ=\
|
||||||
DynareBison.o\
|
DynareBison.o\
|
||||||
ComputingTasks.o\
|
ComputingTasks.o\
|
||||||
DynareMain.o\
|
DynareMain.o\
|
||||||
Expression.o\
|
|
||||||
ModelTree.o\
|
ModelTree.o\
|
||||||
NumericalConstants.o\
|
NumericalConstants.o\
|
||||||
NumericalInitialization.o\
|
NumericalInitialization.o\
|
||||||
|
@ -56,7 +55,6 @@ COMMON_OBJ=\
|
||||||
ModelBlocks.o \
|
ModelBlocks.o \
|
||||||
BlockTriangular.o \
|
BlockTriangular.o \
|
||||||
Model_Graph.o \
|
Model_Graph.o \
|
||||||
interprete.o \
|
|
||||||
SymbolGaussElim.o
|
SymbolGaussElim.o
|
||||||
|
|
||||||
MATLAB_OBJ = InterfaceMatlab.o
|
MATLAB_OBJ = InterfaceMatlab.o
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include "ModFile.hh"
|
#include "ModFile.hh"
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
|
|
||||||
ModFile::ModFile() : model_tree(symbol_table, num_constants),
|
ModFile::ModFile() : expressions_tree(symbol_table, num_constants),
|
||||||
|
model_tree(symbol_table, num_constants),
|
||||||
linear(false)
|
linear(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -59,7 +60,7 @@ ModFile::computingPass()
|
||||||
model_tree.computeThirdDerivatives = true;
|
model_tree.computeThirdDerivatives = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
model_tree.computingPass();
|
model_tree.computingPass(global_eval_context);
|
||||||
|
|
||||||
for(vector<Statement *>::iterator it = statements.begin();
|
for(vector<Statement *>::iterator it = statements.begin();
|
||||||
it != statements.end(); it++)
|
it != statements.end(); it++)
|
||||||
|
|
|
@ -15,6 +15,7 @@ ModelTree::ModelTree(SymbolTable &symbol_table_arg,
|
||||||
DataTree(symbol_table_arg, num_constants_arg),
|
DataTree(symbol_table_arg, num_constants_arg),
|
||||||
mode(eStandardMode),
|
mode(eStandardMode),
|
||||||
compiler(LCC_COMPILE),
|
compiler(LCC_COMPILE),
|
||||||
|
cutoff(1e-6),
|
||||||
computeJacobian(false),
|
computeJacobian(false),
|
||||||
computeJacobianExo(false),
|
computeJacobianExo(false),
|
||||||
computeHessian(false),
|
computeHessian(false),
|
||||||
|
@ -752,7 +753,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writing ouputs
|
// Writing ouputs
|
||||||
if (mode == eStandardMode)
|
if (mode != eDLLMode)
|
||||||
{
|
{
|
||||||
StaticOutput << "global M_ \n";
|
StaticOutput << "global M_ \n";
|
||||||
StaticOutput << "if M_.param_nbr > 0\n params = M_.params;\nend\n";
|
StaticOutput << "if M_.param_nbr > 0\n params = M_.params;\nend\n";
|
||||||
|
@ -1785,8 +1786,8 @@ ModelTree::checkPass() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
void
|
||||||
ModelTree::Evaluate_Jacobian()
|
ModelTree::evaluateJacobian(const eval_context_type &eval_context)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
bool *IM;
|
bool *IM;
|
||||||
|
@ -1797,9 +1798,7 @@ ModelTree::Evaluate_Jacobian()
|
||||||
if (variable_table.getType(it->first.second) == eEndogenous)
|
if (variable_table.getType(it->first.second) == eEndogenous)
|
||||||
{
|
{
|
||||||
NodeID Id = it->second;
|
NodeID Id = it->second;
|
||||||
Id->Evaluate();
|
double val = Id->eval(eval_context);
|
||||||
interprete_.u1 = interprete_.Stack.top();
|
|
||||||
interprete_.Stack.pop();
|
|
||||||
int eq=it->first.first;
|
int eq=it->first.first;
|
||||||
int var=variable_table.getSymbolID(it->first.second);
|
int var=variable_table.getSymbolID(it->first.second);
|
||||||
int k1=variable_table.getLag(it->first.second);
|
int k1=variable_table.getLag(it->first.second);
|
||||||
|
@ -1808,7 +1807,7 @@ ModelTree::Evaluate_Jacobian()
|
||||||
IM=block_triangular.bGet_IM(k1);
|
IM=block_triangular.bGet_IM(k1);
|
||||||
a_variable_lag=k1;
|
a_variable_lag=k1;
|
||||||
}
|
}
|
||||||
if (IM[eq*symbol_table.endo_nbr+var] && (fabs(interprete_.u1)<interprete_.cutoff))
|
if (IM[eq*symbol_table.endo_nbr+var] && (fabs(val) < cutoff))
|
||||||
{
|
{
|
||||||
//cout << "the coefficient related to variable " << var << " with lag " << k1 << " in equation " << eq << " is equal to " << interprete_.u1 << " and is set to 0 in the incidence matrix\n";
|
//cout << "the coefficient related to variable " << var << " with lag " << k1 << " in equation " << eq << " is equal to " << interprete_.u1 << " and is set to 0 in the incidence matrix\n";
|
||||||
block_triangular.unfill_IM(eq, var, k1);
|
block_triangular.unfill_IM(eq, var, k1);
|
||||||
|
@ -1817,10 +1816,10 @@ ModelTree::Evaluate_Jacobian()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i>0)
|
if (i>0)
|
||||||
cout << i << " elements in the incidence matrices are below the cutoff (" << interprete_.cutoff << ") and are discarded\n";
|
cout << i << " elements in the incidence matrices are below the cutoff (" << cutoff << ") and are discarded\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
void
|
||||||
ModelTree::BlockLinear(Model_Block *ModelBlock)
|
ModelTree::BlockLinear(Model_Block *ModelBlock)
|
||||||
{
|
{
|
||||||
int i,j,l,m;
|
int i,j,l,m;
|
||||||
|
@ -1881,7 +1880,7 @@ ModelTree::BlockLinear(Model_Block *ModelBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModelTree::computingPass()
|
ModelTree::computingPass(const eval_context_type &eval_context)
|
||||||
{
|
{
|
||||||
cout << equations.size() << " equation(s) found" << endl;
|
cout << equations.size() << " equation(s) found" << endl;
|
||||||
|
|
||||||
|
@ -1906,8 +1905,7 @@ ModelTree::computingPass()
|
||||||
int HSize;
|
int HSize;
|
||||||
int *Table=variable_table.GetVariableTable(&Size,&HSize);
|
int *Table=variable_table.GetVariableTable(&Size,&HSize);
|
||||||
|
|
||||||
interprete_.create_id_map(Table,Size,HSize);
|
evaluateJacobian(eval_context);
|
||||||
Evaluate_Jacobian();
|
|
||||||
|
|
||||||
if (block_triangular.bt_verbose)
|
if (block_triangular.bt_verbose)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
|
|
||||||
InitParamStatement::InitParamStatement(const string ¶m_name_arg,
|
InitParamStatement::InitParamStatement(const string ¶m_name_arg,
|
||||||
const string ¶m_value_arg,
|
const NodeID param_value_arg,
|
||||||
const SymbolTable &symbol_table_arg) :
|
const SymbolTable &symbol_table_arg) :
|
||||||
param_name(param_name_arg),
|
param_name(param_name_arg),
|
||||||
param_value(param_value_arg),
|
param_value(param_value_arg),
|
||||||
|
@ -14,7 +14,9 @@ void
|
||||||
InitParamStatement::writeOutput(ostream &output, const string &basename) const
|
InitParamStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
{
|
{
|
||||||
int id = symbol_table.getID(param_name) + 1;
|
int id = symbol_table.getID(param_name) + 1;
|
||||||
output << "M_.params( " << id << " ) = " << param_value << ";\n";
|
output << "M_.params( " << id << " ) = ";
|
||||||
|
param_value->writeOutput(output);
|
||||||
|
output << ";" << endl;
|
||||||
output << param_name << " = M_.params( " << id << " );\n";
|
output << param_name << " = M_.params( " << id << " );\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,17 +34,21 @@ InitOrEndValStatement::writeInitValues(ostream &output) const
|
||||||
it != init_values.end(); it++)
|
it != init_values.end(); it++)
|
||||||
{
|
{
|
||||||
const string &name = it->first;
|
const string &name = it->first;
|
||||||
const string &expression = it->second;
|
const NodeID expression = it->second;
|
||||||
|
|
||||||
Type type = symbol_table.getType(name);
|
Type type = symbol_table.getType(name);
|
||||||
int id = symbol_table.getID(name) + 1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
|
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
output << "oo_.steady_state( " << id << " ) = " << expression << ";\n";
|
output << "oo_.steady_state";
|
||||||
else if (type == eExogenous)
|
else if (type == eExogenous)
|
||||||
output << "oo_.exo_steady_state( " << id << " ) = " << expression << ";\n";
|
output << "oo_.exo_steady_state";
|
||||||
else if (type == eExogenousDet)
|
else if (type == eExogenousDet)
|
||||||
output << "oo_.exo_det_steady_state( " << id << " ) = " << expression << ";\n";
|
output << "oo_.exo_det_steady_state";
|
||||||
|
|
||||||
|
output << "( " << id << " ) = ";
|
||||||
|
expression->writeOutput(output);
|
||||||
|
output << ";" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,16 +117,19 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
{
|
{
|
||||||
const string &name = it->first.first;
|
const string &name = it->first.first;
|
||||||
const int &lag = it->first.second;
|
const int &lag = it->first.second;
|
||||||
const string &expression = it->second;
|
const NodeID expression = it->second;
|
||||||
|
|
||||||
Type type = symbol_table.getType(name);
|
Type type = symbol_table.getType(name);
|
||||||
int id = symbol_table.getID(name) + 1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
|
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
output << "oo_.endo_simul( " << id << ", M_.maximum_lag + " << lag + 1 << ") = " << expression << ";\n";
|
output << "oo_.endo_simul( " << id << ", M_.maximum_lag + " << lag + 1 << ") = ";
|
||||||
else if (type == eExogenous)
|
else if (type == eExogenous)
|
||||||
output << "oo_.exo_simul( M_.maximum_lag + " << lag + 1 << ", " << id << " ) = " << expression << ";\n";
|
output << "oo_.exo_simul( M_.maximum_lag + " << lag + 1 << ", " << id << " ) = ";
|
||||||
else if (type != eExogenousDet)
|
else if (type != eExogenousDet)
|
||||||
output << "oo_.exo_det_simul( M_.maximum_lag + " << lag + 1 << ", " << id << " ) = " << expression << ";\n";
|
output << "oo_.exo_det_simul( M_.maximum_lag + " << lag + 1 << ", " << id << " ) = ";
|
||||||
|
|
||||||
|
expression->writeOutput(output);
|
||||||
|
output << ";" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,17 @@ ParsingDriver::check_symbol_existence(const string &name)
|
||||||
error("Unknown symbol: " + name);
|
error("Unknown symbol: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
void
|
||||||
ParsingDriver::get_expression(ExpObj *exp)
|
ParsingDriver::set_current_data_tree(DataTree *data_tree_arg)
|
||||||
{
|
{
|
||||||
// Here we don't call "delete exp", since this will be done by the calling function
|
data_tree = data_tree_arg;
|
||||||
if (exp->second == eTempResult)
|
model_tree = dynamic_cast<ModelTree *>(data_tree_arg);
|
||||||
{
|
}
|
||||||
expression.set();
|
|
||||||
string sexp = expression.get();
|
void
|
||||||
expression.clear();
|
ParsingDriver::reset_data_tree()
|
||||||
return sexp;
|
{
|
||||||
}
|
set_current_data_tree(&mod_file->expressions_tree);
|
||||||
else
|
|
||||||
return expression.getArgument(exp->second, exp->first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModFile *
|
ModFile *
|
||||||
|
@ -44,9 +42,10 @@ ParsingDriver::parse(const string &f)
|
||||||
|
|
||||||
mod_file->symbol_table.error = error;
|
mod_file->symbol_table.error = error;
|
||||||
|
|
||||||
expression.setNumericalConstants(&mod_file->num_constants);
|
|
||||||
tmp_symbol_table = new TmpSymbolTable(mod_file->symbol_table);
|
tmp_symbol_table = new TmpSymbolTable(mod_file->symbol_table);
|
||||||
|
|
||||||
|
reset_data_tree();
|
||||||
|
|
||||||
file = f;
|
file = f;
|
||||||
scan_begin();
|
scan_begin();
|
||||||
yy::parser parser(*this);
|
yy::parser parser(*this);
|
||||||
|
@ -106,22 +105,10 @@ ParsingDriver::declare_parameter(string *name, string *tex_name)
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpObj *
|
|
||||||
ParsingDriver::add_expression_constant(string *constant)
|
|
||||||
{
|
|
||||||
int id = mod_file->num_constants.AddConstant(*constant);
|
|
||||||
|
|
||||||
if(mod_file->model_tree.interprete_.eval)
|
|
||||||
mod_file->model_tree.interprete_.Stack.push(mod_file->model_tree.interprete_.S_to_Val(constant));
|
|
||||||
|
|
||||||
delete constant;
|
|
||||||
return new ExpObj(id, eNumericalConstant);
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_constant(string *constant)
|
ParsingDriver::add_constant(string *constant)
|
||||||
{
|
{
|
||||||
NodeID id = model_tree->AddNumConstant(*constant);
|
NodeID id = data_tree->AddNumConstant(*constant);
|
||||||
delete constant;
|
delete constant;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -133,10 +120,10 @@ ParsingDriver::add_model_variable(string *name)
|
||||||
NodeID id = model_tree->AddVariable(*name);
|
NodeID id = model_tree->AddVariable(*name);
|
||||||
|
|
||||||
Type type = mod_file->symbol_table.getType(*name);
|
Type type = mod_file->symbol_table.getType(*name);
|
||||||
if ((type == eEndogenous) && (mod_file->model_tree.mode == eSparseDLLMode))
|
if ((type == eEndogenous) && (model_tree->mode == eSparseDLLMode))
|
||||||
{
|
{
|
||||||
int ID = mod_file->symbol_table.getID(*name);
|
int ID = mod_file->symbol_table.getID(*name);
|
||||||
mod_file->model_tree.block_triangular.fill_IM(model_tree->equation_number(), ID, 0);
|
model_tree->block_triangular.fill_IM(model_tree->equation_number(), ID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
|
@ -158,113 +145,22 @@ ParsingDriver::add_model_variable(string *name, string *olag)
|
||||||
}
|
}
|
||||||
NodeID id = model_tree->AddVariable(*name, lag);
|
NodeID id = model_tree->AddVariable(*name, lag);
|
||||||
|
|
||||||
if ((type == eEndogenous) && (mod_file->model_tree.mode == eSparseDLLMode))
|
if ((type == eEndogenous) && (model_tree->mode == eSparseDLLMode))
|
||||||
mod_file->model_tree.block_triangular.fill_IM(model_tree->equation_number(), mod_file->symbol_table.getID(*name), lag);
|
model_tree->block_triangular.fill_IM(model_tree->equation_number(), mod_file->symbol_table.getID(*name), lag);
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
delete olag;
|
delete olag;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpObj *
|
NodeID
|
||||||
ParsingDriver::add_expression_variable(string *name)
|
ParsingDriver::add_expression_variable(string *name)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
int id = mod_file->symbol_table.getID(*name);
|
NodeID id = data_tree->AddVariable(*name);
|
||||||
Type type = mod_file->symbol_table.getType(*name);
|
|
||||||
|
|
||||||
if(mod_file->model_tree.interprete_.eval)
|
|
||||||
mod_file->model_tree.interprete_.Stack.push(mod_file->model_tree.interprete_.get_value(name,0));
|
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
return new ExpObj(id, type);
|
return id;
|
||||||
}
|
|
||||||
|
|
||||||
ExpObj *
|
|
||||||
ParsingDriver::add_expression_token(ExpObj *arg1, ExpObj *arg2, int op)
|
|
||||||
{
|
|
||||||
int id = expression.AddToken(arg1->first, arg1->second,
|
|
||||||
arg2->first, arg2->second,
|
|
||||||
op);
|
|
||||||
|
|
||||||
if (mod_file->model_tree.interprete_.eval)
|
|
||||||
{
|
|
||||||
mod_file->model_tree.interprete_.u2 = mod_file->model_tree.interprete_.Stack.top();
|
|
||||||
mod_file->model_tree.interprete_.Stack.pop();
|
|
||||||
mod_file->model_tree.interprete_.u1 = mod_file->model_tree.interprete_.Stack.top();
|
|
||||||
mod_file->model_tree.interprete_.Stack.pop();
|
|
||||||
if (op == token::PLUS)
|
|
||||||
mod_file->model_tree.interprete_.u1+=mod_file->model_tree.interprete_.u2;
|
|
||||||
else if (op == token::MINUS)
|
|
||||||
mod_file->model_tree.interprete_.u1-=mod_file->model_tree.interprete_.u2;
|
|
||||||
else if (op == token::DIVIDE)
|
|
||||||
mod_file->model_tree.interprete_.u1/=mod_file->model_tree.interprete_.u2;
|
|
||||||
else if (op == token::TIMES)
|
|
||||||
mod_file->model_tree.interprete_.u1*=mod_file->model_tree.interprete_.u2;
|
|
||||||
else if (op == token::POWER)
|
|
||||||
mod_file->model_tree.interprete_.u1=pow(mod_file->model_tree.interprete_.u1,mod_file->model_tree.interprete_.u2);
|
|
||||||
mod_file->model_tree.interprete_.Stack.push(mod_file->model_tree.interprete_.u1);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete arg1;
|
|
||||||
delete arg2;
|
|
||||||
return new ExpObj(id, eTempResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExpObj *
|
|
||||||
ParsingDriver::add_expression_token(ExpObj *arg1, int op)
|
|
||||||
{
|
|
||||||
int id = expression.AddToken(arg1->first, arg1->second, op);
|
|
||||||
|
|
||||||
if (mod_file->model_tree.interprete_.eval)
|
|
||||||
{
|
|
||||||
mod_file->model_tree.interprete_.u2 = mod_file->model_tree.interprete_.Stack.top();
|
|
||||||
mod_file->model_tree.interprete_.Stack.pop();
|
|
||||||
if (op == token::UMINUS)
|
|
||||||
mod_file->model_tree.interprete_.u1=-mod_file->model_tree.interprete_.u2;
|
|
||||||
else if (op == token::EXP)
|
|
||||||
mod_file->model_tree.interprete_.u1=exp(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::LOG)
|
|
||||||
mod_file->model_tree.interprete_.u1=log(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::LOG10)
|
|
||||||
mod_file->model_tree.interprete_.u1=log10(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::SIN)
|
|
||||||
mod_file->model_tree.interprete_.u1=sin(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::COS)
|
|
||||||
mod_file->model_tree.interprete_.u1=cos(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::TAN)
|
|
||||||
mod_file->model_tree.interprete_.u1=tan(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::ASIN)
|
|
||||||
mod_file->model_tree.interprete_.u1=asin(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::ACOS)
|
|
||||||
mod_file->model_tree.interprete_.u1=acos(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::ATAN)
|
|
||||||
mod_file->model_tree.interprete_.u1=atan(mod_file->model_tree.interprete_.u2);
|
|
||||||
else if (op == token::SQRT)
|
|
||||||
mod_file->model_tree.interprete_.u1=sqrt(mod_file->model_tree.interprete_.u2);
|
|
||||||
mod_file->model_tree.interprete_.Stack.push(mod_file->model_tree.interprete_.u1);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete arg1;
|
|
||||||
return new ExpObj(id, eTempResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExpObj *
|
|
||||||
ParsingDriver::add_expression_token(ExpObj *arg1, string *op_name)
|
|
||||||
{
|
|
||||||
int id = expression.AddToken(arg1->first, arg1->second, *op_name);
|
|
||||||
|
|
||||||
if (mod_file->model_tree.interprete_.eval)
|
|
||||||
{
|
|
||||||
mod_file->model_tree.interprete_.u2 = mod_file->model_tree.interprete_.Stack.top();
|
|
||||||
mod_file->model_tree.interprete_.Stack.pop();
|
|
||||||
mod_file->model_tree.interprete_.Stack.push(mod_file->model_tree.interprete_.get_value(op_name,mod_file->model_tree.interprete_.u2));
|
|
||||||
mod_file->model_tree.interprete_.Stack.push(mod_file->model_tree.interprete_.u1);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete arg1;
|
|
||||||
delete op_name;
|
|
||||||
return new ExpObj(id, eTempResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -302,24 +198,30 @@ ParsingDriver::dsample(string *arg1, string *arg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::init_param(string *name, ExpObj *rhs)
|
ParsingDriver::init_param(string *name, NodeID rhs)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
if (mod_file->symbol_table.getType(*name) != eParameter)
|
if (mod_file->symbol_table.getType(*name) != eParameter)
|
||||||
error(*name + " is not a parameter");
|
error(*name + " is not a parameter");
|
||||||
|
|
||||||
mod_file->addStatement(new InitParamStatement(*name, get_expression(rhs), mod_file->symbol_table));
|
mod_file->addStatement(new InitParamStatement(*name, rhs, mod_file->symbol_table));
|
||||||
|
|
||||||
mod_file->model_tree.interprete_.u2 = mod_file->model_tree.interprete_.Stack.top();
|
// Update global eval context
|
||||||
mod_file->model_tree.interprete_.Stack.pop();
|
try
|
||||||
mod_file->model_tree.interprete_.put_value(name,mod_file->symbol_table.getID(*name), eParameter, mod_file->model_tree.interprete_.u2);
|
{
|
||||||
|
double val = rhs->eval(mod_file->global_eval_context);
|
||||||
|
int symb_id = mod_file->symbol_table.getID(*name);
|
||||||
|
mod_file->global_eval_context[make_pair(symb_id, eParameter)] = val;
|
||||||
|
}
|
||||||
|
catch(ExprNode::EvalException &e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
delete rhs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::init_val(string *name, ExpObj *rhs)
|
ParsingDriver::init_val(string *name, NodeID rhs)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
Type type = mod_file->symbol_table.getType(*name);
|
Type type = mod_file->symbol_table.getType(*name);
|
||||||
|
@ -329,17 +231,20 @@ ParsingDriver::init_val(string *name, ExpObj *rhs)
|
||||||
&& type != eExogenousDet)
|
&& type != eExogenousDet)
|
||||||
error("initval/endval: " + *name + " should be an endogenous or exogenous variable");
|
error("initval/endval: " + *name + " should be an endogenous or exogenous variable");
|
||||||
|
|
||||||
init_values.push_back(make_pair(*name, get_expression(rhs)));
|
init_values.push_back(make_pair(*name, rhs));
|
||||||
|
|
||||||
if(mod_file->model_tree.interprete_.eval)
|
// Update global evaluation context
|
||||||
|
try
|
||||||
|
{
|
||||||
|
double val = rhs->eval(mod_file->global_eval_context);
|
||||||
|
int symb_id = mod_file->symbol_table.getID(*name);
|
||||||
|
mod_file->global_eval_context[make_pair(symb_id, type)] = val;
|
||||||
|
}
|
||||||
|
catch(ExprNode::EvalException &e)
|
||||||
{
|
{
|
||||||
mod_file->model_tree.interprete_.u2 = mod_file->model_tree.interprete_.Stack.top();
|
|
||||||
mod_file->model_tree.interprete_.Stack.pop();
|
|
||||||
mod_file->model_tree.interprete_.put_value(name, mod_file->symbol_table.getID(*name), type, mod_file->model_tree.interprete_.u2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
delete rhs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -351,7 +256,7 @@ ParsingDriver::init_val_filename(string *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::hist_val(string *name, string *lag, ExpObj *rhs)
|
ParsingDriver::hist_val(string *name, string *lag, NodeID rhs)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
Type type = mod_file->symbol_table.getType(*name);
|
Type type = mod_file->symbol_table.getType(*name);
|
||||||
|
@ -367,33 +272,23 @@ ParsingDriver::hist_val(string *name, string *lag, ExpObj *rhs)
|
||||||
if (hist_values.find(key) != hist_values.end())
|
if (hist_values.find(key) != hist_values.end())
|
||||||
error("hist_val: (" + *name + ", " + *lag + ") declared twice");
|
error("hist_val: (" + *name + ", " + *lag + ") declared twice");
|
||||||
|
|
||||||
hist_values[key] = get_expression(rhs);
|
hist_values[key] = rhs;
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
delete lag;
|
delete lag;
|
||||||
delete rhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ParsingDriver::initialize_model(void)
|
|
||||||
{
|
|
||||||
//Initialize the incidence matrix
|
|
||||||
//cout << "mod_file->symbol_table.endo_nbr=" << mod_file->symbol_table.endo_nbr << "\n";
|
|
||||||
mod_file->model_tree.block_triangular.init_incidence_matrix(mod_file->symbol_table.endo_nbr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::use_dll()
|
ParsingDriver::use_dll()
|
||||||
{
|
{
|
||||||
// Seetting variable momber offset to use C outputs
|
model_tree->mode = eDLLMode;
|
||||||
mod_file->model_tree.mode = eDLLMode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::sparse_dll()
|
ParsingDriver::sparse_dll()
|
||||||
{
|
{
|
||||||
// Seetting variable momber offset to use C outputs
|
model_tree->mode = eSparseDLLMode;
|
||||||
mod_file->model_tree.mode = eSparseDLLMode;
|
model_tree->block_triangular.init_incidence_matrix(mod_file->symbol_table.endo_nbr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -420,9 +315,7 @@ ParsingDriver::end_histval()
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_model()
|
ParsingDriver::begin_model()
|
||||||
{
|
{
|
||||||
model_tree = &mod_file->model_tree;
|
set_current_data_tree(&mod_file->model_tree);
|
||||||
if (mod_file->model_tree.mode == eSparseDLLMode)
|
|
||||||
initialize_model();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -482,35 +375,33 @@ ParsingDriver::add_det_shock(string *var)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_stderr_shock(string *var, ExpObj *value)
|
ParsingDriver::add_stderr_shock(string *var, NodeID value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var);
|
check_symbol_existence(*var);
|
||||||
if (var_shocks.find(*var) != var_shocks.end()
|
if (var_shocks.find(*var) != var_shocks.end()
|
||||||
|| std_shocks.find(*var) != std_shocks.end())
|
|| std_shocks.find(*var) != std_shocks.end())
|
||||||
error("shocks: variance or stderr of shock on " + *var + " declared twice");
|
error("shocks: variance or stderr of shock on " + *var + " declared twice");
|
||||||
|
|
||||||
std_shocks[*var] = get_expression(value);
|
std_shocks[*var] = value;
|
||||||
|
|
||||||
delete var;
|
delete var;
|
||||||
delete value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_var_shock(string *var, ExpObj *value)
|
ParsingDriver::add_var_shock(string *var, NodeID value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var);
|
check_symbol_existence(*var);
|
||||||
if (var_shocks.find(*var) != var_shocks.end()
|
if (var_shocks.find(*var) != var_shocks.end()
|
||||||
|| std_shocks.find(*var) != std_shocks.end())
|
|| std_shocks.find(*var) != std_shocks.end())
|
||||||
error("shocks: variance or stderr of shock on " + *var + " declared twice");
|
error("shocks: variance or stderr of shock on " + *var + " declared twice");
|
||||||
|
|
||||||
var_shocks[*var] = get_expression(value);
|
var_shocks[*var] = value;
|
||||||
|
|
||||||
delete var;
|
delete var;
|
||||||
delete value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_covar_shock(string *var1, string *var2, ExpObj *value)
|
ParsingDriver::add_covar_shock(string *var1, string *var2, NodeID value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var1);
|
check_symbol_existence(*var1);
|
||||||
check_symbol_existence(*var2);
|
check_symbol_existence(*var2);
|
||||||
|
@ -524,15 +415,14 @@ ParsingDriver::add_covar_shock(string *var1, string *var2, ExpObj *value)
|
||||||
error("shocks: covariance or correlation shock on variable pair (" + *var1 + ", "
|
error("shocks: covariance or correlation shock on variable pair (" + *var1 + ", "
|
||||||
+ *var2 + ") declared twice");
|
+ *var2 + ") declared twice");
|
||||||
|
|
||||||
covar_shocks[key] = get_expression(value);
|
covar_shocks[key] = value;
|
||||||
|
|
||||||
delete var1;
|
delete var1;
|
||||||
delete var2;
|
delete var2;
|
||||||
delete value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_correl_shock(string *var1, string *var2, ExpObj *value)
|
ParsingDriver::add_correl_shock(string *var1, string *var2, NodeID value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var1);
|
check_symbol_existence(*var1);
|
||||||
check_symbol_existence(*var2);
|
check_symbol_existence(*var2);
|
||||||
|
@ -546,11 +436,10 @@ ParsingDriver::add_correl_shock(string *var1, string *var2, ExpObj *value)
|
||||||
error("shocks: covariance or correlation shock on variable pair (" + *var1 + ", "
|
error("shocks: covariance or correlation shock on variable pair (" + *var1 + ", "
|
||||||
+ *var2 + ") declared twice");
|
+ *var2 + ") declared twice");
|
||||||
|
|
||||||
corr_shocks[key] = get_expression(value);
|
corr_shocks[key] = value;
|
||||||
|
|
||||||
delete var1;
|
delete var1;
|
||||||
delete var2;
|
delete var2;
|
||||||
delete value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -572,17 +461,21 @@ ParsingDriver::add_period(string *p1)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_value(string *value)
|
ParsingDriver::add_value_const(string *value)
|
||||||
{
|
{
|
||||||
det_shocks_values.push_back(*value);
|
add_value(add_constant(value));
|
||||||
delete value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_value(ExpObj *value)
|
ParsingDriver::add_value_var(string *name)
|
||||||
{
|
{
|
||||||
det_shocks_values.push_back(get_expression(value));
|
add_value(add_expression_variable(name));
|
||||||
delete value;
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParsingDriver::add_value(NodeID value)
|
||||||
|
{
|
||||||
|
det_shocks_values.push_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -607,17 +500,15 @@ ParsingDriver::end_of_row()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_to_row(string *s)
|
ParsingDriver::add_to_row_const(string *s)
|
||||||
{
|
{
|
||||||
sigmae_row.push_back(*s);
|
sigmae_row.push_back(add_constant(s));
|
||||||
delete s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_to_row(ExpObj *v)
|
ParsingDriver::add_to_row(NodeID v)
|
||||||
{
|
{
|
||||||
sigmae_row.push_back(get_expression(v));
|
sigmae_row.push_back(v);
|
||||||
delete v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -656,7 +547,7 @@ ParsingDriver::option_num(const string &name_option, const string &opt)
|
||||||
if ((name_option == "periods") && (mod_file->model_tree.mode == eSparseDLLMode))
|
if ((name_option == "periods") && (mod_file->model_tree.mode == eSparseDLLMode))
|
||||||
mod_file->model_tree.block_triangular.periods = atoi(opt.c_str());
|
mod_file->model_tree.block_triangular.periods = atoi(opt.c_str());
|
||||||
else if (name_option == "cutoff")
|
else if (name_option == "cutoff")
|
||||||
mod_file->model_tree.interprete_.set_cutoff(atof(opt.c_str()));
|
mod_file->model_tree.cutoff = atof(opt.c_str());
|
||||||
|
|
||||||
options_list.num_options[name_option] = opt;
|
options_list.num_options[name_option] = opt;
|
||||||
}
|
}
|
||||||
|
@ -718,7 +609,7 @@ void ParsingDriver::stoch_simul()
|
||||||
|
|
||||||
void ParsingDriver::simulate()
|
void ParsingDriver::simulate()
|
||||||
{
|
{
|
||||||
if(mod_file->model_tree.mode == eSparseDLLMode)
|
if (mod_file->model_tree.mode == eSparseDLLMode)
|
||||||
simul_sparse();
|
simul_sparse();
|
||||||
else
|
else
|
||||||
simul();
|
simul();
|
||||||
|
@ -727,20 +618,14 @@ void ParsingDriver::simulate()
|
||||||
void
|
void
|
||||||
ParsingDriver::simul_sparse()
|
ParsingDriver::simul_sparse()
|
||||||
{
|
{
|
||||||
SimulSparseStatement *st=new SimulSparseStatement(options_list);
|
mod_file->addStatement(new SimulSparseStatement(options_list, mod_file->model_tree.compiler));
|
||||||
st->filename=file;
|
|
||||||
string tmp=st->filename.substr(st->filename.length()-4);
|
|
||||||
if(tmp==".mod"||tmp==".dyn")
|
|
||||||
st->filename.erase(st->filename.length()-4);
|
|
||||||
st->compiler=mod_file->model_tree.compiler;
|
|
||||||
mod_file->addStatement(st);
|
|
||||||
options_list.clear();
|
options_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::init_compiler(int compiler_type)
|
ParsingDriver::init_compiler(int compiler_type)
|
||||||
{
|
{
|
||||||
mod_file->model_tree.compiler=compiler_type;
|
mod_file->model_tree.compiler = compiler_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -863,31 +748,29 @@ ParsingDriver::set_trends()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_trend_element(string *arg1, ExpObj *arg2)
|
ParsingDriver::set_trend_element(string *arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*arg1);
|
check_symbol_existence(*arg1);
|
||||||
if (trend_elements.find(*arg1) != trend_elements.end())
|
if (trend_elements.find(*arg1) != trend_elements.end())
|
||||||
error("observation_trends: " + *arg1 + " declared twice");
|
error("observation_trends: " + *arg1 + " declared twice");
|
||||||
trend_elements[*arg1] = get_expression(arg2);
|
trend_elements[*arg1] = arg2;
|
||||||
delete arg1;
|
delete arg1;
|
||||||
delete arg2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_optim_weights(string *name, ExpObj *value)
|
ParsingDriver::set_optim_weights(string *name, NodeID value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
if (mod_file->symbol_table.getType(*name) != eEndogenous)
|
if (mod_file->symbol_table.getType(*name) != eEndogenous)
|
||||||
error("optim_weights: " + *name + " isn't an endogenous variable");
|
error("optim_weights: " + *name + " isn't an endogenous variable");
|
||||||
if (var_weights.find(*name) != var_weights.end())
|
if (var_weights.find(*name) != var_weights.end())
|
||||||
error("optim_weights: " + *name + " declared twice");
|
error("optim_weights: " + *name + " declared twice");
|
||||||
var_weights[*name] = get_expression(value);
|
var_weights[*name] = value;
|
||||||
delete name;
|
delete name;
|
||||||
delete value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_optim_weights(string *name1, string *name2, ExpObj *value)
|
ParsingDriver::set_optim_weights(string *name1, string *name2, NodeID value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name1);
|
check_symbol_existence(*name1);
|
||||||
if (mod_file->symbol_table.getType(*name1) != eEndogenous)
|
if (mod_file->symbol_table.getType(*name1) != eEndogenous)
|
||||||
|
@ -903,10 +786,9 @@ ParsingDriver::set_optim_weights(string *name1, string *name2, ExpObj *value)
|
||||||
error("optim_weights: pair of variables (" + *name1 + ", " + *name2
|
error("optim_weights: pair of variables (" + *name1 + ", " + *name2
|
||||||
+ ") declared twice");
|
+ ") declared twice");
|
||||||
|
|
||||||
covar_weights[covar_key] = get_expression(value);
|
covar_weights[covar_key] = value;
|
||||||
delete name1;
|
delete name1;
|
||||||
delete name2;
|
delete name2;
|
||||||
delete value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -948,7 +830,7 @@ ParsingDriver::run_olr()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_calib_var(string *name, string *weight, ExpObj *expression)
|
ParsingDriver::set_calib_var(string *name, string *weight, NodeID expression)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
if (mod_file->symbol_table.getType(*name) != eEndogenous
|
if (mod_file->symbol_table.getType(*name) != eEndogenous
|
||||||
|
@ -958,16 +840,15 @@ ParsingDriver::set_calib_var(string *name, string *weight, ExpObj *expression)
|
||||||
if (calib_var.find(*name) != calib_var.end())
|
if (calib_var.find(*name) != calib_var.end())
|
||||||
error("calib_var: " + *name + " declared twice");
|
error("calib_var: " + *name + " declared twice");
|
||||||
|
|
||||||
calib_var[*name] = make_pair(*weight, get_expression(expression));
|
calib_var[*name] = make_pair(*weight, expression);
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
delete weight;
|
delete weight;
|
||||||
delete expression;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_calib_covar(string *name1, string *name2,
|
ParsingDriver::set_calib_covar(string *name1, string *name2,
|
||||||
string *weight, ExpObj *expression)
|
string *weight, NodeID expression)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name1);
|
check_symbol_existence(*name1);
|
||||||
check_symbol_existence(*name2);
|
check_symbol_existence(*name2);
|
||||||
|
@ -983,17 +864,16 @@ ParsingDriver::set_calib_covar(string *name1, string *name2,
|
||||||
error("calib_var: pair of variables (" + *name1 + ", " + *name2
|
error("calib_var: pair of variables (" + *name1 + ", " + *name2
|
||||||
+ ") declared twice");
|
+ ") declared twice");
|
||||||
|
|
||||||
calib_covar[covar_key] = make_pair(*weight, get_expression(expression));
|
calib_covar[covar_key] = make_pair(*weight, expression);
|
||||||
|
|
||||||
delete name1;
|
delete name1;
|
||||||
delete name2;
|
delete name2;
|
||||||
delete weight;
|
delete weight;
|
||||||
delete expression;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_calib_ac(string *name, string *ar,
|
ParsingDriver::set_calib_ac(string *name, string *ar,
|
||||||
string *weight, ExpObj *expression)
|
string *weight, NodeID expression)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
if (mod_file->symbol_table.getType(*name) != eEndogenous)
|
if (mod_file->symbol_table.getType(*name) != eEndogenous)
|
||||||
|
@ -1005,12 +885,11 @@ ParsingDriver::set_calib_ac(string *name, string *ar,
|
||||||
if (calib_ac.find(ac_key) != calib_ac.end())
|
if (calib_ac.find(ac_key) != calib_ac.end())
|
||||||
error("calib_var: autocorr " + *name + "(" + *ar + ") declared twice");
|
error("calib_var: autocorr " + *name + "(" + *ar + ") declared twice");
|
||||||
|
|
||||||
calib_ac[ac_key] = make_pair(*weight, get_expression(expression));
|
calib_ac[ac_key] = make_pair(*weight, expression);
|
||||||
|
|
||||||
delete name;
|
delete name;
|
||||||
delete ar;
|
delete ar;
|
||||||
delete weight;
|
delete weight;
|
||||||
delete expression;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1068,7 +947,7 @@ ParsingDriver::run_model_comparison()
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_planner_objective()
|
ParsingDriver::begin_planner_objective()
|
||||||
{
|
{
|
||||||
model_tree = new ModelTree(mod_file->symbol_table, mod_file->num_constants);
|
set_current_data_tree(new ModelTree(mod_file->symbol_table, mod_file->num_constants));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1079,6 +958,8 @@ ParsingDriver::end_planner_objective(NodeID expr)
|
||||||
model_tree->addEquation(eq);
|
model_tree->addEquation(eq);
|
||||||
|
|
||||||
mod_file->addStatement(new PlannerObjectiveStatement(model_tree));
|
mod_file->addStatement(new PlannerObjectiveStatement(model_tree));
|
||||||
|
|
||||||
|
reset_data_tree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1119,135 +1000,149 @@ ParsingDriver::declare_and_init_local_parameter(string *name, NodeID rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_plus(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_plus(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree->AddPlus(arg1, arg2);
|
return data_tree->AddPlus(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_minus(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_minus(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree->AddMinus(arg1, arg2);
|
return data_tree->AddMinus(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_uminus(NodeID arg1)
|
ParsingDriver::add_uminus(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddUMinus(arg1);
|
return data_tree->AddUMinus(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_times(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_times(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree->AddTimes(arg1, arg2);
|
return data_tree->AddTimes(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_divide(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_divide(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree->AddDivide(arg1, arg2);
|
return data_tree->AddDivide(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_power(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_power(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree->AddPower(arg1, arg2);
|
return data_tree->AddPower(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_exp(NodeID arg1)
|
ParsingDriver::add_exp(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddExp(arg1);
|
return data_tree->AddExp(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_log(NodeID arg1)
|
ParsingDriver::add_log(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddLog(arg1);
|
return data_tree->AddLog(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_log10(NodeID arg1)
|
ParsingDriver::add_log10(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddLog10(arg1);
|
return data_tree->AddLog10(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_cos(NodeID arg1)
|
ParsingDriver::add_cos(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddCos(arg1);
|
return data_tree->AddCos(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_sin(NodeID arg1)
|
ParsingDriver::add_sin(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddSin(arg1);
|
return data_tree->AddSin(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_tan(NodeID arg1)
|
ParsingDriver::add_tan(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddTan(arg1);
|
return data_tree->AddTan(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_acos(NodeID arg1)
|
ParsingDriver::add_acos(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddACos(arg1);
|
return data_tree->AddACos(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_asin(NodeID arg1)
|
ParsingDriver::add_asin(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddASin(arg1);
|
return data_tree->AddASin(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_atan(NodeID arg1)
|
ParsingDriver::add_atan(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddATan(arg1);
|
return data_tree->AddATan(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_cosh(NodeID arg1)
|
ParsingDriver::add_cosh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddCosH(arg1);
|
return data_tree->AddCosH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_sinh(NodeID arg1)
|
ParsingDriver::add_sinh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddSinH(arg1);
|
return data_tree->AddSinH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_tanh(NodeID arg1)
|
ParsingDriver::add_tanh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddTanH(arg1);
|
return data_tree->AddTanH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_acosh(NodeID arg1)
|
ParsingDriver::add_acosh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddACosH(arg1);
|
return data_tree->AddACosH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_asinh(NodeID arg1)
|
ParsingDriver::add_asinh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddASinH(arg1);
|
return data_tree->AddASinH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_atanh(NodeID arg1)
|
ParsingDriver::add_atanh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddATanH(arg1);
|
return data_tree->AddATanH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_sqrt(NodeID arg1)
|
ParsingDriver::add_sqrt(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree->AddSqRt(arg1);
|
return data_tree->AddSqRt(arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParsingDriver::add_unknown_function_arg(NodeID arg)
|
||||||
|
{
|
||||||
|
unknown_function_args.push_back(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeID
|
||||||
|
ParsingDriver::add_unknown_function(string *function_name)
|
||||||
|
{
|
||||||
|
NodeID id = data_tree->AddUnknownFunction(*function_name, unknown_function_args);
|
||||||
|
unknown_function_args.clear();
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -43,15 +43,22 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
|
||||||
{
|
{
|
||||||
const int &period1 = it->second[i].period1;
|
const int &period1 = it->second[i].period1;
|
||||||
const int &period2 = it->second[i].period2;
|
const int &period2 = it->second[i].period2;
|
||||||
const string &value = it->second[i].value;
|
const NodeID value = it->second[i].value;
|
||||||
|
|
||||||
if (period1 == period2)
|
if (period1 == period2)
|
||||||
output << "set_shocks(" << set_shocks_index << "," << period1
|
{
|
||||||
<< ", " << id << ", " << value << ");\n";
|
output << "set_shocks(" << set_shocks_index << "," << period1
|
||||||
|
<< ", " << id << ", ";
|
||||||
|
value->writeOutput(output);
|
||||||
|
output << ");" << endl;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
output << "set_shocks(" << set_shocks_index << "," << period1
|
{
|
||||||
<< ":" << period2 << ", " << id
|
output << "set_shocks(" << set_shocks_index << "," << period1
|
||||||
<< ", " << value << ");\n";
|
<< ":" << period2 << ", " << id << ", ";
|
||||||
|
value->writeOutput(output);
|
||||||
|
output << ");" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (exo_det && (period2 > exo_det_length))
|
if (exo_det && (period2 > exo_det_length))
|
||||||
exo_det_length = period2;
|
exo_det_length = period2;
|
||||||
|
@ -68,15 +75,19 @@ AbstractShocksStatement::writeVarAndStdShocks(ostream &output) const
|
||||||
for(it = var_shocks.begin(); it != var_shocks.end(); it++)
|
for(it = var_shocks.begin(); it != var_shocks.end(); it++)
|
||||||
{
|
{
|
||||||
int id = symbol_table.getID(it->first) + 1;
|
int id = symbol_table.getID(it->first) + 1;
|
||||||
const string &value = it->second;
|
const NodeID value = it->second;
|
||||||
output << "M_.Sigma_e(" << id << ", " << id << ") = " << value << ";\n";
|
output << "M_.Sigma_e(" << id << ", " << id << ") = ";
|
||||||
|
value->writeOutput(output);
|
||||||
|
output << ";" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(it = std_shocks.begin(); it != std_shocks.end(); it++)
|
for(it = std_shocks.begin(); it != std_shocks.end(); it++)
|
||||||
{
|
{
|
||||||
int id = symbol_table.getID(it->first) + 1;
|
int id = symbol_table.getID(it->first) + 1;
|
||||||
const string &value = it->second;
|
const NodeID value = it->second;
|
||||||
output << "M_.Sigma_e(" << id << ", " << id << ") = " << value << "^2;\n";
|
output << "M_.Sigma_e(" << id << ", " << id << ") = (";
|
||||||
|
value->writeOutput(output);
|
||||||
|
output << ")^2;" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,9 +100,10 @@ AbstractShocksStatement::writeCovarAndCorrShocks(ostream &output) const
|
||||||
{
|
{
|
||||||
int id1 = symbol_table.getID(it->first.first) + 1;
|
int id1 = symbol_table.getID(it->first.first) + 1;
|
||||||
int id2 = symbol_table.getID(it->first.second) + 1;
|
int id2 = symbol_table.getID(it->first.second) + 1;
|
||||||
const string &value = it->second;
|
const NodeID value = it->second;
|
||||||
output << "M_.Sigma_e(" << id1 << ", " << id2 << ") = " << value
|
output << "M_.Sigma_e(" << id1 << ", " << id2 << ") = ";
|
||||||
<< "; M_.Sigma_e(" << id2 << ", " << id1 << ") = M_.Sigma_e("
|
value->writeOutput(output);
|
||||||
|
output << "; M_.Sigma_e(" << id2 << ", " << id1 << ") = M_.Sigma_e("
|
||||||
<< id1 << ", " << id2 << ");\n";
|
<< id1 << ", " << id2 << ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +111,10 @@ AbstractShocksStatement::writeCovarAndCorrShocks(ostream &output) const
|
||||||
{
|
{
|
||||||
int id1 = symbol_table.getID(it->first.first) + 1;
|
int id1 = symbol_table.getID(it->first.first) + 1;
|
||||||
int id2 = symbol_table.getID(it->first.second) + 1;
|
int id2 = symbol_table.getID(it->first.second) + 1;
|
||||||
const string &value = it->second;
|
const NodeID value = it->second;
|
||||||
output << "M_.Sigma_e(" << id1 << ", " << id2 << ") = " << value
|
output << "M_.Sigma_e(" << id1 << ", " << id2 << ") = ";
|
||||||
<< "*sqrt(M_.Sigma_e(" << id1 << ", " << id1 << ")*M_.Sigma_e("
|
value->writeOutput(output);
|
||||||
|
output << "*sqrt(M_.Sigma_e(" << id1 << ", " << id1 << ")*M_.Sigma_e("
|
||||||
<< id2 << ", " << id2 << "); M_.Sigma_e(" << id2 << ", "
|
<< id2 << ", " << id2 << "); M_.Sigma_e(" << id2 << ", "
|
||||||
<< id1 << ") = M_.Sigma_e(" << id1 << ", " << id2 << ");\n";
|
<< id1 << ") = M_.Sigma_e(" << id1 << ", " << id2 << ");\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,8 @@ SigmaeStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
ir1 = ir;
|
ir1 = ir;
|
||||||
}
|
}
|
||||||
|
|
||||||
output << matrix[ir1][ic1] << " ";
|
matrix[ir1][ic1]->writeOutput(output);
|
||||||
|
output << " ";
|
||||||
}
|
}
|
||||||
output << ";...\n";
|
output << ";...\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,9 @@ class SimulSparseStatement : public Statement
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const OptionsList options_list;
|
const OptionsList options_list;
|
||||||
|
const int compiler;
|
||||||
public:
|
public:
|
||||||
string filename;
|
SimulSparseStatement(const OptionsList &options_list_arg, int compiler_arg);
|
||||||
int compiler;
|
|
||||||
SimulSparseStatement(const OptionsList &options_list_arg);
|
|
||||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||||
};
|
};
|
||||||
|
@ -167,7 +166,7 @@ public:
|
||||||
class ObservationTrendsStatement : public Statement
|
class ObservationTrendsStatement : public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef map<string, string, less<string> > trend_elements_type;
|
typedef map<string, NodeID> trend_elements_type;
|
||||||
private:
|
private:
|
||||||
const trend_elements_type trend_elements;
|
const trend_elements_type trend_elements;
|
||||||
const SymbolTable &symbol_table;
|
const SymbolTable &symbol_table;
|
||||||
|
@ -332,8 +331,8 @@ public:
|
||||||
class OptimWeightsStatement : public Statement
|
class OptimWeightsStatement : public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef map<string, string, less<string> > var_weights_type;
|
typedef map<string, NodeID> var_weights_type;
|
||||||
typedef map<pair<string, string>, string, less<pair<string, string> > > covar_weights_type;
|
typedef map<pair<string, string>, NodeID> covar_weights_type;
|
||||||
private:
|
private:
|
||||||
const var_weights_type var_weights;
|
const var_weights_type var_weights;
|
||||||
const covar_weights_type covar_weights;
|
const covar_weights_type covar_weights;
|
||||||
|
@ -358,11 +357,11 @@ class CalibVarStatement : public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Maps a variable to a pair (weight, expression)
|
//! Maps a variable to a pair (weight, expression)
|
||||||
typedef map<string, pair<string, string>, less<string> > calib_var_type;
|
typedef map<string, pair<string, NodeID> > calib_var_type;
|
||||||
//! Maps a pair of variables to a pair (weight, expression)
|
//! Maps a pair of variables to a pair (weight, expression)
|
||||||
typedef map<pair<string, string>, pair<string, string>, less<pair<string, string> > > calib_covar_type;
|
typedef map<pair<string, string>, pair<string, NodeID> > calib_covar_type;
|
||||||
//! Maps a pair (variable, autocorr) to a pair (weight, expression)
|
//! Maps a pair (variable, autocorr) to a pair (weight, expression)
|
||||||
typedef map<pair<string, int>, pair<string, string>, less<pair<string, int> > > calib_ac_type;
|
typedef map<pair<string, int>, pair<string, NodeID> > calib_ac_type;
|
||||||
private:
|
private:
|
||||||
const calib_var_type calib_var;
|
const calib_var_type calib_var;
|
||||||
const calib_covar_type calib_covar;
|
const calib_covar_type calib_covar;
|
||||||
|
|
|
@ -12,8 +12,6 @@ using namespace std;
|
||||||
#include "VariableTable.hh"
|
#include "VariableTable.hh"
|
||||||
#include "ExprNode.hh"
|
#include "ExprNode.hh"
|
||||||
|
|
||||||
#include "interprete.hh"
|
|
||||||
|
|
||||||
class DataTree
|
class DataTree
|
||||||
{
|
{
|
||||||
friend class ExprNode;
|
friend class ExprNode;
|
||||||
|
@ -38,7 +36,8 @@ protected:
|
||||||
|
|
||||||
typedef map<int, NodeID> num_const_node_map_type;
|
typedef map<int, NodeID> num_const_node_map_type;
|
||||||
num_const_node_map_type num_const_node_map;
|
num_const_node_map_type num_const_node_map;
|
||||||
typedef map<pair<int, Type>, NodeID> variable_node_map_type;
|
//! Type (symbol_id, type, lag) used as key
|
||||||
|
typedef map<pair<pair<int, Type>, int>, NodeID> variable_node_map_type;
|
||||||
variable_node_map_type variable_node_map;
|
variable_node_map_type variable_node_map;
|
||||||
typedef map<pair<NodeID, int>, NodeID> unary_op_node_map_type;
|
typedef map<pair<NodeID, int>, NodeID> unary_op_node_map_type;
|
||||||
unary_op_node_map_type unary_op_node_map;
|
unary_op_node_map_type unary_op_node_map;
|
||||||
|
@ -53,8 +52,6 @@ public:
|
||||||
//! The variable table
|
//! The variable table
|
||||||
VariableTable variable_table;
|
VariableTable variable_table;
|
||||||
NodeID Zero, One, MinusOne;
|
NodeID Zero, One, MinusOne;
|
||||||
//! Complete set to interpret the model parameters and variables
|
|
||||||
interprete interprete_;
|
|
||||||
|
|
||||||
//! Raised when a local parameter is declared twice
|
//! Raised when a local parameter is declared twice
|
||||||
class LocalParameterException
|
class LocalParameterException
|
||||||
|
@ -113,6 +110,9 @@ public:
|
||||||
//! Adds "arg1=arg2" to model tree
|
//! Adds "arg1=arg2" to model tree
|
||||||
NodeID AddEqual(NodeID iArg1, NodeID iArg2);
|
NodeID AddEqual(NodeID iArg1, NodeID iArg2);
|
||||||
void AddLocalParameter(const string &name, NodeID value) throw (LocalParameterException);
|
void AddLocalParameter(const string &name, NodeID value) throw (LocalParameterException);
|
||||||
|
//! Adds an unknown function node
|
||||||
|
/*! \todo Use a map to share identical nodes */
|
||||||
|
NodeID AddUnknownFunction(const string &function_name, const vector<NodeID> &arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline NodeID
|
inline NodeID
|
||||||
|
|
|
@ -54,15 +54,11 @@ using namespace std;
|
||||||
|
|
||||||
class ParsingDriver;
|
class ParsingDriver;
|
||||||
|
|
||||||
#include "SymbolTableTypes.hh"
|
|
||||||
#include "ExprNode.hh"
|
#include "ExprNode.hh"
|
||||||
|
|
||||||
//! Type for semantic value of non-derivable expressions
|
|
||||||
typedef pair<int, Type> ExpObj;
|
|
||||||
|
|
||||||
|
|
||||||
/* Line 35 of lalr1.cc. */
|
/* Line 35 of lalr1.cc. */
|
||||||
#line 66 "DynareBison.hh"
|
#line 62 "DynareBison.hh"
|
||||||
|
|
||||||
#include "location.hh"
|
#include "location.hh"
|
||||||
|
|
||||||
|
@ -113,14 +109,13 @@ namespace yy
|
||||||
/// Symbol semantic values.
|
/// Symbol semantic values.
|
||||||
#ifndef YYSTYPE
|
#ifndef YYSTYPE
|
||||||
union semantic_type
|
union semantic_type
|
||||||
#line 31 "DynareBison.yy"
|
#line 27 "DynareBison.yy"
|
||||||
{
|
{
|
||||||
string *string_val;
|
string *string_val;
|
||||||
ExpObj *exp_val;
|
NodeID node_val;
|
||||||
NodeID model_val;
|
|
||||||
}
|
}
|
||||||
/* Line 35 of lalr1.cc. */
|
/* Line 35 of lalr1.cc. */
|
||||||
#line 124 "DynareBison.hh"
|
#line 119 "DynareBison.hh"
|
||||||
;
|
;
|
||||||
#else
|
#else
|
||||||
typedef YYSTYPE semantic_type;
|
typedef YYSTYPE semantic_type;
|
||||||
|
|
|
@ -5,6 +5,7 @@ using namespace std;
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "SymbolTableTypes.hh"
|
#include "SymbolTableTypes.hh"
|
||||||
|
|
||||||
|
@ -31,6 +32,11 @@ enum ExprNodeOutputType
|
||||||
oMatlabOutsideModel //!< Matlab code, outside model block (for example in initval)
|
oMatlabOutsideModel //!< Matlab code, outside model block (for example in initval)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Type for evaluation contexts
|
||||||
|
/*! The key is a pair (symbol id, symbol type)
|
||||||
|
Lags are assumed to be null */
|
||||||
|
typedef map<pair<int, Type>, double> eval_context_type;
|
||||||
|
|
||||||
/* Equal to 1 for Matlab langage, or to 0 for C language
|
/* Equal to 1 for Matlab langage, or to 0 for C language
|
||||||
In Matlab, array indexes begin at 1, while they begin at 0 in C */
|
In Matlab, array indexes begin at 1, while they begin at 0 in C */
|
||||||
#define OFFSET(output_type) ((output_type == oMatlabStaticModel) \
|
#define OFFSET(output_type) ((output_type == oMatlabStaticModel) \
|
||||||
|
@ -105,6 +111,9 @@ public:
|
||||||
//! Writes output of node, using a Txxx notation for nodes in temporary_terms
|
//! Writes output of node, using a Txxx notation for nodes in temporary_terms
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const = 0;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const = 0;
|
||||||
|
|
||||||
|
//! Writes output of node (with no temporary terms and with "outside model" output type)
|
||||||
|
void writeOutput(ostream &output);
|
||||||
|
|
||||||
//! Collects the Endogenous in a expression
|
//! Collects the Endogenous in a expression
|
||||||
virtual void collectEndogenous(NodeID &Id) = 0;
|
virtual void collectEndogenous(NodeID &Id) = 0;
|
||||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
|
@ -114,7 +123,12 @@ public:
|
||||||
Model_Block *ModelBlock) const;
|
Model_Block *ModelBlock) const;
|
||||||
int present_endogenous_size() const;
|
int present_endogenous_size() const;
|
||||||
int present_endogenous_find(int var, int lag) const;
|
int present_endogenous_find(int var, int lag) const;
|
||||||
virtual void Evaluate() const = 0;
|
|
||||||
|
class EvalException
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Object used to compare two nodes (using their indexes)
|
//! Object used to compare two nodes (using their indexes)
|
||||||
|
@ -137,23 +151,25 @@ public:
|
||||||
NumConstNode(DataTree &datatree_arg, int id_arg);
|
NumConstNode(DataTree &datatree_arg, int id_arg);
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(NodeID &Id);
|
||||||
virtual void Evaluate() const;
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Symbol or variable node
|
//! Symbol or variable node
|
||||||
class VariableNode : public ExprNode
|
class VariableNode : public ExprNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
//! Id of the symbol/variable
|
//! Id from the symbol table
|
||||||
/*! For an endogenous, exogenous or recursive variable, the id is taken from the variable table (before sorting). For other types of symbols, it's the id from the symbol table. */
|
const int symb_id;
|
||||||
const int id;
|
|
||||||
const Type type;
|
const Type type;
|
||||||
|
const int lag;
|
||||||
|
//! Id from the variable table (-1 if not a endogenous/exogenous/recursive)
|
||||||
|
int var_id;
|
||||||
virtual NodeID computeDerivative(int varID);
|
virtual NodeID computeDerivative(int varID);
|
||||||
public:
|
public:
|
||||||
VariableNode(DataTree &datatree_arg, int id_arg, Type type_arg);
|
VariableNode(DataTree &datatree_arg, int symb_id_arg, Type type_arg, int lag_arg);
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms = temporary_terms_type()) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms = temporary_terms_type()) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(NodeID &Id);
|
||||||
virtual void Evaluate() const;
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum UnaryOpcode
|
enum UnaryOpcode
|
||||||
|
@ -186,7 +202,7 @@ private:
|
||||||
const UnaryOpcode op_code;
|
const UnaryOpcode op_code;
|
||||||
virtual NodeID computeDerivative(int varID);
|
virtual NodeID computeDerivative(int varID);
|
||||||
|
|
||||||
int cost(const temporary_terms_type &temporary_terms, bool is_matlab) const;
|
virtual int cost(const temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||||
public:
|
public:
|
||||||
UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg);
|
UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg);
|
||||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||||
|
@ -197,7 +213,7 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
Model_Block *ModelBlock) const;
|
Model_Block *ModelBlock) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(NodeID &Id);
|
||||||
virtual void Evaluate() const;
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BinaryOpcode
|
enum BinaryOpcode
|
||||||
|
@ -218,7 +234,7 @@ private:
|
||||||
const NodeID arg1, arg2;
|
const NodeID arg1, arg2;
|
||||||
const BinaryOpcode op_code;
|
const BinaryOpcode op_code;
|
||||||
virtual NodeID computeDerivative(int varID);
|
virtual NodeID computeDerivative(int varID);
|
||||||
int cost(const temporary_terms_type &temporary_terms, bool is_matlab) const;
|
virtual int cost(const temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||||
public:
|
public:
|
||||||
BinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
BinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
||||||
BinaryOpcode op_code_arg, const NodeID arg2_arg);
|
BinaryOpcode op_code_arg, const NodeID arg2_arg);
|
||||||
|
@ -231,7 +247,27 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
Model_Block *ModelBlock) const;
|
Model_Block *ModelBlock) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(NodeID &Id);
|
||||||
virtual void Evaluate() const;
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
|
};
|
||||||
|
|
||||||
|
class UnknownFunctionNode : public ExprNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const string function_name;
|
||||||
|
const vector<NodeID> arguments;
|
||||||
|
virtual NodeID computeDerivative(int varID);
|
||||||
|
public:
|
||||||
|
UnknownFunctionNode(DataTree &datatree_arg, const string &function_name_arg,
|
||||||
|
const vector<NodeID> &arguments_arg);
|
||||||
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||||
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||||
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
|
temporary_terms_type &temporary_terms,
|
||||||
|
map<NodeID, int> &first_occurence,
|
||||||
|
int Curr_block,
|
||||||
|
Model_Block *ModelBlock) const;
|
||||||
|
virtual void collectEndogenous(NodeID &Id);
|
||||||
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct IM_compact
|
typedef struct IM_compact
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
#ifndef _EXPRESSION_HH
|
|
||||||
#define _EXPRESSION_HH
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/** \file
|
|
||||||
* \version 1.0
|
|
||||||
* \date 04/13/2004
|
|
||||||
* \par This file defines the Expression class .
|
|
||||||
*/
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "SymbolTableTypes.hh"
|
|
||||||
#include "NumericalConstants.hh"
|
|
||||||
|
|
||||||
struct Token
|
|
||||||
{
|
|
||||||
/*! ID of first operand */
|
|
||||||
int id1;
|
|
||||||
/*! Type of first operand */
|
|
||||||
Type type1;
|
|
||||||
/*! Flag : operand 1 is followed or not */
|
|
||||||
bool followed1;
|
|
||||||
/*! ID of second operand */
|
|
||||||
int id2;
|
|
||||||
/*! Type of second operand */
|
|
||||||
Type type2;
|
|
||||||
/*! Flag : operand 2 is followed or not */
|
|
||||||
bool followed2;
|
|
||||||
/*! Operator code */
|
|
||||||
int op_code;
|
|
||||||
/*! Operator name */
|
|
||||||
std::string op_name;
|
|
||||||
/*! costructor */
|
|
||||||
Token(){followed1=followed2=false;};
|
|
||||||
};
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/*!
|
|
||||||
\class Expression
|
|
||||||
\brief Handles expressions appearing
|
|
||||||
in initialization statements. These expressions aren't meant to be derived
|
|
||||||
*/
|
|
||||||
class Expression
|
|
||||||
{
|
|
||||||
private :
|
|
||||||
/*! Vector tokens */
|
|
||||||
std::vector<Token> expression_list;
|
|
||||||
/*! Output string of the class */
|
|
||||||
std::ostringstream output;
|
|
||||||
//! Pointer to numerical constants table
|
|
||||||
NumericalConstants *num_constants;
|
|
||||||
|
|
||||||
public :
|
|
||||||
/*! Constructor */
|
|
||||||
Expression();
|
|
||||||
/*! Destructor */
|
|
||||||
~Expression();
|
|
||||||
//! Set numerical constants pointer
|
|
||||||
void setNumericalConstants(NumericalConstants *num_constants_arg);
|
|
||||||
/*! Adds binary token to expression list */
|
|
||||||
int AddToken(int id1,Type type1, int id2,Type type2,int op_code);
|
|
||||||
/*! Adds unary token to expression list */
|
|
||||||
int AddToken(int id1,Type type1, int op_code);
|
|
||||||
/*! Adds unkown function to expression list */
|
|
||||||
int AddToken(int id1,Type type1, std::string ufunction);
|
|
||||||
/*! Returns output string */
|
|
||||||
std::string get();
|
|
||||||
/*! Clear expression list */
|
|
||||||
void clear(void);
|
|
||||||
/*! Print expression to output string */
|
|
||||||
void set(void);
|
|
||||||
/*! Gets output argument name */
|
|
||||||
std::string getArgument(Type type, int id);
|
|
||||||
};
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#endif
|
|
|
@ -21,10 +21,15 @@ public:
|
||||||
SymbolTable symbol_table;
|
SymbolTable symbol_table;
|
||||||
//! Numerical constants table
|
//! Numerical constants table
|
||||||
NumericalConstants num_constants;
|
NumericalConstants num_constants;
|
||||||
|
//! Expressions outside model block
|
||||||
|
DataTree expressions_tree;
|
||||||
//! Model equations and their derivatives
|
//! Model equations and their derivatives
|
||||||
ModelTree model_tree;
|
ModelTree model_tree;
|
||||||
//! Option linear
|
//! Option linear
|
||||||
bool linear;
|
bool linear;
|
||||||
|
//! Global evaluation context
|
||||||
|
/*! Filled using initval blocks and parameters initializations */
|
||||||
|
eval_context_type global_eval_context;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! List of statements
|
//! List of statements
|
||||||
|
|
|
@ -95,10 +95,8 @@ private:
|
||||||
void writeSparseDLLDynamicHFile(const string &dynamic_basename) const;
|
void writeSparseDLLDynamicHFile(const string &dynamic_basename) const;
|
||||||
//! Writes dynamic model file when SparseDLL option is on
|
//! Writes dynamic model file when SparseDLL option is on
|
||||||
void writeSparseDLLDynamicCFileAndBinFile(const string &dynamic_basename, const string &bin_basename) const;
|
void writeSparseDLLDynamicCFileAndBinFile(const string &dynamic_basename, const string &bin_basename) const;
|
||||||
//! Evaluates part of a model tree
|
void evaluateJacobian(const eval_context_type &eval_context);
|
||||||
inline double Evaluate_Expression(NodeID StartID);
|
void BlockLinear(Model_Block *ModelBlock);
|
||||||
inline void Evaluate_Jacobian();
|
|
||||||
inline void BlockLinear(Model_Block *ModelBlock);
|
|
||||||
string reform(string name) const;
|
string reform(string name) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -107,6 +105,8 @@ public:
|
||||||
ModelTreeMode mode;
|
ModelTreeMode mode;
|
||||||
//! Type of compiler used in matlab for SPARSE_DLL option: 0 = LCC or 1 = GCC
|
//! Type of compiler used in matlab for SPARSE_DLL option: 0 = LCC or 1 = GCC
|
||||||
int compiler;
|
int compiler;
|
||||||
|
//! Absolute value under which a number is considered to be zero
|
||||||
|
double cutoff;
|
||||||
|
|
||||||
//! Declare a node as an equation of the model
|
//! Declare a node as an equation of the model
|
||||||
void addEquation(NodeID eq);
|
void addEquation(NodeID eq);
|
||||||
|
@ -124,7 +124,7 @@ public:
|
||||||
bool computeThirdDerivatives;
|
bool computeThirdDerivatives;
|
||||||
//! Execute computations (variable sorting + derivation)
|
//! Execute computations (variable sorting + derivation)
|
||||||
/*! You must set computeJacobian, computeJacobianExo, computeHessian, computeStaticHessian and computeThirdDerivatives to correct values before calling this function */
|
/*! You must set computeJacobian, computeJacobianExo, computeHessian, computeStaticHessian and computeThirdDerivatives to correct values before calling this function */
|
||||||
void computingPass();
|
void computingPass(const eval_context_type &eval_context);
|
||||||
//! Writes model initialization and lead/lag incidence matrix to output
|
//! Writes model initialization and lead/lag incidence matrix to output
|
||||||
void writeOutput(ostream &output) const;
|
void writeOutput(ostream &output) const;
|
||||||
//! Writes static model file
|
//! Writes static model file
|
||||||
|
|
|
@ -7,16 +7,17 @@ using namespace std;
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "SymbolTable.hh"
|
#include "SymbolTable.hh"
|
||||||
|
#include "ExprNode.hh"
|
||||||
#include "Statement.hh"
|
#include "Statement.hh"
|
||||||
|
|
||||||
class InitParamStatement : public Statement
|
class InitParamStatement : public Statement
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const string param_name;
|
const string param_name;
|
||||||
const string param_value;
|
const NodeID param_value;
|
||||||
const SymbolTable &symbol_table;
|
const SymbolTable &symbol_table;
|
||||||
public:
|
public:
|
||||||
InitParamStatement(const string ¶m_name_arg, const string ¶m_value_arg,
|
InitParamStatement(const string ¶m_name_arg, const NodeID param_value_arg,
|
||||||
const SymbolTable &symbol_table_arg);
|
const SymbolTable &symbol_table_arg);
|
||||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||||
};
|
};
|
||||||
|
@ -28,7 +29,7 @@ public:
|
||||||
We use a vector instead of a map, since the order of declaration matters:
|
We use a vector instead of a map, since the order of declaration matters:
|
||||||
an initialization can depend on a previously initialized variable inside the block
|
an initialization can depend on a previously initialized variable inside the block
|
||||||
*/
|
*/
|
||||||
typedef vector<pair<string, string> > init_values_type;
|
typedef vector<pair<string, NodeID> > init_values_type;
|
||||||
protected:
|
protected:
|
||||||
const init_values_type init_values;
|
const init_values_type init_values;
|
||||||
const SymbolTable &symbol_table;
|
const SymbolTable &symbol_table;
|
||||||
|
@ -62,7 +63,7 @@ public:
|
||||||
Contrary to Initval and Endval, we use a map, since it is impossible to reuse
|
Contrary to Initval and Endval, we use a map, since it is impossible to reuse
|
||||||
a given initialization value in a second initialization inside the block.
|
a given initialization value in a second initialization inside the block.
|
||||||
*/
|
*/
|
||||||
typedef map<pair<string, int>, string> hist_values_type;
|
typedef map<pair<string, int>, NodeID> hist_values_type;
|
||||||
private:
|
private:
|
||||||
const hist_values_type hist_values;
|
const hist_values_type hist_values;
|
||||||
const SymbolTable &symbol_table;
|
const SymbolTable &symbol_table;
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
#define _PARSING_DRIVER_HH
|
#define _PARSING_DRIVER_HH
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "ModFile.hh"
|
#include "ModFile.hh"
|
||||||
#include "Expression.hh"
|
|
||||||
#include "TmpSymbolTable.hh"
|
#include "TmpSymbolTable.hh"
|
||||||
#include "DynareBison.hh"
|
#include "DynareBison.hh"
|
||||||
#include "ComputingTasks.hh"
|
#include "ComputingTasks.hh"
|
||||||
|
@ -39,23 +39,25 @@ private:
|
||||||
/*! Body defined at the end of DynareFlex.ll, for convenience reasons. */
|
/*! Body defined at the end of DynareFlex.ll, for convenience reasons. */
|
||||||
void scan_end();
|
void scan_end();
|
||||||
|
|
||||||
//! Returns string output of last expression parsed
|
|
||||||
string get_expression(ExpObj *exp);
|
|
||||||
|
|
||||||
//! Checks that a given symbol exists, and stops with an error message if it doesn't
|
//! Checks that a given symbol exists, and stops with an error message if it doesn't
|
||||||
void check_symbol_existence(const string &name);
|
void check_symbol_existence(const string &name);
|
||||||
|
|
||||||
//! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name
|
//! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name
|
||||||
void optim_options_helper(const string &name);
|
void optim_options_helper(const string &name);
|
||||||
|
|
||||||
//! Stores expressions
|
|
||||||
Expression expression;
|
|
||||||
//! Stores temporary symbol table
|
//! Stores temporary symbol table
|
||||||
TmpSymbolTable *tmp_symbol_table;
|
TmpSymbolTable *tmp_symbol_table;
|
||||||
|
|
||||||
|
//! The data tree in which to add expressions currently parsed
|
||||||
|
DataTree *data_tree;
|
||||||
|
|
||||||
//! The model tree in which to add expressions currently parsed
|
//! The model tree in which to add expressions currently parsed
|
||||||
|
/*! It is only a dynamic cast of data_tree pointer, and is therefore null if data_tree is not a ModelTree instance */
|
||||||
ModelTree *model_tree;
|
ModelTree *model_tree;
|
||||||
|
|
||||||
|
//! Sets data_tree and model_tree pointers
|
||||||
|
void set_current_data_tree(DataTree *data_tree_arg);
|
||||||
|
|
||||||
//! Stores options lists
|
//! Stores options lists
|
||||||
OptionsList options_list;
|
OptionsList options_list;
|
||||||
//! Temporary storage for trend elements
|
//! Temporary storage for trend elements
|
||||||
|
@ -79,7 +81,7 @@ private:
|
||||||
//! Temporary storage for periods of deterministic shocks
|
//! Temporary storage for periods of deterministic shocks
|
||||||
vector<pair<int, int> > det_shocks_periods;
|
vector<pair<int, int> > det_shocks_periods;
|
||||||
//! Temporary storage for values of deterministic shocks
|
//! Temporary storage for values of deterministic shocks
|
||||||
vector<string> det_shocks_values;
|
vector<NodeID> det_shocks_values;
|
||||||
//! Temporary storage for variances of shocks
|
//! Temporary storage for variances of shocks
|
||||||
ShocksStatement::var_and_std_shocks_type var_shocks;
|
ShocksStatement::var_and_std_shocks_type var_shocks;
|
||||||
//! Temporary storage for standard errors of shocks
|
//! Temporary storage for standard errors of shocks
|
||||||
|
@ -97,6 +99,9 @@ private:
|
||||||
//! Temporary storage for histval blocks
|
//! Temporary storage for histval blocks
|
||||||
HistValStatement::hist_values_type hist_values;
|
HistValStatement::hist_values_type hist_values;
|
||||||
|
|
||||||
|
//! Temporary storage for argument list of unknown function
|
||||||
|
vector<NodeID> unknown_function_args;
|
||||||
|
|
||||||
//! The mod file representation constructed by this ParsingDriver
|
//! The mod file representation constructed by this ParsingDriver
|
||||||
ModFile *mod_file;
|
ModFile *mod_file;
|
||||||
|
|
||||||
|
@ -144,12 +149,10 @@ public:
|
||||||
|
|
||||||
//! Check if a given symbol exists in the parsing context
|
//! Check if a given symbol exists in the parsing context
|
||||||
bool exists_symbol(const char *s);
|
bool exists_symbol(const char *s);
|
||||||
//! Sets variable offset of ModelTree class to use C output
|
//! Sets mode of ModelTree class to use C output
|
||||||
void use_dll();
|
void use_dll();
|
||||||
//! Sets variable offset of ModelTree class to block decompose the model and to use C output
|
//! Sets mode of ModelTree class to block decompose the model and triggers the creation of the incidence matrix
|
||||||
void sparse_dll();
|
void sparse_dll();
|
||||||
//! Initialize the model => creation of the incidence matrix
|
|
||||||
void initialize_model();
|
|
||||||
//! Sets the compiler type used in conjunction with SPARCE_DLL
|
//! Sets the compiler type used in conjunction with SPARCE_DLL
|
||||||
void init_compiler(int compiler_type);
|
void init_compiler(int compiler_type);
|
||||||
//! Sets the FILENAME for the initial value in initval
|
//! Sets the FILENAME for the initial value in initval
|
||||||
|
@ -164,22 +167,14 @@ public:
|
||||||
void declare_parameter(string *name, string *tex_name = new string);
|
void declare_parameter(string *name, string *tex_name = new string);
|
||||||
//! Declares and initializes a local parameter
|
//! Declares and initializes a local parameter
|
||||||
void declare_and_init_local_parameter(string *name, NodeID rhs);
|
void declare_and_init_local_parameter(string *name, NodeID rhs);
|
||||||
//! Adds an Expression's numerical constant
|
//! Adds a constant to DataTree
|
||||||
ExpObj *add_expression_constant(string *constant);
|
NodeID add_constant(string *constant);
|
||||||
//! Adds a model constant to ModelTree
|
|
||||||
NodeID add_model_constant(string *constant);
|
|
||||||
//! Adds a model variable to ModelTree and VariableTable
|
//! Adds a model variable to ModelTree and VariableTable
|
||||||
NodeID add_model_variable(string *name);
|
NodeID add_model_variable(string *name);
|
||||||
//! Adds a model lagged variable to ModelTree and VariableTable
|
//! Adds a model lagged variable to ModelTree and VariableTable
|
||||||
NodeID add_model_variable(string *name, string *olag);
|
NodeID add_model_variable(string *name, string *olag);
|
||||||
//! Adds an Expression's variable
|
//! Adds an Expression's variable
|
||||||
ExpObj *add_expression_variable(string *name);
|
NodeID add_expression_variable(string *name);
|
||||||
//! Adds a binary token to an expression
|
|
||||||
ExpObj *add_expression_token(ExpObj *arg1, ExpObj *arg2, int op);
|
|
||||||
//! Adds an unary token to an expression
|
|
||||||
ExpObj *add_expression_token(ExpObj *arg1, int op);
|
|
||||||
//! Adds a unary token to an expression, with function name unknown
|
|
||||||
ExpObj *add_expression_token(ExpObj *arg1, string *op_name);
|
|
||||||
//! Adds a "periods" statement
|
//! Adds a "periods" statement
|
||||||
void periods(string *periods);
|
void periods(string *periods);
|
||||||
//! Adds a "cutoff" statement
|
//! Adds a "cutoff" statement
|
||||||
|
@ -189,11 +184,11 @@ public:
|
||||||
//! Adds a "dsample" statement
|
//! Adds a "dsample" statement
|
||||||
void dsample(string *arg1, string *arg2);
|
void dsample(string *arg1, string *arg2);
|
||||||
//! Writes parameter intitialisation expression
|
//! Writes parameter intitialisation expression
|
||||||
void init_param(string *name, ExpObj *rhs);
|
void init_param(string *name, NodeID rhs);
|
||||||
//! Writes an initval block
|
//! Writes an initval block
|
||||||
void init_val(string *name, ExpObj *rhs);
|
void init_val(string *name, NodeID rhs);
|
||||||
//! Writes an histval block
|
//! Writes an histval block
|
||||||
void hist_val(string *name, string *lag, ExpObj *rhs);
|
void hist_val(string *name, string *lag, NodeID rhs);
|
||||||
//! Writes end of an initval block
|
//! Writes end of an initval block
|
||||||
void end_initval();
|
void end_initval();
|
||||||
//! Writes end of an endval block
|
//! Writes end of an endval block
|
||||||
|
@ -209,29 +204,31 @@ public:
|
||||||
//! Adds a deterministic chock
|
//! Adds a deterministic chock
|
||||||
void add_det_shock(string *var);
|
void add_det_shock(string *var);
|
||||||
//! Adds a std error chock
|
//! Adds a std error chock
|
||||||
void add_stderr_shock(string *var, ExpObj *value);
|
void add_stderr_shock(string *var, NodeID value);
|
||||||
//! Adds a variance chock
|
//! Adds a variance chock
|
||||||
void add_var_shock(string *var, ExpObj *value);
|
void add_var_shock(string *var, NodeID value);
|
||||||
//! Adds a covariance chock
|
//! Adds a covariance chock
|
||||||
void add_covar_shock(string *var1, string *var2, ExpObj *value);
|
void add_covar_shock(string *var1, string *var2, NodeID value);
|
||||||
//! Adds a correlated chock
|
//! Adds a correlated chock
|
||||||
void add_correl_shock(string *var1, string *var2, ExpObj *value);
|
void add_correl_shock(string *var1, string *var2, NodeID value);
|
||||||
//! Adds a shock period range
|
//! Adds a shock period range
|
||||||
void add_period(string *p1, string *p2);
|
void add_period(string *p1, string *p2);
|
||||||
//! Adds a shock period
|
//! Adds a shock period
|
||||||
void add_period(string *p1);
|
void add_period(string *p1);
|
||||||
//! Adds a shock value
|
//! Adds a shock value (when only a numerical constant)
|
||||||
void add_value(string *value);
|
void add_value_const(string *value);
|
||||||
//! Adds a shock value
|
//! Adds a shock value (when only a variable name)
|
||||||
void add_value(ExpObj *value);
|
void add_value_var(string *name);
|
||||||
|
//! Adds a shock value (when it is a complete expression)
|
||||||
|
void add_value(NodeID value);
|
||||||
//! Writes a Sigma_e block
|
//! Writes a Sigma_e block
|
||||||
void do_sigma_e();
|
void do_sigma_e();
|
||||||
//! Ends row of Sigma_e block
|
//! Ends row of Sigma_e block
|
||||||
void end_of_row();
|
void end_of_row();
|
||||||
//! Adds an element to current row of Sigma_e
|
//! Adds a constant element to current row of Sigma_e
|
||||||
void add_to_row(string *s);
|
void add_to_row_const(string *s);
|
||||||
//! Adds an element to current row of Sigma_e
|
//! Adds an expression element to current row of Sigma_e
|
||||||
void add_to_row(ExpObj *v);
|
void add_to_row(NodeID v);
|
||||||
//! Write a steady command
|
//! Write a steady command
|
||||||
void steady();
|
void steady();
|
||||||
//! Sets an option to a numerical value
|
//! Sets an option to a numerical value
|
||||||
|
@ -283,19 +280,19 @@ public:
|
||||||
//! Prints varops instructions
|
//! Prints varops instructions
|
||||||
void set_varobs();
|
void set_varobs();
|
||||||
void set_trends();
|
void set_trends();
|
||||||
void set_trend_element(string *arg1, ExpObj *arg2);
|
void set_trend_element(string *arg1, NodeID arg2);
|
||||||
void set_unit_root_vars();
|
void set_unit_root_vars();
|
||||||
void optim_weights();
|
void optim_weights();
|
||||||
void set_optim_weights(string *name, ExpObj *value);
|
void set_optim_weights(string *name, NodeID value);
|
||||||
void set_optim_weights(string *name1, string *name2, ExpObj *value);
|
void set_optim_weights(string *name1, string *name2, NodeID value);
|
||||||
void set_osr_params();
|
void set_osr_params();
|
||||||
void run_osr();
|
void run_osr();
|
||||||
void set_olr_inst();
|
void set_olr_inst();
|
||||||
void run_olr();
|
void run_olr();
|
||||||
void run_calib_var();
|
void run_calib_var();
|
||||||
void set_calib_var(string *name, string *weight, ExpObj *expression);
|
void set_calib_var(string *name, string *weight, NodeID expression);
|
||||||
void set_calib_covar(string *name1, string *name2, string *weight, ExpObj *expression);
|
void set_calib_covar(string *name1, string *name2, string *weight, NodeID expression);
|
||||||
void set_calib_ac(string *name, string *ar, string *weight, ExpObj *expression);
|
void set_calib_ac(string *name, string *ar, string *weight, NodeID expression);
|
||||||
void run_calib(int covar);
|
void run_calib(int covar);
|
||||||
void run_dynasave(string *arg1, string *arg2 = new string);
|
void run_dynasave(string *arg1, string *arg2 = new string);
|
||||||
void run_dynatype(string *arg1, string *arg2 = new string);
|
void run_dynatype(string *arg1, string *arg2 = new string);
|
||||||
|
@ -312,51 +309,57 @@ public:
|
||||||
//! Writes token "arg=0" to model tree
|
//! Writes token "arg=0" to model tree
|
||||||
NodeID add_model_equal_with_zero_rhs(NodeID arg);
|
NodeID add_model_equal_with_zero_rhs(NodeID arg);
|
||||||
//! Writes token "arg1+arg2" to model tree
|
//! Writes token "arg1+arg2" to model tree
|
||||||
NodeID add_model_plus(NodeID arg1, NodeID arg2);
|
NodeID add_plus(NodeID arg1, NodeID arg2);
|
||||||
//! Writes token "arg1-arg2" to model tree
|
//! Writes token "arg1-arg2" to model tree
|
||||||
NodeID add_model_minus(NodeID arg1, NodeID arg2);
|
NodeID add_minus(NodeID arg1, NodeID arg2);
|
||||||
//! Writes token "-arg1" to model tree
|
//! Writes token "-arg1" to model tree
|
||||||
NodeID add_model_uminus(NodeID arg1);
|
NodeID add_uminus(NodeID arg1);
|
||||||
//! Writes token "arg1*arg2" to model tree
|
//! Writes token "arg1*arg2" to model tree
|
||||||
NodeID add_model_times(NodeID arg1, NodeID arg2);
|
NodeID add_times(NodeID arg1, NodeID arg2);
|
||||||
//! Writes token "arg1/arg2" to model tree
|
//! Writes token "arg1/arg2" to model tree
|
||||||
NodeID add_model_divide(NodeID arg1, NodeID arg2);
|
NodeID add_divide(NodeID arg1, NodeID arg2);
|
||||||
//! Writes token "arg1^arg2" to model tree
|
//! Writes token "arg1^arg2" to model tree
|
||||||
NodeID add_model_power(NodeID arg1, NodeID arg2);
|
NodeID add_power(NodeID arg1, NodeID arg2);
|
||||||
//! Writes token "exp(arg1)" to model tree
|
//! Writes token "exp(arg1)" to model tree
|
||||||
NodeID add_model_exp(NodeID arg1);
|
NodeID add_exp(NodeID arg1);
|
||||||
//! Writes token "log(arg1)" to model tree
|
//! Writes token "log(arg1)" to model tree
|
||||||
NodeID add_model_log(NodeID arg1);
|
NodeID add_log(NodeID arg1);
|
||||||
//! Writes token "log10(arg1)" to model tree
|
//! Writes token "log10(arg1)" to model tree
|
||||||
NodeID add_model_log10(NodeID arg1);
|
NodeID add_log10(NodeID arg1);
|
||||||
//! Writes token "cos(arg1)" to model tree
|
//! Writes token "cos(arg1)" to model tree
|
||||||
NodeID add_model_cos(NodeID arg1);
|
NodeID add_cos(NodeID arg1);
|
||||||
//! Writes token "sin(arg1)" to model tree
|
//! Writes token "sin(arg1)" to model tree
|
||||||
NodeID add_model_sin(NodeID arg1);
|
NodeID add_sin(NodeID arg1);
|
||||||
//! Writes token "tan(arg1)" to model tree
|
//! Writes token "tan(arg1)" to model tree
|
||||||
NodeID add_model_tan(NodeID arg1);
|
NodeID add_tan(NodeID arg1);
|
||||||
//! Writes token "acos(arg1)" to model tree
|
//! Writes token "acos(arg1)" to model tree
|
||||||
NodeID add_model_acos(NodeID arg1);
|
NodeID add_acos(NodeID arg1);
|
||||||
//! Writes token "asin(arg1)" to model tree
|
//! Writes token "asin(arg1)" to model tree
|
||||||
NodeID add_model_asin(NodeID arg1);
|
NodeID add_asin(NodeID arg1);
|
||||||
//! Writes token "atan(arg1)" to model tree
|
//! Writes token "atan(arg1)" to model tree
|
||||||
NodeID add_model_atan(NodeID arg1);
|
NodeID add_atan(NodeID arg1);
|
||||||
//! Writes token "cosh(arg1)" to model tree
|
//! Writes token "cosh(arg1)" to model tree
|
||||||
NodeID add_model_cosh(NodeID arg1);
|
NodeID add_cosh(NodeID arg1);
|
||||||
//! Writes token "sinh(arg1)" to model tree
|
//! Writes token "sinh(arg1)" to model tree
|
||||||
NodeID add_model_sinh(NodeID arg1);
|
NodeID add_sinh(NodeID arg1);
|
||||||
//! Writes token "tanh(arg1)" to model tree
|
//! Writes token "tanh(arg1)" to model tree
|
||||||
NodeID add_model_tanh(NodeID arg1);
|
NodeID add_tanh(NodeID arg1);
|
||||||
//! Writes token "acosh(arg1)" to model tree
|
//! Writes token "acosh(arg1)" to model tree
|
||||||
NodeID add_model_acosh(NodeID arg1);
|
NodeID add_acosh(NodeID arg1);
|
||||||
//! Writes token "asin(arg1)" to model tree
|
//! Writes token "asin(arg1)" to model tree
|
||||||
NodeID add_model_asinh(NodeID arg1);
|
NodeID add_asinh(NodeID arg1);
|
||||||
//! Writes token "atanh(arg1)" to model tree
|
//! Writes token "atanh(arg1)" to model tree
|
||||||
NodeID add_model_atanh(NodeID arg1);
|
NodeID add_atanh(NodeID arg1);
|
||||||
//! Writes token "sqrt(arg1)" to model tree
|
//! Writes token "sqrt(arg1)" to model tree
|
||||||
NodeID add_model_sqrt(NodeID arg1);
|
NodeID add_sqrt(NodeID arg1);
|
||||||
|
//! Adds an unknwon function argument
|
||||||
|
void add_unknown_function_arg(NodeID arg);
|
||||||
|
//! Adds an unknown function call node
|
||||||
|
NodeID add_unknown_function(string *function_name);
|
||||||
//! Adds a native statement
|
//! Adds a native statement
|
||||||
void add_native(const char *s);
|
void add_native(const char *s);
|
||||||
|
//! Resets data_tree and model_tree pointers to default (i.e. mod_file->expressions_tree)
|
||||||
|
void reset_data_tree();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ! PARSING_DRIVER_HH
|
#endif // ! PARSING_DRIVER_HH
|
||||||
|
|
|
@ -9,6 +9,7 @@ using namespace std;
|
||||||
|
|
||||||
#include "Statement.hh"
|
#include "Statement.hh"
|
||||||
#include "SymbolTable.hh"
|
#include "SymbolTable.hh"
|
||||||
|
#include "ExprNode.hh"
|
||||||
|
|
||||||
class AbstractShocksStatement : public Statement
|
class AbstractShocksStatement : public Statement
|
||||||
{
|
{
|
||||||
|
@ -17,11 +18,11 @@ public:
|
||||||
{
|
{
|
||||||
int period1;
|
int period1;
|
||||||
int period2;
|
int period2;
|
||||||
string value;
|
NodeID value;
|
||||||
};
|
};
|
||||||
typedef map<string, vector<DetShockElement> > det_shocks_type;
|
typedef map<string, vector<DetShockElement> > det_shocks_type;
|
||||||
typedef map<string, string> var_and_std_shocks_type;
|
typedef map<string, NodeID> var_and_std_shocks_type;
|
||||||
typedef map<pair<string, string>, string> covar_and_corr_shocks_type;
|
typedef map<pair<string, string>, NodeID> covar_and_corr_shocks_type;
|
||||||
protected:
|
protected:
|
||||||
//! Is this statement a "mshocks" statement ? (instead of a "shocks" statement)
|
//! Is this statement a "mshocks" statement ? (instead of a "shocks" statement)
|
||||||
const bool mshocks;
|
const bool mshocks;
|
||||||
|
|
|
@ -6,6 +6,7 @@ using namespace std;
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "ExprNode.hh"
|
||||||
#include "Statement.hh"
|
#include "Statement.hh"
|
||||||
|
|
||||||
//! Stores a Sigma_e statement
|
//! Stores a Sigma_e statement
|
||||||
|
@ -19,7 +20,7 @@ public:
|
||||||
eUpper = 1 //!< Upper triangular matrix
|
eUpper = 1 //!< Upper triangular matrix
|
||||||
};
|
};
|
||||||
//! Type of a matrix row
|
//! Type of a matrix row
|
||||||
typedef vector<string> row_type;
|
typedef vector<NodeID> row_type;
|
||||||
//! Type of a complete matrix
|
//! Type of a complete matrix
|
||||||
typedef vector<row_type> matrix_type;
|
typedef vector<row_type> matrix_type;
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
\par This file defines the SymbolTable class .
|
\par This file defines the SymbolTable class .
|
||||||
*/
|
*/
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "SymbolTableTypes.hh"
|
#include "SymbolTableTypes.hh"
|
||||||
|
|
||||||
|
@ -114,7 +117,10 @@ inline Type SymbolTable::getType(const std::string &name) const
|
||||||
{
|
{
|
||||||
symboltable_const_iterator iter = symboltable.find(name);
|
symboltable_const_iterator iter = symboltable.find(name);
|
||||||
if (iter == symboltable.end())
|
if (iter == symboltable.end())
|
||||||
return eUNDEF;
|
{
|
||||||
|
cerr << "SymbolTable::getType: unknwon symbol: " << name << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return iter->second.type;
|
return iter->second.type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
#ifndef _SYMBOLTABLETYPES_HH
|
#ifndef _SYMBOLTABLETYPES_HH
|
||||||
#define _SYMBOLTABLETYPES_HH
|
#define _SYMBOLTABLETYPES_HH
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/*! \file
|
|
||||||
\version 1.0
|
|
||||||
\date 04/26/2004
|
|
||||||
\par This file defines types related to SymbolTable.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <vector>
|
//! Symbol type enum
|
||||||
|
|
||||||
/*! Symbol type enum */
|
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
eEndogenous = 0, //!< Endogenous
|
eEndogenous = 0, //!< Endogenous
|
||||||
|
@ -18,35 +10,27 @@ enum Type
|
||||||
eRecursiveVariable = 3, //!< Recursive variable (reserved for future use)
|
eRecursiveVariable = 3, //!< Recursive variable (reserved for future use)
|
||||||
eParameter = 4, //!< Parameter
|
eParameter = 4, //!< Parameter
|
||||||
eLocalParameter = 10, //!< Parameter local to a model
|
eLocalParameter = 10, //!< Parameter local to a model
|
||||||
eTempResult = 6, //!< Temporary result, used only in Expression class
|
|
||||||
eNumericalConstant = 7, //!< Numerical constant, used only in Expression class
|
|
||||||
eUNDEF = 9 //!< Undefined
|
|
||||||
};
|
};
|
||||||
/*! Symbol reference flag enum */
|
|
||||||
|
//! Symbol reference flag enum
|
||||||
enum Reference
|
enum Reference
|
||||||
{
|
{
|
||||||
eNotReferenced, //!< Not yet referenced in model
|
eNotReferenced, //!< Not yet referenced in model
|
||||||
eReferenced, //!< Already referenced in model
|
eReferenced, //!< Already referenced in model
|
||||||
};
|
};
|
||||||
/*!
|
|
||||||
\class Symbol
|
|
||||||
\brief Symbol structure
|
|
||||||
*/
|
|
||||||
struct Symbol
|
struct Symbol
|
||||||
{
|
{
|
||||||
/*! Symbol type */
|
//! Symbol type
|
||||||
Type type;
|
Type type;
|
||||||
/*! Symbol ID : for each type */
|
//! Symbol ID : for each type
|
||||||
int id;
|
int id;
|
||||||
/*! Symbol reference flag */
|
//! Symbol reference flag
|
||||||
Reference referenced;
|
Reference referenced;
|
||||||
|
|
||||||
Symbol()
|
Symbol() : id(-1), referenced(eNotReferenced)
|
||||||
{
|
{
|
||||||
type = eUNDEF;
|
|
||||||
id = -1;
|
|
||||||
referenced = eNotReferenced;
|
|
||||||
}
|
}
|
||||||
} ;
|
};
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#ifndef _INTERPRETE_HH
|
|
||||||
#define _INTERPRETE_HH
|
|
||||||
#include <stack>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include "SymbolTable.hh"
|
|
||||||
#include "VariableTable.hh"
|
|
||||||
#include "ExprNode.hh"
|
|
||||||
//#define PRINT_IT
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
typedef struct t_val_index
|
|
||||||
{
|
|
||||||
int index,type,indexed;
|
|
||||||
double value;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct t_val1_index
|
|
||||||
{
|
|
||||||
string name;
|
|
||||||
double value;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef stack<double> STACK_SIMPLE00;
|
|
||||||
typedef map<string, t_val_index, less<string > > t_map_to_val_index;
|
|
||||||
typedef map<int, t_val1_index > t_map_int;
|
|
||||||
|
|
||||||
class interprete
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
double cutoff;
|
|
||||||
bool eval;
|
|
||||||
double u1, u2;
|
|
||||||
STACK_SIMPLE00 Stack;
|
|
||||||
interprete();
|
|
||||||
double S_to_Val(string *str);
|
|
||||||
double get_value(string *str, double ll);
|
|
||||||
void put_value(string *str, int num,int Type, double val);
|
|
||||||
void print_all();
|
|
||||||
void create_id_map(int* Table, int Size, int HSize);
|
|
||||||
double GetDataValue(/*NodeID*/int id, Type type);
|
|
||||||
void set_cutoff(double r);
|
|
||||||
private:
|
|
||||||
string tmp_put_value_name;
|
|
||||||
t_map_to_val_index variable;
|
|
||||||
t_map_int i_endo_variable, i_exo_variable, i_param_variable;
|
|
||||||
};
|
|
||||||
#endif
|
|
|
@ -1,95 +0,0 @@
|
||||||
#include "interprete.hh"
|
|
||||||
|
|
||||||
interprete::interprete()
|
|
||||||
{
|
|
||||||
eval=true;
|
|
||||||
cutoff=1.0e-6;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
interprete::set_cutoff(double r)
|
|
||||||
{
|
|
||||||
cutoff=r;
|
|
||||||
}
|
|
||||||
|
|
||||||
double
|
|
||||||
interprete::S_to_Val(string *str)
|
|
||||||
{
|
|
||||||
double v=atof((*str).c_str());
|
|
||||||
#ifdef PRINT_IT
|
|
||||||
cout << "v=" << v << "\n";
|
|
||||||
#endif
|
|
||||||
return(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
double
|
|
||||||
interprete::get_value(string *str, double ll)
|
|
||||||
{
|
|
||||||
#ifdef PRINT_IT
|
|
||||||
cout << "value[" << *str << "]=" << variable[(*str)].value << "\n";
|
|
||||||
#endif
|
|
||||||
return(variable[(*str)].value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
interprete::put_value(string *str, int num,int Type, double val)
|
|
||||||
{
|
|
||||||
#ifdef PRINT_IT
|
|
||||||
cout << "*str=" << *str << " val=" << val << "\n";
|
|
||||||
#endif
|
|
||||||
tmp_put_value_name=*str;
|
|
||||||
variable[(*str)].value=val;
|
|
||||||
variable[(*str)].index=num;
|
|
||||||
variable[(*str)].type=Type;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
interprete::print_all()
|
|
||||||
{
|
|
||||||
map<string, t_val_index>::iterator iter;
|
|
||||||
for( iter = variable.begin(); iter != variable.end(); iter++ )
|
|
||||||
{
|
|
||||||
cout << "Name= " << iter->first << ", Value= " << iter->second.value << ", Index= " << iter->second.index << ", Type= " << iter->second.type << ", Indexed=" << iter->second.index << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
interprete::create_id_map(int *Table, int Size, int HSize)
|
|
||||||
{
|
|
||||||
map<string, t_val_index>::iterator iter;
|
|
||||||
for( iter = variable.begin(); iter != variable.end(); iter++ )
|
|
||||||
{
|
|
||||||
if(iter->second.type==0)
|
|
||||||
{
|
|
||||||
i_endo_variable[iter->second.index].name=iter->first;
|
|
||||||
i_endo_variable[iter->second.index].value=iter->second.value;
|
|
||||||
}
|
|
||||||
else if(iter->second.type==1)
|
|
||||||
{
|
|
||||||
i_exo_variable[iter->second.index].name=iter->first;
|
|
||||||
i_exo_variable[iter->second.index].value=iter->second.value;
|
|
||||||
}
|
|
||||||
else if(iter->second.type==4)
|
|
||||||
{
|
|
||||||
i_param_variable[iter->second.index].name=iter->first;
|
|
||||||
i_param_variable[iter->second.index].value=iter->second.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double
|
|
||||||
interprete::GetDataValue(int id, Type type)
|
|
||||||
{
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case eParameter:
|
|
||||||
return(i_param_variable[(long int) id].value);
|
|
||||||
case eEndogenous:
|
|
||||||
return(i_endo_variable[(long int) id].value);
|
|
||||||
case eExogenous:
|
|
||||||
return(i_exo_variable[(long int) id].value);
|
|
||||||
default:
|
|
||||||
cerr << "interprete::GetDataValue: unhandled type!!";
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue