v4 parser: created ModFile class, which is the abstract representation of a mod file; removed all static variables
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1110 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
442bf232b0
commit
d5ac5b1fbd
|
@ -13,7 +13,7 @@ using namespace std;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//ostringstream ComputingTasks::output;
|
//ostringstream ComputingTasks::output;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
ComputingTasks::ComputingTasks()
|
ComputingTasks::ComputingTasks(const SymbolTable &symbol_table_arg) : symbol_table(symbol_table_arg)
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,8 @@ void ComputingTasks::setEstimationInit(void)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setOptimOptions(string str1, string str2, int task)
|
void ComputingTasks::setOptimOptions(string str1, string str2, int task)
|
||||||
{
|
{
|
||||||
static string optim_string;
|
string optim_string;
|
||||||
static int start;
|
int start;
|
||||||
switch(task)
|
switch(task)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -160,12 +160,12 @@ void ComputingTasks::setOptimOptions(string str1, string str2, int task)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setEstimatedElements(void)
|
void ComputingTasks::setEstimatedElements(void)
|
||||||
{
|
{
|
||||||
if (!SymbolTable::Exist(EstimParams->name))
|
if (!symbol_table.Exist(EstimParams->name))
|
||||||
{
|
{
|
||||||
string msg = "Unknown symbol: "+EstimParams->name;
|
string msg = "Unknown symbol: "+EstimParams->name;
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced & EstimParams->name != "dsge_prior_weight")
|
if (symbol_table.isReferenced(EstimParams->name) == eNotReferenced & EstimParams->name != "dsge_prior_weight")
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -176,31 +176,31 @@ void ComputingTasks::setEstimatedElements(void)
|
||||||
switch(EstimParams->type)
|
switch(EstimParams->type)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
if( SymbolTable::getType(EstimParams->name) == eExogenous)
|
if (symbol_table.getType(EstimParams->name) == eExogenous)
|
||||||
{
|
{
|
||||||
*output << "estim_params_.var_exo = [estim_params_.var_exo; ";
|
*output << "estim_params_.var_exo = [estim_params_.var_exo; ";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eEndogenous)
|
else if (symbol_table.getType(EstimParams->name) == eEndogenous)
|
||||||
{
|
{
|
||||||
*output << "estim_params_.var_endo = [estim_params_.var_endo; ";
|
*output << "estim_params_.var_endo = [estim_params_.var_endo; ";
|
||||||
}
|
}
|
||||||
*output << SymbolTable::getID(EstimParams->name)+1;
|
*output << symbol_table.getID(EstimParams->name)+1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
*output << "estim_params_.param_vals = [estim_params_.param_vals; ";
|
*output << "estim_params_.param_vals = [estim_params_.param_vals; ";
|
||||||
*output << SymbolTable::getID(EstimParams->name)+1;
|
*output << symbol_table.getID(EstimParams->name)+1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if( SymbolTable::getType(EstimParams->name) == eExogenous)
|
if (symbol_table.getType(EstimParams->name) == eExogenous)
|
||||||
{
|
{
|
||||||
*output << "estim_params_.corrx = [estim_params_.corrx; ";
|
*output << "estim_params_.corrx = [estim_params_.corrx; ";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eEndogenous)
|
else if (symbol_table.getType(EstimParams->name) == eEndogenous)
|
||||||
{
|
{
|
||||||
*output << "estim_params_.corrn = [estim_params_.corrn; ";
|
*output << "estim_params_.corrn = [estim_params_.corrn; ";
|
||||||
}
|
}
|
||||||
*output << SymbolTable::getID(EstimParams->name)+1;
|
*output << symbol_table.getID(EstimParams->name)+1;
|
||||||
*output << " " << SymbolTable::getID(EstimParams->name2)+1;
|
*output << " " << symbol_table.getID(EstimParams->name2)+1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*output << " " << EstimParams->init_val << " " << EstimParams->low_bound << " " <<
|
*output << " " << EstimParams->init_val << " " << EstimParams->low_bound << " " <<
|
||||||
|
@ -213,12 +213,12 @@ void ComputingTasks::setEstimatedElements(void)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setEstimatedInitElements(void)
|
void ComputingTasks::setEstimatedInitElements(void)
|
||||||
{
|
{
|
||||||
if (!SymbolTable::Exist(EstimParams->name))
|
if (!symbol_table.Exist(EstimParams->name))
|
||||||
{
|
{
|
||||||
string msg = "Unknown symbol: "+EstimParams->name;
|
string msg = "Unknown symbol: "+EstimParams->name;
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced)
|
if (symbol_table.isReferenced(EstimParams->name) == eNotReferenced)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -228,32 +228,32 @@ void ComputingTasks::setEstimatedInitElements(void)
|
||||||
}
|
}
|
||||||
if (EstimParams->type < 3)
|
if (EstimParams->type < 3)
|
||||||
{
|
{
|
||||||
if( SymbolTable::getType(EstimParams->name) == eExogenous)
|
if (symbol_table.getType(EstimParams->name) == eExogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find(estim_params_.var_exo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n";
|
*output << "tmp1 = find(estim_params_.var_exo(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ");\n";
|
||||||
*output << "estim_params_.var_exo(tmp1,2) = " << EstimParams->init_val << ";\n";
|
*output << "estim_params_.var_exo(tmp1,2) = " << EstimParams->init_val << ";\n";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eEndogenous)
|
else if (symbol_table.getType(EstimParams->name) == eEndogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find(estim_params_.var_endo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n";
|
*output << "tmp1 = find(estim_params_.var_endo(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ");\n";
|
||||||
*output << "estim_params_.var_endo(tmp1,2) = " << EstimParams->init_val << ";\n";
|
*output << "estim_params_.var_endo(tmp1,2) = " << EstimParams->init_val << ";\n";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eParameter)
|
else if (symbol_table.getType(EstimParams->name) == eParameter)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find(estim_params_.param_vals(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n";
|
*output << "tmp1 = find(estim_params_.param_vals(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ");\n";
|
||||||
*output << "estim_params_.param_vals(tmp1,2) = " << EstimParams->init_val << ";\n";
|
*output << "estim_params_.param_vals(tmp1,2) = " << EstimParams->init_val << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( SymbolTable::getType(EstimParams->name) == eExogenous)
|
if (symbol_table.getType(EstimParams->name) == eExogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find((estim_params_.corrx(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrx(:,2)==SymbolTable::getID(EstimParams->name2)+1);\n";
|
*output << "tmp1 = find((estim_params_.corrx(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ")) & (estim_params_.corrx(:,2)==" << symbol_table.getID(EstimParams->name2)+1 << ");\n";
|
||||||
*output << "estim_params_.corrx(tmp1,3) = " << EstimParams->init_val << ";\n";
|
*output << "estim_params_.corrx(tmp1,3) = " << EstimParams->init_val << ";\n";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eEndogenous)
|
else if (symbol_table.getType(EstimParams->name) == eEndogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find((estim_params_.corrn(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrn(:,2)==" << SymbolTable::getID(EstimParams->name2)+1 << ";\n";
|
*output << "tmp1 = find((estim_params_.corrn(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ")) & (estim_params_.corrn(:,2)==" << symbol_table.getID(EstimParams->name2)+1 << ";\n";
|
||||||
*output << "estim_params_.corrx(tmp1,3) = " << EstimParams->init_val << ";\n";
|
*output << "estim_params_.corrx(tmp1,3) = " << EstimParams->init_val << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,12 +263,12 @@ void ComputingTasks::setEstimatedInitElements(void)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setEstimatedBoundsElements(void)
|
void ComputingTasks::setEstimatedBoundsElements(void)
|
||||||
{
|
{
|
||||||
if (!SymbolTable::Exist(EstimParams->name))
|
if (!symbol_table.Exist(EstimParams->name))
|
||||||
{
|
{
|
||||||
string msg = "Unknown symbol: "+EstimParams->name;
|
string msg = "Unknown symbol: "+EstimParams->name;
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced)
|
if (symbol_table.isReferenced(EstimParams->name) == eNotReferenced)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -278,36 +278,36 @@ void ComputingTasks::setEstimatedBoundsElements(void)
|
||||||
}
|
}
|
||||||
if (EstimParams->type < 3)
|
if (EstimParams->type < 3)
|
||||||
{
|
{
|
||||||
if( SymbolTable::getType(EstimParams->name) == eExogenous)
|
if (symbol_table.getType(EstimParams->name) == eExogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find(estim_params_.var_exo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n";
|
*output << "tmp1 = find(estim_params_.var_exo(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ");\n";
|
||||||
*output << "estim_params_.var_exo(tmp1,3) = " << EstimParams->low_bound << ";\n";
|
*output << "estim_params_.var_exo(tmp1,3) = " << EstimParams->low_bound << ";\n";
|
||||||
*output << "estim_params_.var_exo(tmp1,4) = " << EstimParams->up_bound << ";\n";
|
*output << "estim_params_.var_exo(tmp1,4) = " << EstimParams->up_bound << ";\n";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eEndogenous)
|
else if (symbol_table.getType(EstimParams->name) == eEndogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find(estim_params_.var_endo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n";
|
*output << "tmp1 = find(estim_params_.var_endo(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ");\n";
|
||||||
*output << "estim_params_.var_endo(tmp1,3) = " << EstimParams->low_bound << ";\n";
|
*output << "estim_params_.var_endo(tmp1,3) = " << EstimParams->low_bound << ";\n";
|
||||||
*output << "estim_params_.var_endo(tmp1,4) = " << EstimParams->up_bound << ";\n";
|
*output << "estim_params_.var_endo(tmp1,4) = " << EstimParams->up_bound << ";\n";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eParameter)
|
else if (symbol_table.getType(EstimParams->name) == eParameter)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find(estim_params_.param_vals(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n";
|
*output << "tmp1 = find(estim_params_.param_vals(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ");\n";
|
||||||
*output << "estim_params_.param_vals(tmp1,3) = " << EstimParams->low_bound << ";\n";
|
*output << "estim_params_.param_vals(tmp1,3) = " << EstimParams->low_bound << ";\n";
|
||||||
*output << "estim_params_.param_vals(tmp1,4) = " << EstimParams->up_bound << ";\n";
|
*output << "estim_params_.param_vals(tmp1,4) = " << EstimParams->up_bound << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( SymbolTable::getType(EstimParams->name) == eExogenous)
|
if (symbol_table.getType(EstimParams->name) == eExogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find((estim_params_.corrx(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrx(:,2)==SymbolTable::getID(EstimParams->name2)+1);\n";
|
*output << "tmp1 = find((estim_params_.corrx(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ")) & (estim_params_.corrx(:,2)==" << symbol_table.getID(EstimParams->name2)+1 << ");\n";
|
||||||
*output << "estim_params_.corrx(tmp1,4) = " << EstimParams->low_bound << ";\n";
|
*output << "estim_params_.corrx(tmp1,4) = " << EstimParams->low_bound << ";\n";
|
||||||
*output << "estim_params_.corrx(tmp1,5) = " << EstimParams->up_bound << ";\n";
|
*output << "estim_params_.corrx(tmp1,5) = " << EstimParams->up_bound << ";\n";
|
||||||
}
|
}
|
||||||
else if ( SymbolTable::getType(EstimParams->name) == eEndogenous)
|
else if (symbol_table.getType(EstimParams->name) == eEndogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = find((estim_params_.corrn(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrn(:,2)==" << SymbolTable::getID(EstimParams->name2)+1 << ";\n";
|
*output << "tmp1 = find((estim_params_.corrn(:,1)==" << symbol_table.getID(EstimParams->name)+1 << ")) & (estim_params_.corrn(:,2)==" << symbol_table.getID(EstimParams->name2)+1 << ";\n";
|
||||||
*output << "estim_params_.corrx(tmp1,4) = " << EstimParams->low_bound << ";\n";
|
*output << "estim_params_.corrx(tmp1,4) = " << EstimParams->low_bound << ";\n";
|
||||||
*output << "estim_params_.corrx(tmp1,5) = " << EstimParams->up_bound << ";\n";
|
*output << "estim_params_.corrx(tmp1,5) = " << EstimParams->up_bound << ";\n";
|
||||||
}
|
}
|
||||||
|
@ -319,13 +319,13 @@ void ComputingTasks::setEstimatedBoundsElements(void)
|
||||||
void ComputingTasks::set_trend_element (string name, string expression)
|
void ComputingTasks::set_trend_element (string name, string expression)
|
||||||
{
|
{
|
||||||
//Testing if symbol exists
|
//Testing if symbol exists
|
||||||
if (!SymbolTable::Exist(name))
|
if (!symbol_table.Exist(name))
|
||||||
{
|
{
|
||||||
string msg = "Unknown variable: " + name;
|
string msg = "Unknown variable: " + name;
|
||||||
(* error) (msg.c_str());
|
(* error) (msg.c_str());
|
||||||
}
|
}
|
||||||
Type type = SymbolTable::getType(name);
|
Type type = symbol_table.getType(name);
|
||||||
// int id = SymbolTable::getID(name);
|
// int id = symbol_table.getID(name);
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
{
|
{
|
||||||
*output << "tmp1 = strmatch('" << name << "',options_.varobs,'exact');\n";
|
*output << "tmp1 = strmatch('" << name << "',options_.varobs,'exact');\n";
|
||||||
|
@ -354,19 +354,19 @@ void ComputingTasks::BeginCalibVar(void)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setCalibVar(string name, string weight, string expression)
|
void ComputingTasks::setCalibVar(string name, string weight, string expression)
|
||||||
{
|
{
|
||||||
if (!SymbolTable::Exist(name))
|
if (!symbol_table.Exist(name))
|
||||||
{
|
{
|
||||||
string msg = "calib_var: " + name + " doesn't exist";
|
string msg = "calib_var: " + name + " doesn't exist";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
int id = SymbolTable::getID(name)+1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
if (SymbolTable::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 << "];\n";
|
||||||
}
|
}
|
||||||
else if (SymbolTable::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";
|
||||||
|
@ -382,30 +382,30 @@ void ComputingTasks::setCalibVar(string name, string weight, string expression)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setCalibVar(string name1, string name2, string weight, string expression)
|
void ComputingTasks::setCalibVar(string name1, string name2, string weight, string expression)
|
||||||
{
|
{
|
||||||
if (!SymbolTable::Exist(name1))
|
if (!symbol_table.Exist(name1))
|
||||||
{
|
{
|
||||||
string msg = "calib_var: " + name1 + " doesn't exist";
|
string msg = "calib_var: " + name1 + " doesn't exist";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
if (!SymbolTable::Exist(name2))
|
if (!symbol_table.Exist(name2))
|
||||||
{
|
{
|
||||||
string msg = "calib_var: " + name2 + " doesn't exist";
|
string msg = "calib_var: " + name2 + " doesn't exist";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
if (SymbolTable::getType(name1) != SymbolTable::getType(name2))
|
if (symbol_table.getType(name1) != symbol_table.getType(name2))
|
||||||
{
|
{
|
||||||
string msg = "calib_var: " + name1 + " and " + name2 + " don't have the same type";
|
string msg = "calib_var: " + name1 + " and " + name2 + " don't have the same type";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
int id1 = SymbolTable::getID(name1)+1;
|
int id1 = symbol_table.getID(name1) + 1;
|
||||||
int id2 = SymbolTable::getID(name2)+1;
|
int id2 = symbol_table.getID(name2) + 1;
|
||||||
if (SymbolTable::getType(name1) == eEndogenous)
|
if (symbol_table.getType(name1) == eEndogenous)
|
||||||
{
|
{
|
||||||
*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 << "];\n";
|
||||||
}
|
}
|
||||||
else if (SymbolTable::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";
|
||||||
|
@ -420,13 +420,13 @@ void ComputingTasks::setCalibVar(string name1, string name2, string weight, stri
|
||||||
|
|
||||||
void ComputingTasks::setCalibAc(string name, string ar, string weight, string expression)
|
void ComputingTasks::setCalibAc(string name, string ar, string weight, string expression)
|
||||||
{
|
{
|
||||||
static int max_iar = 3;
|
int max_iar = 3;
|
||||||
if (!SymbolTable::Exist(name))
|
if (!symbol_table.Exist(name))
|
||||||
{
|
{
|
||||||
string msg = "calib_var: " + name + " doesn't exist";
|
string msg = "calib_var: " + name + " doesn't exist";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
int id = SymbolTable::getID(name)+1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
int iar = atoi(ar.c_str())+3;
|
int iar = atoi(ar.c_str())+3;
|
||||||
if (iar > max_iar)
|
if (iar > max_iar)
|
||||||
{
|
{
|
||||||
|
@ -439,7 +439,7 @@ void ComputingTasks::setCalibAc(string name, string ar, string weight, string ex
|
||||||
}
|
}
|
||||||
max_iar = iar;
|
max_iar = iar;
|
||||||
}
|
}
|
||||||
if (SymbolTable::getType(name) == eEndogenous)
|
if (symbol_table.getType(name) == eEndogenous)
|
||||||
{
|
{
|
||||||
*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";
|
||||||
|
@ -498,12 +498,12 @@ void ComputingTasks::BeginOptimWeights(void)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setOptimWeights(string name, string exp)
|
void ComputingTasks::setOptimWeights(string name, string exp)
|
||||||
{
|
{
|
||||||
if (!SymbolTable::Exist(name) || SymbolTable::getType(name) != eEndogenous)
|
if (!symbol_table.Exist(name) || symbol_table.getType(name) != eEndogenous)
|
||||||
{
|
{
|
||||||
string msg = "optim_weights: " + name + " isn't an endogenous variable";
|
string msg = "optim_weights: " + name + " isn't an endogenous variable";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
int id = SymbolTable::getID(name)+1;
|
int id = symbol_table.getID(name) + 1;
|
||||||
*output << "optim_weights_(" << id << "," << id << ") = " << exp << ";\n";
|
*output << "optim_weights_(" << id << "," << id << ") = " << exp << ";\n";
|
||||||
*output << "obj_var_ = [obj_var_; " << id << "];\n";
|
*output << "obj_var_ = [obj_var_; " << id << "];\n";
|
||||||
}
|
}
|
||||||
|
@ -511,18 +511,18 @@ void ComputingTasks::setOptimWeights(string name, string exp)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void ComputingTasks::setOptimWeights(string name1, string name2, string exp)
|
void ComputingTasks::setOptimWeights(string name1, string name2, string exp)
|
||||||
{
|
{
|
||||||
if (!SymbolTable::Exist(name1) || SymbolTable::getType(name1) != eEndogenous)
|
if (!symbol_table.Exist(name1) || symbol_table.getType(name1) != eEndogenous)
|
||||||
{
|
{
|
||||||
string msg = "optim_weights: " + name1 + " isn't an endogenous variable";
|
string msg = "optim_weights: " + name1 + " isn't an endogenous variable";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
if (!SymbolTable::Exist(name2) || SymbolTable::getType(name2) != eEndogenous)
|
if (!symbol_table.Exist(name2) || symbol_table.getType(name2) != eEndogenous)
|
||||||
{
|
{
|
||||||
string msg = "optim_weights: " + name2 + " isn't an endogenous variable";
|
string msg = "optim_weights: " + name2 + " isn't an endogenous variable";
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
int id1 = SymbolTable::getID(name1)+1;
|
int id1 = symbol_table.getID(name1) + 1;
|
||||||
int id2 = SymbolTable::getID(name2)+1;
|
int id2 = symbol_table.getID(name2) + 1;
|
||||||
*output << "optim_weights_(" << id1 << "," << id2 << ") = " << exp << ";\n";
|
*output << "optim_weights_(" << id1 << "," << id2 << ") = " << exp << ";\n";
|
||||||
*output << "obj_var_ = [obj_var_; " << id1 << " " << id2 << "];\n";
|
*output << "obj_var_ = [obj_var_; " << id1 << " " << id2 << "];\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,35 +16,30 @@ using namespace std;
|
||||||
#include "VariableTable.hh"
|
#include "VariableTable.hh"
|
||||||
#include "NumericalConstants.hh"
|
#include "NumericalConstants.hh"
|
||||||
#include "DataTree.hh"
|
#include "DataTree.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
const int DataTree::NoOpCode = -1;
|
DataTree::DataTree(SymbolTable &symbol_table_arg, VariableTable &variable_table_arg) :
|
||||||
const NodeID DataTree::NullID = NULL;
|
symbol_table(symbol_table_arg),
|
||||||
const NodeID DataTree::Zero = new MetaToken(reinterpret_cast <NodeID> (0), eNumericalConstant, NULL, -1);
|
variable_table(variable_table_arg),
|
||||||
const NodeID DataTree::One = new MetaToken(reinterpret_cast <NodeID> (1), eNumericalConstant, NULL, -1);
|
NoOpCode(-1), NullID(NULL)
|
||||||
const NodeID DataTree::MinusOne = new MetaToken(One, eTempResult, NULL, token::UMINUS);
|
|
||||||
const NodeID DataTree::ZeroEqZero = new MetaToken(Zero, eTempResult, Zero, token::EQUAL);
|
|
||||||
int DataTree::offset = 1;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
DataTree::DataTree()
|
|
||||||
{
|
{
|
||||||
|
offset = 1;
|
||||||
current_order = 0;
|
current_order = 0;
|
||||||
//Here "0" and "1" have been added to NumericalConstants class
|
|
||||||
SymbolTable::AddSymbolDeclar("0.0",eNumericalConstant, "");
|
|
||||||
SymbolTable::AddSymbolDeclar("1.0",eNumericalConstant, "");
|
|
||||||
|
|
||||||
|
Zero = new MetaToken(reinterpret_cast <NodeID> (0), eNumericalConstant, NULL, -1);
|
||||||
Zero->op_name = "";
|
Zero->op_name = "";
|
||||||
Zero->reference_count.resize(current_order+1,2);
|
Zero->reference_count.resize(current_order+1,2);
|
||||||
Zero->idx = 0;
|
Zero->idx = 0;
|
||||||
mModelTree.push_back(Zero);
|
mModelTree.push_back(Zero);
|
||||||
mIndexOfTokens[*Zero]=Zero;
|
mIndexOfTokens[*Zero]=Zero;
|
||||||
|
|
||||||
|
One = new MetaToken(reinterpret_cast <NodeID> (1), eNumericalConstant, NULL, -1); One->op_name = "";
|
||||||
One->op_name = "";
|
One->op_name = "";
|
||||||
One->reference_count.resize(current_order+1,1);
|
One->reference_count.resize(current_order+1,1);
|
||||||
One->idx = 1;
|
One->idx = 1;
|
||||||
mModelTree.push_back(One);
|
mModelTree.push_back(One);
|
||||||
mIndexOfTokens[*One]=One;
|
mIndexOfTokens[*One]=One;
|
||||||
|
|
||||||
|
MinusOne = new MetaToken(One, eTempResult, NULL, token::UMINUS);
|
||||||
MinusOne->op_name = operator_table.str(token::UMINUS);
|
MinusOne->op_name = operator_table.str(token::UMINUS);
|
||||||
MinusOne->reference_count.resize(current_order+1,1);
|
MinusOne->reference_count.resize(current_order+1,1);
|
||||||
MinusOne->idx = 2;
|
MinusOne->idx = 2;
|
||||||
|
@ -52,6 +47,7 @@ DataTree::DataTree()
|
||||||
mIndexOfTokens[*MinusOne]=MinusOne;
|
mIndexOfTokens[*MinusOne]=MinusOne;
|
||||||
|
|
||||||
// Pushing "0=0" into mModelTree
|
// Pushing "0=0" into mModelTree
|
||||||
|
ZeroEqZero = new MetaToken(Zero, eTempResult, Zero, token::EQUAL);
|
||||||
ZeroEqZero->op_name = operator_table.str(token::EQUAL);
|
ZeroEqZero->op_name = operator_table.str(token::EQUAL);
|
||||||
ZeroEqZero->reference_count.resize(current_order+1,1);
|
ZeroEqZero->reference_count.resize(current_order+1,1);
|
||||||
ZeroEqZero->idx = 3;
|
ZeroEqZero->idx = 3;
|
||||||
|
|
|
@ -331,11 +331,10 @@ typedef pair<int, Type> ExpObj;
|
||||||
|
|
||||||
model
|
model
|
||||||
: MODEL ';' equation_list END
|
: MODEL ';' equation_list END
|
||||||
{driver.check_model();}
|
|
||||||
| MODEL '(' LINEAR ')' ';' {driver.option_num("linear","1");}
|
| MODEL '(' LINEAR ')' ';' {driver.option_num("linear","1");}
|
||||||
equation_list END {driver.check_model();}
|
equation_list END
|
||||||
| MODEL '(' USE_DLL ')' ';' {driver.use_dll();}
|
| MODEL '(' USE_DLL ')' ';' {driver.use_dll();}
|
||||||
equation_list END {driver.check_model();}
|
equation_list END
|
||||||
;
|
;
|
||||||
|
|
||||||
equation_list
|
equation_list
|
||||||
|
@ -349,7 +348,7 @@ typedef pair<int, Type> ExpObj;
|
||||||
: hand_side EQUAL hand_side ';'
|
: hand_side EQUAL hand_side ';'
|
||||||
{$$ = driver.add_model_equal($1, $3);}
|
{$$ = driver.add_model_equal($1, $3);}
|
||||||
| hand_side ';'
|
| hand_side ';'
|
||||||
{$$ = driver.add_model_equal($1);}
|
{$$ = driver.add_model_equal_with_zero_rhs($1);}
|
||||||
;
|
;
|
||||||
|
|
||||||
hand_side
|
hand_side
|
||||||
|
|
|
@ -258,7 +258,7 @@ int sigma_e = 0;
|
||||||
otherwise it is a native statement until the end of the line
|
otherwise it is a native statement until the end of the line
|
||||||
*/
|
*/
|
||||||
<INITIAL>[A-Za-z_][A-Za-z0-9_]* {
|
<INITIAL>[A-Za-z_][A-Za-z0-9_]* {
|
||||||
if (SymbolTable::getID(yytext) != -1)
|
if (driver.exists_symbol(yytext))
|
||||||
{
|
{
|
||||||
BEGIN DYNARE_STATEMENT;
|
BEGIN DYNARE_STATEMENT;
|
||||||
yylval->string_val = new string(yytext);
|
yylval->string_val = new string(yytext);
|
||||||
|
@ -267,14 +267,14 @@ int sigma_e = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BEGIN NATIVE;
|
BEGIN NATIVE;
|
||||||
*(driver.output) << yytext;
|
driver.add_native(yytext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<INITIAL>. {BEGIN NATIVE; *(driver.output) << yytext;}
|
<INITIAL>. {BEGIN NATIVE; driver.add_native(yytext); }
|
||||||
|
|
||||||
/* NATIVE Block */
|
/* NATIVE Block */
|
||||||
<NATIVE>.* {BEGIN INITIAL; *(driver.output) << yytext << endl;}
|
<NATIVE>.* {BEGIN INITIAL; driver.add_native(yytext); driver.add_native("\n"); }
|
||||||
|
|
||||||
<*>. {return yy::parser::token_type (yytext[0]);}
|
<*>. {return yy::parser::token_type (yytext[0]);}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ using namespace std;
|
||||||
|
|
||||||
#include "ParsingDriver.hh"
|
#include "ParsingDriver.hh"
|
||||||
#include "OutputFile.hh"
|
#include "OutputFile.hh"
|
||||||
|
#include "ModFile.hh"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Main function of Dynare.
|
\brief Main function of Dynare.
|
||||||
|
@ -48,7 +49,7 @@ main(int argc, char** argv)
|
||||||
cout << "Parsing your model file ..." << endl;
|
cout << "Parsing your model file ..." << endl;
|
||||||
|
|
||||||
// Launch parsing
|
// Launch parsing
|
||||||
p.parse(argv[1]);
|
ModFile *mod_file = p.parse(argv[1]);
|
||||||
|
|
||||||
// Execute final instructions
|
// Execute final instructions
|
||||||
p.finish();
|
p.finish();
|
||||||
|
@ -56,9 +57,11 @@ main(int argc, char** argv)
|
||||||
string name = argv[1];
|
string name = argv[1];
|
||||||
name.erase(name.size() - 4,4);
|
name.erase(name.size() - 4,4);
|
||||||
// Opening and init main Output file (.m or .sci file)
|
// Opening and init main Output file (.m or .sci file)
|
||||||
output_file.Open(name);
|
output_file.Open(name, mod_file);
|
||||||
// Writing remaining string output to output file
|
// Writing remaining string output to output file
|
||||||
output_file.Save(output);
|
output_file.Save(output, mod_file);
|
||||||
|
|
||||||
|
delete mod_file;
|
||||||
|
|
||||||
cout << "Parsing done" << endl;
|
cout << "Parsing done" << endl;
|
||||||
cout << "Starting Matlab computing ..." << endl;
|
cout << "Starting Matlab computing ..." << endl;
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include "Expression.hh"
|
#include "Expression.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
ostringstream Expression::output;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
Expression::Expression()
|
Expression::Expression()
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
|
@ -22,7 +20,12 @@ Expression::~Expression()
|
||||||
// Empty
|
// 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)
|
int Expression::AddToken(int id1,Type type1,int id2,Type type2,int op_code)
|
||||||
{
|
{
|
||||||
Token token;
|
Token token;
|
||||||
|
@ -261,13 +264,13 @@ string Expression::getArgument(Type type,int id)
|
||||||
}
|
}
|
||||||
else if (type == eNumericalConstant)
|
else if (type == eNumericalConstant)
|
||||||
{
|
{
|
||||||
argument << NumericalConstants::get(id);
|
argument << num_constants->get(id);
|
||||||
}
|
}
|
||||||
return argument.str();
|
return argument.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
string Expression::get(void)
|
string Expression::get()
|
||||||
{
|
{
|
||||||
return output.str();
|
return output.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ endif
|
||||||
|
|
||||||
ifeq ($(CROSS_WIN32), yes)
|
ifeq ($(CROSS_WIN32), yes)
|
||||||
CPP = i586-mingw32msvc-g++
|
CPP = i586-mingw32msvc-g++
|
||||||
|
# Detection of uninitialized variables is buggy in MinGW and generates spurious warnings
|
||||||
|
CPPFLAGS += -Wno-uninitialized
|
||||||
DYNARE_M = dynare_m.exe
|
DYNARE_M = dynare_m.exe
|
||||||
DYNARE_S = dynare_s.exe
|
DYNARE_S = dynare_s.exe
|
||||||
endif
|
endif
|
||||||
|
@ -48,7 +50,8 @@ COMMON_OBJ=\
|
||||||
TmpSymbolTable.o\
|
TmpSymbolTable.o\
|
||||||
VariableTable.o\
|
VariableTable.o\
|
||||||
ParsingDriver.o\
|
ParsingDriver.o\
|
||||||
DataTree.o
|
DataTree.o \
|
||||||
|
ModFile.o
|
||||||
|
|
||||||
MATLAB_OBJ = InterfaceMatlab.o
|
MATLAB_OBJ = InterfaceMatlab.o
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "ModFile.hh"
|
||||||
|
|
||||||
|
ModFile::ModFile() : symbol_table(model_parameters),
|
||||||
|
variable_table(symbol_table, model_parameters),
|
||||||
|
numerical_initialization(symbol_table, model_parameters),
|
||||||
|
computing_tasks(symbol_table),
|
||||||
|
model_tree(symbol_table, variable_table, model_parameters, num_constants)
|
||||||
|
{
|
||||||
|
}
|
|
@ -3,41 +3,20 @@
|
||||||
\date 04/09/2004
|
\date 04/09/2004
|
||||||
\par This file implements the ModelParemeters class methodes.
|
\par This file implements the ModelParemeters class methodes.
|
||||||
*/
|
*/
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <iostream>
|
|
||||||
#include "ModelParameters.hh"
|
#include "ModelParameters.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int ModelParameters::eq_nbr = 0;
|
ModelParameters::ModelParameters() : eq_nbr(0),
|
||||||
int ModelParameters::exo_nbr = 0;
|
exo_nbr(0), var_exo_nbr(0),
|
||||||
int ModelParameters::var_exo_nbr = 0;
|
exo_det_nbr(0), var_exo_det_nbr(0),
|
||||||
int ModelParameters::exo_det_nbr = 0;
|
endo_nbr(0), var_endo_nbr(0),
|
||||||
int ModelParameters::var_exo_det_nbr = 0;
|
parameter_nbr(0), local_parameter_nbr(0),
|
||||||
int ModelParameters::endo_nbr = 0;
|
recur_nbr(0),
|
||||||
int ModelParameters::var_endo_nbr = 0;
|
max_lag(0), max_lead(0),
|
||||||
int ModelParameters::parameter_nbr = 0;
|
max_endo_lag(0), max_endo_lead(0),
|
||||||
int ModelParameters::local_parameter_nbr = 0;
|
max_exo_lag(0), max_exo_lead(0),
|
||||||
int ModelParameters::recur_nbr = 0;
|
max_exo_det_lag(0), max_exo_det_lead(0),
|
||||||
int ModelParameters::max_lag = 0;
|
max_recur_lag(0), max_recur_lead(0)
|
||||||
int ModelParameters::max_lead = 0;
|
|
||||||
int ModelParameters::max_endo_lag = 0;
|
|
||||||
int ModelParameters::max_endo_lead = 0;
|
|
||||||
int ModelParameters::max_exo_lag = 0;
|
|
||||||
int ModelParameters::max_exo_lead = 0;
|
|
||||||
int ModelParameters::max_exo_det_lag = 0;
|
|
||||||
int ModelParameters::max_exo_det_lead = 0;
|
|
||||||
int ModelParameters::max_recur_lag = 0;
|
|
||||||
int ModelParameters::max_recur_lead = 0;
|
|
||||||
using namespace std;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
ModelParameters::ModelParameters()
|
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
ModelParameters::~ModelParameters()
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
|
@ -20,24 +20,25 @@ using namespace std;
|
||||||
#include "ModelTree.hh"
|
#include "ModelTree.hh"
|
||||||
#include "ModelParameters.hh"
|
#include "ModelParameters.hh"
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
ostringstream ModelTree::output;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
inline NodeID MetaToken::getDerivativeAddress(int iVarID)
|
inline NodeID MetaToken::getDerivativeAddress(int iVarID, const ModelTree &model_tree) const
|
||||||
{
|
{
|
||||||
std::map<int, NodeID, std::less<int> >::iterator iter = d1.find(iVarID);
|
std::map<int, NodeID, std::less<int> >::const_iterator iter = d1.find(iVarID);
|
||||||
if (iter == d1.end())
|
if (iter == d1.end())
|
||||||
// No entry in map, derivative is therefore null
|
// No entry in map, derivative is therefore null
|
||||||
if (op_code == token::EQUAL)
|
if (op_code == token::EQUAL)
|
||||||
return DataTree::ZeroEqZero;
|
return model_tree.ZeroEqZero;
|
||||||
else
|
else
|
||||||
return DataTree::Zero;
|
return model_tree.Zero;
|
||||||
else
|
else
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelTree::ModelTree()
|
ModelTree::ModelTree(SymbolTable &symbol_table_arg, VariableTable &variable_table_arg,
|
||||||
|
ModelParameters &mod_param_arg, const NumericalConstants &num_constants_arg) :
|
||||||
|
DataTree(symbol_table_arg, variable_table_arg),
|
||||||
|
mod_param(mod_param_arg),
|
||||||
|
num_constants(num_constants_arg)
|
||||||
{
|
{
|
||||||
computeJacobian = false;
|
computeJacobian = false;
|
||||||
computeJacobianExo = false;
|
computeJacobianExo = false;
|
||||||
|
@ -199,7 +200,7 @@ void ModelTree::SaveCFiles()
|
||||||
mStaticModelFile << " if (nlhs >= 1)\n";
|
mStaticModelFile << " if (nlhs >= 1)\n";
|
||||||
mStaticModelFile << " {\n";
|
mStaticModelFile << " {\n";
|
||||||
mStaticModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
mStaticModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
||||||
mStaticModelFile << " plhs[0] = mxCreateDoubleMatrix(" << ModelParameters::eq_nbr << ",1, mxREAL);\n";
|
mStaticModelFile << " plhs[0] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ",1, mxREAL);\n";
|
||||||
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
||||||
mStaticModelFile << " residual = mxGetPr(plhs[0]);\n";
|
mStaticModelFile << " residual = mxGetPr(plhs[0]);\n";
|
||||||
mStaticModelFile << " }\n\n";
|
mStaticModelFile << " }\n\n";
|
||||||
|
@ -207,7 +208,7 @@ void ModelTree::SaveCFiles()
|
||||||
mStaticModelFile << " if (nlhs >= 2)\n";
|
mStaticModelFile << " if (nlhs >= 2)\n";
|
||||||
mStaticModelFile << " {\n";
|
mStaticModelFile << " {\n";
|
||||||
mStaticModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
mStaticModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
||||||
mStaticModelFile << " plhs[1] = mxCreateDoubleMatrix(" << ModelParameters::eq_nbr << ", " << ModelParameters::endo_nbr << ", mxREAL);\n";
|
mStaticModelFile << " plhs[1] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << mod_param.endo_nbr << ", mxREAL);\n";
|
||||||
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
||||||
mStaticModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
mStaticModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
||||||
mStaticModelFile << " }\n\n";
|
mStaticModelFile << " }\n\n";
|
||||||
|
@ -247,7 +248,7 @@ void ModelTree::SaveCFiles()
|
||||||
mDynamicModelFile << " if (nlhs >= 1)\n";
|
mDynamicModelFile << " if (nlhs >= 1)\n";
|
||||||
mDynamicModelFile << " {\n";
|
mDynamicModelFile << " {\n";
|
||||||
mDynamicModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
mDynamicModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
||||||
mDynamicModelFile << " plhs[0] = mxCreateDoubleMatrix(" << ModelParameters::eq_nbr << ",1, mxREAL);\n";
|
mDynamicModelFile << " plhs[0] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ",1, mxREAL);\n";
|
||||||
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
||||||
mDynamicModelFile << " residual = mxGetPr(plhs[0]);\n";
|
mDynamicModelFile << " residual = mxGetPr(plhs[0]);\n";
|
||||||
mDynamicModelFile << " }\n\n";
|
mDynamicModelFile << " }\n\n";
|
||||||
|
@ -256,9 +257,9 @@ void ModelTree::SaveCFiles()
|
||||||
mDynamicModelFile << " {\n";
|
mDynamicModelFile << " {\n";
|
||||||
mDynamicModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
mDynamicModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
||||||
if (computeJacobianExo)
|
if (computeJacobianExo)
|
||||||
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << ModelParameters::eq_nbr << ", " << VariableTable::size() << ", mxREAL);\n";
|
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << variable_table.size() << ", mxREAL);\n";
|
||||||
else if (computeJacobian)
|
else if (computeJacobian)
|
||||||
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << ModelParameters::eq_nbr << ", " << ModelParameters::var_endo_nbr << ", mxREAL);\n";
|
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << mod_param.var_endo_nbr << ", mxREAL);\n";
|
||||||
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
||||||
mDynamicModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
mDynamicModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
||||||
mDynamicModelFile << " }\n\n";
|
mDynamicModelFile << " }\n\n";
|
||||||
|
@ -266,7 +267,7 @@ void ModelTree::SaveCFiles()
|
||||||
mDynamicModelFile << " if (nlhs >= 3)\n";
|
mDynamicModelFile << " if (nlhs >= 3)\n";
|
||||||
mDynamicModelFile << " {\n";
|
mDynamicModelFile << " {\n";
|
||||||
mDynamicModelFile << " /* Set the output pointer to the output matrix g2. */\n";
|
mDynamicModelFile << " /* Set the output pointer to the output matrix g2. */\n";
|
||||||
mDynamicModelFile << " plhs[2] = mxCreateDoubleMatrix(" << ModelParameters::eq_nbr << ", " << VariableTable::size()*VariableTable::size() << ", mxREAL);\n";
|
mDynamicModelFile << " plhs[2] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << variable_table.size()*variable_table.size() << ", mxREAL);\n";
|
||||||
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
||||||
mDynamicModelFile << " g2 = mxGetPr(plhs[2]);\n";
|
mDynamicModelFile << " g2 = mxGetPr(plhs[2]);\n";
|
||||||
mDynamicModelFile << " }\n\n";
|
mDynamicModelFile << " }\n\n";
|
||||||
|
@ -552,21 +553,21 @@ void ModelTree::derive(int iOrder)
|
||||||
|
|
||||||
// Filling mDerivativeIndex
|
// Filling mDerivativeIndex
|
||||||
// Loop on variables of derivation, skipping symmetric elements
|
// Loop on variables of derivation, skipping symmetric elements
|
||||||
for (int var = 0; var < VariableTable::size(); var++)
|
for (int var = 0; var < variable_table.size(); var++)
|
||||||
{
|
{
|
||||||
int starti = var*Order*(Order-1)*ModelParameters::eq_nbr/2;
|
int starti = var*Order*(Order-1)*mod_param.eq_nbr/2;
|
||||||
for (unsigned int i = starti; i < EqualTokenIDs.size() ; i++ )
|
for (unsigned int i = starti; i < EqualTokenIDs.size() ; i++ )
|
||||||
{
|
{
|
||||||
t1 = EqualTokenIDs[i]->getDerivativeAddress(var);
|
t1 = EqualTokenIDs[i]->getDerivativeAddress(var, *this);
|
||||||
if (Order == 1)
|
if (Order == 1)
|
||||||
mDerivativeIndex[0].push_back(DerivativeIndex(t1, i-starti, var));
|
mDerivativeIndex[0].push_back(DerivativeIndex(t1, i-starti, var));
|
||||||
else if (Order == 2)
|
else if (Order == 2)
|
||||||
{
|
{
|
||||||
int var1 = VariableTable::getSortID(i/ModelParameters::eq_nbr);
|
int var1 = variable_table.getSortID(i/mod_param.eq_nbr);
|
||||||
int var2 = VariableTable::getSortID(var);
|
int var2 = variable_table.getSortID(var);
|
||||||
mDerivativeIndex[1].push_back(DerivativeIndex(t1,
|
mDerivativeIndex[1].push_back(DerivativeIndex(t1,
|
||||||
i-ModelParameters::eq_nbr*(i/ModelParameters::eq_nbr),
|
i-mod_param.eq_nbr*(i/mod_param.eq_nbr),
|
||||||
var1*VariableTable::size()+var2));
|
var1*variable_table.size()+var2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -634,23 +635,13 @@ inline NodeID ModelTree::DeriveArgument(NodeID iArg, Type iType, int iVarID)
|
||||||
switch(iType)
|
switch(iType)
|
||||||
{
|
{
|
||||||
case eTempResult :
|
case eTempResult :
|
||||||
return iArg->getDerivativeAddress(iVarID);
|
return iArg->getDerivativeAddress(iVarID, *this);
|
||||||
case eExogenous :
|
case eExogenous :
|
||||||
case eExogenousDet :
|
case eExogenousDet :
|
||||||
case eEndogenous :
|
case eEndogenous :
|
||||||
case eRecursiveVariable :
|
case eRecursiveVariable :
|
||||||
if ((long int) iArg == iVarID)
|
if ((long int) iArg == iVarID)
|
||||||
//if ((VariableTable::getSymbolID(iArg) == VariableTable::getSymbolID(iVarID)) &&
|
|
||||||
// (VariableTable::getType(iArg) == VariableTable::getType(iVarID)))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
cout << SymbolTable::getNameByID(iType,
|
|
||||||
VariableTable::getSymbolID(iArg)) << endl;
|
|
||||||
cout << SymbolTable::getNameByID(iType,
|
|
||||||
VariableTable::getSymbolID(iVarID)) << endl;
|
|
||||||
*/
|
|
||||||
return One;
|
return One;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Zero;
|
return Zero;
|
||||||
|
@ -684,7 +675,7 @@ string ModelTree::setStaticModel(void)
|
||||||
int d = current_order; // Minimum number of times a temparary expression apears in equations
|
int d = current_order; // Minimum number of times a temparary expression apears in equations
|
||||||
int EquationNBR; // Number of model equations
|
int EquationNBR; // Number of model equations
|
||||||
|
|
||||||
EquationNBR = ModelParameters::eq_nbr;
|
EquationNBR = mod_param.eq_nbr;
|
||||||
// Reference count of token "0=0" is set to 0
|
// Reference count of token "0=0" is set to 0
|
||||||
// Not to be printed as a temp expression
|
// Not to be printed as a temp expression
|
||||||
fill(ZeroEqZero->reference_count.begin(),
|
fill(ZeroEqZero->reference_count.begin(),
|
||||||
|
@ -702,7 +693,7 @@ string ModelTree::setStaticModel(void)
|
||||||
model_output << " = ";
|
model_output << " = ";
|
||||||
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
||||||
}
|
}
|
||||||
else if (lEquationNBR < ModelParameters::eq_nbr)
|
else if (lEquationNBR < mod_param.eq_nbr)
|
||||||
{
|
{
|
||||||
model_output << "lhs =";
|
model_output << "lhs =";
|
||||||
model_output << getExpression((*tree_it)->id1, eStaticEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression((*tree_it)->id1, eStaticEquations, lEquationNBR) << ";" << endl;
|
||||||
|
@ -750,7 +741,7 @@ string ModelTree::setStaticModel(void)
|
||||||
lEquationNBR = 0;
|
lEquationNBR = 0;
|
||||||
for (unsigned int i = 0; i < mDerivativeIndex[0].size(); i++)
|
for (unsigned int i = 0; i < mDerivativeIndex[0].size(); i++)
|
||||||
{
|
{
|
||||||
if (VariableTable::getType(mDerivativeIndex[0][i].derivators) == eEndogenous)
|
if (variable_table.getType(mDerivativeIndex[0][i].derivators) == eEndogenous)
|
||||||
{
|
{
|
||||||
NodeID startJacobian = mDerivativeIndex[0][i].token_id;
|
NodeID startJacobian = mDerivativeIndex[0][i].token_id;
|
||||||
if (startJacobian != ZeroEqZero)
|
if (startJacobian != ZeroEqZero)
|
||||||
|
@ -758,7 +749,7 @@ string ModelTree::setStaticModel(void)
|
||||||
string exp = getExpression(startJacobian->id1, eStaticDerivatives);
|
string exp = getExpression(startJacobian->id1, eStaticDerivatives);
|
||||||
ostringstream g1;
|
ostringstream g1;
|
||||||
g1 << " g1" << lpar << mDerivativeIndex[0][i].equation_id+1 << ", " <<
|
g1 << " g1" << lpar << mDerivativeIndex[0][i].equation_id+1 << ", " <<
|
||||||
VariableTable::getSymbolID(mDerivativeIndex[0][i].derivators)+1 << rpar;
|
variable_table.getSymbolID(mDerivativeIndex[0][i].derivators)+1 << rpar;
|
||||||
jacobian_output << g1.str() << "=" << g1.str() << "+" << exp << ";\n";
|
jacobian_output << g1.str() << "=" << g1.str() << "+" << exp << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -770,7 +761,7 @@ string ModelTree::setStaticModel(void)
|
||||||
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";
|
||||||
|
|
||||||
StaticOutput << " residual = zeros( " << ModelParameters::eq_nbr << ", 1);\n";
|
StaticOutput << " residual = zeros( " << mod_param.eq_nbr << ", 1);\n";
|
||||||
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
||||||
StaticOutput << "Model equations\n\t";
|
StaticOutput << "Model equations\n\t";
|
||||||
StaticOutput << interfaces::comment() + "\n\n";
|
StaticOutput << interfaces::comment() + "\n\n";
|
||||||
|
@ -780,8 +771,8 @@ string ModelTree::setStaticModel(void)
|
||||||
StaticOutput << "end\n";
|
StaticOutput << "end\n";
|
||||||
StaticOutput << "if nargout >= 2,\n";
|
StaticOutput << "if nargout >= 2,\n";
|
||||||
StaticOutput << " g1 = " <<
|
StaticOutput << " g1 = " <<
|
||||||
"zeros(" << ModelParameters::eq_nbr << ", " <<
|
"zeros(" << mod_param.eq_nbr << ", " <<
|
||||||
ModelParameters::endo_nbr << ");\n" ;
|
mod_param.endo_nbr << ");\n" ;
|
||||||
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
||||||
StaticOutput << "Jacobian matrix\n\t";
|
StaticOutput << "Jacobian matrix\n\t";
|
||||||
StaticOutput << interfaces::comment() + "\n\n";
|
StaticOutput << interfaces::comment() + "\n\n";
|
||||||
|
@ -856,7 +847,7 @@ string ModelTree::setDynamicModel(void)
|
||||||
model_output << " = ";
|
model_output << " = ";
|
||||||
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
||||||
}
|
}
|
||||||
else if (lEquationNBR < ModelParameters::eq_nbr)
|
else if (lEquationNBR < mod_param.eq_nbr)
|
||||||
{
|
{
|
||||||
model_output << "lhs =";
|
model_output << "lhs =";
|
||||||
model_output << getExpression(((*tree_it)->id1), eDynamicEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression(((*tree_it)->id1), eDynamicEquations, lEquationNBR) << ";" << endl;
|
||||||
|
@ -925,7 +916,7 @@ string ModelTree::setDynamicModel(void)
|
||||||
lEquationNBR = 0;
|
lEquationNBR = 0;
|
||||||
for (unsigned int i = 0; i < mDerivativeIndex[0].size(); i++)
|
for (unsigned int i = 0; i < mDerivativeIndex[0].size(); i++)
|
||||||
{
|
{
|
||||||
if (computeJacobianExo || VariableTable::getType(mDerivativeIndex[0][i].derivators) == eEndogenous)
|
if (computeJacobianExo || variable_table.getType(mDerivativeIndex[0][i].derivators) == eEndogenous)
|
||||||
{
|
{
|
||||||
NodeID startJacobian = mDerivativeIndex[0][i].token_id;
|
NodeID startJacobian = mDerivativeIndex[0][i].token_id;
|
||||||
if (startJacobian != ZeroEqZero)
|
if (startJacobian != ZeroEqZero)
|
||||||
|
@ -933,7 +924,7 @@ string ModelTree::setDynamicModel(void)
|
||||||
string exp = getExpression(startJacobian->id1, eDynamicDerivatives);
|
string exp = getExpression(startJacobian->id1, eDynamicDerivatives);
|
||||||
ostringstream g1;
|
ostringstream g1;
|
||||||
g1 << " g1" << lpar << mDerivativeIndex[0][i].equation_id+1 << ", " <<
|
g1 << " g1" << lpar << mDerivativeIndex[0][i].equation_id+1 << ", " <<
|
||||||
VariableTable::getSortID(mDerivativeIndex[0][i].derivators)+1 << rpar;
|
variable_table.getSortID(mDerivativeIndex[0][i].derivators)+1 << rpar;
|
||||||
jacobian_output << g1.str() << "=" << g1.str() << "+" << exp << ";\n";
|
jacobian_output << g1.str() << "=" << g1.str() << "+" << exp << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -956,14 +947,14 @@ string ModelTree::setDynamicModel(void)
|
||||||
{
|
{
|
||||||
string exp = getExpression(startHessian->id1, eDynamicDerivatives);
|
string exp = getExpression(startHessian->id1, eDynamicDerivatives);
|
||||||
|
|
||||||
int varID1 = mDerivativeIndex[1][i].derivators/VariableTable::size();
|
int varID1 = mDerivativeIndex[1][i].derivators / variable_table.size();
|
||||||
int varID2 = mDerivativeIndex[1][i].derivators-varID1*VariableTable::size();
|
int varID2 = mDerivativeIndex[1][i].derivators - varID1 * variable_table.size();
|
||||||
hessian_output << " g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " <<
|
hessian_output << " g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " <<
|
||||||
mDerivativeIndex[1][i].derivators+1 << rpar << " = " << exp << ";\n";
|
mDerivativeIndex[1][i].derivators+1 << rpar << " = " << exp << ";\n";
|
||||||
// Treating symetric elements
|
// Treating symetric elements
|
||||||
if (varID1 != varID2)
|
if (varID1 != varID2)
|
||||||
lsymetric << " g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " <<
|
lsymetric << " g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " <<
|
||||||
varID2*VariableTable::size()+varID1+1 << rpar << " = " <<
|
varID2*variable_table.size()+varID1+1 << rpar << " = " <<
|
||||||
"g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " <<
|
"g2" << lpar << mDerivativeIndex[1][i].equation_id+1 << ", " <<
|
||||||
mDerivativeIndex[1][i].derivators+1 << rpar << ";\n";
|
mDerivativeIndex[1][i].derivators+1 << rpar << ";\n";
|
||||||
}
|
}
|
||||||
|
@ -971,8 +962,8 @@ string ModelTree::setDynamicModel(void)
|
||||||
}
|
}
|
||||||
cout << "done \n";
|
cout << "done \n";
|
||||||
}
|
}
|
||||||
int nrows = ModelParameters::eq_nbr;
|
int nrows = mod_param.eq_nbr;
|
||||||
int nvars = ModelParameters::var_endo_nbr+ModelParameters::exo_nbr+ModelParameters::exo_det_nbr;
|
int nvars = mod_param.var_endo_nbr + mod_param.exo_nbr + mod_param.exo_det_nbr;
|
||||||
if (offset == 1)
|
if (offset == 1)
|
||||||
{
|
{
|
||||||
DynamicOutput << "global M_ it_\n";
|
DynamicOutput << "global M_ it_\n";
|
||||||
|
@ -1163,16 +1154,16 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
|
||||||
}
|
}
|
||||||
else if (type == eLocalParameter)
|
else if (type == eLocalParameter)
|
||||||
{
|
{
|
||||||
argument << SymbolTable::getNameByID(eLocalParameter,(long int)id);
|
argument << symbol_table.getNameByID(eLocalParameter, (long int) id);
|
||||||
}
|
}
|
||||||
else if (type == eNumericalConstant)
|
else if (type == eNumericalConstant)
|
||||||
{
|
{
|
||||||
argument << NumericalConstants::get((long int) id);
|
argument << num_constants.get((long int) id);
|
||||||
}
|
}
|
||||||
else if (type == eEndogenous || type == eExogenous || type == eExogenousDet)
|
else if (type == eEndogenous || type == eExogenous || type == eExogenousDet)
|
||||||
if (iEquationType == eStaticEquations || iEquationType == eStaticDerivatives)
|
if (iEquationType == eStaticEquations || iEquationType == eStaticDerivatives)
|
||||||
{
|
{
|
||||||
int idx = VariableTable::getSymbolID((long int) id)+offset;
|
int idx = variable_table.getSymbolID((long int) id)+offset;
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
{
|
{
|
||||||
argument << "y" << lpar << idx << rpar;
|
argument << "y" << lpar << idx << rpar;
|
||||||
|
@ -1183,7 +1174,7 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
|
||||||
}
|
}
|
||||||
else if (type == eExogenousDet)
|
else if (type == eExogenousDet)
|
||||||
{
|
{
|
||||||
idx += ModelParameters::exo_nbr;
|
idx += mod_param.exo_nbr;
|
||||||
argument << "x" << lpar << idx << rpar;
|
argument << "x" << lpar << idx << rpar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1191,13 +1182,13 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
|
||||||
{
|
{
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
{
|
{
|
||||||
int idx = VariableTable::getPrintIndex((long int) id)+offset;
|
int idx = variable_table.getPrintIndex((long int) id) + offset;
|
||||||
argument << "y" << lpar << idx << rpar;
|
argument << "y" << lpar << idx << rpar;
|
||||||
}
|
}
|
||||||
else if (type == eExogenous)
|
else if (type == eExogenous)
|
||||||
{
|
{
|
||||||
int idx = VariableTable::getSymbolID((long int) id)+offset;
|
int idx = variable_table.getSymbolID((long int) id) + offset;
|
||||||
int lag = VariableTable::getLag((long int) id);
|
int lag = variable_table.getLag((long int) id);
|
||||||
if (offset == 1)
|
if (offset == 1)
|
||||||
{
|
{
|
||||||
if ( lag != 0)
|
if ( lag != 0)
|
||||||
|
@ -1225,8 +1216,8 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
|
||||||
}
|
}
|
||||||
else if (type == eExogenousDet)
|
else if (type == eExogenousDet)
|
||||||
{
|
{
|
||||||
int idx = VariableTable::getSymbolID((long int) id)+ModelParameters::exo_nbr+offset;
|
int idx = variable_table.getSymbolID((long int) id) + mod_param.exo_nbr + offset;
|
||||||
int lag = VariableTable::getLag((long int) id);
|
int lag = variable_table.getLag((long int) id);
|
||||||
if (offset == 1)
|
if (offset == 1)
|
||||||
{
|
{
|
||||||
if (lag != 0)
|
if (lag != 0)
|
||||||
|
@ -1261,13 +1252,13 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
|
||||||
void ModelTree::ModelInitialization(void)
|
void ModelTree::ModelInitialization(void)
|
||||||
{
|
{
|
||||||
// Exit if there is no equation in model file*/
|
// Exit if there is no equation in model file*/
|
||||||
if (ModelParameters::eq_nbr == 0)
|
if (mod_param.eq_nbr == 0)
|
||||||
{
|
{
|
||||||
(* error) ("no equations found in model file");
|
(* error) ("no equations found in model file");
|
||||||
}
|
}
|
||||||
cout << ModelParameters::eq_nbr << " equation(s) found \n";
|
cout << mod_param.eq_nbr << " equation(s) found \n";
|
||||||
// Sorting variable table
|
// Sorting variable table
|
||||||
VariableTable::Sort();
|
variable_table.Sort();
|
||||||
|
|
||||||
// Setting number of equations in ModelParameters class
|
// Setting number of equations in ModelParameters class
|
||||||
// Here no derivative are computed
|
// Here no derivative are computed
|
||||||
|
@ -1298,25 +1289,25 @@ void ModelTree::ModelInitialization(void)
|
||||||
output << "M_.lead_lag_incidence = [";
|
output << "M_.lead_lag_incidence = [";
|
||||||
/*
|
/*
|
||||||
zeros(" <<
|
zeros(" <<
|
||||||
ModelParameters::max_lag+ModelParameters::max_lead+1 << ", " <<
|
mod_param.max_lag+mod_param.max_lead+1 << ", " <<
|
||||||
ModelParameters::endo_nbr << ");\n";
|
mod_param.endo_nbr << ");\n";
|
||||||
*/
|
*/
|
||||||
// Loop on endogenous variables
|
// Loop on endogenous variables
|
||||||
for (int endoID = 0; endoID < ModelParameters::endo_nbr; endoID++)
|
for (int endoID = 0; endoID < mod_param.endo_nbr; endoID++)
|
||||||
{
|
{
|
||||||
output << "\n\t";
|
output << "\n\t";
|
||||||
// Loop on periods
|
// Loop on periods
|
||||||
for (int lag = -ModelParameters::max_endo_lag; lag <= ModelParameters::max_endo_lead; lag++)
|
for (int lag = -mod_param.max_endo_lag; lag <= mod_param.max_endo_lead; lag++)
|
||||||
{
|
{
|
||||||
// Getting name of symbol
|
// Getting name of symbol
|
||||||
string name = SymbolTable::getNameByID(eEndogenous, endoID);
|
string name = symbol_table.getNameByID(eEndogenous, endoID);
|
||||||
// and its variableID if exists with current period
|
// and its variableID if exists with current period
|
||||||
int varID = VariableTable::getID(name, lag);
|
int varID = variable_table.getID(name, lag);
|
||||||
//cout << name << " " << varID << " " << lag << " " << VariableTable::getPrintIndex(varID)+1 << " " << VariableTable::getSortID(varID)+1 << endl;
|
//cout << name << " " << varID << " " << lag << " " << variable_table.getPrintIndex(varID)+1 << " " << variable_table.getSortID(varID)+1 << endl;
|
||||||
|
|
||||||
if (varID >=0)
|
if (varID >=0)
|
||||||
{
|
{
|
||||||
output << " " << VariableTable::getPrintIndex(varID)+1;
|
output << " " << variable_table.getPrintIndex(varID) + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1328,36 +1319,36 @@ void ModelTree::ModelInitialization(void)
|
||||||
output << "]';\n";
|
output << "]';\n";
|
||||||
|
|
||||||
// Writing initialization for some other variables
|
// Writing initialization for some other variables
|
||||||
output << "M_.exo_names_orig_ord = [1:" << ModelParameters::exo_nbr << "];\n";
|
output << "M_.exo_names_orig_ord = [1:" << mod_param.exo_nbr << "];\n";
|
||||||
output << "M_.maximum_lag = " << ModelParameters::max_lag << ";\n";
|
output << "M_.maximum_lag = " << mod_param.max_lag << ";\n";
|
||||||
output << "M_.maximum_lead = " << ModelParameters::max_lead<< ";\n";
|
output << "M_.maximum_lead = " << mod_param.max_lead << ";\n";
|
||||||
if (ModelParameters::endo_nbr)
|
if (mod_param.endo_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_endo_lag = " << ModelParameters::max_endo_lag << ";\n";
|
output << "M_.maximum_endo_lag = " << mod_param.max_endo_lag << ";\n";
|
||||||
output << "M_.maximum_endo_lead = " << ModelParameters::max_endo_lead<< ";\n";
|
output << "M_.maximum_endo_lead = " << mod_param.max_endo_lead << ";\n";
|
||||||
output << "oo_.steady_state = zeros(" << ModelParameters::endo_nbr << ", 1);\n";
|
output << "oo_.steady_state = zeros(" << mod_param.endo_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (ModelParameters::exo_nbr)
|
if (mod_param.exo_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_exo_lag = " << ModelParameters::max_exo_lag << ";\n";
|
output << "M_.maximum_exo_lag = " << mod_param.max_exo_lag << ";\n";
|
||||||
output << "M_.maximum_exo_lead = " << ModelParameters::max_exo_lead<< ";\n";
|
output << "M_.maximum_exo_lead = " << mod_param.max_exo_lead << ";\n";
|
||||||
output << "oo_.exo_steady_state = zeros(" << ModelParameters::exo_nbr << ", 1);\n";
|
output << "oo_.exo_steady_state = zeros(" << mod_param.exo_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (ModelParameters::exo_det_nbr)
|
if (mod_param.exo_det_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_exo_det_lag = " << ModelParameters::max_exo_det_lag << ";\n";
|
output << "M_.maximum_exo_det_lag = " << mod_param.max_exo_det_lag << ";\n";
|
||||||
output << "M_.maximum_exo_det_lead = " << ModelParameters::max_exo_det_lead<< ";\n";
|
output << "M_.maximum_exo_det_lead = " << mod_param.max_exo_det_lead << ";\n";
|
||||||
output << "oo_.exo_det_steady_state = zeros(" << ModelParameters::exo_det_nbr << ", 1);\n";
|
output << "oo_.exo_det_steady_state = zeros(" << mod_param.exo_det_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (ModelParameters::recur_nbr)
|
if (mod_param.recur_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_recur_lag = " << ModelParameters::max_recur_lag << ";\n";
|
output << "M_.maximum_recur_lag = " << mod_param.max_recur_lag << ";\n";
|
||||||
output << "M_.maximum_recur_lead = " << ModelParameters::max_recur_lead<< ";\n";
|
output << "M_.maximum_recur_lead = " << mod_param.max_recur_lead << ";\n";
|
||||||
output << "oo_.recur_steady_state = zeros(" << ModelParameters::recur_nbr << ", 1);\n";
|
output << "oo_.recur_steady_state = zeros(" << mod_param.recur_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (ModelParameters::parameter_nbr)
|
if (mod_param.parameter_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.params = zeros(" << ModelParameters::parameter_nbr << ", 1);\n";
|
output << "M_.params = zeros(" << mod_param.parameter_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,89 +1389,3 @@ inline int ModelTree::optimize(NodeID node)
|
||||||
node->tmp_status = 0;
|
node->tmp_status = 0;
|
||||||
return tmp_status;
|
return tmp_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#ifdef TEST_MODELTREE
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
SymbolTable st;
|
|
||||||
VariableTable vt;
|
|
||||||
NumericalConstants nc;
|
|
||||||
ModelTree model;
|
|
||||||
vector<int> t(20);
|
|
||||||
|
|
||||||
//Adding 2 different symbols with AddSymbolDeclar
|
|
||||||
SymbolTable::AddSymbolDeclar("c",eExogenous);
|
|
||||||
//SymbolTable::PrintSymbolTable();
|
|
||||||
SymbolTable::AddSymbolDeclar("k",eEndogenous);
|
|
||||||
//SymbolTable::PrintSymbolTable();
|
|
||||||
SymbolTable::AddSymbolDeclar("aa",eParameter);
|
|
||||||
//SymbolTable::PrintSymbolTable();
|
|
||||||
SymbolTable::AddSymbolDeclar("x",eExogenous);
|
|
||||||
SymbolTable::AddSymbolDeclar("alph",eParameter);
|
|
||||||
SymbolTable::AddSymbolDeclar("delt",eParameter);
|
|
||||||
|
|
||||||
VariableTable::AddVariable("k",0);
|
|
||||||
VariableTable::AddVariable("x",-1);
|
|
||||||
VariableTable::AddVariable("c",-1);
|
|
||||||
|
|
||||||
SymbolTable::AddSymbolDeclar("x1",eEndogenous);
|
|
||||||
SymbolTable::AddSymbolDeclar("x2",eExogenousDet);
|
|
||||||
//SymbolTable::AddSymbolDeclar("x3",eExogenous);
|
|
||||||
|
|
||||||
VariableTable::AddVariable("x1",-1);
|
|
||||||
VariableTable::AddVariable("x2",1);
|
|
||||||
//VariableTable::AddVariable("x3",-1);
|
|
||||||
//VariableTable::AddVariable("k",1);
|
|
||||||
//VariableTable::AddVariable("y",0);
|
|
||||||
|
|
||||||
t[0] = model.AddToken("aa");
|
|
||||||
t[1] = model.AddToken("x",-1);
|
|
||||||
t[2] = model.AddToken("k",0);
|
|
||||||
t[3] = model.AddToken(Argument(t[0], eTempResult),
|
|
||||||
Argument(t[1], eTempResult), TIMES);
|
|
||||||
t[4] = model.AddToken("alph");
|
|
||||||
t[5] = model.AddToken(Argument(t[2], eTempResult),
|
|
||||||
Argument(t[4], eTempResult), POWER);
|
|
||||||
t[6] = model.AddToken(Argument(t[3], eTempResult),
|
|
||||||
Argument(t[5], eTempResult), TIMES);
|
|
||||||
|
|
||||||
t[7] = model.AddToken("delt");
|
|
||||||
//t[8] = model.AddToken("1");
|
|
||||||
t[9] = model.AddToken(Argument(1, eTempResult),
|
|
||||||
Argument(t[7], eTempResult), MINUS);
|
|
||||||
t[10] = model.AddToken(Argument(t[9], eTempResult),
|
|
||||||
Argument(t[2], eTempResult), TIMES);
|
|
||||||
|
|
||||||
t[11] = model.AddToken(Argument(t[2], eTempResult),
|
|
||||||
UMINUS);
|
|
||||||
|
|
||||||
t[12] = model.AddToken(Argument(t[11], eTempResult),
|
|
||||||
Argument(t[6], eTempResult), PLUS);
|
|
||||||
t[13] = model.AddToken(Argument(t[12], eTempResult),
|
|
||||||
Argument(t[10], eTempResult), PLUS);
|
|
||||||
t[14] = model.AddToken(Argument(t[13], eTempResult),
|
|
||||||
Argument(t[10], eTempResult), PLUS);
|
|
||||||
t[15] = model.AddToken("c",-1);
|
|
||||||
t[16] = model.AddToken(Argument(t[15], eTempResult),
|
|
||||||
Argument(t[14], eTempResult), EQUAL);
|
|
||||||
//try
|
|
||||||
//{
|
|
||||||
model.derive(2);
|
|
||||||
model.setStaticModel();
|
|
||||||
model.setDynamicStochasticModel();
|
|
||||||
model.Open("static_model.m", "dynamic_model.m");
|
|
||||||
model.Save();
|
|
||||||
//cout << model.getStaticModel();
|
|
||||||
//}
|
|
||||||
//catch(Error err)
|
|
||||||
//{
|
|
||||||
// cout << "error---------------------\n";
|
|
||||||
// exit(-1);
|
|
||||||
//}
|
|
||||||
//cout << model.getDynamicDeterministicModel() << endl;
|
|
||||||
//cout << model.getDynamicStochasticModel() << endl;
|
|
||||||
//VariableTable::Sort();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
|
@ -8,11 +8,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include "NumericalConstants.hh"
|
#include "NumericalConstants.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
vector<string> NumericalConstants::mNumericalConstants;
|
|
||||||
map<string, int, less<string> > NumericalConstants::numConstantsIndex;
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
NumericalConstants::NumericalConstants()
|
NumericalConstants::NumericalConstants()
|
||||||
{
|
{
|
||||||
AddConstant("0.0");
|
AddConstant("0.0");
|
||||||
|
@ -40,7 +36,7 @@ int NumericalConstants::AddConstant(string iConst)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
string NumericalConstants::get(int ID)
|
string NumericalConstants::get(int ID) const
|
||||||
{
|
{
|
||||||
if (ID < (int)mNumericalConstants.size())
|
if (ID < (int)mNumericalConstants.size())
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,10 +8,11 @@ using namespace std;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include "NumericalInitialization.hh"
|
#include "NumericalInitialization.hh"
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
//ostringstream NumericalInitialization::output;
|
NumericalInitialization::NumericalInitialization(const SymbolTable &symbol_table_arg,
|
||||||
//------------------------------------------------------------------------------
|
const ModelParameters &mod_param_arg) :
|
||||||
NumericalInitialization::NumericalInitialization()
|
symbol_table(symbol_table_arg),
|
||||||
|
mod_param(mod_param_arg)
|
||||||
{
|
{
|
||||||
//Empty
|
//Empty
|
||||||
}
|
}
|
||||||
|
@ -33,20 +34,20 @@ void NumericalInitialization::SetConstant (string name, string expression)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Testing if symbol exists
|
//Testing if symbol exists
|
||||||
if (!SymbolTable::Exist(name))
|
if (!symbol_table.Exist(name))
|
||||||
{
|
{
|
||||||
string msg = "Unknown parameter: " + name;
|
string msg = "Unknown parameter: " + name;
|
||||||
(* error) (msg.c_str());
|
(* error) (msg.c_str());
|
||||||
}
|
}
|
||||||
// Testing symbol type
|
// Testing symbol type
|
||||||
if (SymbolTable::getType(name) != eParameter)
|
if (symbol_table.getType(name) != eParameter)
|
||||||
{
|
{
|
||||||
string msg = "Non-parameter used as a parameter: " + name;
|
string msg = "Non-parameter used as a parameter: " + name;
|
||||||
(* error) (msg.c_str());
|
(* error) (msg.c_str());
|
||||||
}
|
}
|
||||||
// Writing expression
|
// Writing expression
|
||||||
*output << "M_.params( " << SymbolTable::getID(name)+1 << " ) = " << expression << ";\n";
|
*output << "M_.params( " << symbol_table.getID(name)+1 << " ) = " << expression << ";\n";
|
||||||
*output << name << " = M_.params( " << SymbolTable::getID(name)+1 << " );\n";
|
*output << name << " = M_.params( " << symbol_table.getID(name)+1 << " );\n";
|
||||||
// Deleting expression
|
// Deleting expression
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
|
@ -61,10 +62,9 @@ void NumericalInitialization::BeginInitval (void)
|
||||||
<< interfaces::comment() << "\n";
|
<< interfaces::comment() << "\n";
|
||||||
// Writing initval block to set initial values for variables
|
// Writing initval block to set initial values for variables
|
||||||
*output << "options_.initval_file = 0;\nendval_=0;\n";
|
*output << "options_.initval_file = 0;\nendval_=0;\n";
|
||||||
if(ModelParameters::recur_nbr > 0)
|
|
||||||
{
|
if (mod_param.recur_nbr > 0)
|
||||||
*output << "recurs_ = zeros(" << ModelParameters::recur_nbr << ", 1);\n";
|
*output << "recurs_ = zeros(" << mod_param.recur_nbr << ", 1);\n";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -72,13 +72,13 @@ void NumericalInitialization::SetInit (string name, string expression)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Testing if symbol exists
|
//Testing if symbol exists
|
||||||
if (!SymbolTable::Exist(name))
|
if (!symbol_table.Exist(name))
|
||||||
{
|
{
|
||||||
string msg = "Unknown variable: " + name;
|
string msg = "Unknown variable: " + name;
|
||||||
(* error) (msg.c_str());
|
(* error) (msg.c_str());
|
||||||
}
|
}
|
||||||
Type type = SymbolTable::getType(name);
|
Type type = symbol_table.getType(name);
|
||||||
int id = SymbolTable::getID(name);
|
int id = symbol_table.getID(name);
|
||||||
// Writing instrcuction that set initial or terminal value
|
// Writing instrcuction that set initial or terminal value
|
||||||
// for a variable
|
// for a variable
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
|
@ -141,13 +141,13 @@ void NumericalInitialization::BeginHistval (void)
|
||||||
void NumericalInitialization::SetHist (string name, int lag, string expression)
|
void NumericalInitialization::SetHist (string name, int lag, string expression)
|
||||||
{
|
{
|
||||||
//Testing if symbol exists
|
//Testing if symbol exists
|
||||||
if (!SymbolTable::Exist(name))
|
if (!symbol_table.Exist(name))
|
||||||
{
|
{
|
||||||
string msg = "Unknown parameter: " + name;
|
string msg = "Unknown parameter: " + name;
|
||||||
(* error) (msg.c_str());
|
(* error) (msg.c_str());
|
||||||
}
|
}
|
||||||
Type type = SymbolTable::getType(name);
|
Type type = symbol_table.getType(name);
|
||||||
int id = SymbolTable::getID(name);
|
int id = symbol_table.getID(name);
|
||||||
// Testing symbol type
|
// Testing symbol type
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,7 @@ OutputFile::~OutputFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void OutputFile::Open(string iFileName)
|
void OutputFile::Open(string iFileName, ModFile *mod_file)
|
||||||
{
|
{
|
||||||
if (iFileName.size())
|
if (iFileName.size())
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ void OutputFile::Open(string iFileName)
|
||||||
mOutputFile << "warning on;\nwarning backtrace;\n";
|
mOutputFile << "warning on;\nwarning backtrace;\n";
|
||||||
mOutputFile << "logname_ = '" << iFileName << ".log';\n";
|
mOutputFile << "logname_ = '" << iFileName << ".log';\n";
|
||||||
mOutputFile << "diary '" << iFileName << ".log';\n";
|
mOutputFile << "diary '" << iFileName << ".log';\n";
|
||||||
if (ModelTree::offset == 0)
|
if (mod_file->model_tree.offset == 0)
|
||||||
{
|
{
|
||||||
mOutputFile << "if ";
|
mOutputFile << "if ";
|
||||||
mOutputFile << interfaces::file_exist(iFileName + "_static.c)")+"\n";
|
mOutputFile << interfaces::file_exist(iFileName + "_static.c)")+"\n";
|
||||||
|
@ -89,10 +89,10 @@ void OutputFile::Open(string iFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void OutputFile::Save(ostringstream& iOutput)
|
void OutputFile::Save(ostringstream& iOutput, ModFile *mod_file)
|
||||||
{
|
{
|
||||||
mOutputFile << SymbolTable::get();
|
mOutputFile << mod_file->symbol_table.get();
|
||||||
mOutputFile << ModelTree::get();
|
mOutputFile << mod_file->model_tree.get();
|
||||||
mOutputFile << iOutput.str();
|
mOutputFile << iOutput.str();
|
||||||
mOutputFile << "\ndisp(['Total computing time : ' sec2hms(round(toc)) ]);\n";
|
mOutputFile << "\ndisp(['Total computing time : ' sec2hms(round(toc)) ]);\n";
|
||||||
mOutputFile.close();
|
mOutputFile.close();
|
||||||
|
|
|
@ -2,25 +2,36 @@
|
||||||
|
|
||||||
ParsingDriver::ParsingDriver() : trace_scanning(false), trace_parsing(false)
|
ParsingDriver::ParsingDriver() : trace_scanning(false), trace_parsing(false)
|
||||||
{
|
{
|
||||||
order = -1;
|
mod_file = new ModFile();
|
||||||
linear = -1;
|
mod_file->order = -1;
|
||||||
model_tree.error = error;
|
mod_file->linear = -1;
|
||||||
symbol_table.error = error;
|
|
||||||
variable_table.error = error;
|
mod_file->model_tree.error = error;
|
||||||
shocks.error = error;
|
mod_file->symbol_table.error = error;
|
||||||
numerical_initialization.error = error;
|
mod_file->variable_table.error = error;
|
||||||
computing_tasks.error = error;
|
mod_file->shocks.error = error;
|
||||||
|
mod_file->numerical_initialization.error = error;
|
||||||
|
mod_file->computing_tasks.error = error;
|
||||||
tmp_symbol_table.error = error;
|
tmp_symbol_table.error = error;
|
||||||
|
|
||||||
|
tmp_symbol_table.setGlobalSymbolTable(&mod_file->symbol_table);
|
||||||
|
expression.setNumericalConstants(&mod_file->num_constants);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParsingDriver::~ParsingDriver()
|
ParsingDriver::~ParsingDriver()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ParsingDriver::exists_symbol(const char *s)
|
||||||
|
{
|
||||||
|
return mod_file->symbol_table.Exist(s);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::check_symbol_existence(const string &name)
|
ParsingDriver::check_symbol_existence(const string &name)
|
||||||
{
|
{
|
||||||
if (!symbol_table.Exist(name))
|
if (!mod_file->symbol_table.Exist(name))
|
||||||
error("Unknown symbol: " + name);
|
error("Unknown symbol: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +47,10 @@ ParsingDriver::get_expression(ExpObj *exp)
|
||||||
return sexp;
|
return sexp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return Expression::getArgument(exp->second, exp->first);
|
return expression.getArgument(exp->second, exp->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
ModFile *
|
||||||
ParsingDriver::parse(const string &f)
|
ParsingDriver::parse(const string &f)
|
||||||
{
|
{
|
||||||
file = f;
|
file = f;
|
||||||
|
@ -48,6 +59,7 @@ ParsingDriver::parse(const string &f)
|
||||||
parser.set_debug_level(trace_parsing);
|
parser.set_debug_level(trace_parsing);
|
||||||
parser.parse();
|
parser.parse();
|
||||||
scan_end();
|
scan_end();
|
||||||
|
return mod_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -60,8 +72,7 @@ ParsingDriver::error(const yy::parser::location_type &l, const string &m)
|
||||||
void
|
void
|
||||||
ParsingDriver::error(const string &m)
|
ParsingDriver::error(const string &m)
|
||||||
{
|
{
|
||||||
extern int yylineno;
|
cerr << file << ": " << m << endl;
|
||||||
cerr << file << ":" << yylineno << ": " << m << endl;
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,16 +80,16 @@ void
|
||||||
ParsingDriver::setoutput(ostringstream *ostr)
|
ParsingDriver::setoutput(ostringstream *ostr)
|
||||||
{
|
{
|
||||||
output = ostr;
|
output = ostr;
|
||||||
numerical_initialization.setOutput(ostr);
|
mod_file->numerical_initialization.setOutput(ostr);
|
||||||
shocks.setOutput(ostr);
|
mod_file->shocks.setOutput(ostr);
|
||||||
sigmae.setOutput(ostr);
|
mod_file->sigmae.setOutput(ostr);
|
||||||
computing_tasks.setOutput(ostr);
|
mod_file->computing_tasks.setOutput(ostr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_endogenous(string *name, string *tex_name)
|
ParsingDriver::declare_endogenous(string *name, string *tex_name)
|
||||||
{
|
{
|
||||||
symbol_table.AddSymbolDeclar(*name, eEndogenous, *tex_name);
|
mod_file->symbol_table.AddSymbolDeclar(*name, eEndogenous, *tex_name);
|
||||||
delete name;
|
delete name;
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +97,7 @@ ParsingDriver::declare_endogenous(string *name, string *tex_name)
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_exogenous(string *name, string *tex_name)
|
ParsingDriver::declare_exogenous(string *name, string *tex_name)
|
||||||
{
|
{
|
||||||
symbol_table.AddSymbolDeclar(*name, eExogenous, *tex_name);
|
mod_file->symbol_table.AddSymbolDeclar(*name, eExogenous, *tex_name);
|
||||||
delete name;
|
delete name;
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +105,7 @@ ParsingDriver::declare_exogenous(string *name, string *tex_name)
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_exogenous_det(string *name, string *tex_name)
|
ParsingDriver::declare_exogenous_det(string *name, string *tex_name)
|
||||||
{
|
{
|
||||||
symbol_table.AddSymbolDeclar(*name, eExogenousDet, *tex_name);
|
mod_file->symbol_table.AddSymbolDeclar(*name, eExogenousDet, *tex_name);
|
||||||
delete name;
|
delete name;
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +113,7 @@ ParsingDriver::declare_exogenous_det(string *name, string *tex_name)
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_parameter(string *name, string *tex_name)
|
ParsingDriver::declare_parameter(string *name, string *tex_name)
|
||||||
{
|
{
|
||||||
symbol_table.AddSymbolDeclar(*name, eParameter, *tex_name);
|
mod_file->symbol_table.AddSymbolDeclar(*name, eParameter, *tex_name);
|
||||||
delete name;
|
delete name;
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +121,7 @@ ParsingDriver::declare_parameter(string *name, string *tex_name)
|
||||||
ExpObj *
|
ExpObj *
|
||||||
ParsingDriver::add_expression_constant(string *constant)
|
ParsingDriver::add_expression_constant(string *constant)
|
||||||
{
|
{
|
||||||
int id = num_constants.AddConstant(*constant);
|
int id = mod_file->num_constants.AddConstant(*constant);
|
||||||
delete constant;
|
delete constant;
|
||||||
return new ExpObj(id, eNumericalConstant);
|
return new ExpObj(id, eNumericalConstant);
|
||||||
}
|
}
|
||||||
|
@ -118,23 +129,23 @@ ParsingDriver::add_expression_constant(string *constant)
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_constant(string *constant)
|
ParsingDriver::add_model_constant(string *constant)
|
||||||
{
|
{
|
||||||
int id = num_constants.AddConstant(*constant);
|
int id = mod_file->num_constants.AddConstant(*constant);
|
||||||
delete constant;
|
delete constant;
|
||||||
return model_tree.AddTerminal((NodeID) id, eNumericalConstant);
|
return mod_file->model_tree.AddTerminal((NodeID) id, eNumericalConstant);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_variable(string *name)
|
ParsingDriver::add_model_variable(string *name)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
Type type = symbol_table.getType(*name);
|
Type type = mod_file->symbol_table.getType(*name);
|
||||||
|
|
||||||
if ((type == eEndogenous)
|
if ((type == eEndogenous)
|
||||||
|| (type == eExogenous)
|
|| (type == eExogenous)
|
||||||
|| (type == eExogenousDet))
|
|| (type == eExogenousDet))
|
||||||
variable_table.AddVariable(*name, 0);
|
mod_file->variable_table.AddVariable(*name, 0);
|
||||||
|
|
||||||
NodeID id = model_tree.AddTerminal(*name);
|
NodeID id = mod_file->model_tree.AddTerminal(*name);
|
||||||
delete name;
|
delete name;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +154,7 @@ NodeID
|
||||||
ParsingDriver::add_model_variable(string *name, string *olag)
|
ParsingDriver::add_model_variable(string *name, string *olag)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
Type type = symbol_table.getType(*name);
|
Type type = mod_file->symbol_table.getType(*name);
|
||||||
int lag = atoi(olag->c_str());
|
int lag = atoi(olag->c_str());
|
||||||
|
|
||||||
if ((type == eExogenous) && lag != 0)
|
if ((type == eExogenous) && lag != 0)
|
||||||
|
@ -154,9 +165,9 @@ ParsingDriver::add_model_variable(string *name, string *olag)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type == eEndogenous) || (type == eExogenous))
|
if ((type == eEndogenous) || (type == eExogenous))
|
||||||
variable_table.AddVariable(*name, lag);
|
mod_file->variable_table.AddVariable(*name, lag);
|
||||||
|
|
||||||
NodeID id = model_tree.AddTerminal(*name, lag);
|
NodeID id = mod_file->model_tree.AddTerminal(*name, lag);
|
||||||
delete name;
|
delete name;
|
||||||
delete olag;
|
delete olag;
|
||||||
return id;
|
return id;
|
||||||
|
@ -166,8 +177,8 @@ ExpObj *
|
||||||
ParsingDriver::add_expression_variable(string *name)
|
ParsingDriver::add_expression_variable(string *name)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*name);
|
check_symbol_existence(*name);
|
||||||
int id = symbol_table.getID(*name);
|
int id = mod_file->symbol_table.getID(*name);
|
||||||
Type type = symbol_table.getType(*name);
|
Type type = mod_file->symbol_table.getType(*name);
|
||||||
delete name;
|
delete name;
|
||||||
return new ExpObj(id, type);
|
return new ExpObj(id, type);
|
||||||
}
|
}
|
||||||
|
@ -203,7 +214,7 @@ ParsingDriver::add_expression_token(ExpObj *arg1, string *op_name)
|
||||||
void
|
void
|
||||||
ParsingDriver::init_param(string *name, ExpObj *rhs)
|
ParsingDriver::init_param(string *name, ExpObj *rhs)
|
||||||
{
|
{
|
||||||
numerical_initialization.SetConstant(*name, get_expression(rhs));
|
mod_file->numerical_initialization.SetConstant(*name, get_expression(rhs));
|
||||||
delete name;
|
delete name;
|
||||||
delete rhs;
|
delete rhs;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +222,7 @@ ParsingDriver::init_param(string *name, ExpObj *rhs)
|
||||||
void
|
void
|
||||||
ParsingDriver::init_val(string *name, ExpObj *rhs)
|
ParsingDriver::init_val(string *name, ExpObj *rhs)
|
||||||
{
|
{
|
||||||
numerical_initialization.SetInit(*name, get_expression(rhs));
|
mod_file->numerical_initialization.SetInit(*name, get_expression(rhs));
|
||||||
delete name;
|
delete name;
|
||||||
delete rhs;
|
delete rhs;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +231,7 @@ void
|
||||||
ParsingDriver::hist_val(string *name, string *lag, ExpObj *rhs)
|
ParsingDriver::hist_val(string *name, string *lag, ExpObj *rhs)
|
||||||
{
|
{
|
||||||
int ilag = atoi(lag->c_str());
|
int ilag = atoi(lag->c_str());
|
||||||
numerical_initialization.SetHist(*name, ilag, get_expression(rhs));
|
mod_file->numerical_initialization.SetHist(*name, ilag, get_expression(rhs));
|
||||||
delete name;
|
delete name;
|
||||||
delete lag;
|
delete lag;
|
||||||
delete rhs;
|
delete rhs;
|
||||||
|
@ -230,14 +241,7 @@ void
|
||||||
ParsingDriver::use_dll()
|
ParsingDriver::use_dll()
|
||||||
{
|
{
|
||||||
// Seetting variable momber offset to use C outputs
|
// Seetting variable momber offset to use C outputs
|
||||||
model_tree.offset = 0;
|
mod_file->model_tree.offset = 0;
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ParsingDriver::check_model()
|
|
||||||
{
|
|
||||||
// creates too many problems MJ 11/12/06
|
|
||||||
// symbol_table.clean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -246,42 +250,38 @@ ParsingDriver::finish()
|
||||||
string model_file_name(file);
|
string model_file_name(file);
|
||||||
|
|
||||||
// Setting flags to compute what is necessary
|
// Setting flags to compute what is necessary
|
||||||
if (order == 1 || linear == 1)
|
if (mod_file->order == 1 || mod_file->linear == 1)
|
||||||
{
|
{
|
||||||
model_tree.computeJacobianExo = true;
|
mod_file->model_tree.computeJacobianExo = true;
|
||||||
model_tree.computeJacobian = false;
|
mod_file->model_tree.computeJacobian = false;
|
||||||
}
|
}
|
||||||
else if (order != -1 && linear != -1)
|
else if (mod_file->order != -1 && mod_file->linear != -1)
|
||||||
{
|
{
|
||||||
model_tree.computeHessian = true;
|
mod_file->model_tree.computeHessian = true;
|
||||||
model_tree.computeJacobianExo = true;
|
mod_file->model_tree.computeJacobianExo = true;
|
||||||
}
|
}
|
||||||
// Removing extension chars
|
// Removing extension chars
|
||||||
model_file_name.erase(model_file_name.size()-4,4);
|
model_file_name.erase(model_file_name.size()-4,4);
|
||||||
model_tree.ModelInitialization();
|
mod_file->model_tree.ModelInitialization();
|
||||||
|
|
||||||
if ( model_tree.computeHessian )
|
if (mod_file->model_tree.computeHessian )
|
||||||
{
|
mod_file->model_tree.derive(2);
|
||||||
model_tree.derive(2);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
mod_file->model_tree.derive(1);
|
||||||
model_tree.derive(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Processing outputs ..." << endl;
|
cout << "Processing outputs ..." << endl;
|
||||||
model_tree.setStaticModel();
|
mod_file->model_tree.setStaticModel();
|
||||||
model_tree.setDynamicModel();
|
mod_file->model_tree.setDynamicModel();
|
||||||
|
|
||||||
if (model_tree.offset == 0)
|
if (mod_file->model_tree.offset == 0)
|
||||||
{
|
{
|
||||||
model_tree.OpenCFiles(model_file_name+"_static", model_file_name+"_dynamic");
|
mod_file->model_tree.OpenCFiles(model_file_name+"_static", model_file_name+"_dynamic");
|
||||||
model_tree.SaveCFiles();
|
mod_file->model_tree.SaveCFiles();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
model_tree.OpenMFiles(model_file_name+"_static", model_file_name+"_dynamic");
|
mod_file->model_tree.OpenMFiles(model_file_name+"_static", model_file_name+"_dynamic");
|
||||||
model_tree.SaveMFiles();
|
mod_file->model_tree.SaveMFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
*output << "save('" << model_file_name << "_results', 'oo_');\n";
|
*output << "save('" << model_file_name << "_results', 'oo_');\n";
|
||||||
|
@ -293,63 +293,63 @@ ParsingDriver::finish()
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_initval()
|
ParsingDriver::begin_initval()
|
||||||
{
|
{
|
||||||
numerical_initialization.BeginInitval();
|
mod_file->numerical_initialization.BeginInitval();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::end_initval()
|
ParsingDriver::end_initval()
|
||||||
{
|
{
|
||||||
numerical_initialization.EndInitval();
|
mod_file->numerical_initialization.EndInitval();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_endval()
|
ParsingDriver::begin_endval()
|
||||||
{
|
{
|
||||||
numerical_initialization.BeginEndval();
|
mod_file->numerical_initialization.BeginEndval();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::end_endval()
|
ParsingDriver::end_endval()
|
||||||
{
|
{
|
||||||
numerical_initialization.EndEndval();
|
mod_file->numerical_initialization.EndEndval();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_histval()
|
ParsingDriver::begin_histval()
|
||||||
{
|
{
|
||||||
numerical_initialization.BeginHistval();
|
mod_file->numerical_initialization.BeginHistval();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_shocks()
|
ParsingDriver::begin_shocks()
|
||||||
{
|
{
|
||||||
shocks.BeginShocks();
|
mod_file->shocks.BeginShocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_mshocks()
|
ParsingDriver::begin_mshocks()
|
||||||
{
|
{
|
||||||
shocks.BeginMShocks();
|
mod_file->shocks.BeginMShocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::end_shocks()
|
ParsingDriver::end_shocks()
|
||||||
{
|
{
|
||||||
shocks.EndShocks();
|
mod_file->shocks.EndShocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_det_shock(string *var)
|
ParsingDriver::add_det_shock(string *var)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var);
|
check_symbol_existence(*var);
|
||||||
int id = symbol_table.getID(*var);
|
int id = mod_file->symbol_table.getID(*var);
|
||||||
switch (symbol_table.getType(*var))
|
switch (mod_file->symbol_table.getType(*var))
|
||||||
{
|
{
|
||||||
case eExogenous:
|
case eExogenous:
|
||||||
shocks.AddDetShockExo(id);
|
mod_file->shocks.AddDetShockExo(id);
|
||||||
break;
|
break;
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
shocks.AddDetShockExoDet(id);
|
mod_file->shocks.AddDetShockExoDet(id);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Shocks can only be applied to exogenous variables");
|
error("Shocks can only be applied to exogenous variables");
|
||||||
|
@ -361,8 +361,8 @@ void
|
||||||
ParsingDriver::add_stderr_shock(string *var, ExpObj *value)
|
ParsingDriver::add_stderr_shock(string *var, ExpObj *value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var);
|
check_symbol_existence(*var);
|
||||||
int id = symbol_table.getID(*var);
|
int id = mod_file->symbol_table.getID(*var);
|
||||||
shocks.AddSTDShock(id, get_expression(value));
|
mod_file->shocks.AddSTDShock(id, get_expression(value));
|
||||||
delete var;
|
delete var;
|
||||||
delete value;
|
delete value;
|
||||||
}
|
}
|
||||||
|
@ -371,8 +371,8 @@ void
|
||||||
ParsingDriver::add_var_shock(string *var, ExpObj *value)
|
ParsingDriver::add_var_shock(string *var, ExpObj *value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var);
|
check_symbol_existence(*var);
|
||||||
int id = symbol_table.getID(*var);
|
int id = mod_file->symbol_table.getID(*var);
|
||||||
shocks.AddVARShock(id, get_expression(value));
|
mod_file->shocks.AddVARShock(id, get_expression(value));
|
||||||
delete var;
|
delete var;
|
||||||
delete value;
|
delete value;
|
||||||
}
|
}
|
||||||
|
@ -382,9 +382,9 @@ ParsingDriver::add_covar_shock(string *var1, string *var2, ExpObj *value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var1);
|
check_symbol_existence(*var1);
|
||||||
check_symbol_existence(*var2);
|
check_symbol_existence(*var2);
|
||||||
int id1 = symbol_table.getID(*var1);
|
int id1 = mod_file->symbol_table.getID(*var1);
|
||||||
int id2 = symbol_table.getID(*var2);
|
int id2 = mod_file->symbol_table.getID(*var2);
|
||||||
shocks.AddCOVAShock(id1, id2, get_expression(value));
|
mod_file->shocks.AddCOVAShock(id1, id2, get_expression(value));
|
||||||
delete var1;
|
delete var1;
|
||||||
delete var2;
|
delete var2;
|
||||||
delete value;
|
delete value;
|
||||||
|
@ -395,9 +395,9 @@ ParsingDriver::add_correl_shock(string *var1, string *var2, ExpObj *value)
|
||||||
{
|
{
|
||||||
check_symbol_existence(*var1);
|
check_symbol_existence(*var1);
|
||||||
check_symbol_existence(*var2);
|
check_symbol_existence(*var2);
|
||||||
int id1 = symbol_table.getID(*var1);
|
int id1 = mod_file->symbol_table.getID(*var1);
|
||||||
int id2 = symbol_table.getID(*var2);
|
int id2 = mod_file->symbol_table.getID(*var2);
|
||||||
shocks.AddCORRShock(id1, id2, get_expression(value));
|
mod_file->shocks.AddCORRShock(id1, id2, get_expression(value));
|
||||||
delete var1;
|
delete var1;
|
||||||
delete var2;
|
delete var2;
|
||||||
delete value;
|
delete value;
|
||||||
|
@ -406,7 +406,7 @@ ParsingDriver::add_correl_shock(string *var1, string *var2, ExpObj *value)
|
||||||
void
|
void
|
||||||
ParsingDriver::add_period(string *p1, string *p2)
|
ParsingDriver::add_period(string *p1, string *p2)
|
||||||
{
|
{
|
||||||
shocks.AddPeriod(*p1, *p2);
|
mod_file->shocks.AddPeriod(*p1, *p2);
|
||||||
delete p1;
|
delete p1;
|
||||||
delete p2;
|
delete p2;
|
||||||
}
|
}
|
||||||
|
@ -414,61 +414,61 @@ ParsingDriver::add_period(string *p1, string *p2)
|
||||||
void
|
void
|
||||||
ParsingDriver::add_period(string *p1)
|
ParsingDriver::add_period(string *p1)
|
||||||
{
|
{
|
||||||
shocks.AddPeriod(*p1, *p1);
|
mod_file->shocks.AddPeriod(*p1, *p1);
|
||||||
delete p1;
|
delete p1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_value(string *value)
|
ParsingDriver::add_value(string *value)
|
||||||
{
|
{
|
||||||
shocks.AddValue(*value);
|
mod_file->shocks.AddValue(*value);
|
||||||
delete value;
|
delete value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_value(ExpObj *value)
|
ParsingDriver::add_value(ExpObj *value)
|
||||||
{
|
{
|
||||||
shocks.AddValue(get_expression(value));
|
mod_file->shocks.AddValue(get_expression(value));
|
||||||
delete value;
|
delete value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::do_sigma_e()
|
ParsingDriver::do_sigma_e()
|
||||||
{
|
{
|
||||||
sigmae.set();
|
mod_file->sigmae.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::end_of_row()
|
ParsingDriver::end_of_row()
|
||||||
{
|
{
|
||||||
sigmae.EndOfRow();
|
mod_file->sigmae.EndOfRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_to_row(string *s)
|
ParsingDriver::add_to_row(string *s)
|
||||||
{
|
{
|
||||||
sigmae.AddExpression(*s);
|
mod_file->sigmae.AddExpression(*s);
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_to_row(ExpObj *v)
|
ParsingDriver::add_to_row(ExpObj *v)
|
||||||
{
|
{
|
||||||
sigmae.AddExpression(get_expression(v));
|
mod_file->sigmae.AddExpression(get_expression(v));
|
||||||
delete v;
|
delete v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::steady()
|
ParsingDriver::steady()
|
||||||
{
|
{
|
||||||
computing_tasks.setSteady();
|
mod_file->computing_tasks.setSteady();
|
||||||
model_tree.computeJacobian = true;
|
mod_file->model_tree.computeJacobian = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::option_num(const string &name_option, string *opt1, string *opt2)
|
ParsingDriver::option_num(const string &name_option, string *opt1, string *opt2)
|
||||||
{
|
{
|
||||||
computing_tasks.setOption(name_option, *opt1, *opt2);
|
mod_file->computing_tasks.setOption(name_option, *opt1, *opt2);
|
||||||
delete opt1;
|
delete opt1;
|
||||||
delete opt2;
|
delete opt2;
|
||||||
}
|
}
|
||||||
|
@ -483,11 +483,11 @@ ParsingDriver::option_num(const string &name_option, string *opt)
|
||||||
void
|
void
|
||||||
ParsingDriver::option_num(const string &name_option, const string &opt)
|
ParsingDriver::option_num(const string &name_option, const string &opt)
|
||||||
{
|
{
|
||||||
computing_tasks.setOption(name_option, opt);
|
mod_file->computing_tasks.setOption(name_option, opt);
|
||||||
if (name_option == "order")
|
if (name_option == "order")
|
||||||
order = atoi(opt.c_str());
|
mod_file->order = atoi(opt.c_str());
|
||||||
else if (name_option == "linear")
|
else if (name_option == "linear")
|
||||||
linear = atoi(opt.c_str());
|
mod_file->linear = atoi(opt.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -500,7 +500,7 @@ ParsingDriver::option_str(const string &name_option, string *opt)
|
||||||
void
|
void
|
||||||
ParsingDriver::option_str(const string &name_option, const string &opt)
|
ParsingDriver::option_str(const string &name_option, const string &opt)
|
||||||
{
|
{
|
||||||
computing_tasks.setOption(name_option, "'" + opt + "'");
|
mod_file->computing_tasks.setOption(name_option, "'" + opt + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -522,64 +522,61 @@ void ParsingDriver::rplot()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runRplot(tmp);
|
mod_file->computing_tasks.runRplot(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParsingDriver::stoch_simul()
|
void ParsingDriver::stoch_simul()
|
||||||
{
|
{
|
||||||
// If order and linear not set, then set them to default values
|
// If order and linear not set, then set them to default values
|
||||||
if (order == -1)
|
if (mod_file->order == -1)
|
||||||
{
|
mod_file->order = 2;
|
||||||
order = 2;
|
|
||||||
}
|
if (mod_file->linear == -1)
|
||||||
if (linear == -1)
|
mod_file->linear = 0;
|
||||||
{
|
|
||||||
linear = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.setStochSimul(tmp);
|
mod_file->computing_tasks.setStochSimul(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::simul()
|
ParsingDriver::simul()
|
||||||
{
|
{
|
||||||
computing_tasks.setSimul();
|
mod_file->computing_tasks.setSimul();
|
||||||
model_tree.computeJacobian = true;
|
mod_file->model_tree.computeJacobian = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::check()
|
ParsingDriver::check()
|
||||||
{
|
{
|
||||||
computing_tasks.setCheck();
|
mod_file->computing_tasks.setCheck();
|
||||||
model_tree.computeJacobian = true;
|
mod_file->model_tree.computeJacobian = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::estimation_init()
|
ParsingDriver::estimation_init()
|
||||||
{
|
{
|
||||||
computing_tasks.EstimParams = &estim_params;
|
mod_file->computing_tasks.EstimParams = &estim_params;
|
||||||
computing_tasks.setEstimationInit();
|
mod_file->computing_tasks.setEstimationInit();
|
||||||
model_tree.computeJacobianExo = true;
|
mod_file->model_tree.computeJacobianExo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_estimated_elements()
|
ParsingDriver::set_estimated_elements()
|
||||||
{
|
{
|
||||||
computing_tasks.setEstimatedElements();
|
mod_file->computing_tasks.setEstimatedElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_estimated_init_elements()
|
ParsingDriver::set_estimated_init_elements()
|
||||||
{
|
{
|
||||||
computing_tasks.setEstimatedInitElements();
|
mod_file->computing_tasks.setEstimatedInitElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_estimated_bounds_elements()
|
ParsingDriver::set_estimated_bounds_elements()
|
||||||
{
|
{
|
||||||
computing_tasks.setEstimatedBoundsElements();
|
mod_file->computing_tasks.setEstimatedBoundsElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -594,7 +591,7 @@ ParsingDriver::run_estimation()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runEstimation(tmp);
|
mod_file->computing_tasks.runEstimation(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -602,7 +599,7 @@ ParsingDriver::run_prior_analysis()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runPriorAnalysis(tmp);
|
mod_file->computing_tasks.runPriorAnalysis(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -610,13 +607,13 @@ ParsingDriver::run_posterior_analysis()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runPosteriorAnalysis(tmp);
|
mod_file->computing_tasks.runPosteriorAnalysis(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::optim_options(string *str1, string *str2, int task)
|
ParsingDriver::optim_options(string *str1, string *str2, int task)
|
||||||
{
|
{
|
||||||
computing_tasks.setOptimOptions(*str1, *str2, task);
|
mod_file->computing_tasks.setOptimOptions(*str1, *str2, task);
|
||||||
delete str1;
|
delete str1;
|
||||||
delete str2;
|
delete str2;
|
||||||
}
|
}
|
||||||
|
@ -637,7 +634,7 @@ ParsingDriver::set_trend_init()
|
||||||
void
|
void
|
||||||
ParsingDriver::set_trend_element(string *arg1, ExpObj *arg2)
|
ParsingDriver::set_trend_element(string *arg1, ExpObj *arg2)
|
||||||
{
|
{
|
||||||
computing_tasks.set_trend_element(*arg1, get_expression(arg2));
|
mod_file->computing_tasks.set_trend_element(*arg1, get_expression(arg2));
|
||||||
delete arg1;
|
delete arg1;
|
||||||
delete arg2;
|
delete arg2;
|
||||||
}
|
}
|
||||||
|
@ -645,13 +642,13 @@ ParsingDriver::set_trend_element(string *arg1, ExpObj *arg2)
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_optim_weights()
|
ParsingDriver::begin_optim_weights()
|
||||||
{
|
{
|
||||||
computing_tasks.BeginOptimWeights();
|
mod_file->computing_tasks.BeginOptimWeights();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_optim_weights(string *arg1, ExpObj *arg2)
|
ParsingDriver::set_optim_weights(string *arg1, ExpObj *arg2)
|
||||||
{
|
{
|
||||||
computing_tasks.setOptimWeights(*arg1, get_expression(arg2));
|
mod_file->computing_tasks.setOptimWeights(*arg1, get_expression(arg2));
|
||||||
delete arg1;
|
delete arg1;
|
||||||
delete arg2;
|
delete arg2;
|
||||||
}
|
}
|
||||||
|
@ -659,7 +656,7 @@ ParsingDriver::set_optim_weights(string *arg1, ExpObj *arg2)
|
||||||
void
|
void
|
||||||
ParsingDriver::set_optim_weights(string *arg1, string *arg2, ExpObj *arg3)
|
ParsingDriver::set_optim_weights(string *arg1, string *arg2, ExpObj *arg3)
|
||||||
{
|
{
|
||||||
computing_tasks.setOptimWeights(*arg1, *arg2, get_expression(arg3));
|
mod_file->computing_tasks.setOptimWeights(*arg1, *arg2, get_expression(arg3));
|
||||||
delete arg1;
|
delete arg1;
|
||||||
delete arg2;
|
delete arg2;
|
||||||
delete arg3;
|
delete arg3;
|
||||||
|
@ -670,7 +667,7 @@ ParsingDriver::set_osr_params()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("osr_params_");
|
tmp_symbol_table.set("osr_params_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.setOsrParams(tmp);
|
mod_file->computing_tasks.setOsrParams(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -678,8 +675,8 @@ ParsingDriver::run_osr()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runOsr(tmp);
|
mod_file->computing_tasks.runOsr(tmp);
|
||||||
model_tree.computeJacobianExo = true;
|
mod_file->model_tree.computeJacobianExo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -687,7 +684,7 @@ ParsingDriver::set_olr_inst()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("options_.olr_inst");
|
tmp_symbol_table.set("options_.olr_inst");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.setOlrInst(tmp);
|
mod_file->computing_tasks.setOlrInst(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -695,19 +692,19 @@ ParsingDriver::run_olr()
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runOlr(tmp);
|
mod_file->computing_tasks.runOlr(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_calib_var()
|
ParsingDriver::begin_calib_var()
|
||||||
{
|
{
|
||||||
computing_tasks.BeginCalibVar();
|
mod_file->computing_tasks.BeginCalibVar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::set_calib_var(string *name, string *weight, ExpObj *expression)
|
ParsingDriver::set_calib_var(string *name, string *weight, ExpObj *expression)
|
||||||
{
|
{
|
||||||
computing_tasks.setCalibVar(*name, *weight, get_expression(expression));
|
mod_file->computing_tasks.setCalibVar(*name, *weight, get_expression(expression));
|
||||||
delete name;
|
delete name;
|
||||||
delete weight;
|
delete weight;
|
||||||
delete expression;
|
delete expression;
|
||||||
|
@ -717,7 +714,7 @@ void
|
||||||
ParsingDriver::set_calib_var(string *name1, string *name2,
|
ParsingDriver::set_calib_var(string *name1, string *name2,
|
||||||
string *weight, ExpObj *expression)
|
string *weight, ExpObj *expression)
|
||||||
{
|
{
|
||||||
computing_tasks.setCalibVar(*name1, *name2, *weight, get_expression(expression));
|
mod_file->computing_tasks.setCalibVar(*name1, *name2, *weight, get_expression(expression));
|
||||||
delete name1;
|
delete name1;
|
||||||
delete name2;
|
delete name2;
|
||||||
delete weight;
|
delete weight;
|
||||||
|
@ -728,7 +725,7 @@ void
|
||||||
ParsingDriver::set_calib_ac(string *name, string *ar,
|
ParsingDriver::set_calib_ac(string *name, string *ar,
|
||||||
string *weight, ExpObj *expression)
|
string *weight, ExpObj *expression)
|
||||||
{
|
{
|
||||||
computing_tasks.setCalibAc(*name, *ar, *weight, get_expression(expression));
|
mod_file->computing_tasks.setCalibAc(*name, *ar, *weight, get_expression(expression));
|
||||||
delete name;
|
delete name;
|
||||||
delete ar;
|
delete ar;
|
||||||
delete weight;
|
delete weight;
|
||||||
|
@ -738,7 +735,7 @@ ParsingDriver::set_calib_ac(string *name, string *ar,
|
||||||
void
|
void
|
||||||
ParsingDriver::run_calib(int flag)
|
ParsingDriver::run_calib(int flag)
|
||||||
{
|
{
|
||||||
computing_tasks.runCalib(flag);
|
mod_file->computing_tasks.runCalib(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -746,7 +743,7 @@ ParsingDriver::run_dynatype(string *filename, string *ext)
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runDynatype(*filename, *ext, tmp);
|
mod_file->computing_tasks.runDynatype(*filename, *ext, tmp);
|
||||||
delete filename;
|
delete filename;
|
||||||
delete ext;
|
delete ext;
|
||||||
}
|
}
|
||||||
|
@ -756,7 +753,7 @@ ParsingDriver::run_dynasave(string *filename, string *ext)
|
||||||
{
|
{
|
||||||
tmp_symbol_table.set("var_list_");
|
tmp_symbol_table.set("var_list_");
|
||||||
string tmp = tmp_symbol_table.get();
|
string tmp = tmp_symbol_table.get();
|
||||||
computing_tasks.runDynasave(*filename, *ext, tmp);
|
mod_file->computing_tasks.runDynasave(*filename, *ext, tmp);
|
||||||
delete filename;
|
delete filename;
|
||||||
delete ext;
|
delete ext;
|
||||||
}
|
}
|
||||||
|
@ -764,13 +761,13 @@ ParsingDriver::run_dynasave(string *filename, string *ext)
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_model_comparison()
|
ParsingDriver::begin_model_comparison()
|
||||||
{
|
{
|
||||||
computing_tasks.beginModelComparison();
|
mod_file->computing_tasks.beginModelComparison();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::add_mc_filename(string *filename, string *prior)
|
ParsingDriver::add_mc_filename(string *filename, string *prior)
|
||||||
{
|
{
|
||||||
computing_tasks.addMcFilename(*filename, *prior);
|
mod_file->computing_tasks.addMcFilename(*filename, *prior);
|
||||||
delete filename;
|
delete filename;
|
||||||
delete prior;
|
delete prior;
|
||||||
}
|
}
|
||||||
|
@ -778,154 +775,166 @@ ParsingDriver::add_mc_filename(string *filename, string *prior)
|
||||||
void
|
void
|
||||||
ParsingDriver::run_model_comparison()
|
ParsingDriver::run_model_comparison()
|
||||||
{
|
{
|
||||||
computing_tasks.runModelComparison();
|
mod_file->computing_tasks.runModelComparison();
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_equal(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_model_equal(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
NodeID id = model_tree.AddEqual(arg1, arg2);
|
NodeID id = mod_file->model_tree.AddEqual(arg1, arg2);
|
||||||
model_parameters.eq_nbr++;
|
mod_file->model_parameters.eq_nbr++;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeID
|
||||||
|
ParsingDriver::add_model_equal_with_zero_rhs(NodeID arg)
|
||||||
|
{
|
||||||
|
return add_model_equal(arg, mod_file->model_tree.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_and_init_local_parameter(string *name, NodeID rhs)
|
ParsingDriver::declare_and_init_local_parameter(string *name, NodeID rhs)
|
||||||
{
|
{
|
||||||
symbol_table.AddSymbolDeclar(*name, eLocalParameter, *name);
|
mod_file->symbol_table.AddSymbolDeclar(*name, eLocalParameter, *name);
|
||||||
NodeID id = model_tree.AddTerminal(*name);
|
NodeID id = mod_file->model_tree.AddTerminal(*name);
|
||||||
model_tree.AddAssign(id, rhs);
|
mod_file->model_tree.AddAssign(id, rhs);
|
||||||
delete name;
|
delete name;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_plus(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_model_plus(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree.AddPlus(arg1, arg2);
|
return mod_file->model_tree.AddPlus(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_minus(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_model_minus(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree.AddMinus(arg1, arg2);
|
return mod_file->model_tree.AddMinus(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_uminus(NodeID arg1)
|
ParsingDriver::add_model_uminus(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddUMinus(arg1);
|
return mod_file->model_tree.AddUMinus(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_times(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_model_times(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree.AddTimes(arg1, arg2);
|
return mod_file->model_tree.AddTimes(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_divide(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_model_divide(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree.AddDivide(arg1, arg2);
|
return mod_file->model_tree.AddDivide(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_power(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_model_power(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
return model_tree.AddPower(arg1, arg2);
|
return mod_file->model_tree.AddPower(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_exp(NodeID arg1)
|
ParsingDriver::add_model_exp(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddExp(arg1);
|
return mod_file->model_tree.AddExp(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_log(NodeID arg1)
|
ParsingDriver::add_model_log(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddLog(arg1);
|
return mod_file->model_tree.AddLog(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_log10(NodeID arg1)
|
ParsingDriver::add_model_log10(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddLog10(arg1);
|
return mod_file->model_tree.AddLog10(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_cos(NodeID arg1)
|
ParsingDriver::add_model_cos(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddCos(arg1);
|
return mod_file->model_tree.AddCos(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_sin(NodeID arg1)
|
ParsingDriver::add_model_sin(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddSin(arg1);
|
return mod_file->model_tree.AddSin(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_tan(NodeID arg1)
|
ParsingDriver::add_model_tan(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddTan(arg1);
|
return mod_file->model_tree.AddTan(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_acos(NodeID arg1)
|
ParsingDriver::add_model_acos(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddACos(arg1);
|
return mod_file->model_tree.AddACos(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_asin(NodeID arg1)
|
ParsingDriver::add_model_asin(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddASin(arg1);
|
return mod_file->model_tree.AddASin(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_atan(NodeID arg1)
|
ParsingDriver::add_model_atan(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddATan(arg1);
|
return mod_file->model_tree.AddATan(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_cosh(NodeID arg1)
|
ParsingDriver::add_model_cosh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddCosH(arg1);
|
return mod_file->model_tree.AddCosH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_sinh(NodeID arg1)
|
ParsingDriver::add_model_sinh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddSinH(arg1);
|
return mod_file->model_tree.AddSinH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_tanh(NodeID arg1)
|
ParsingDriver::add_model_tanh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddTanH(arg1);
|
return mod_file->model_tree.AddTanH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_acosh(NodeID arg1)
|
ParsingDriver::add_model_acosh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddACosH(arg1);
|
return mod_file->model_tree.AddACosH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_asinh(NodeID arg1)
|
ParsingDriver::add_model_asinh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddASinH(arg1);
|
return mod_file->model_tree.AddASinH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_atanh(NodeID arg1)
|
ParsingDriver::add_model_atanh(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddATanH(arg1);
|
return mod_file->model_tree.AddATanH(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_model_sqrt(NodeID arg1)
|
ParsingDriver::add_model_sqrt(NodeID arg1)
|
||||||
{
|
{
|
||||||
return model_tree.AddSqRt(arg1);
|
return mod_file->model_tree.AddSqRt(arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParsingDriver::add_native(const char *s)
|
||||||
|
{
|
||||||
|
*output << s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,7 @@ using namespace std;
|
||||||
#include "ModelParameters.hh"
|
#include "ModelParameters.hh"
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
|
|
||||||
static int mshock_flag = 0;
|
Shocks::Shocks() : mshock_flag(0), exo_det_length(0)
|
||||||
static int exo_det_length = 0;
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
//ostringstream Shocks::output;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
Shocks::Shocks()
|
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,34 +3,26 @@
|
||||||
\date 04/09/2004
|
\date 04/09/2004
|
||||||
\par This file implements the SymbolTable class methodes.
|
\par This file implements the SymbolTable class methodes.
|
||||||
*/
|
*/
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
//------------------------------------------------------------------------------
|
#include <sstream>
|
||||||
|
|
||||||
#include "SymbolTable.hh"
|
#include "SymbolTable.hh"
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// = *(new symbolmap);
|
SymbolTable::SymbolTable(ModelParameters &mod_param_arg) : mod_param(mod_param_arg)
|
||||||
map<string, Symbol, less<string> > SymbolTable::symboltable;
|
|
||||||
vector< vector<string> > SymbolTable::name_table;
|
|
||||||
vector< vector<string> > SymbolTable::tex_name_table;
|
|
||||||
ostringstream SymbolTable::output;
|
|
||||||
void (* SymbolTable::error) (const char* ) = NULL;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
SymbolTable::SymbolTable()
|
|
||||||
{
|
{
|
||||||
name_table.resize(20);
|
name_table.resize(20);
|
||||||
tex_name_table.resize(20);
|
tex_name_table.resize(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
SymbolTable::~SymbolTable()
|
SymbolTable::~SymbolTable()
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int SymbolTable::AddSymbol(string name,Type type, string tex_name)
|
int SymbolTable::AddSymbol(string name,Type type, string tex_name)
|
||||||
{
|
{
|
||||||
symboltable[name].type = type;
|
symboltable[name].type = type;
|
||||||
|
@ -41,29 +33,23 @@ int SymbolTable::AddSymbol(string name,Type type, string tex_name)
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case eExogenous:
|
case eExogenous:
|
||||||
symboltable[name].id = ModelParameters::exo_nbr;
|
symboltable[name].id = mod_param.exo_nbr;
|
||||||
ModelParameters::exo_nbr++;
|
return mod_param.exo_nbr++;
|
||||||
return ModelParameters::exo_nbr-1;
|
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
symboltable[name].id = ModelParameters::exo_det_nbr;
|
symboltable[name].id = mod_param.exo_det_nbr;
|
||||||
ModelParameters::exo_det_nbr++;
|
return mod_param.exo_det_nbr++;
|
||||||
return ModelParameters::exo_det_nbr-1;
|
|
||||||
case eEndogenous:
|
case eEndogenous:
|
||||||
symboltable[name].id = ModelParameters::endo_nbr;
|
symboltable[name].id = mod_param.endo_nbr;
|
||||||
ModelParameters::endo_nbr++;
|
return mod_param.endo_nbr++;
|
||||||
return ModelParameters::endo_nbr-1;
|
|
||||||
case eParameter:
|
case eParameter:
|
||||||
symboltable[name].id = ModelParameters::parameter_nbr;
|
symboltable[name].id = mod_param.parameter_nbr;
|
||||||
ModelParameters::parameter_nbr++;
|
return mod_param.parameter_nbr++;
|
||||||
return ModelParameters::parameter_nbr-1;
|
|
||||||
case eRecursiveVariable:
|
case eRecursiveVariable:
|
||||||
symboltable[name].id = ModelParameters::recur_nbr;
|
symboltable[name].id = mod_param.recur_nbr;
|
||||||
ModelParameters::recur_nbr++;
|
return mod_param.recur_nbr++;
|
||||||
return ModelParameters::recur_nbr-1;
|
|
||||||
case eLocalParameter:
|
case eLocalParameter:
|
||||||
symboltable[name].id = ModelParameters::local_parameter_nbr;
|
symboltable[name].id = mod_param.local_parameter_nbr;
|
||||||
ModelParameters::local_parameter_nbr++;
|
return mod_param.local_parameter_nbr++;
|
||||||
return ModelParameters::local_parameter_nbr-1;
|
|
||||||
default:
|
default:
|
||||||
// should never happen
|
// should never happen
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -71,7 +57,6 @@ int SymbolTable::AddSymbol(string name,Type type, string tex_name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int SymbolTable::AddSymbolDeclar(string name,Type type, string tex_name)
|
int SymbolTable::AddSymbolDeclar(string name,Type type, string tex_name)
|
||||||
{
|
{
|
||||||
//Testing if the symbol exist in the map
|
//Testing if the symbol exist in the map
|
||||||
|
@ -98,45 +83,28 @@ int SymbolTable::AddSymbolDeclar(string name,Type type, string tex_name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SymbolTable::AddSymbolRange(string name,int nbr,Type type, string tex_name)
|
void SymbolTable::AddSymbolRange(string name,int nbr,Type type, string tex_name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SymbolTable::AddLag(string name,int lag)
|
|
||||||
{
|
|
||||||
//Testing if the symbol exist in the map
|
|
||||||
if ( !Exist(name) )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Type type = symboltable[name].type;
|
|
||||||
if ((type == eEndogenous) || (type == eExogenous))
|
|
||||||
{
|
|
||||||
symboltable[name].lags.push_back(lag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SymbolTable::ResetType(string name,Type new_type)
|
void SymbolTable::ResetType(string name,Type new_type)
|
||||||
{
|
{
|
||||||
symboltable[name].type = new_type;
|
symboltable[name].type = new_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SymbolTable::SetReferenced(string name)
|
void SymbolTable::SetReferenced(string name)
|
||||||
{
|
{
|
||||||
symboltable[name].referenced = eReferenced;
|
symboltable[name].referenced = eReferenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
Reference SymbolTable::isReferenced(const std::string &name) const
|
||||||
Reference SymbolTable::isReferenced(std::string name)
|
|
||||||
{
|
{
|
||||||
return symboltable[name].referenced;
|
symboltable_const_iterator iter = symboltable.find(name);
|
||||||
|
return iter->second.referenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
#if 0 // Commented out on 27/11/2006, SV
|
||||||
|
|
||||||
void SymbolTable::clean()
|
void SymbolTable::clean()
|
||||||
{
|
{
|
||||||
string unused;
|
string unused;
|
||||||
|
@ -148,9 +116,9 @@ void SymbolTable::clean()
|
||||||
types[1] = eExogenous;
|
types[1] = eExogenous;
|
||||||
types[2] = eExogenousDet;
|
types[2] = eExogenousDet;
|
||||||
|
|
||||||
nb_type[0] = ModelParameters::endo_nbr;
|
nb_type[0] = mod_param.endo_nbr;
|
||||||
nb_type[1] = ModelParameters::exo_nbr;
|
nb_type[1] = mod_param.exo_nbr;
|
||||||
nb_type[2] = ModelParameters::exo_det_nbr;
|
nb_type[2] = mod_param.exo_det_nbr;
|
||||||
|
|
||||||
// Removing unused variables
|
// Removing unused variables
|
||||||
for (int t = 0; t < 3; t++)
|
for (int t = 0; t < 3; t++)
|
||||||
|
@ -190,9 +158,9 @@ void SymbolTable::clean()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModelParameters::endo_nbr = nb_type[0];
|
mod_param.endo_nbr = nb_type[0];
|
||||||
ModelParameters::exo_nbr = nb_type[1];
|
mod_param.exo_nbr = nb_type[1];
|
||||||
ModelParameters::exo_det_nbr = nb_type[2];
|
mod_param.exo_det_nbr = nb_type[2];
|
||||||
/*
|
/*
|
||||||
// Checking if unused parameters
|
// Checking if unused parameters
|
||||||
for (int s1 = 0; s1 < ModelParameters::parameter_nbr; s1++)
|
for (int s1 = 0; s1 < ModelParameters::parameter_nbr; s1++)
|
||||||
|
@ -219,81 +187,69 @@ void SymbolTable::clean()
|
||||||
}
|
}
|
||||||
//PrintSymbolTable();
|
//PrintSymbolTable();
|
||||||
}
|
}
|
||||||
|
#endif // Comment
|
||||||
|
|
||||||
string SymbolTable::get()
|
string SymbolTable::get()
|
||||||
{
|
{
|
||||||
if (ModelParameters::exo_nbr > 0)
|
ostringstream output;
|
||||||
|
|
||||||
|
if (mod_param.exo_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.exo_names = '" << getNameByID(eExogenous, 0) << "';\n";
|
output << "M_.exo_names = '" << getNameByID(eExogenous, 0) << "';\n";
|
||||||
output << "M_.exo_names_tex = '" << getTexNameByID(eExogenous, 0) << "';\n";
|
output << "M_.exo_names_tex = '" << getTexNameByID(eExogenous, 0) << "';\n";
|
||||||
for (int id = 1; id < ModelParameters::exo_nbr; id++)
|
for (int id = 1; id < mod_param.exo_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.exo_names = " + interfaces::strvcat("M_.exo_names","'"+getNameByID(eExogenous, id)+"'") + ";\n";
|
output << "M_.exo_names = " + interfaces::strvcat("M_.exo_names","'"+getNameByID(eExogenous, id)+"'") + ";\n";
|
||||||
output << "M_.exo_names_tex = " + interfaces::strvcat("M_.exo_names_tex","'"+getTexNameByID(eExogenous, id)+"'") + ";\n";
|
output << "M_.exo_names_tex = " + interfaces::strvcat("M_.exo_names_tex","'"+getTexNameByID(eExogenous, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelParameters::exo_det_nbr > 0)
|
if (mod_param.exo_det_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "lgxdet_ = '" << getNameByID(eExogenousDet, 0) << "';\n";
|
output << "lgxdet_ = '" << getNameByID(eExogenousDet, 0) << "';\n";
|
||||||
output << "lgxdet_tex_ = '" << getTexNameByID(eExogenousDet, 0) << "';\n";
|
output << "lgxdet_tex_ = '" << getTexNameByID(eExogenousDet, 0) << "';\n";
|
||||||
for (int id = 1; id < ModelParameters::exo_det_nbr; id++)
|
for (int id = 1; id < mod_param.exo_det_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "lgxdet_ = " + interfaces::strvcat("lgxdet_","'"+getNameByID(eExogenousDet, id)+"'") + ";\n";
|
output << "lgxdet_ = " + interfaces::strvcat("lgxdet_","'"+getNameByID(eExogenousDet, id)+"'") + ";\n";
|
||||||
output << "lgxdet_tex_ = " + interfaces::strvcat("lgxdet_tex_","'"+getTexNameByID(eExogenousDet, id)+"'") + ";\n";
|
output << "lgxdet_tex_ = " + interfaces::strvcat("lgxdet_tex_","'"+getTexNameByID(eExogenousDet, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelParameters::endo_nbr > 0)
|
if (mod_param.endo_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.endo_names = '" << getNameByID(eEndogenous, 0) << "';\n";
|
output << "M_.endo_names = '" << getNameByID(eEndogenous, 0) << "';\n";
|
||||||
output << "M_.endo_names_tex = '" << getTexNameByID(eEndogenous, 0) << "';\n";
|
output << "M_.endo_names_tex = '" << getTexNameByID(eEndogenous, 0) << "';\n";
|
||||||
for (int id = 1; id < ModelParameters::endo_nbr; id++)
|
for (int id = 1; id < mod_param.endo_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.endo_names = " + interfaces::strvcat("M_.endo_names","'"+getNameByID(eEndogenous, id)+"'") + ";\n";
|
output << "M_.endo_names = " + interfaces::strvcat("M_.endo_names","'"+getNameByID(eEndogenous, id)+"'") + ";\n";
|
||||||
output << "M_.endo_names_tex = " + interfaces::strvcat("M_.endo_names_tex","'"+getTexNameByID(eEndogenous, id)+"'") + ";\n";
|
output << "M_.endo_names_tex = " + interfaces::strvcat("M_.endo_names_tex","'"+getTexNameByID(eEndogenous, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelParameters::recur_nbr > 0)
|
if (mod_param.recur_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.recur_names = '" << getNameByID(eRecursiveVariable, 0) << "';\n";
|
output << "M_.recur_names = '" << getNameByID(eRecursiveVariable, 0) << "';\n";
|
||||||
output << "M_.recur_names_tex = '" << getTexNameByID(eRecursiveVariable, 0) << "';\n";
|
output << "M_.recur_names_tex = '" << getTexNameByID(eRecursiveVariable, 0) << "';\n";
|
||||||
for (int id = 1; id < ModelParameters::recur_nbr; id++)
|
for (int id = 1; id < mod_param.recur_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.recur_names = " + interfaces::strvcat("M_.recur_names","'"+getNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
output << "M_.recur_names = " + interfaces::strvcat("M_.recur_names","'"+getNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
||||||
output << "M_.recur_names_tex = " + interfaces::strvcat("M_.recur_names_tex","'"+getTexNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
output << "M_.recur_names_tex = " + interfaces::strvcat("M_.recur_names_tex","'"+getTexNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ModelParameters::parameter_nbr > 0)
|
if (mod_param.parameter_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.param_names = '" << getNameByID(eParameter, 0) << "';\n";
|
output << "M_.param_names = '" << getNameByID(eParameter, 0) << "';\n";
|
||||||
output << "M_.param_names_tex = '" << getTexNameByID(eParameter, 0) << "';\n";
|
output << "M_.param_names_tex = '" << getTexNameByID(eParameter, 0) << "';\n";
|
||||||
for (int id = 1; id < ModelParameters::parameter_nbr; id++)
|
for (int id = 1; id < mod_param.parameter_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.param_names = " + interfaces::strvcat("M_.param_names","'"+getNameByID(eParameter, id)+"'") + ";\n";
|
output << "M_.param_names = " + interfaces::strvcat("M_.param_names","'"+getNameByID(eParameter, id)+"'") + ";\n";
|
||||||
output << "M_.param_names_tex = " + interfaces::strvcat("M_.param_names_tex","'"+getTexNameByID(eParameter, id)+"'") + ";\n";
|
output << "M_.param_names_tex = " + interfaces::strvcat("M_.param_names_tex","'"+getTexNameByID(eParameter, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output << "M_.exo_det_nbr = " << ModelParameters::exo_det_nbr << ";\n";
|
output << "M_.exo_det_nbr = " << mod_param.exo_det_nbr << ";\n";
|
||||||
output << "M_.exo_nbr = " << ModelParameters::exo_nbr << ";\n";
|
output << "M_.exo_nbr = " << mod_param.exo_nbr << ";\n";
|
||||||
output << "M_.Sigma_e = zeros(" << ModelParameters::exo_nbr
|
output << "M_.Sigma_e = zeros(" << mod_param.exo_nbr
|
||||||
<< ", " << ModelParameters::exo_nbr << ");\n";
|
<< ", " << mod_param.exo_nbr << ");\n";
|
||||||
output << "M_.endo_nbr = " << ModelParameters::endo_nbr << ";\n";
|
output << "M_.endo_nbr = " << mod_param.endo_nbr << ";\n";
|
||||||
output << "M_.recur_nbr = " << ModelParameters::recur_nbr << ";\n";
|
output << "M_.recur_nbr = " << mod_param.recur_nbr << ";\n";
|
||||||
output << "M_.param_nbr = " << ModelParameters::parameter_nbr << ";\n";
|
output << "M_.param_nbr = " << mod_param.parameter_nbr << ";\n";
|
||||||
return output.str();
|
return output.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SymbolTable::erase_local_parameters(void)
|
|
||||||
{
|
|
||||||
std::map<std::string, Symbol, std::less<std::string> >::iterator i = symboltable.begin();
|
|
||||||
for(; i != symboltable.end(); ++i)
|
|
||||||
{
|
|
||||||
if ((i->second).type == eLocalParameter)
|
|
||||||
{
|
|
||||||
symboltable.erase(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
|
@ -15,23 +15,19 @@ TmpSymbolTable::TmpSymbolTable()
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
TmpSymbolTable::TmpSymbolTable(const TmpSymbolTable &tst)
|
|
||||||
{
|
|
||||||
tmpsymboltable = tst.tmpsymboltable;
|
|
||||||
output.str(tst.output.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
TmpSymbolTable::~TmpSymbolTable()
|
TmpSymbolTable::~TmpSymbolTable()
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
void TmpSymbolTable::setGlobalSymbolTable(SymbolTable *symbol_table_arg)
|
||||||
|
{
|
||||||
|
symbol_table = symbol_table_arg;
|
||||||
|
}
|
||||||
|
|
||||||
void TmpSymbolTable::AddTempSymbol(string symbol)
|
void TmpSymbolTable::AddTempSymbol(string symbol)
|
||||||
{
|
{
|
||||||
if (SymbolTable::Exist(symbol))
|
if (symbol_table->Exist(symbol))
|
||||||
tmpsymboltable.push_back(symbol);
|
tmpsymboltable.push_back(symbol);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -43,7 +39,7 @@ void TmpSymbolTable::AddTempSymbol(string symbol)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void TmpSymbolTable::AddTempSymbol(string symbol1, string symbol2)
|
void TmpSymbolTable::AddTempSymbol(string symbol1, string symbol2)
|
||||||
{
|
{
|
||||||
if (SymbolTable::Exist(symbol1))
|
if (symbol_table->Exist(symbol1))
|
||||||
tmpsymboltable.push_back(symbol1);
|
tmpsymboltable.push_back(symbol1);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -51,7 +47,7 @@ void TmpSymbolTable::AddTempSymbol(string symbol1, string symbol2)
|
||||||
error(msg.c_str());
|
error(msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SymbolTable::Exist(symbol2))
|
if (symbol_table->Exist(symbol2))
|
||||||
NameTable.push_back(symbol2);
|
NameTable.push_back(symbol2);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -68,7 +64,7 @@ void TmpSymbolTable::set(string varname)
|
||||||
output << "\n" << varname << "=[];\n";
|
output << "\n" << varname << "=[];\n";
|
||||||
for (it = tmpsymboltable.begin(); it!= tmpsymboltable.end(); it++)
|
for (it = tmpsymboltable.begin(); it!= tmpsymboltable.end(); it++)
|
||||||
{
|
{
|
||||||
if (SymbolTable::isReferenced(*it) == eReferenced)
|
if (symbol_table->isReferenced(*it) == eReferenced)
|
||||||
{
|
{
|
||||||
output << varname << " = ";
|
output << varname << " = ";
|
||||||
output << interfaces::strvcat(varname,"'"+*it+"'")+";\n";
|
output << interfaces::strvcat(varname,"'"+*it+"'")+";\n";
|
||||||
|
|
|
@ -10,14 +10,11 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include "VariableTable.hh"
|
#include "VariableTable.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
map<varKey,int> VariableTable::mVariableTable;
|
VariableTable::VariableTable(const SymbolTable &symbol_table_arg,
|
||||||
vector<varKey> VariableTable::mVariableIndex;
|
ModelParameters &mod_param_arg) :
|
||||||
vector<int> VariableTable::mSortedVariableID;
|
symbol_table(symbol_table_arg),
|
||||||
vector<int> VariableTable::mPrintFormatIndex;
|
mod_param(mod_param_arg)
|
||||||
void (* VariableTable::error) (const char* ) = NULL;
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
VariableTable::VariableTable()
|
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
@ -35,7 +32,7 @@ int VariableTable::AddVariable(string iName, int iLag)
|
||||||
//Variable lVariable;
|
//Variable lVariable;
|
||||||
varKey key;
|
varKey key;
|
||||||
// Testing if symbol exists
|
// Testing if symbol exists
|
||||||
if (!SymbolTable::Exist(iName))
|
if (!symbol_table.Exist(iName))
|
||||||
{
|
{
|
||||||
string msg = "unknown symbol: " + iName;
|
string msg = "unknown symbol: " + iName;
|
||||||
(* error) (msg.c_str());
|
(* error) (msg.c_str());
|
||||||
|
@ -57,66 +54,45 @@ int VariableTable::AddVariable(string iName, int iLag)
|
||||||
//mVariableTable[key] = lVariable;
|
//mVariableTable[key] = lVariable;
|
||||||
mVariableTable[key] = lVariableID;
|
mVariableTable[key] = lVariableID;
|
||||||
mVariableIndex.push_back(key);
|
mVariableIndex.push_back(key);
|
||||||
// Setting lags field in symbol table
|
|
||||||
SymbolTable::AddLag(iName, iLag);
|
|
||||||
// Setting variable numbers
|
// Setting variable numbers
|
||||||
Type type = getType(lVariableID);
|
Type type = getType(lVariableID);
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
ModelParameters::var_endo_nbr++;
|
mod_param.var_endo_nbr++;
|
||||||
if (type == eExogenous)
|
if (type == eExogenous)
|
||||||
ModelParameters::var_exo_nbr++;
|
mod_param.var_exo_nbr++;
|
||||||
if (type == eExogenousDet)
|
if (type == eExogenousDet)
|
||||||
ModelParameters::var_exo_det_nbr++;
|
mod_param.var_exo_det_nbr++;
|
||||||
// Setting Maximum and minimum lags
|
// Setting Maximum and minimum lags
|
||||||
if (ModelParameters::max_lead < iLag)
|
if (mod_param.max_lead < iLag)
|
||||||
{
|
mod_param.max_lead = iLag;
|
||||||
ModelParameters::max_lead = iLag;
|
else if (-mod_param.max_lag > iLag)
|
||||||
}
|
mod_param.max_lag = -iLag;
|
||||||
else if (-ModelParameters::max_lag > iLag)
|
|
||||||
{
|
|
||||||
ModelParameters::max_lag = -iLag;
|
|
||||||
}
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case eEndogenous:
|
case eEndogenous:
|
||||||
if (ModelParameters::max_endo_lead < iLag)
|
if (mod_param.max_endo_lead < iLag)
|
||||||
{
|
mod_param.max_endo_lead = iLag;
|
||||||
ModelParameters::max_endo_lead = iLag;
|
else if (-mod_param.max_endo_lag > iLag)
|
||||||
}
|
mod_param.max_endo_lag = -iLag;
|
||||||
else if (-ModelParameters::max_endo_lag > iLag)
|
|
||||||
{
|
|
||||||
ModelParameters::max_endo_lag = -iLag;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case eExogenous:
|
case eExogenous:
|
||||||
if (ModelParameters::max_exo_lead < iLag)
|
if (mod_param.max_exo_lead < iLag)
|
||||||
{
|
mod_param.max_exo_lead = iLag;
|
||||||
ModelParameters::max_exo_lead = iLag;
|
else if (-mod_param.max_exo_lag > iLag)
|
||||||
}
|
mod_param.max_exo_lag = -iLag;
|
||||||
else if (-ModelParameters::max_exo_lag > iLag)
|
|
||||||
{
|
|
||||||
ModelParameters::max_exo_lag = -iLag;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
if (ModelParameters::max_exo_det_lead < iLag)
|
if (mod_param.max_exo_det_lead < iLag)
|
||||||
{
|
mod_param.max_exo_det_lead = iLag;
|
||||||
ModelParameters::max_exo_det_lead = iLag;
|
else if (-mod_param.max_exo_det_lag > iLag)
|
||||||
}
|
mod_param.max_exo_det_lag = -iLag;
|
||||||
else if (-ModelParameters::max_exo_det_lag > iLag)
|
|
||||||
{
|
|
||||||
ModelParameters::max_exo_det_lag = -iLag;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case eRecursiveVariable:
|
case eRecursiveVariable:
|
||||||
if (ModelParameters::max_recur_lead < iLag)
|
if (mod_param.max_recur_lead < iLag)
|
||||||
{
|
mod_param.max_recur_lead = iLag;
|
||||||
ModelParameters::max_recur_lead = iLag;
|
else if (-mod_param.max_recur_lag > iLag)
|
||||||
}
|
mod_param.max_recur_lag = -iLag;
|
||||||
else if (-ModelParameters::max_recur_lag > iLag)
|
|
||||||
{
|
|
||||||
ModelParameters::max_recur_lag = -iLag;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
;
|
;
|
||||||
|
@ -149,7 +125,7 @@ void VariableTable::decSymbolID(string iName, int id, int iLag, Type iType)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void VariableTable::Sort(void)
|
void VariableTable::Sort()
|
||||||
{
|
{
|
||||||
varKey key;
|
varKey key;
|
||||||
int variable;
|
int variable;
|
||||||
|
@ -175,7 +151,7 @@ void VariableTable::Sort(void)
|
||||||
IDs.push_back(getSymbolID(variable));
|
IDs.push_back(getSymbolID(variable));
|
||||||
Types.push_back(getType(variable));
|
Types.push_back(getType(variable));
|
||||||
Lags.push_back(key.second);
|
Lags.push_back(key.second);
|
||||||
unsigned long long int lag = Lags[id]+ModelParameters::max_lag;
|
unsigned long long int lag = Lags[id]+mod_param.max_lag;
|
||||||
lag = lag << (4*sizeof(int));
|
lag = lag << (4*sizeof(int));
|
||||||
unsigned long long int type = Types[id];
|
unsigned long long int type = Types[id];
|
||||||
type = type << 8*sizeof(int);
|
type = type << 8*sizeof(int);
|
||||||
|
|
|
@ -62,10 +62,12 @@ class ComputingTasks
|
||||||
private :
|
private :
|
||||||
//! Output of this class
|
//! Output of this class
|
||||||
std::ostringstream *output;
|
std::ostringstream *output;
|
||||||
|
//! A reference to the symbol table
|
||||||
|
const SymbolTable &symbol_table;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
//! Constructor
|
//! Constructor
|
||||||
ComputingTasks();
|
ComputingTasks(const SymbolTable &symbol_table_arg);
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~ComputingTasks();
|
~ComputingTasks();
|
||||||
/*! Pointer to error function of parser class */
|
/*! Pointer to error function of parser class */
|
||||||
|
@ -144,7 +146,7 @@ public :
|
||||||
|
|
||||||
void set(void);
|
void set(void);
|
||||||
|
|
||||||
static std::string get(void);
|
std::string get(void);
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,6 +32,11 @@ typedef TreeList::iterator TreeIterator;
|
||||||
class DataTree
|
class DataTree
|
||||||
{
|
{
|
||||||
protected :
|
protected :
|
||||||
|
//! A reference to the symbol table
|
||||||
|
SymbolTable &symbol_table;
|
||||||
|
//! A reference to the variable table
|
||||||
|
VariableTable &variable_table;
|
||||||
|
|
||||||
/*! A list of structures "token" */
|
/*! A list of structures "token" */
|
||||||
TreeList mModelTree;
|
TreeList mModelTree;
|
||||||
/*! matches key with entry id in list of token */
|
/*! matches key with entry id in list of token */
|
||||||
|
@ -52,14 +57,14 @@ protected :
|
||||||
inline NodeID getIDOfToken(const MToken &iToken);
|
inline NodeID getIDOfToken(const MToken &iToken);
|
||||||
public :
|
public :
|
||||||
/*! Flag for empty operator (final toekn) */
|
/*! Flag for empty operator (final toekn) */
|
||||||
static const int NoOpCode;
|
const int NoOpCode;
|
||||||
static const NodeID NullID;
|
const NodeID NullID;
|
||||||
static const NodeID Zero;
|
NodeID Zero;
|
||||||
static const NodeID One;
|
NodeID One;
|
||||||
static const NodeID MinusOne;
|
NodeID MinusOne;
|
||||||
static const NodeID ZeroEqZero;
|
NodeID ZeroEqZero;
|
||||||
/*! Type of output 0 for C and 1 for Matlab (default) , also used as matrix index offset*/
|
/*! Type of output 0 for C and 1 for Matlab (default) , also used as matrix index offset*/
|
||||||
static int offset;
|
int offset;
|
||||||
/*! Pointer to error function of parser class */
|
/*! Pointer to error function of parser class */
|
||||||
void (* error) (const char* m);
|
void (* error) (const char* m);
|
||||||
/*! Increment reference count of given token */
|
/*! Increment reference count of given token */
|
||||||
|
@ -118,7 +123,7 @@ public :
|
||||||
inline NodeID AddAssign(NodeID iArg1, NodeID iArg2);
|
inline NodeID AddAssign(NodeID iArg1, NodeID iArg2);
|
||||||
public :
|
public :
|
||||||
/*! Constructor */
|
/*! Constructor */
|
||||||
DataTree();
|
DataTree(SymbolTable &symbol_table_arg, VariableTable &variable_table_arg);
|
||||||
/*! Destructor */
|
/*! Destructor */
|
||||||
~DataTree();
|
~DataTree();
|
||||||
};
|
};
|
||||||
|
@ -213,22 +218,22 @@ inline NodeID DataTree::AddTerminal(std::string iArgName, int iLag)
|
||||||
int id;
|
int id;
|
||||||
Type type;
|
Type type;
|
||||||
|
|
||||||
if (!SymbolTable::Exist(iArgName))
|
if (!symbol_table.Exist(iArgName))
|
||||||
{
|
{
|
||||||
std::string msg = "unknown symbol: " + iArgName;
|
std::string msg = "unknown symbol: " + iArgName;
|
||||||
(* error) (msg.c_str());
|
(* error) (msg.c_str());
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
type = SymbolTable::getType(iArgName);
|
type = symbol_table.getType(iArgName);
|
||||||
if (type != eUNDEF)
|
if (type != eUNDEF)
|
||||||
{
|
{
|
||||||
SymbolTable::SetReferenced(iArgName);
|
symbol_table.SetReferenced(iArgName);
|
||||||
if (type == eEndogenous ||
|
if (type == eEndogenous ||
|
||||||
type == eExogenousDet ||
|
type == eExogenousDet ||
|
||||||
type == eExogenous ||
|
type == eExogenous ||
|
||||||
type == eRecursiveVariable)
|
type == eRecursiveVariable)
|
||||||
{
|
{
|
||||||
id = VariableTable::getID(iArgName,iLag);
|
id = variable_table.getID(iArgName,iLag);
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
{
|
{
|
||||||
std::string msg = "unknown variable " + iArgName;
|
std::string msg = "unknown variable " + iArgName;
|
||||||
|
@ -237,7 +242,7 @@ inline NodeID DataTree::AddTerminal(std::string iArgName, int iLag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
id = SymbolTable::getID(iArgName);
|
id = symbol_table.getID(iArgName);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -751,7 +756,7 @@ inline NodeID DataTree::AddSqRt(NodeID iArg1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeID DataTree::AddEqual(NodeID iArg1, NodeID iArg2=Zero)
|
inline NodeID DataTree::AddEqual(NodeID iArg1, NodeID iArg2)
|
||||||
{
|
{
|
||||||
if (iArg1 == Zero && iArg2 == Zero)
|
if (iArg1 == Zero && iArg2 == Zero)
|
||||||
return ZeroEqZero;
|
return ZeroEqZero;
|
||||||
|
@ -767,7 +772,7 @@ inline NodeID DataTree::AddEqual(NodeID iArg1, NodeID iArg2=Zero)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeID DataTree::AddAssign(NodeID iArg1, NodeID iArg2=Zero)
|
inline NodeID DataTree::AddAssign(NodeID iArg1, NodeID iArg2)
|
||||||
{
|
{
|
||||||
MToken lToken(iArg1, eTempResult, iArg2, token::ASSIGN);
|
MToken lToken(iArg1, eTempResult, iArg2, token::ASSIGN);
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,17 @@ private :
|
||||||
/*! Operator table : names and precedences */
|
/*! Operator table : names and precedences */
|
||||||
OperatorTable operator_table;
|
OperatorTable operator_table;
|
||||||
/*! Output string of the class */
|
/*! Output string of the class */
|
||||||
static std::ostringstream output;
|
std::ostringstream output;
|
||||||
|
//! Pointer to numerical constants table
|
||||||
|
NumericalConstants *num_constants;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
/*! Constructor */
|
/*! Constructor */
|
||||||
Expression();
|
Expression();
|
||||||
/*! Destructor */
|
/*! Destructor */
|
||||||
~Expression();
|
~Expression();
|
||||||
|
//! Set numerical constants pointer
|
||||||
|
void setNumericalConstants(NumericalConstants *num_constants_arg);
|
||||||
/*! Adds binary token to expression list */
|
/*! Adds binary token to expression list */
|
||||||
int AddToken(int id1,Type type1, int id2,Type type2,int op_code);
|
int AddToken(int id1,Type type1, int id2,Type type2,int op_code);
|
||||||
/*! Adds unary token to expression list */
|
/*! Adds unary token to expression list */
|
||||||
|
@ -63,13 +67,13 @@ public :
|
||||||
/*! Adds unkown function to expression list */
|
/*! Adds unkown function to expression list */
|
||||||
int AddToken(int id1,Type type1, std::string ufunction);
|
int AddToken(int id1,Type type1, std::string ufunction);
|
||||||
/*! Returns output string */
|
/*! Returns output string */
|
||||||
static std::string get(void);
|
std::string get();
|
||||||
/*! Clear expression list */
|
/*! Clear expression list */
|
||||||
void clear(void);
|
void clear(void);
|
||||||
/*! Print expression to output string */
|
/*! Print expression to output string */
|
||||||
void set(void);
|
void set(void);
|
||||||
/*! Gets output argument name */
|
/*! Gets output argument name */
|
||||||
static std::string getArgument(Type type,int id);
|
std::string getArgument(Type type, int id);
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef _MOD_FILE_HH
|
||||||
|
#define _MOD_FILE_HH
|
||||||
|
|
||||||
|
#include "ModelParameters.hh"
|
||||||
|
#include "SymbolTable.hh"
|
||||||
|
#include "NumericalConstants.hh"
|
||||||
|
#include "NumericalInitialization.hh"
|
||||||
|
#include "Shocks.hh"
|
||||||
|
#include "SigmaeInitialization.hh"
|
||||||
|
#include "ComputingTasks.hh"
|
||||||
|
#include "ModelTree.hh"
|
||||||
|
#include "VariableTable.hh"
|
||||||
|
|
||||||
|
//! The abstract representation of a "mod" file
|
||||||
|
class ModFile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
ModFile();
|
||||||
|
//! Model parameters
|
||||||
|
ModelParameters model_parameters;
|
||||||
|
//! Symbol table
|
||||||
|
SymbolTable symbol_table;
|
||||||
|
//! Variable table
|
||||||
|
VariableTable variable_table;
|
||||||
|
//! Numerical constants
|
||||||
|
NumericalConstants num_constants;
|
||||||
|
//! Numerical initalisations
|
||||||
|
NumericalInitialization numerical_initialization;
|
||||||
|
//! Shocks instructions
|
||||||
|
Shocks shocks;
|
||||||
|
//! Sigma_e instructions
|
||||||
|
SigmaeInitialization sigmae;
|
||||||
|
//! Computing tasks instructions
|
||||||
|
ComputingTasks computing_tasks;
|
||||||
|
//! Model equations and their derivatives
|
||||||
|
ModelTree model_tree;
|
||||||
|
//! Option order
|
||||||
|
int order;
|
||||||
|
//! Option linear
|
||||||
|
int linear;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ! MOD_FILE_HH
|
|
@ -14,40 +14,38 @@
|
||||||
class ModelParameters
|
class ModelParameters
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
/*! Constructor */
|
//! Constructor
|
||||||
ModelParameters();
|
ModelParameters();
|
||||||
/*! Destructor */
|
|
||||||
~ModelParameters();
|
|
||||||
/*! Number of equations*/
|
/*! Number of equations*/
|
||||||
static int eq_nbr;
|
int eq_nbr;
|
||||||
/*! Number of declared Exogenous variables */
|
/*! Number of declared Exogenous variables */
|
||||||
static int exo_nbr;
|
int exo_nbr;
|
||||||
/*! Number of Exogenous variables that apear in model equations*/
|
/*! Number of Exogenous variables that apear in model equations*/
|
||||||
static int var_exo_nbr;
|
int var_exo_nbr;
|
||||||
/*! Number of deterministic Exogenous variables */
|
/*! Number of deterministic Exogenous variables */
|
||||||
static int exo_det_nbr;
|
int exo_det_nbr;
|
||||||
static int var_exo_det_nbr;
|
int var_exo_det_nbr;
|
||||||
/*! Number of declared Endogenous variables */
|
/*! Number of declared Endogenous variables */
|
||||||
static int endo_nbr;
|
int endo_nbr;
|
||||||
/*! Number of Endogenous variables that apear in model equations*/
|
/*! Number of Endogenous variables that apear in model equations*/
|
||||||
static int var_endo_nbr;
|
int var_endo_nbr;
|
||||||
/*! Number of parameters */
|
/*! Number of parameters */
|
||||||
static int parameter_nbr;
|
int parameter_nbr;
|
||||||
/*! Number of local parameters */
|
/*! Number of local parameters */
|
||||||
static int local_parameter_nbr;
|
int local_parameter_nbr;
|
||||||
/*! Number of recursive variables */
|
/*! Number of recursive variables */
|
||||||
static int recur_nbr;
|
int recur_nbr;
|
||||||
|
|
||||||
static int max_lag;
|
int max_lag;
|
||||||
static int max_lead;
|
int max_lead;
|
||||||
static int max_endo_lag;
|
int max_endo_lag;
|
||||||
static int max_endo_lead;
|
int max_endo_lead;
|
||||||
static int max_exo_lag;
|
int max_exo_lag;
|
||||||
static int max_exo_lead;
|
int max_exo_lead;
|
||||||
static int max_exo_det_lag;
|
int max_exo_det_lag;
|
||||||
static int max_exo_det_lead;
|
int max_exo_det_lead;
|
||||||
static int max_recur_lag;
|
int max_recur_lag;
|
||||||
static int max_recur_lead;
|
int max_recur_lead;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,7 +35,7 @@ private :
|
||||||
/*! Output for dynamic model */
|
/*! Output for dynamic model */
|
||||||
std::ostringstream DynamicOutput;
|
std::ostringstream DynamicOutput;
|
||||||
/*! Output for main file */
|
/*! Output for main file */
|
||||||
static std::ostringstream output;
|
std::ostringstream output;
|
||||||
/*! Output file stream for static model */
|
/*! Output file stream for static model */
|
||||||
std::ofstream mStaticModelFile;
|
std::ofstream mStaticModelFile;
|
||||||
/*! Output file stream for dynamic model */
|
/*! Output file stream for dynamic model */
|
||||||
|
@ -49,6 +49,10 @@ private :
|
||||||
char lpar, rpar;
|
char lpar, rpar;
|
||||||
/*! Name of parameter variables ("params" for C output, and M_.params for Matlab) */
|
/*! Name of parameter variables ("params" for C output, and M_.params for Matlab) */
|
||||||
std::string param_name;
|
std::string param_name;
|
||||||
|
//! Reference to model parameters
|
||||||
|
ModelParameters &mod_param;
|
||||||
|
//! Reference to numerical constants table
|
||||||
|
const NumericalConstants &num_constants;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
/*! Computes argument derivative */
|
/*! Computes argument derivative */
|
||||||
|
@ -66,7 +70,7 @@ public :
|
||||||
/*! When Hessian is writen this flag is set to true */
|
/*! When Hessian is writen this flag is set to true */
|
||||||
bool computeHessian;
|
bool computeHessian;
|
||||||
/*! Constructor */
|
/*! Constructor */
|
||||||
ModelTree();
|
ModelTree(SymbolTable &symbol_table_arg, VariableTable &variable_table_arg, ModelParameters &mod_param_arg, const NumericalConstants &num_constants);
|
||||||
/*! Destructor */
|
/*! Destructor */
|
||||||
~ModelTree();
|
~ModelTree();
|
||||||
/*! Opens output M files (1st and 2nd derivatives) */
|
/*! Opens output M files (1st and 2nd derivatives) */
|
||||||
|
@ -94,7 +98,7 @@ public :
|
||||||
/*! Writes initialization of various Matlab variables */
|
/*! Writes initialization of various Matlab variables */
|
||||||
void ModelInitialization(void);
|
void ModelInitialization(void);
|
||||||
/*! Returns string output for main file */
|
/*! Returns string output for main file */
|
||||||
static std::string get();
|
std::string get();
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -89,7 +89,9 @@ struct MTokenLess
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
// For MetaToken::getDerivativeAddress()
|
||||||
|
class ModelTree;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\struct MetaToken
|
\struct MetaToken
|
||||||
\brief Meta token structure
|
\brief Meta token structure
|
||||||
|
@ -205,11 +207,15 @@ public :
|
||||||
d1[iVarID] = iDerivative;
|
d1[iVarID] = iDerivative;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Get derivative with respect to iVarID.
|
//! Get derivative with respect to iVarID.
|
||||||
Defined in ModelTree.cc because it needs DataTree::Zero and DataTree::ZeroEqZero
|
/*
|
||||||
|
Defined in ModelTree.cc because it needs a reference to the enclosing ModelTree,
|
||||||
and is only used in that source file.
|
and is only used in that source file.
|
||||||
|
|
||||||
|
\param iVarID variable with respect to get derivative
|
||||||
|
\param model_tree enclosing ModelTree
|
||||||
*/
|
*/
|
||||||
inline NodeID getDerivativeAddress(int iVarID);
|
inline NodeID getDerivativeAddress(int iVarID, const ModelTree &model_tree) const;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/*! Equation type enum */
|
/*! Equation type enum */
|
||||||
|
|
|
@ -19,18 +19,18 @@ class NumericalConstants
|
||||||
{
|
{
|
||||||
private :
|
private :
|
||||||
/*! Vector of numerical constants */
|
/*! Vector of numerical constants */
|
||||||
static std::vector<std::string> mNumericalConstants;
|
std::vector<std::string> mNumericalConstants;
|
||||||
//! Map matching constants to their id
|
//! Map matching constants to their id
|
||||||
static std::map<std::string, int, std::less<std::string> > numConstantsIndex;
|
std::map<std::string, int, std::less<std::string> > numConstantsIndex;
|
||||||
public :
|
public :
|
||||||
/*! Construcor */
|
/*! Construcor */
|
||||||
NumericalConstants();
|
NumericalConstants();
|
||||||
/*! Destructor */
|
/*! Destructor */
|
||||||
~NumericalConstants();
|
~NumericalConstants();
|
||||||
/*! Adds a constant to mNumericalConstants */
|
/*! Adds a constant to mNumericalConstants */
|
||||||
static int AddConstant(std::string iConst);
|
int AddConstant(std::string iConst);
|
||||||
/*! Gets a constant form mNumericalConstants */
|
/*! Gets a constant form mNumericalConstants */
|
||||||
static std::string get(int iID);
|
std::string get(int iID) const;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,9 +21,13 @@ class NumericalInitialization
|
||||||
private :
|
private :
|
||||||
/*! Output of this class */
|
/*! Output of this class */
|
||||||
std::ostringstream *output;
|
std::ostringstream *output;
|
||||||
|
//! Reference to symbol table
|
||||||
|
const SymbolTable &symbol_table;
|
||||||
|
//! Reference to model parameters
|
||||||
|
const ModelParameters &mod_param;
|
||||||
public :
|
public :
|
||||||
/*! Constructor */
|
/*! Constructor */
|
||||||
NumericalInitialization();
|
NumericalInitialization(const SymbolTable &symbol_table_arg, const ModelParameters &mod_param_arg);
|
||||||
/*! Destrcutor */
|
/*! Destrcutor */
|
||||||
~NumericalInitialization();
|
~NumericalInitialization();
|
||||||
/*! Pointer to error function of parser class */
|
/*! Pointer to error function of parser class */
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "ModFile.hh"
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/*!
|
/*!
|
||||||
\class OutputFile
|
\class OutputFile
|
||||||
|
@ -28,9 +30,9 @@ public :
|
||||||
/*! Destructor */
|
/*! Destructor */
|
||||||
~OutputFile();
|
~OutputFile();
|
||||||
/*! Opens a given file and writes some initialization */
|
/*! Opens a given file and writes some initialization */
|
||||||
void Open(std::string iFileName);
|
void Open(std::string iFileName, ModFile *mod_file);
|
||||||
/*! Writes output data from SymbolTable and passed strings to output file */
|
/*! Writes output data from SymbolTable and passed strings to output file */
|
||||||
void Save(std::ostringstream& iOutput);
|
void Save(std::ostringstream& iOutput, ModFile *mod_file);
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
#ifndef _PARSING_DRIVER_HH
|
#ifndef _PARSING_DRIVER_HH
|
||||||
#define _PARSING_DRIVER_HH
|
#define _PARSING_DRIVER_HH
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "ModelParameters.hh"
|
#include "ModFile.hh"
|
||||||
#include "SymbolTable.hh"
|
|
||||||
#include "Expression.hh"
|
#include "Expression.hh"
|
||||||
#include "NumericalInitialization.hh"
|
|
||||||
#include "ModelTree.hh"
|
|
||||||
#include "VariableTable.hh"
|
|
||||||
#include "Shocks.hh"
|
|
||||||
#include "SigmaeInitialization.hh"
|
|
||||||
#include "ComputingTasks.hh"
|
|
||||||
#include "TmpSymbolTable.hh"
|
#include "TmpSymbolTable.hh"
|
||||||
#include "DynareBison.hh"
|
#include "DynareBison.hh"
|
||||||
|
#include "ComputingTasks.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -46,49 +39,31 @@ private:
|
||||||
//! 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);
|
||||||
|
|
||||||
//! Stores model parameters
|
|
||||||
ModelParameters model_parameters;
|
|
||||||
//! Stores symbol table
|
|
||||||
SymbolTable symbol_table;
|
|
||||||
//! Stores expressions
|
//! Stores expressions
|
||||||
Expression expression;
|
Expression expression;
|
||||||
//! Stores numerical constants
|
|
||||||
NumericalConstants num_constants;
|
|
||||||
//! Handles numerical initalisations
|
|
||||||
NumericalInitialization numerical_initialization;
|
|
||||||
//! Handles shock command
|
|
||||||
Shocks shocks;
|
|
||||||
//! Handles sigma_e command
|
|
||||||
SigmaeInitialization sigmae;
|
|
||||||
//! Handles computing tasks commands
|
|
||||||
ComputingTasks computing_tasks;
|
|
||||||
//! Stores temporary symbol table
|
//! Stores temporary symbol table
|
||||||
TmpSymbolTable tmp_symbol_table;
|
TmpSymbolTable tmp_symbol_table;
|
||||||
//! Stores model tree
|
|
||||||
ModelTree model_tree;
|
|
||||||
//! Stores variable table
|
|
||||||
VariableTable variable_table;
|
|
||||||
//! Stores operator table
|
//! Stores operator table
|
||||||
OperatorTable op_table;
|
OperatorTable op_table;
|
||||||
//! Value of option order
|
|
||||||
int order;
|
|
||||||
//! Value of option linear
|
|
||||||
int linear;
|
|
||||||
|
|
||||||
public:
|
//! The mod file representation constructed by this ParsingDriver
|
||||||
|
ModFile *mod_file;
|
||||||
|
|
||||||
//! Reference to output string
|
//! Reference to output string
|
||||||
ostringstream *output;
|
ostringstream *output;
|
||||||
//! Estimation parameters
|
|
||||||
EstimationParams estim_params;
|
|
||||||
|
|
||||||
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
ParsingDriver();
|
ParsingDriver();
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~ParsingDriver();
|
virtual ~ParsingDriver();
|
||||||
|
|
||||||
//! Starts parsing
|
//! Starts parsing, and constructs the MOD file representation
|
||||||
/*! \param f Name of file to parse */
|
/*! \param f Name of file to parse
|
||||||
void parse(const string &f);
|
|
||||||
|
The returned pointer should be deleted after use.
|
||||||
|
*/
|
||||||
|
ModFile *parse(const string &f);
|
||||||
|
|
||||||
//! Name of file being parsed
|
//! Name of file being parsed
|
||||||
string file;
|
string file;
|
||||||
|
@ -102,6 +77,9 @@ public:
|
||||||
/*! If set to true before calling parse(), the bison parser will dump debugging information. Defaults to false. */
|
/*! If set to true before calling parse(), the bison parser will dump debugging information. Defaults to false. */
|
||||||
bool trace_parsing;
|
bool trace_parsing;
|
||||||
|
|
||||||
|
//! Estimation parameters
|
||||||
|
EstimationParams estim_params;
|
||||||
|
|
||||||
//! Error handler with location
|
//! Error handler with location
|
||||||
void error(const yy::parser::location_type &l, const string &m);
|
void error(const yy::parser::location_type &l, const string &m);
|
||||||
//! Error handler without location
|
//! Error handler without location
|
||||||
|
@ -118,10 +96,10 @@ public:
|
||||||
|
|
||||||
//! Sets reference to output string
|
//! Sets reference to output string
|
||||||
void setoutput(ostringstream *ostr);
|
void setoutput(ostringstream *ostr);
|
||||||
//! Remove unused symbol from symbol table
|
|
||||||
void check_model();
|
|
||||||
//! Executes final instructions
|
//! Executes final instructions
|
||||||
void finish();
|
void finish();
|
||||||
|
//! Check if a given symbol exists in the parsing context
|
||||||
|
bool exists_symbol(const char *s);
|
||||||
//! Sets variable offset of ModelTree class to use C output
|
//! Sets variable offset of ModelTree class to use C output
|
||||||
void use_dll();
|
void use_dll();
|
||||||
//! Declares an endogenous variable by adding it to SymbolTable
|
//! Declares an endogenous variable by adding it to SymbolTable
|
||||||
|
@ -257,7 +235,9 @@ public:
|
||||||
void add_mc_filename(string *filename, string *prior = new string("1"));
|
void add_mc_filename(string *filename, string *prior = new string("1"));
|
||||||
void run_model_comparison();
|
void run_model_comparison();
|
||||||
//! Writes token "arg1=arg2" to model tree
|
//! Writes token "arg1=arg2" to model tree
|
||||||
NodeID add_model_equal(NodeID arg1, NodeID arg2 = ModelTree::Zero);
|
NodeID add_model_equal(NodeID arg1, NodeID arg2);
|
||||||
|
//! Writes token "arg=0" to model tree
|
||||||
|
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_model_plus(NodeID arg1, NodeID arg2);
|
||||||
//! Writes token "arg1-arg2" to model tree
|
//! Writes token "arg1-arg2" to model tree
|
||||||
|
@ -302,6 +282,8 @@ public:
|
||||||
NodeID add_model_atanh(NodeID arg1);
|
NodeID add_model_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_model_sqrt(NodeID arg1);
|
||||||
|
//! Adds a native statement
|
||||||
|
void add_native(const char *s);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ! PARSING_DRIVER_HH
|
#endif // ! PARSING_DRIVER_HH
|
||||||
|
|
|
@ -21,6 +21,7 @@ class Shocks
|
||||||
{
|
{
|
||||||
private :
|
private :
|
||||||
int mshock_flag;
|
int mshock_flag;
|
||||||
|
int exo_det_length;
|
||||||
/*!
|
/*!
|
||||||
\class ShockElement
|
\class ShockElement
|
||||||
\brief Shock element strcuture
|
\brief Shock element strcuture
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include "ModelParameters.hh"
|
#include "ModelParameters.hh"
|
||||||
#include "SymbolTableTypes.hh"
|
#include "SymbolTableTypes.hh"
|
||||||
|
@ -19,12 +18,11 @@
|
||||||
\class SymbolTable
|
\class SymbolTable
|
||||||
\brief This class keeps track of symbols
|
\brief This class keeps track of symbols
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class SymbolTable
|
class SymbolTable
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
private :
|
//! A reference to the model parameters
|
||||||
static std::ostringstream output;
|
ModelParameters &mod_param;
|
||||||
/*! Adds symbol into symbol table
|
/*! Adds symbol into symbol table
|
||||||
\param name a string.
|
\param name a string.
|
||||||
\param type a Type struct.
|
\param type a Type struct.
|
||||||
|
@ -35,64 +33,60 @@ private :
|
||||||
- set Name and Type
|
- set Name and Type
|
||||||
- increase corresponding counter in ModelParameters class
|
- increase corresponding counter in ModelParameters class
|
||||||
*/
|
*/
|
||||||
static int AddSymbol(std::string name,Type type, std::string tex_name);
|
int AddSymbol(std::string name, Type type, std::string tex_name);
|
||||||
protected :
|
|
||||||
/*! Symbol table map */
|
/*! Symbol table map */
|
||||||
static std::map<std::string, Symbol, std::less<std::string> > symboltable;
|
std::map<std::string, Symbol, std::less<std::string> > symboltable;
|
||||||
|
//! Typedef for const iterator on symboltable map
|
||||||
|
typedef std::map<std::string, Symbol, std::less<std::string> >::const_iterator symboltable_const_iterator;
|
||||||
/*! Symbol name table indexed by type and ID */
|
/*! Symbol name table indexed by type and ID */
|
||||||
static std::vector< std::vector<std::string> > name_table;
|
std::vector< std::vector<std::string> > name_table;
|
||||||
static std::vector< std::vector<std::string> > tex_name_table;
|
std::vector< std::vector<std::string> > tex_name_table;
|
||||||
protected :
|
|
||||||
/*! Changes type of a symbol */
|
/*! Changes type of a symbol */
|
||||||
static void ResetType(std::string name,Type new_type);
|
void ResetType(std::string name, Type new_type);
|
||||||
public :
|
public :
|
||||||
/*! Constructor */
|
/*! Constructor */
|
||||||
SymbolTable();
|
SymbolTable(ModelParameters &mod_param_arg);
|
||||||
/*! Destructor*/
|
/*! Destructor*/
|
||||||
~SymbolTable();
|
~SymbolTable();
|
||||||
/*! Pointer to error function of parser class */
|
/*! Pointer to error function of parser class */
|
||||||
static void (* error) (const char* m);
|
void (* error) (const char* m);
|
||||||
/*! Adds a symbol apearing in declaration
|
/*! Adds a symbol apearing in declaration
|
||||||
- warning if symbol is already set with same type
|
- warning if symbol is already set with same type
|
||||||
- error if symbol is already set with different type
|
- error if symbol is already set with different type
|
||||||
- set name, type
|
- set name, type
|
||||||
- increase corresponding counter in ModelParameters
|
- increase corresponding counter in ModelParameters
|
||||||
*/
|
*/
|
||||||
static int AddSymbolDeclar(std::string name,Type type, std::string tex_name);
|
int AddSymbolDeclar(std::string name, Type type, std::string tex_name);
|
||||||
/*! Adds symbol range */
|
/*! Adds symbol range */
|
||||||
static void AddSymbolRange(std::string name,int nbr,Type type, std::string tex_name);
|
void AddSymbolRange(std::string name, int nbr, Type type, std::string tex_name);
|
||||||
/*! Adds a lag to field lags */
|
|
||||||
static void AddLag(std::string name,int lag);
|
|
||||||
/*! Sets a symbol as referenced */
|
/*! Sets a symbol as referenced */
|
||||||
static void SetReferenced(std::string name);
|
void SetReferenced(std::string name);
|
||||||
/*! Return eReferenced if symbol is referenced eNotReferenced otherwise*/
|
/*! Return eReferenced if symbol is referenced eNotReferenced otherwise*/
|
||||||
static Reference isReferenced(std::string name);
|
Reference isReferenced(const std::string &name) const;
|
||||||
/*! Tests if symbol exists in symbol table
|
/*! Tests if symbol exists in symbol table
|
||||||
\return true if exists, false outherwise
|
\return true if exists, false outherwise
|
||||||
*/
|
*/
|
||||||
inline static bool Exist(std::string name);
|
inline bool Exist(const std::string &name) const;
|
||||||
/*! Gets name by type and ID */
|
/*! Gets name by type and ID */
|
||||||
inline static std::string getNameByID(Type type,int id);
|
inline std::string getNameByID(Type type, int id);
|
||||||
/*! Gets tex name by type and ID */
|
/*! Gets tex name by type and ID */
|
||||||
inline static std::string getTexNameByID(Type type,int id);
|
inline std::string getTexNameByID(Type type, int id);
|
||||||
/*! Gets type by name */
|
/*! Gets type by name */
|
||||||
inline static Type getType(std::string name);
|
inline Type getType(const std::string &name) const;
|
||||||
/*! Gets ID by name */
|
/*! Gets ID by name */
|
||||||
inline static int getID(std::string name);
|
inline int getID(const std::string &name) const;
|
||||||
/*! Gets output string of this class */
|
/*! Gets output string of this class */
|
||||||
static std::string get();
|
std::string get();
|
||||||
|
#if 0 // Commented out on 27/11/2006, SV
|
||||||
/*! Checks if symbols are used in model equations, removes unused symbol */
|
/*! Checks if symbols are used in model equations, removes unused symbol */
|
||||||
void clean();
|
void clean();
|
||||||
void erase_local_parameters();
|
#endif // Comment
|
||||||
};
|
};
|
||||||
inline bool SymbolTable::Exist(std::string name)
|
|
||||||
{
|
|
||||||
std::map<std::string, Symbol, std::less<std::string> >::iterator iter;
|
|
||||||
|
|
||||||
iter = symboltable.find(name);
|
inline bool SymbolTable::Exist(const std::string &name) const
|
||||||
//Testing if symbol exists
|
{
|
||||||
if (iter == symboltable.end()) return false;
|
symboltable_const_iterator iter = symboltable.find(name);
|
||||||
else return true;
|
return (iter != symboltable.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -112,21 +106,23 @@ inline std::string SymbolTable::getTexNameByID(Type type,int id)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
inline Type SymbolTable::getType(std::string name)
|
inline Type SymbolTable::getType(const std::string &name) const
|
||||||
{
|
{
|
||||||
if (Exist(name))
|
symboltable_const_iterator iter = symboltable.find(name);
|
||||||
return(symboltable[name].type);
|
if (iter == symboltable.end())
|
||||||
else
|
|
||||||
return eUNDEF;
|
return eUNDEF;
|
||||||
|
else
|
||||||
|
return iter->second.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
inline int SymbolTable::getID(std::string name)
|
inline int SymbolTable::getID(const std::string &name) const
|
||||||
{
|
{
|
||||||
if (Exist(name))
|
symboltable_const_iterator iter = symboltable.find(name);
|
||||||
return(symboltable[name].id);
|
if (iter == symboltable.end())
|
||||||
else
|
|
||||||
return -1;
|
return -1;
|
||||||
|
else
|
||||||
|
return(iter->second.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
|
@ -40,8 +40,7 @@ struct Symbol
|
||||||
int id;
|
int id;
|
||||||
/*! Symbol reference flag */
|
/*! Symbol reference flag */
|
||||||
Reference referenced;
|
Reference referenced;
|
||||||
/*! Lags of symbol if it is a variable */
|
|
||||||
std::vector<int> lags;
|
|
||||||
Symbol()
|
Symbol()
|
||||||
{
|
{
|
||||||
type = eUNDEF;
|
type = eUNDEF;
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
#include "SymbolTable.hh"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class TmpSymbolTable
|
\class TmpSymbolTable
|
||||||
\brief Defines temparary symbol table used with computing tasks
|
\brief Defines temparary symbol table used with computing tasks
|
||||||
|
@ -23,13 +25,15 @@ private :
|
||||||
std::list<std::string> NameTable;
|
std::list<std::string> NameTable;
|
||||||
/*! Output of this class */
|
/*! Output of this class */
|
||||||
std::ostringstream output;
|
std::ostringstream output;
|
||||||
|
//! Pointer to global symbol table
|
||||||
|
SymbolTable *symbol_table;
|
||||||
public :
|
public :
|
||||||
/*! Constrcutor */
|
/*! Constrcutor */
|
||||||
TmpSymbolTable();
|
TmpSymbolTable();
|
||||||
/*! Copy constructor */
|
|
||||||
TmpSymbolTable(const TmpSymbolTable &tst);
|
|
||||||
/*! Destructor*/
|
/*! Destructor*/
|
||||||
~TmpSymbolTable();
|
~TmpSymbolTable();
|
||||||
|
//! Sets global symbol table pointer
|
||||||
|
void setGlobalSymbolTable(SymbolTable *symbol_table_arg);
|
||||||
/*! Pointer to error function of parser class */
|
/*! Pointer to error function of parser class */
|
||||||
void (* error) (const char* m);
|
void (* error) (const char* m);
|
||||||
/*! Adds a temp symbol */
|
/*! Adds a temp symbol */
|
||||||
|
|
|
@ -37,18 +37,21 @@ typedef std::pair<std::string, int> varKey;
|
||||||
class VariableTable
|
class VariableTable
|
||||||
{
|
{
|
||||||
private :
|
private :
|
||||||
|
//! A reference to the symbol table
|
||||||
|
const SymbolTable &symbol_table;
|
||||||
|
//! A reference to model parameters
|
||||||
|
ModelParameters &mod_param;
|
||||||
/*! Variable table data */
|
/*! Variable table data */
|
||||||
//static std::map<varKey,Variable> mVariableTable;
|
std::map<varKey,int> mVariableTable;
|
||||||
static std::map<varKey,int> mVariableTable;
|
|
||||||
/*! Index (IDs) of variables in variable table */
|
/*! Index (IDs) of variables in variable table */
|
||||||
static std::vector<varKey> mVariableIndex;
|
std::vector<varKey> mVariableIndex;
|
||||||
/*! Variable IDs of sorted variable table */
|
/*! Variable IDs of sorted variable table */
|
||||||
static std::vector<int> mSortedVariableID;
|
std::vector<int> mSortedVariableID;
|
||||||
/*! Output index for variable table */
|
/*! Output index for variable table */
|
||||||
static std::vector<int> mPrintFormatIndex;
|
std::vector<int> mPrintFormatIndex;
|
||||||
public :
|
public :
|
||||||
/*! */
|
/*! */
|
||||||
VariableTable();
|
VariableTable(const SymbolTable &symbol_table_arg, ModelParameters &mod_param_arg);
|
||||||
/*! */
|
/*! */
|
||||||
~VariableTable();
|
~VariableTable();
|
||||||
/*! Find type and ID in SymbolTable
|
/*! Find type and ID in SymbolTable
|
||||||
|
@ -56,27 +59,27 @@ public :
|
||||||
- Make variable
|
- Make variable
|
||||||
- Push variable on variabletable
|
- Push variable on variabletable
|
||||||
*/
|
*/
|
||||||
static int AddVariable(std::string iName, int iLag);
|
int AddVariable(std::string iName, int iLag);
|
||||||
/*! Pointer to error function of parser class */
|
/*! Pointer to error function of parser class */
|
||||||
static void (* error) (const char* m);
|
void (* error) (const char* m);
|
||||||
/*! Decremente a symbol id of a variable */
|
/*! Decremente a symbol id of a variable */
|
||||||
static void decSymbolID(std::string iName, int id, int iLag, Type iType);
|
void decSymbolID(std::string iName, int id, int iLag, Type iType);
|
||||||
/*! Return VariableTable[name,lag].variable_id */
|
/*! Return VariableTable[name,lag].variable_id */
|
||||||
inline static int getID(std::string iName, int iLag);
|
inline int getID(std::string iName, int iLag);
|
||||||
/*! Return lag of variable */
|
/*! Return lag of variable */
|
||||||
inline static int getLag(int iID);
|
inline int getLag(int iID);
|
||||||
/*! Return symbol ID of variable */
|
/*! Return symbol ID of variable */
|
||||||
inline static int getSymbolID(int ivarID);
|
inline int getSymbolID(int ivarID);
|
||||||
/*! Gets varibale type */
|
/*! Gets varibale type */
|
||||||
inline static Type getType(int ivarID);
|
inline Type getType(int ivarID);
|
||||||
/*! Gets nomber of variables in mVariableTable */
|
/*! Gets nomber of variables in mVariableTable */
|
||||||
inline static int size(void);
|
inline int size();
|
||||||
/*! Gets variable ID of sorted variable table */
|
/*! Gets variable ID of sorted variable table */
|
||||||
inline static int getSortID(int);
|
inline int getSortID(int);
|
||||||
/*! Return variable index to print in format : y(index) or oo_.y_simul(index) ... */
|
/*! Return variable index to print in format : y(index) or oo_.y_simul(index) ... */
|
||||||
inline static int getPrintIndex(int iVarID);
|
inline int getPrintIndex(int iVarID);
|
||||||
/*! Sorts variable table */
|
/*! Sorts variable table */
|
||||||
static void Sort(void);
|
void Sort();
|
||||||
};
|
};
|
||||||
inline int VariableTable::getSortID(int iVarID)
|
inline int VariableTable::getSortID(int iVarID)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +110,7 @@ inline Type VariableTable::getType(int ivarID)
|
||||||
{
|
{
|
||||||
varKey key = mVariableIndex[ivarID];
|
varKey key = mVariableIndex[ivarID];
|
||||||
//return mVariableTable[key].type;
|
//return mVariableTable[key].type;
|
||||||
return SymbolTable::getType(key.first);
|
return symbol_table.getType(key.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -115,7 +118,7 @@ inline int VariableTable::getSymbolID(int ivarID)
|
||||||
{
|
{
|
||||||
varKey key = mVariableIndex[ivarID];
|
varKey key = mVariableIndex[ivarID];
|
||||||
//return mVariableTable[key].symbol_id;
|
//return mVariableTable[key].symbol_id;
|
||||||
return SymbolTable::getID(key.first);
|
return symbol_table.getID(key.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -125,12 +128,9 @@ inline int VariableTable::getLag(int iID)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
inline int VariableTable::size(void)
|
inline int VariableTable::size()
|
||||||
{
|
{
|
||||||
return mVariableTable.size();
|
return mVariableTable.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue