Commit 41a18b1d authored by sebastien's avatar sebastien
Browse files

v4 parser: reindentation of all C++ code, and conversion to UNIX newline convention


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1031 ac1d8469-bf42-47a9-8791-bf33cf982152
parent c50f757b
......@@ -3,7 +3,7 @@
* \date 12/16/2003
* \par This file implements the ComputingTasks class methodes.
*/
#include <iostream>
#include <iostream>
#include <sstream>
using namespace std;
......@@ -17,36 +17,43 @@ ComputingTasks::ComputingTasks()
{
// Empty
}
//------------------------------------------------------------------------------
ComputingTasks::~ComputingTasks()
{
// Empty
}
//------------------------------------------------------------------------------
void ComputingTasks::setOutput(ostringstream* iOutput)
{
output = iOutput;
}
//------------------------------------------------------------------------------
void ComputingTasks::set(void)
{
// Empty
}
//------------------------------------------------------------------------------
void ComputingTasks::setSteady(void)
{
*output << "steady;\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setCheck(void)
{
*output << "check;\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setSimul(void)
{
*output << "simul(oo_.dr);\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setStochSimul(string tmp1)
......@@ -54,28 +61,33 @@ void ComputingTasks::setStochSimul(string tmp1)
*output << tmp1;
*output << "stoch_simul(var_list_);\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setOption(string name, string value)
{
*output << "options_." << name << " = " << value << ";\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setOption(string name, string value1, string value2)
{
*output << "options_." << name << " = [" << value1 << "; " << value2 << "];\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::runEstimation(string tmp1)
{
*output << tmp1;
*output << "dynare_estimation(var_list_);\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::runRplot(string tmp1)
{
*output << tmp1;
*output << "rplot(var_list_);\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setEstimationInit(void)
{
......@@ -90,12 +102,14 @@ void ComputingTasks::setEstimationInit(void)
*output << "estim_params_.param_vals = [];\n";
*output << "M_.H = 0;\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setOptimOptions(string str1, string str2, int task)
{
static string optim_string;
static int start;
switch(task){
switch(task)
{
case 1:
optim_string = "options_.optim_opt = '";
start = 0;
......@@ -128,6 +142,7 @@ void ComputingTasks::setOptimOptions(string str1, string str2, int task)
*output << optim_string;
}
}
//------------------------------------------------------------------------------
void ComputingTasks::setEstimatedElements(void)
{
......@@ -180,6 +195,7 @@ void ComputingTasks::setEstimatedElements(void)
EstimParams->p3 << " " << EstimParams->p4 << " " << EstimParams->jscale << "];\n";
EstimParams->clear();
}
//------------------------------------------------------------------------------
void ComputingTasks::setEstimatedInitElements(void)
{
......@@ -229,6 +245,7 @@ void ComputingTasks::setEstimatedInitElements(void)
}
EstimParams->clear();
}
//------------------------------------------------------------------------------
void ComputingTasks::setEstimatedBoundsElements(void)
{
......@@ -283,6 +300,7 @@ void ComputingTasks::setEstimatedBoundsElements(void)
}
EstimParams->clear();
}
//-----------------------------------------------------------------------
void ComputingTasks::set_trend_element (string name, string expression)
{
......@@ -318,6 +336,7 @@ void ComputingTasks::BeginCalibVar(void)
*output << "calib_weights{" << i << "}=[];\n";
}
}
//------------------------------------------------------------------------------
void ComputingTasks::setCalibVar(string name, string weight, string expression)
{
......@@ -345,6 +364,7 @@ void ComputingTasks::setCalibVar(string name, string weight, string expression)
error(msg.c_str());
}
}
//------------------------------------------------------------------------------
void ComputingTasks::setCalibVar(string name1, string name2, string weight, string expression)
{
......@@ -383,6 +403,7 @@ void ComputingTasks::setCalibVar(string name1, string name2, string weight, stri
error(msg.c_str());
}
}
void ComputingTasks::setCalibAc(string name, string ar, string weight, string expression)
{
static int max_iar = 3;
......@@ -416,27 +437,32 @@ void ComputingTasks::setCalibAc(string name, string ar, string weight, string ex
error(msg.c_str());
}
}
//------------------------------------------------------------------------------
void ComputingTasks::runCalib(int cova)
{
*output << "M_.Sigma_e=calib(calib_var_index,calib_targets,calib_weights," << cova << ",Sigma_e_);\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setOsrParams(string tmp)
{
*output << tmp;
}
//------------------------------------------------------------------------------
void ComputingTasks::runOsr(string tmp1)
{
*output << tmp1;
*output << "osr(var_list_,osr_params_,obj_var_,optim_weights_);\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setOlrInst(string tmp)
{
*output << tmp;
}
//------------------------------------------------------------------------------
void ComputingTasks::runOlr(string tmp1)
{
......@@ -446,6 +472,7 @@ void ComputingTasks::runOlr(string tmp1)
*output << "options_.olr_inst = olr_inst_;\n";
*output << "info = stoch_simul(var_list_);\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::BeginOptimWeights(void)
{
......@@ -453,6 +480,7 @@ void ComputingTasks::BeginOptimWeights(void)
*output << "optim_weights_ = sparse(M_.endo_nbr,M_.endo_nbr);\n";
*output << "obj_var_ = [];\n\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setOptimWeights(string name, string exp)
{
......@@ -465,6 +493,7 @@ void ComputingTasks::setOptimWeights(string name, string exp)
*output << "optim_weights_(" << id << "," << id << ") = " << exp << ";\n";
*output << "obj_var_ = [obj_var_; " << id << "];\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::setOptimWeights(string name1, string name2, string exp)
{
......@@ -483,6 +512,7 @@ void ComputingTasks::setOptimWeights(string name1, string name2, string exp)
*output << "optim_weights_(" << id1 << "," << id2 << ") = " << exp << ";\n";
*output << "obj_var_ = [obj_var_; " << id1 << " " << id2 << "];\n";
}
//------------------------------------------------------------------------------
void ComputingTasks::runDynasave(string filename, string ext, string varlist)
{
......@@ -494,6 +524,7 @@ void ComputingTasks::runDynasave(string filename, string ext, string varlist)
}
*output << ",varlist_);\n";
}
void ComputingTasks::runDynatype(string filename, string ext, string varlist)
{
*output << varlist;
......@@ -504,23 +535,27 @@ void ComputingTasks::runDynatype(string filename, string ext, string varlist)
}
*output << ",varlist_);\n";
}
void ComputingTasks::beginModelComparison(void)
{
*output << "ModelNames_ = {};\n";
*output << "ModelPriors_ = {};\n";
}
void ComputingTasks::addMcFilename(string filename, string prior)
{
*output << "ModelNames_ = { ModelNames_{:} '" << filename << "};\n";
*output << "ModelPriors_ = { ModelPriors_{:} '" << prior << "};\n";
}
void ComputingTasks::runModelComparison(void)
{
*output << "model_comparison(ModelNames_,ModelPriors_);\n";
}
/*
string ComputingTasks::get(void)
{
string ComputingTasks::get(void)
{
return output.str();
}
}
*/
......@@ -42,7 +42,6 @@ DataTree::DataTree()
mModelTree.push_back(Zero);
mIndexOfTokens[Zero->Key()]=Zero;
One->op_name = "";
One->reference_count.resize(current_order+1,1);
One->idx = 1;
......@@ -65,6 +64,7 @@ DataTree::DataTree()
BeginModel = mModelTree.end();
BeginModel--;
}
//------------------------------------------------------------------------------
DataTree::~DataTree()
{
......
......@@ -26,7 +26,8 @@ int main(int argc, char** argv)
OutputFile output_file;
ostringstream output;
int retval = 0;
try {
try
{
if (argc <2)
{
cout << "Missing model file\n";
......@@ -75,7 +76,8 @@ int main(int argc, char** argv)
}
// Handeling parser and scanner exeptions
catch (std::exception& e) {
catch (std::exception& e)
{
cout << e.what() << std::endl;
return 0;
}
......@@ -83,4 +85,5 @@ int main(int argc, char** argv)
cout << "Starting Matlab computing ...\n";
return retval;
}
//------------------------------------------------------------------------------
......@@ -39,24 +39,28 @@ dynare::Objects* dynare::parser::add_endogenous(Objects* obj, Objects* tex_name)
obj->type = eEndogenous;
return (obj);
}
dynare::Objects* dynare::parser::add_exogenous(Objects* obj, Objects* tex_name)
{
obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eExogenous, tex_name->symbol);
obj->type = eExogenous;
return (obj);
}
dynare::Objects* dynare::parser::add_exogenous_det(Objects* obj, Objects* tex_name)
{
obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eExogenousDet, tex_name->symbol);
obj->type = eExogenousDet;
return (obj);
}
dynare::Objects* dynare::parser::add_parameter(Objects* obj, Objects* tex_name)
{
obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eParameter, tex_name->symbol);
obj->type = eParameter;
return (obj);
}
dynare::Objects* dynare::parser::add_local_parameter(Objects* obj)
{
obj->ID = (NodeID) symbol_table.AddSymbolDeclar(obj->symbol,eLocalParameter, obj->symbol);
......@@ -64,18 +68,21 @@ dynare::Objects* dynare::parser::add_local_parameter(Objects* obj)
NodeID id = model_tree.AddTerminal(obj->symbol);
return new Objects("", id, eTempResult);
}
dynare::Objects* dynare::parser::add_constant(Objects* obj)
{
obj->ID = (NodeID) num_constants.AddConstant(obj->symbol);
obj->type = eNumericalConstant;
return obj;
}
dynare::Objects* dynare::parser::add_model_constant(Objects* constant)
{
constant = add_constant(constant);
NodeID id = model_tree.AddTerminal(constant->ID, eNumericalConstant);
return new Objects("", id, eTempResult);
}
dynare::Objects* dynare::parser::add_variable(Objects* var)
{
//cout << "add_variable1 : " << var->symbol << endl;
......@@ -88,6 +95,7 @@ dynare::Objects* dynare::parser::add_variable(Objects* var)
NodeID id = model_tree.AddTerminal(var->symbol);
return new Objects("", id, eTempResult);
}
dynare::Objects* dynare::parser::add_variable(Objects* var,Objects* olag)
{
//cout << "add_variable2\n";
......@@ -108,6 +116,7 @@ dynare::Objects* dynare::parser::add_variable(Objects* var,Objects* olag)
NodeID id = model_tree.AddTerminal(var->symbol,lag);
return new Objects("", id, eTempResult);
}
dynare::Objects* dynare::parser::get_symbol(Objects* obj)
{
if (!symbol_table.Exist(obj->symbol))
......@@ -119,6 +128,7 @@ dynare::Objects* dynare::parser::get_symbol(Objects* obj)
obj->type = symbol_table.getType(obj->symbol);
return obj;
}
dynare::Objects* dynare::parser::translate_symbol(Objects* obj)
{
if (!symbol_table.Exist(obj->symbol))
......@@ -164,6 +174,7 @@ dynare::Objects* dynare::parser::add_expression_token( Objects* arg1, Objects*
//cout << "after add_expression_token\n";
return new Objects("", (NodeID) id, eTempResult);
}
dynare::Objects* dynare::parser::add_expression_token( Objects* arg1, Objects* op)
{
int id;
......@@ -181,6 +192,7 @@ dynare::Objects* dynare::parser::add_expression_token( Objects* arg1, Objects* o
//cout << "after add_expression_token\n";
return new Objects("", (NodeID) id, eTempResult);
}
dynare::Objects* dynare::parser::get_expression(Objects* exp)
{
if (exp->type == eTempResult)
......@@ -193,40 +205,48 @@ dynare::Objects* dynare::parser::get_expression(Objects* exp)
else
return exp;
}
dynare::Objects* dynare::parser::cat(Objects* string1, Objects* string2)
{
dynare::Objects* result = new dynare::Objects;
result->symbol = string1->symbol+string2->symbol;
return result;
}
dynare::Objects* dynare::parser::cat_with_space(Objects* string1, Objects* string2)
{
dynare::Objects* result = new dynare::Objects;
result->symbol = string1->symbol+" "+string2->symbol;
return result;
}
void dynare::parser::init_param(Objects* lhs, Objects* rhs)
{
numerical_initialization.SetConstant(lhs->symbol, rhs->symbol);
}
void dynare::parser::init_val(Objects* lhs, Objects* rhs)
{
numerical_initialization.SetInit(lhs->symbol, rhs->symbol);
}
void dynare::parser::hist_val(Objects* lhs, Objects* slag, Objects* rhs)
{
int lag = atoi((slag->symbol).c_str());
numerical_initialization.SetHist(lhs->symbol, lag, rhs->symbol);
}
void dynare::parser::use_dll(void)
{
// Seetting variable momber offset to use C outputs
model_tree.offset = 0;
}
void dynare::parser::check_model(void)
{
symbol_table.clean();
}
void dynare::parser::finish(void)
{
......@@ -276,38 +296,47 @@ void dynare::parser::finish(void)
symbol_table.erase_local_parameters();
}
void dynare::parser::begin_initval(void)
{
numerical_initialization.BeginInitval();
}
void dynare::parser::end_initval(void)
{
numerical_initialization.EndInitval();
}
void dynare::parser::begin_endval(void)
{
numerical_initialization.BeginEndval();
}
void dynare::parser::end_endval(void)
{
numerical_initialization.EndEndval();
}
void dynare::parser::begin_histval(void)
{
numerical_initialization.BeginHistval();
}
void dynare::parser::begin_shocks(void)
{
shocks.BeginShocks();
}
void dynare::parser::begin_mshocks(void)
{
shocks.BeginMShocks();
}
void dynare::parser::end_shocks(void)
{
shocks.EndShocks();
}
void dynare::parser::add_det_shock(Objects* var)
{
if (!symbol_table.Exist(var->symbol))
......@@ -328,6 +357,7 @@ void dynare::parser::add_det_shock(Objects* var)
error("Shocks can only be applied to exogenous variables");
}
}
void dynare::parser::add_stderr_shock(Objects* var, Objects* value)
{
if (!symbol_table.Exist(var->symbol))
......@@ -338,6 +368,7 @@ void dynare::parser::add_stderr_shock(Objects* var, Objects* value)
int id = symbol_table.getID(var->symbol);
shocks.AddSTDShock(id, value->symbol);
}
void dynare::parser::add_var_shock(Objects* var, Objects* value)
{
if (!symbol_table.Exist(var->symbol))
......@@ -348,6 +379,7 @@ void dynare::parser::add_var_shock(Objects* var, Objects* value)
int id = symbol_table.getID(var->symbol);
shocks.AddVARShock(id, value->symbol);
}
void dynare::parser::add_covar_shock(Objects* var1, Objects* var2, Objects* value)
{
if (!symbol_table.Exist(var1->symbol))
......@@ -364,6 +396,7 @@ void dynare::parser::add_covar_shock(Objects* var1, Objects* var2, Objects* valu
int id2 = symbol_table.getID(var2->symbol);
shocks.AddCOVAShock(id1, id2, value->symbol);
}
void dynare::parser::add_correl_shock(Objects* var1, Objects* var2, Objects* value)
{
if (!symbol_table.Exist(var1->symbol))
......@@ -380,35 +413,43 @@ void dynare::parser::add_correl_shock(Objects* var1, Objects* var2, Objects* val
int id2 = symbol_table.getID(var2->symbol);
shocks.AddCORRShock(id1, id2, value->symbol);
}
void dynare::parser::add_period(Objects* p1, Objects* p2)
{
shocks.AddPeriod(p1->symbol, p2->symbol);
}
void dynare::parser::add_period(Objects* p1)
{
shocks.AddPeriod(p1->symbol, p1->symbol);
}
void dynare::parser::add_value(Objects* value)
{
shocks.AddValue(value->symbol);
}
void dynare::parser::do_sigma_e(void)
{
sigmae.set();
}
void dynare::parser::end_of_row(void)
{
sigmae.EndOfRow();
}
void dynare::parser::add_to_row(Objects* s)
{
sigmae.AddExpression(s->symbol);
}
void dynare::parser::steady(void)
{
computing_tasks.setSteady();
model_tree.computeJacobian = true;
}
void dynare::parser::option_num(string name_option, Objects* opt)
{
computing_tasks.setOption(name_option, opt->symbol);
......@@ -417,10 +458,12 @@ void dynare::parser::option_num(string name_option, Objects* opt)
else if (name_option == "linear")
linear = atoi((opt->symbol).c_str());
}
void dynare::parser::option_num(string name_option, Objects* opt1, Objects* opt2)
{
computing_tasks.setOption(name_option, opt1->symbol, opt2->symbol);
}
void dynare::parser::option_num(string name_option, string opt)
{
computing_tasks.setOption(name_option, opt);
......@@ -429,26 +472,31 @@ void dynare::parser::option_num(string name_option, string opt)
else if (name_option == "linear")
linear = atoi(opt.c_str());
}
void dynare::parser::option_str(string name_option, Objects* opt)
{
opt->symbol = "'"+opt->symbol;
opt->symbol += "'";
computing_tasks.setOption(name_option, opt->symbol);
}
void dynare::parser::option_str(string name_option, string opt)
{
opt = "'"+opt;
opt += "'";
computing_tasks.setOption(name_option, opt);
}
void dynare::parser::add_tmp_var(Objects* tmp_var1, Objects* tmp_var2)
{
tmp_symbol_table.AddTempSymbol(tmp_var1->symbol, tmp_var2->symbol);
}
void dynare::parser::add_tmp_var(Objects* tmp_var)
{
tmp_symbol_table.AddTempSymbol(tmp_var->symbol);
}
// dynare::Objects* get_tmp_var(string)
// {
// //string str = tmp_symbol_table.get
......@@ -459,6 +507,7 @@ void dynare::parser::rplot()
string tmp = tmp_symbol_table.get();
computing_tasks.runRplot(tmp);
}
void dynare::parser::stoch_simul()
{
// If order and linear not set, then set them to default values
......@@ -475,84 +524,102 @@ void dynare::parser::stoch_simul()
string tmp = tmp_symbol_table.get();
computing_tasks.setStochSimul(tmp);
}
void dynare::parser::simul()
{
computing_tasks.setSimul();
model_tree.computeJacobian = true;
}
void dynare::parser::check()
{
computing_tasks.setCheck();
model_tree.computeJacobian = true;
}
void dynare::parser::estimation_init()
{
computing_tasks.EstimParams = &estim_params;
computing_tasks.setEstimationInit();
model_tree.computeJacobianExo = true;
}
void dynare::parser::set_estimated_elements(void)
{
computing_tasks.setEstimatedElements();