Commit d0a7a76f authored by sebastien's avatar sebastien
Browse files

v4 parser: removed unused functions or enumeration types, tweaked some documentation strings


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@989 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 2b045e2b
......@@ -294,13 +294,11 @@
;
model
: MODEL {_parser->initialize_model();} ';' equation_list END
: MODEL ';' equation_list END
{_parser->check_model();}
| MODEL '(' LINEAR ')' ';' {_parser->option_num("linear","1");
_parser->initialize_model();}
| MODEL '(' LINEAR ')' ';' {_parser->option_num("linear","1");}
equation_list END {_parser->check_model();}
| MODEL '(' USE_DLL ')' ';' {_parser->use_dll();
_parser->initialize_model();}
| MODEL '(' USE_DLL ')' ';' {_parser->use_dll();}
equation_list END {_parser->check_model();}
;
......
......@@ -209,13 +209,6 @@ void dynare::parser::init_param(Objects* lhs, Objects* rhs)
{
numerical_initialization.SetConstant(lhs->symbol, rhs->symbol);
}
void dynare::parser::init_param(Objects* lhs)
{
//cout << "Befor set\n";
expression.set();
numerical_initialization.SetConstant(lhs->symbol, expression.get());
expression.clear();
}
void dynare::parser::init_val(Objects* lhs, Objects* rhs)
{
numerical_initialization.SetInit(lhs->symbol, rhs->symbol);
......@@ -225,16 +218,6 @@ 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::hist_val(Objects* lhs, Objects* slag)
{
int lag = atoi((slag->symbol).c_str());
expression.set();
numerical_initialization.SetHist(lhs->symbol, lag, expression.get());
expression.clear();
}
void dynare::parser::initialize_model(void)
{
}
void dynare::parser::use_dll(void)
{
// Seetting variable momber offset to use C outputs
......
......@@ -658,7 +658,6 @@ inline NodeID ModelTree::DeriveArgument(NodeID iArg, Type iType, int iVarID)
case eUNDEF :
return NullID;
case eLoopIndex :
case eUnkownFunction :
return Zero;
default :
cout << "ModelTree::DeriveArgument : Error: Unknown Type\n";
......@@ -1141,130 +1140,6 @@ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationTy
return exp.str();
}
//------------------------------------------------------------------------------
/*
void ModelTree::RemoveUnref(int iBeginID, int iEndID, int iOrder)
{
int id = iEndID;
while (id >= iBeginID)
{
//cout << id;
if (accumulate(mModelTree[id].reference_count.begin(),mModelTree[id].reference_count.end(),0) == 0)
{
//cout << " Removed" << endl;
//Decreasing reference count of arguments model tree
// First argument is a temporary result,
if (mModelTree[id].type1 == eTempResult)
{
//Decreasing reference count of argument 1 in model tree
int arg = mModelTree[id].id1;
mModelTree[arg].reference_count[iOrder]--;
}
// Second argument has id >=0 (temporary result),
if (mModelTree[id].id2 >= 0)
{
//Decreasing reference count of argument 2 in model tree
int arg = mModelTree[id].id2;
mModelTree[arg].reference_count[iOrder]--;
}
//Updating equals ids in mDerivativeIndex
for (int d=0; d<mDerivativeIndex[iOrder-1].size();d++)
{
if (mDerivativeIndex[iOrder-1][d].token_id>id)
mDerivativeIndex[iOrder-1][d].token_id--;
}
//cout << "ModelTree size : " << mModelTree.size() << endl;
//Updatting upper token ids in model tree and map
mIndexOfTokens.erase(Key((MToken) mModelTree[id]));
for (int id2 = id+1; id2 <= iEndID; id2++)
{
//cout << " - " << mIndexOfTokens[Key((MToken) mModelTree[id2])];
mIndexOfTokens.erase(Key((MToken) mModelTree[id2]));
}
//cout << endl;
for (int id2 = id+1; id2 <= iEndID; id2++)
{
// Updating derivative ids
map<int, int, less<int> >::iterator it;
for (it = mModelTree[id2].p1.begin(); it != mModelTree[id2].p1.end(); it++)
{
int p1 = (*it).second;
int var = (*it).first;
//cout << "===========" << mModelTree[p1].d1[var] << "/";
mModelTree[p1].d1[var] = id2-1;
//cout << mModelTree[p1].d1[var] << endl;
}
// Updating ModelTree map
if (mModelTree[id2].type1 == eTempResult)
{
if (mModelTree[id2].id1>id)
{
mModelTree[id2].id1--;
}
}
if (mModelTree[id2].id2>id)
{
mModelTree[id2].id2--;
}
}
mModelTree.erase(mModelTree.begin()+id);
for (int id2 = id; id2 < iEndID; id2++)
{
mIndexOfTokens[Key((MToken) mModelTree[id2])] = id2;
//cout << " - " << mIndexOfTokens[Key((MToken) mModelTree[id2])];
}
//Removing token from model tree
//cout << "ModelTree size : " << mModelTree.size() << endl;
iEndID--;
id--;
}
else
{
id--;
//cout << endl;
}
}
}
//------------------------------------------------------------------------------
*/
/*
void ModelTree::DecrementUnref(int iBeginID, int iEndID, int iOrder)
{
int id = iEndID;
while (id >= iBeginID)
{
//cout << id;
if (accumulate(mModelTree[id].reference_count.begin(),mModelTree[id].reference_count.end(),0) == 0)
{
//Decreasing reference count of arguments model tree
// First argument is a temporary result,
if (mModelTree[id].type1 == eTempResult)
{
//Decreasing reference count of argument 1 in model tree
int arg = mModelTree[id].id1;
mModelTree[arg].reference_count[iOrder]--;
}
// Second argument has id >=0 (temporary result),
if (mModelTree[id].id2 >= 0)
{
//Decreasing reference count of argument 2 in model tree
int arg = mModelTree[id].id2;
mModelTree[arg].reference_count[iOrder]--;
}
id--;
}
else
{
id--;
//cout << endl;
}
}
}
*/
//------------------------------------------------------------------------------
inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquationType)
{
......
......@@ -48,28 +48,6 @@ void NumericalInitialization::SetConstant (string name, string expression)
}
//------------------------------------------------------------------------------
void NumericalInitialization::SetLocalConstant (string name, string expression)
{
//Testing if symbol exists
if (SymbolTable::Exist(name))
{
if (SymbolTable::getType(name) != eLocalParameter)
{
string msg = "Using existing symbol " + name +
" as local parameter name";
(* error) (msg.c_str());
}
}
else
{
SymbolTable::AddSymbolDeclar(name,eLocalParameter,name);
}
// Writing expression
*output << name << " = " << expression << ";\n";
}
//------------------------------------------------------------------------------
void NumericalInitialization::BeginInitval (void)
{
......
......@@ -116,11 +116,6 @@ void SymbolTable::SetReferenced(string name)
symboltable[name].referenced = eReferenced;
}
//------------------------------------------------------------------------------
void SymbolTable::SetOutOfScoop(string name)
{
symboltable[name].referenced = eOutOfScoop;
}
//------------------------------------------------------------------------------
Reference SymbolTable::isReferenced(std::string name)
{
return symboltable[name].referenced;
......@@ -283,34 +278,3 @@ void SymbolTable::erase_local_parameters(void)
}
}
//------------------------------------------------------------------------------
/*
ostream & operator << (ostream & output, Symbol s)
{
switch (s.type) {
case eExogenous : output << "Exogenous , "; break;
case eExogenousDet : output << "ExogenousDet ,"; break;
case eEndogenous : output << "Endogenous , "; break;
case eRecursiveVariable : output << "RecursiveVariable , "; break;
case eParameter : output << "Parameter , "; break;
case eLoopIndex : output << "LoopIndex , "; break;
}
output << s.id;
switch (s.referenced) {
case eReferenced : cout << ", Referenced, "; break;
case eNotReferenced : cout << ", NotReferenced, "; break;
case eOutOfScoop : cout << ", OutOfScoop, "; break;
}
return output;
}
//------------------------------------------------------------------------------
void SymbolTable::PrintSymbolTable(void)
{
map<string, Symbol, less<string> >::iterator iter;
cout << "\nCurrent Map :\n";
for (iter = symboltable.begin();iter != symboltable.end(); iter++)
cout << (*iter).first << " , " << (*iter).second << endl;;
}
//------------------------------------------------------------------------------
*/
......@@ -120,8 +120,6 @@ namespace dynare
void check_model(void);
/*! Executes final instructions */
void finish(void);
/*! Initializes the model */
void initialize_model(void);
/*! Sets variable offset of ModelTree class to use C output */
void use_dll(void);
/*! Adds an endogenous variable to SymbolTable*/
......@@ -152,19 +150,16 @@ namespace dynare
Objects* add_expression_token( Objects* arg1, Objects* op);
/*! Gets literal expression string */
Objects* get_expression(Objects* exp);
/* Concatenates two string objects */
/*! Concatenates two string objects */
Objects* cat(Objects* string1, Objects* string2);
/*! Concatenates two string objects with a space between */
Objects* cat_with_space(Objects* string1, Objects* string2);
/*! Writes parameter intitialisation expression */
void init_param(Objects* lhs, Objects* rhs);
/*! Writes parameter intitialisation expression */
void init_param(Objects* lhs);
/*! Writes an initval block */
void init_val(Objects* lhs, Objects* rhs);
/*! Writes an histval block */
void hist_val(Objects* lhs, Objects* lag, Objects* rhs);
/*! Writes an histval block */
void hist_val(Objects* lhs, Objects* lag);
/*! Writes begining of an initval block */
void begin_initval(void);
/*! Writes end of an initval block */
......
......@@ -13,7 +13,6 @@
#include <stack>
#include <sstream>
#include <fstream>
//#include <ext/hash_map>
//------------------------------------------------------------------------------
#include "SymbolTable.h"
#include "OperatorTable.h"
......@@ -31,10 +30,6 @@ class ModelTree : public DataTree
/*! Stores ID of equations and their derivatives */
std::vector<std::vector<DerivativeIndex> > mDerivativeIndex;
/*! Stores ID of equations and their 1st ordre derivatives */
//vector<DerivativeIndex> mDerivative1Index;
/*! Stores ID of equations and their 2nd ordre derivatives */
//vector<DerivativeIndex> mDerivative2Index;
/*! Only used for C++ standalone version */
std::vector<double> mResults;
/*! Output for static model */
......@@ -71,10 +66,6 @@ class ModelTree : public DataTree
depending on its time cost and number of times it is referenced in model tree
*/
inline bool writeAsTemp(NodeID id);
/*! Remove unreferenced tokens after a derivation */
//void RemoveUnref(int iBeginID, int iEndID, int iOrder);
/*! Decrementing reference couter of unreferenced tokens in last derivative */
void DecrementUnref(int iBeginID, int iEndID, int iOrder);
inline int optimize(NodeID id);
public :
/*! When Jacobian (vs endogenous) is writen this flag is set to true */
......
......@@ -212,7 +212,6 @@ struct MetaToken : public MToken
};
//------------------------------------------------------------------------------
/*!
\function oparator <
\brief Less operator define comparaison function for map class
*/
......
......@@ -39,7 +39,6 @@ class NumericalInitialization
- in C++, evaluate expression and set value for Name in Parameters_Table\n
*/
void SetConstant(std::string name,std::string expression);
void SetLocalConstant(std::string name,std::string expression);
/*!
\par Description
Initializes an initval block to set initial values for variables
......
......@@ -34,8 +34,6 @@ class SymbolTable
- set Name and Type\n
- increase corresponding counter in ModelParameters class\n
*/
/*! Pointer to current parssing line to set by class parser*/
//int *current_line;
static int AddSymbol(std::string name,Type type, std::string tex_name);
protected :
/*! Symbol table map */
......@@ -51,28 +49,26 @@ class SymbolTable
SymbolTable();
/*! Destructor*/
~SymbolTable();
/*! Pointer to error function of parser class */
static void (* error) (const char* m);
/*! Adds a symbol apearing in declaration
- warning if symbol is already set with same type
- error if symbol is already set with different type
- set name, type
- increase corresponding counter in ModelParameters
*/
/*! Pointer to error function of parser class */
static void (* error) (const char* m);
static int AddSymbolDeclar(std::string name,Type type, std::string tex_name);
/*! Adds symbol range */
static 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);
/*! Tests if symbol exists in symbol table
\return true if exists, false outherwise
*/
/*! Sets a symbol as referenced */
static void SetReferenced(std::string name);
/*! Return eReferenced if symbol is referenced eNotReferenced otherwise*/
static Reference isReferenced(std::string name);
/*! Sets a symbol as out of scoop */
static void SetOutOfScoop(std::string name);
/*! Tests if symbol exists in symbol table
\return true if exists, false outherwise
*/
inline static bool Exist(std::string name);
/*! Gets name by type and ID */
inline static std::string getNameByID(Type type,int id);
......@@ -87,7 +83,6 @@ class SymbolTable
/*! Checks if symbols are used in model equations, removes unused symbol */
void clean();
void erase_local_parameters();
//void PrintSymbolTable(void);
};
inline bool SymbolTable::Exist(std::string name)
{
......
......@@ -12,24 +12,22 @@
/*! Symbol type enum */
enum Type
{
eEndogenous = 0, //!< Endogenousous
eExogenous = 1, //!< Exogenousous
eExogenousDet = 2, //!< Exogenousous deterministic (new)
eEndogenous = 0, //!< Endogenous
eExogenous = 1, //!< Exogenous
eExogenousDet = 2, //!< Exogenous deterministic (new)
eRecursiveVariable = 3, //!< Recursive variable (reserved for future use)
eParameter = 4, //!< Parameter
eLocalParameter = 10, //!< Parameter local to a model
eLoopIndex = 5, //!< Loop index
eTempResult = 6, //!< Temporary result, used only in Expression class
eNumericalConstant = 7, //!< Numerical constant, used only in Expression class
eUnkownFunction = 8, //!< Unkown functions, used only in Expression class
eUNDEF = 9 //!< Undefinded
eUNDEF = 9 //!< Undefined
};
/*! Symbol reference flag enum */
enum Reference
{
eNotReferenced, //!< Not yet referenced in model
eReferenced, //!< Already referenced in model
eOutOfScoop, //!< Out of scoop (for loop index)
};
/*!
\class Symbol
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment