diff --git a/parser.src/ModelTree.cc b/parser.src/ModelTree.cc index 95069526f..18d076d5f 100644 --- a/parser.src/ModelTree.cc +++ b/parser.src/ModelTree.cc @@ -753,7 +753,7 @@ string ModelTree::setStaticModel(void) if (offset == 1) { StaticOutput << "global M_ \n"; - StaticOutput << "params = M_.params;\n"; + StaticOutput << "if M_.param_nbr > 0\n params = M_.params;\nend\n"; StaticOutput << " residual = zeros( " << ModelParameters::eq_nbr << ", 1);\n"; StaticOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; @@ -944,7 +944,7 @@ string ModelTree::setDynamicModel(void) if (offset == 1) { DynamicOutput << "global M_ it_\n"; - DynamicOutput << "params = M_.params;\n"; + DynamicOutput << "if M_.param_nbr > 0\n params = M_.params;\nend\n"; DynamicOutput << "\n\t%\n\t% Model equations\n\t%\n\n"; DynamicOutput << "residual = zeros(" << nrows << ", 1);\n"; @@ -1045,10 +1045,11 @@ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationTy // of lesser precedence than previous one, insert '(' if ( precedence_current_op < precedence_last_op || (last_op_code == MINUS & - precedence_current_op == precedence_last_op) || + precedence_current_op == precedence_last_op)|| current_op_code == UMINUS) { exp << "("; + current_token_ID->close_parenthesis = 1; } // set flag: left argument has been explored current_token_ID->left_done = 1; @@ -1058,15 +1059,18 @@ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationTy { exp << "pow("; precedence_last_op = 0; + current_token_ID->close_parenthesis = 1; } else if ( current_op_code == UMINUS) { exp << "-"; + current_token_ID->close_parenthesis = 1; } else if ( operator_table.isfunction(current_op_code) == true) { exp << current_token_ID->op_name << "("; precedence_last_op = 0; + current_token_ID->close_parenthesis = 1; } stack_token.push(current_token_ID->id1); } @@ -1078,11 +1082,7 @@ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationTy { exp << ","; } - else if ( operator_table.isfunction(current_op_code) == true || - precedence_current_op > precedence_last_op ) - { - exp << ")"; - } + if ( current_token_ID->id2 != NullID ) { exp << current_token_ID->op_name; @@ -1092,12 +1092,13 @@ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationTy } else { - if ( (offset == 0 && current_op_code == POWER) || - ( precedence_current_op > precedence_last_op && - operator_table.isfunction(current_op_code) == false) || - (current_op_code == MINUS && - precedence_current_op == precedence_last_op) || - current_op_code == UMINUS) +// if ( (offset == 0 && current_op_code == POWER) || +// ( precedence_current_op > precedence_last_op && +// operator_table.isfunction(current_op_code) == false) || +// (current_op_code == MINUS && +// precedence_current_op == precedence_last_op) || +// current_op_code == UMINUS) + if ( current_token_ID->close_parenthesis == 1) { exp << ")"; } @@ -1105,6 +1106,7 @@ inline string ModelTree::getExpression(NodeID StartID, EquationType iEquationTy last_op_code = current_op_code; current_token_ID->left_done=0; current_token_ID->right_done=0; + current_token_ID->close_parenthesis=0; stack_token.pop(); } } diff --git a/parser.src/VariableTable.cc b/parser.src/VariableTable.cc index 903bea2be..3f055dc9d 100644 --- a/parser.src/VariableTable.cc +++ b/parser.src/VariableTable.cc @@ -81,6 +81,7 @@ int VariableTable::AddVariable(string iName, int iLag) { ModelParameters::max_endo_lag = -iLag; } + break; case eExogenous: if (ModelParameters::max_exo_lead < iLag) { @@ -90,6 +91,7 @@ int VariableTable::AddVariable(string iName, int iLag) { ModelParameters::max_exo_lag = -iLag; } + break; case eExogenousDet: if (ModelParameters::max_exo_det_lead < iLag) { @@ -99,6 +101,7 @@ int VariableTable::AddVariable(string iName, int iLag) { ModelParameters::max_exo_det_lag = -iLag; } + break; case eRecursiveVariable: if (ModelParameters::max_recur_lead < iLag) { @@ -108,6 +111,7 @@ int VariableTable::AddVariable(string iName, int iLag) { ModelParameters::max_recur_lag = -iLag; } + break; default: ; } diff --git a/parser.src/include/ModelTypes.h b/parser.src/include/ModelTypes.h index 00292cb88..9d5ae1d07 100644 --- a/parser.src/include/ModelTypes.h +++ b/parser.src/include/ModelTypes.h @@ -144,6 +144,8 @@ struct MetaToken : public MToken int left_done; // set to one when right node has been treated int right_done; + // set to one if closing parenthesis after token + int close_parenthesis; inline operator MToken() const { @@ -170,6 +172,7 @@ struct MetaToken : public MToken tmp_status = t1.tmp_status; left_done = t1.left_done; right_done = t1.right_done; + close_parenthesis = t1.close_parenthesis; //cout << "Creation by equality\n"; return *this; } @@ -182,6 +185,7 @@ struct MetaToken : public MToken tmp_status = 0; left_done = 0; right_done = 0; + close_parenthesis = 0; } /* Copy constructor */ inline MetaToken(const MetaToken& mt)