Commit 573227a0 authored by sebastien's avatar sebastien
Browse files

v4 parser:

* removed Expression class; the "ExprNode" class is therefore now used everywhere
* removed interprete class, and replaced it by a method in ExprNode and an global evaluation context in ModFile
* fixed breakage of SparseDLL / Block decomposition code introduced in previous revision


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1204 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 30c70a35
......@@ -60,8 +60,10 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const
output << "simul(oo_.dr);\n";
}
SimulSparseStatement::SimulSparseStatement(const OptionsList &options_list_arg) :
options_list(options_list_arg)
SimulSparseStatement::SimulSparseStatement(const OptionsList &options_list_arg,
int compiler_arg) :
options_list(options_list_arg),
compiler(compiler_arg)
{
}
......@@ -81,10 +83,10 @@ SimulSparseStatement::writeOutput(ostream &output, const string &basename) const
output << "end\n";
output << "disp('compiling...');\n";
if (compiler == 0)
output << "mex " << filename << "_dynamic.c;\n";
output << "mex " << basename << "_dynamic.c;\n";
else
output << "mex " << filename << "_dynamic.cc;\n";
output << "oo_.endo_simul=" << filename << "_dynamic;\n";
output << "mex " << basename << "_dynamic.cc;\n";
output << "oo_.endo_simul=" << basename << "_dynamic;\n";
}
StochSimulStatement::StochSimulStatement(const TmpSymbolTable &tmp_symbol_table_arg,
......@@ -452,7 +454,9 @@ ObservationTrendsStatement::writeOutput(ostream &output, const string &basename)
if (type == eEndogenous)
{
output << "tmp1 = strmatch('" << it->first << "',options_.varobs,'exact');\n";
output << "options_.trend_coeffs{tmp1} = '" << it->second << "';\n";
output << "options_.trend_coeffs{tmp1} = '";
it->second->writeOutput(output);
output << "';" << endl;
}
else
cout << "Error : Non-variable symbol used in TREND_COEFF: " << it->first << endl;
......@@ -490,20 +494,24 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
{
const string &name = it->first;
const string &weight = it->second.first;
const string &expression = it->second.second;
const NodeID expression = it->second.second;
int id = symbol_table.getID(name) + 1;
if (symbol_table.getType(name) == eEndogenous)
{
output << "calib_var_index{1} = [calib_var_index{1};" << id << "," << id << "];\n";
output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n";
output << "calib_targets{1} =[calib_targets{1}; " << expression << "];\n";
output << "calib_targets{1} =[calib_targets{1}; ";
expression->writeOutput(output);
output << "];\n";
}
else if (symbol_table.getType(name) == eExogenous)
{
output << "calib_var_index{3} = [calib_var_index{3};" << id << "," << id << "];\n";
output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n";
output << "calib_targets{3} =[calib_targets{3}; " << expression << "];\n";
output << "calib_targets{3} =[calib_targets{3}; ";
expression->writeOutput(output);
output << "];\n";
}
}
......@@ -514,7 +522,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
const string &name1 = it->first.first;
const string &name2 = it->first.second;
const string &weight = it->second.first;
const string &expression = it->second.second;
const NodeID expression = it->second.second;
int id1 = symbol_table.getID(name1) + 1;
int id2 = symbol_table.getID(name2) + 1;
......@@ -522,13 +530,17 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
{
output << "calib_var_index{1} = [calib_var_index{1};" << id1 << "," << id2 << "];\n";
output << "calib_weights{1} = [calib_weights{1}; " << weight << "];\n";
output << "calib_targets{1} =[calib_targets{1}; " << expression << "];\n";
output << "calib_targets{1} =[calib_targets{1}; ";
expression->writeOutput(output);
output << "];\n";
}
else if (symbol_table.getType(name1) == eExogenous)
{
output << "calib_var_index{3} = [calib_var_index{3};" << id1 << "," << id2 << "];\n";
output << "calib_weights{3} = [calib_weights{3}; " << weight << "];\n";
output << "calib_targets{3} =[calib_targets{3}; " << expression << "];\n";
output << "calib_targets{3} =[calib_targets{3}; ";
expression->writeOutput(output);
output << "];\n";
}
}
......@@ -541,7 +553,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
const string &name = it->first.first;
int iar = it->first.second + 3;
const string &weight = it->second.first;
const string &expression = it->second.second;
const NodeID expression = it->second.second;
int id = symbol_table.getID(name) + 1;
......@@ -559,7 +571,9 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
output << "calib_var_index{" << iar << "} = [calib_var_index{" << iar << "};" << id << "];\n";
output << "calib_weights{" << iar << "} = [calib_weights{" << iar << "}; " << weight << "];\n";
output << "calib_targets{" << iar << "} =[calib_targets{" << iar << "}; " << expression << "];\n";
output << "calib_targets{" << iar << "} =[calib_targets{" << iar << "}; ";
expression->writeOutput(output);
output << "];\n";
}
}
......@@ -671,9 +685,11 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
it != var_weights.end(); it++)
{
const string &name = it->first;
const string &value = it->second;
const NodeID value = it->second;
int id = symbol_table.getID(name) + 1;
output << "optim_weights_(" << id << "," << id << ") = " << value << ";\n";
output << "optim_weights_(" << id << "," << id << ") = ";
value->writeOutput(output);
output << ";" << endl;
output << "obj_var_ = [obj_var_; " << id << "];\n";
}
......@@ -682,10 +698,12 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
{
const string &name1 = it->first.first;
const string &name2 = it->first.second;
const string &value = it->second;
const NodeID value = it->second;
int id1 = symbol_table.getID(name1) + 1;
int id2 = symbol_table.getID(name2) + 1;
output << "optim_weights_(" << id1 << "," << id2 << ") = " << value << ";\n";
output << "optim_weights_(" << id1 << "," << id2 << ") = ";
value->writeOutput(output);
output << ";" << endl;
output << "obj_var_ = [obj_var_; " << id1 << " " << id2 << "];\n";
}
}
......@@ -770,7 +788,7 @@ void
PlannerObjectiveStatement::computingPass()
{
model_tree->computeStaticHessian = true;
model_tree->computingPass();
model_tree->computingPass(eval_context_type());
}
void
......
......@@ -43,21 +43,14 @@ DataTree::AddVariable(const string &name, int lag)
symbol_table.SetReferenced(name);
int symb_id = symbol_table.getID(name);
Type type = symbol_table.getType(name);
int id;
if (type == eEndogenous
|| type == eExogenousDet
|| type == eExogenous
|| type == eRecursiveVariable)
id = variable_table.AddVariable(name, lag);
else
id = symbol_table.getID(name);
variable_node_map_type::iterator it = variable_node_map.find(make_pair(id, type));
variable_node_map_type::iterator it = variable_node_map.find(make_pair(make_pair(symb_id, type), lag));
if (it != variable_node_map.end())
return it->second;
else
return new VariableNode(*this, id, type);
return new VariableNode(*this, symb_id, type, lag);
}
NodeID
......@@ -346,3 +339,9 @@ DataTree::AddLocalParameter(const string &name, NodeID value) throw (LocalParame
local_parameters_table[id] = value;
}
NodeID
DataTree::AddUnknownFunction(const string &function_name, const vector<NodeID> &arguments)
{
return new UnknownFunctionNode(*this, function_name, arguments);
}
......@@ -36,7 +36,7 @@
#include "DynareBison.hh"
/* User implementation prologue. */
#line 37 "DynareBison.yy"
#line 32 "DynareBison.yy"
#include "ParsingDriver.hh"
......@@ -273,7 +273,7 @@ namespace yy
/* User initialization code. */
#line 22 "DynareBison.yy"
#line 18 "DynareBison.yy"
{
// Initialize the location filenames
yylloc.begin.filename = yylloc.end.filename = &driver.file;
......@@ -395,803 +395,823 @@ namespace yy
switch (yyn)
{
case 46:
#line 143 "DynareBison.yy"
#line 138 "DynareBison.yy"
{ driver.dsample((yysemantic_stack_[(3) - (2)].string_val));;}
break;
case 47:
#line 144 "DynareBison.yy"
#line 139 "DynareBison.yy"
{driver.dsample((yysemantic_stack_[(4) - (2)].string_val), (yysemantic_stack_[(4) - (3)].string_val));;}
break;
case 48:
#line 147 "DynareBison.yy"
#line 142 "DynareBison.yy"
{driver.rplot();;}
break;
case 53:
#line 167 "DynareBison.yy"
#line 162 "DynareBison.yy"
{ driver.declare_endogenous((yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 54:
#line 169 "DynareBison.yy"
#line 164 "DynareBison.yy"
{ driver.declare_endogenous((yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 55:
#line 171 "DynareBison.yy"
#line 166 "DynareBison.yy"
{ driver.declare_endogenous((yysemantic_stack_[(1) - (1)].string_val)); ;}
break;
case 56:
#line 173 "DynareBison.yy"
#line 168 "DynareBison.yy"
{ driver.declare_endogenous((yysemantic_stack_[(3) - (2)].string_val), (yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 57:
#line 175 "DynareBison.yy"
#line 170 "DynareBison.yy"
{ driver.declare_endogenous((yysemantic_stack_[(4) - (3)].string_val), (yysemantic_stack_[(4) - (4)].string_val)); ;}
break;
case 58:
#line 177 "DynareBison.yy"
#line 172 "DynareBison.yy"
{ driver.declare_endogenous((yysemantic_stack_[(2) - (1)].string_val), (yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 59:
#line 182 "DynareBison.yy"
#line 177 "DynareBison.yy"
{ driver.declare_exogenous((yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 60:
#line 184 "DynareBison.yy"
#line 179 "DynareBison.yy"
{ driver.declare_exogenous((yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 61:
#line 186 "DynareBison.yy"
#line 181 "DynareBison.yy"
{ driver.declare_exogenous((yysemantic_stack_[(1) - (1)].string_val)); ;}
break;
case 62:
#line 188 "DynareBison.yy"
#line 183 "DynareBison.yy"
{ driver.declare_exogenous((yysemantic_stack_[(3) - (2)].string_val), (yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 63:
#line 190 "DynareBison.yy"
#line 185 "DynareBison.yy"
{ driver.declare_exogenous((yysemantic_stack_[(4) - (3)].string_val), (yysemantic_stack_[(4) - (4)].string_val)); ;}
break;
case 64:
#line 192 "DynareBison.yy"
#line 187 "DynareBison.yy"
{ driver.declare_exogenous((yysemantic_stack_[(2) - (1)].string_val), (yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 65:
#line 197 "DynareBison.yy"
#line 192 "DynareBison.yy"
{ driver.declare_exogenous_det((yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 66:
#line 199 "DynareBison.yy"
#line 194 "DynareBison.yy"
{ driver.declare_exogenous_det((yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 67:
#line 201 "DynareBison.yy"
#line 196 "DynareBison.yy"
{ driver.declare_exogenous_det((yysemantic_stack_[(1) - (1)].string_val)); ;}
break;
case 68:
#line 203 "DynareBison.yy"
#line 198 "DynareBison.yy"
{ driver.declare_exogenous_det((yysemantic_stack_[(3) - (2)].string_val), (yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 69:
#line 205 "DynareBison.yy"
#line 200 "DynareBison.yy"
{ driver.declare_exogenous_det((yysemantic_stack_[(4) - (3)].string_val), (yysemantic_stack_[(4) - (4)].string_val)); ;}
break;
case 70:
#line 207 "DynareBison.yy"
#line 202 "DynareBison.yy"
{ driver.declare_exogenous_det((yysemantic_stack_[(2) - (1)].string_val), (yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 71:
#line 212 "DynareBison.yy"
#line 207 "DynareBison.yy"
{ driver.declare_parameter((yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 72:
#line 214 "DynareBison.yy"
#line 209 "DynareBison.yy"
{ driver.declare_parameter((yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 73:
#line 216 "DynareBison.yy"
#line 211 "DynareBison.yy"
{ driver.declare_parameter((yysemantic_stack_[(1) - (1)].string_val)); ;}
break;
case 74:
#line 218 "DynareBison.yy"
#line 213 "DynareBison.yy"
{ driver.declare_parameter((yysemantic_stack_[(3) - (2)].string_val), (yysemantic_stack_[(3) - (3)].string_val)); ;}
break;
case 75:
#line 220 "DynareBison.yy"
#line 215 "DynareBison.yy"
{ driver.declare_parameter((yysemantic_stack_[(4) - (3)].string_val), (yysemantic_stack_[(4) - (4)].string_val)); ;}
break;
case 76:
#line 222 "DynareBison.yy"
#line 217 "DynareBison.yy"
{ driver.declare_parameter((yysemantic_stack_[(2) - (1)].string_val), (yysemantic_stack_[(2) - (2)].string_val)); ;}
break;
case 77:
#line 227 "DynareBison.yy"
#line 222 "DynareBison.yy"
{
driver.periods((yysemantic_stack_[(3) - (2)].string_val));
;}
break;
case 78:
#line 231 "DynareBison.yy"
#line 226 "DynareBison.yy"
{
driver.periods((yysemantic_stack_[(4) - (3)].string_val));
;}
break;
case 79:
#line 238 "DynareBison.yy"
#line 233 "DynareBison.yy"
{
driver.cutoff((yysemantic_stack_[(3) - (2)].string_val));
;}
break;
case 80:
#line 242 "DynareBison.yy"
#line 237 "DynareBison.yy"
{
driver.cutoff((yysemantic_stack_[(4) - (3)].string_val));
;}
break;
case 81:
#line 249 "DynareBison.yy"
{driver.init_param((yysemantic_stack_[(4) - (1)].string_val), (yysemantic_stack_[(4) - (3)].exp_val));;}
#line 244 "DynareBison.yy"
{driver.init_param((yysemantic_stack_[(4) - (1)].string_val), (yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 82:
#line 254 "DynareBison.yy"
{ (yyval.exp_val) = (yysemantic_stack_[(3) - (2)].exp_val);;}
#line 249 "DynareBison.yy"
{ (yyval.node_val) = (yysemantic_stack_[(3) - (2)].node_val);;}
break;
case 83:
#line 256 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_variable((yysemantic_stack_[(1) - (1)].string_val));;}
#line 251 "DynareBison.yy"
{(yyval.node_val) = driver.add_expression_variable((yysemantic_stack_[(1) - (1)].string_val));;}
break;
case 84:
#line 258 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_constant((yysemantic_stack_[(1) - (1)].string_val));;}
#line 253 "DynareBison.yy"
{(yyval.node_val) = driver.add_constant((yysemantic_stack_[(1) - (1)].string_val));;}
break;
case 85:
#line 260 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_constant((yysemantic_stack_[(1) - (1)].string_val));;}
#line 255 "DynareBison.yy"
{(yyval.node_val) = driver.add_constant((yysemantic_stack_[(1) - (1)].string_val));;}
break;
case 86:
#line 262 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(3) - (1)].exp_val), (yysemantic_stack_[(3) - (3)].exp_val), token::PLUS);;}
#line 257 "DynareBison.yy"
{(yyval.node_val) = driver.add_plus((yysemantic_stack_[(3) - (1)].node_val), (yysemantic_stack_[(3) - (3)].node_val));;}
break;
case 87:
#line 264 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(3) - (1)].exp_val), (yysemantic_stack_[(3) - (3)].exp_val), token::MINUS);;}
#line 259 "DynareBison.yy"
{(yyval.node_val) = driver.add_minus((yysemantic_stack_[(3) - (1)].node_val), (yysemantic_stack_[(3) - (3)].node_val));;}
break;
case 88:
#line 266 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(3) - (1)].exp_val), (yysemantic_stack_[(3) - (3)].exp_val), token::DIVIDE);;}
#line 261 "DynareBison.yy"
{(yyval.node_val) = driver.add_divide((yysemantic_stack_[(3) - (1)].node_val), (yysemantic_stack_[(3) - (3)].node_val));;}
break;
case 89:
#line 268 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(3) - (1)].exp_val), (yysemantic_stack_[(3) - (3)].exp_val), token::TIMES);;}
#line 263 "DynareBison.yy"
{(yyval.node_val) = driver.add_times((yysemantic_stack_[(3) - (1)].node_val), (yysemantic_stack_[(3) - (3)].node_val));;}
break;
case 90:
#line 270 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(3) - (1)].exp_val), (yysemantic_stack_[(3) - (3)].exp_val), token::POWER);;}
#line 265 "DynareBison.yy"
{(yyval.node_val) = driver.add_power((yysemantic_stack_[(3) - (1)].node_val), (yysemantic_stack_[(3) - (3)].node_val));;}
break;
case 91:
#line 272 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(2) - (2)].exp_val), token::UMINUS);;}
#line 267 "DynareBison.yy"
{(yyval.node_val) = driver.add_uminus((yysemantic_stack_[(2) - (2)].node_val));;}
break;
case 92:
#line 274 "DynareBison.yy"
{(yyval.exp_val) = (yysemantic_stack_[(2) - (2)].exp_val);;}
#line 269 "DynareBison.yy"
{(yyval.node_val) = (yysemantic_stack_[(2) - (2)].node_val);;}
break;
case 93:
#line 276 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::EXP);;}
#line 271 "DynareBison.yy"
{(yyval.node_val) = driver.add_exp((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 94:
#line 278 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::LOG);;}
#line 273 "DynareBison.yy"
{(yyval.node_val) = driver.add_log((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 95:
#line 280 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::LOG10);;}
#line 275 "DynareBison.yy"
{(yyval.node_val) = driver.add_log10((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 96:
#line 282 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::SIN);;}
#line 277 "DynareBison.yy"
{(yyval.node_val) = driver.add_sin((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 97:
#line 284 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::COS);;}
#line 279 "DynareBison.yy"
{(yyval.node_val) = driver.add_cos((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 98:
#line 286 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::TAN);;}
#line 281 "DynareBison.yy"
{(yyval.node_val) = driver.add_tan((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 99:
#line 288 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::ASIN);;}
#line 283 "DynareBison.yy"
{(yyval.node_val) = driver.add_asin((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 100:
#line 290 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::ACOS);;}
#line 285 "DynareBison.yy"
{(yyval.node_val) = driver.add_acos((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 101:
#line 292 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::ATAN);;}
#line 287 "DynareBison.yy"
{(yyval.node_val) = driver.add_atan((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 102:
#line 294 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), token::SQRT);;}
#line 289 "DynareBison.yy"
{(yyval.node_val) = driver.add_sqrt((yysemantic_stack_[(4) - (3)].node_val));;}
break;
case 103:
#line 296 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), (yysemantic_stack_[(4) - (1)].string_val));;}
#line 291 "DynareBison.yy"
{(yyval.node_val) = driver.add_unknown_function((yysemantic_stack_[(4) - (1)].string_val));;}
break;
case 104:
#line 298 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(4) - (3)].exp_val), (yysemantic_stack_[(4) - (1)].string_val));;}
#line 296 "DynareBison.yy"
{ driver.add_unknown_function_arg((yysemantic_stack_[(1) - (1)].node_val)); ;}
break;
case 105:
#line 303 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(3) - (1)].exp_val), (yysemantic_stack_[(3) - (3)].exp_val), token::COMMA);;}
#line 298 "DynareBison.yy"
{ driver.add_unknown_function_arg((yysemantic_stack_[(3) - (3)].node_val)); ;}
break;
case 106:
#line 305 "DynareBison.yy"
{(yyval.exp_val) = driver.add_expression_token((yysemantic_stack_[(3) - (1)].exp_val), (yysemantic_stack_[(3) - (3)].exp_val), token::COMMA);;}
#line 302 "DynareBison.yy"
{driver.end_initval();;}
break;
case 107:
#line 309 "DynareBison.yy"
#line 304 "DynareBison.yy"
{driver.end_initval();;}
break;
case 108:
#line 311 "DynareBison.yy"
{driver.end_initval();;}
break;