2008-02-03 11:28:36 +01:00
/*
2018-01-12 16:54:17 +01:00
* Copyright ( C ) 2003 - 2018 Dynare Team
2008-02-03 11:28:36 +01:00
*
* This file is part of Dynare .
*
* Dynare is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* Dynare is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with Dynare . If not , see < http : //www.gnu.org/licenses/>.
*/
2008-06-28 13:20:45 +02:00
# include <cstdlib>
2008-02-03 11:28:36 +01:00
# include <fstream>
# include <iostream>
2010-02-22 17:33:38 +01:00
# include <cassert>
2010-10-20 14:47:03 +02:00
# include <sstream>
2011-01-13 19:10:16 +01:00
# include <cmath>
2008-02-03 11:28:36 +01:00
# include "ParsingDriver.hh"
# include "Statement.hh"
2010-04-06 11:07:19 +02:00
# include "ExprNode.hh"
2012-01-23 16:52:27 +01:00
# include "WarningConsolidation.hh"
2008-02-03 11:28:36 +01:00
bool
2010-02-22 17:33:38 +01:00
ParsingDriver : : symbol_exists_and_is_not_modfile_local_or_external_function ( const char * s )
2008-02-03 11:28:36 +01:00
{
if ( ! mod_file - > symbol_table . exists ( s ) )
return false ;
2009-02-26 11:46:54 +01:00
SymbolType type = mod_file - > symbol_table . getType ( s ) ;
2010-02-22 17:33:38 +01:00
return ( type ! = eModFileLocalVariable & & type ! = eExternalFunction ) ;
2008-02-03 11:28:36 +01:00
}
2016-09-23 15:22:25 +02:00
void
ParsingDriver : : check_symbol_existence_in_model_block ( const string & name )
{
if ( ! mod_file - > symbol_table . exists ( name ) )
model_error ( " Unknown symbol: " + name ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : check_symbol_existence ( const string & name )
{
if ( ! mod_file - > symbol_table . exists ( name ) )
error ( " Unknown symbol: " + name ) ;
}
2011-12-11 15:35:26 +01:00
void
ParsingDriver : : check_symbol_is_parameter ( string * name )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
if ( mod_file - > symbol_table . getType ( symb_id ) ! = eParameter )
error ( * name + " is not a parameter " ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : set_current_data_tree ( DataTree * data_tree_arg )
{
data_tree = data_tree_arg ;
model_tree = dynamic_cast < ModelTree * > ( data_tree_arg ) ;
2009-07-07 16:20:48 +02:00
dynamic_model = dynamic_cast < DynamicModel * > ( data_tree_arg ) ;
2008-02-03 11:28:36 +01:00
}
void
ParsingDriver : : reset_data_tree ( )
{
set_current_data_tree ( & mod_file - > expressions_tree ) ;
}
2010-02-22 17:33:38 +01:00
void
ParsingDriver : : reset_current_external_function_options ( )
{
current_external_function_options . nargs = eExtFunSetDefaultNargs ;
current_external_function_options . firstDerivSymbID = eExtFunNotSet ;
current_external_function_options . secondDerivSymbID = eExtFunNotSet ;
2010-02-24 15:10:11 +01:00
current_external_function_id = eExtFunNotSet ;
2010-02-22 17:33:38 +01:00
}
2008-02-03 11:28:36 +01:00
ModFile *
2008-03-28 18:38:10 +01:00
ParsingDriver : : parse ( istream & in , bool debug )
2008-02-03 11:28:36 +01:00
{
2013-02-26 16:50:05 +01:00
mod_file = new ModFile ( warnings ) ;
2008-02-03 11:28:36 +01:00
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
reset_data_tree ( ) ;
2009-01-22 16:05:38 +01:00
estim_params . init ( * data_tree ) ;
2016-05-10 18:01:00 +02:00
osr_params . init ( * data_tree ) ;
2010-02-22 17:33:38 +01:00
reset_current_external_function_options ( ) ;
2008-02-03 11:28:36 +01:00
lexer = new DynareFlex ( & in ) ;
2008-03-28 18:21:45 +01:00
lexer - > set_debug ( debug ) ;
2008-02-03 11:28:36 +01:00
Dynare : : parser parser ( * this ) ;
2008-03-28 18:21:45 +01:00
parser . set_debug_level ( debug ) ;
2008-02-03 11:28:36 +01:00
parser . parse ( ) ;
delete lexer ;
return mod_file ;
}
void
ParsingDriver : : error ( const Dynare : : parser : : location_type & l , const string & m )
{
2016-09-23 15:22:25 +02:00
create_error_string ( l , m , cerr ) ;
exit ( EXIT_FAILURE ) ;
}
void
ParsingDriver : : error ( const string & m )
{
error ( location , m ) ;
}
void
ParsingDriver : : create_error_string ( const Dynare : : parser : : location_type & l , const string & m , ostream & stream )
{
stream < < " ERROR: " < < * l . begin . filename < < " : line " < < l . begin . line ;
2013-05-31 18:19:12 +02:00
if ( l . begin . line = = l . end . line )
if ( l . begin . column = = l . end . column - 1 )
2016-09-23 15:22:25 +02:00
stream < < " , col " < < l . begin . column ;
2013-05-31 18:19:12 +02:00
else
2016-09-23 15:22:25 +02:00
stream < < " , cols " < < l . begin . column < < " - " < < l . end . column - 1 ;
2013-05-31 18:19:12 +02:00
else
2016-09-23 15:22:25 +02:00
stream < < " , col " < < l . begin . column < < " - "
2017-06-01 19:58:32 +02:00
< < " line " < < l . end . line < < " , col " < < l . end . column - 1 ;
2016-09-23 15:22:25 +02:00
stream < < " : " < < m < < endl ;
2008-02-03 11:28:36 +01:00
}
void
2016-09-23 15:22:25 +02:00
ParsingDriver : : model_error ( const string & m )
2008-02-03 11:28:36 +01:00
{
2016-09-23 15:22:25 +02:00
create_error_string ( location , m , model_errors ) ;
model_error_encountered = true ;
2008-02-03 11:28:36 +01:00
}
void
ParsingDriver : : warning ( const string & m )
{
2013-02-26 16:50:05 +01:00
warnings < < " WARNING: " < < location < < " : " < < m < < endl ;
2008-02-03 11:28:36 +01:00
}
void
2016-06-24 17:38:54 +02:00
ParsingDriver : : declare_symbol ( const string * name , SymbolType type , const string * tex_name , const vector < pair < string * , string * > * > * partition_value )
2008-02-03 11:28:36 +01:00
{
try
{
2016-02-26 16:23:39 +01:00
if ( tex_name = = NULL & & partition_value = = NULL )
2009-04-30 15:14:33 +02:00
mod_file - > symbol_table . addSymbol ( * name , type ) ;
else
2013-12-09 15:51:27 +01:00
if ( tex_name = = NULL )
2016-02-26 16:23:39 +01:00
mod_file - > symbol_table . addSymbol ( * name , type , " " , partition_value ) ;
else if ( partition_value = = NULL )
mod_file - > symbol_table . addSymbol ( * name , type , * tex_name , NULL ) ;
2013-11-15 09:46:18 +01:00
else
2016-02-26 16:23:39 +01:00
mod_file - > symbol_table . addSymbol ( * name , type , * tex_name , partition_value ) ;
2008-02-03 11:28:36 +01:00
}
2009-12-16 18:13:23 +01:00
catch ( SymbolTable : : AlreadyDeclaredException & e )
2008-02-03 11:28:36 +01:00
{
if ( e . same_type )
warning ( " Symbol " + * name + " declared twice. " ) ;
else
error ( " Symbol " + * name + " declared twice with different types! " ) ;
}
}
void
2016-06-24 17:38:54 +02:00
ParsingDriver : : declare_endogenous ( string * name , string * tex_name , vector < pair < string * , string * > * > * partition_value )
2008-02-03 11:28:36 +01:00
{
2016-02-26 16:23:39 +01:00
declare_symbol ( name , eEndogenous , tex_name , partition_value ) ;
2010-02-22 17:33:38 +01:00
delete name ;
if ( tex_name ! = NULL )
delete tex_name ;
2016-02-26 16:23:39 +01:00
if ( partition_value ! = NULL )
{
2016-06-24 17:38:54 +02:00
for ( vector < pair < string * , string * > * > : : iterator it = partition_value - > begin ( ) ;
it ! = partition_value - > end ( ) ; + + it )
{
delete ( * it ) - > first ;
delete ( * it ) - > second ;
delete ( * it ) ;
}
2016-02-26 16:23:39 +01:00
delete partition_value ;
}
2008-02-03 11:28:36 +01:00
}
2017-05-04 15:50:33 +02:00
void
ParsingDriver : : declare_var_endogenous ( string * name )
{
if ( mod_file - > symbol_table . exists ( * name ) )
{
SymbolType type = mod_file - > symbol_table . getType ( * name ) ;
if ( type ! = eEndogenous & & type ! = eExogenous & & type ! = eExogenousDet )
2017-06-01 19:58:32 +02:00
error ( " Symbol " + * name + " used in a VAR must be either endogenous or "
+ " exogenous if it is also used elsewhere in the .mod file " ) ;
2017-05-04 15:50:33 +02:00
add_in_symbol_list ( name ) ;
return ;
}
declare_symbol ( name , eEndogenousVAR , NULL , NULL ) ;
add_in_symbol_list ( name ) ;
}
2008-02-03 11:28:36 +01:00
void
2016-06-24 17:38:54 +02:00
ParsingDriver : : declare_exogenous ( string * name , string * tex_name , vector < pair < string * , string * > * > * partition_value )
2008-02-03 11:28:36 +01:00
{
2016-02-26 16:23:39 +01:00
declare_symbol ( name , eExogenous , tex_name , partition_value ) ;
2010-02-22 17:33:38 +01:00
delete name ;
if ( tex_name ! = NULL )
delete tex_name ;
2016-02-26 16:23:39 +01:00
if ( partition_value ! = NULL )
{
2016-06-24 17:38:54 +02:00
for ( vector < pair < string * , string * > * > : : iterator it = partition_value - > begin ( ) ;
it ! = partition_value - > end ( ) ; + + it )
{
delete ( * it ) - > first ;
delete ( * it ) - > second ;
delete ( * it ) ;
}
2016-02-26 16:23:39 +01:00
delete partition_value ;
}
2008-02-03 11:28:36 +01:00
}
void
2016-06-24 17:38:54 +02:00
ParsingDriver : : declare_exogenous_det ( string * name , string * tex_name , vector < pair < string * , string * > * > * partition_value )
2008-02-03 11:28:36 +01:00
{
2016-02-26 16:23:39 +01:00
declare_symbol ( name , eExogenousDet , tex_name , partition_value ) ;
2010-02-22 17:33:38 +01:00
delete name ;
if ( tex_name ! = NULL )
delete tex_name ;
2016-02-26 16:23:39 +01:00
if ( partition_value ! = NULL )
{
2016-06-24 17:38:54 +02:00
for ( vector < pair < string * , string * > * > : : iterator it = partition_value - > begin ( ) ;
it ! = partition_value - > end ( ) ; + + it )
{
delete ( * it ) - > first ;
delete ( * it ) - > second ;
delete ( * it ) ;
}
2016-02-26 16:23:39 +01:00
delete partition_value ;
}
2008-02-03 11:28:36 +01:00
}
void
2016-06-24 17:38:54 +02:00
ParsingDriver : : declare_parameter ( string * name , string * tex_name , vector < pair < string * , string * > * > * partition_value )
2008-02-03 11:28:36 +01:00
{
2016-02-26 16:23:39 +01:00
declare_symbol ( name , eParameter , tex_name , partition_value ) ;
2010-02-22 17:33:38 +01:00
delete name ;
if ( tex_name ! = NULL )
delete tex_name ;
2016-02-26 16:23:39 +01:00
if ( partition_value ! = NULL )
{
2016-06-24 17:38:54 +02:00
for ( vector < pair < string * , string * > * > : : iterator it = partition_value - > begin ( ) ;
it ! = partition_value - > end ( ) ; + + it )
{
delete ( * it ) - > first ;
delete ( * it ) - > second ;
delete ( * it ) ;
}
2016-02-26 16:23:39 +01:00
delete partition_value ;
}
2008-02-03 11:28:36 +01:00
}
2011-12-14 13:58:21 +01:00
void
ParsingDriver : : declare_statement_local_variable ( string * name )
{
if ( mod_file - > symbol_table . exists ( * name ) )
2017-06-01 19:58:32 +02:00
error ( " Symbol " + * name + " cannot be assigned within a statement "
+ " while being assigned elsewhere in the modfile " ) ;
2013-11-15 09:46:18 +01:00
declare_symbol ( name , eStatementDeclaredVariable , NULL , NULL ) ;
2011-12-14 13:58:21 +01:00
delete name ;
}
2011-03-29 18:18:32 +02:00
void
2011-05-24 15:34:03 +02:00
ParsingDriver : : declare_optimal_policy_discount_factor_parameter ( expr_t exprnode )
2011-03-29 18:18:32 +02:00
{
2011-05-24 15:34:03 +02:00
string * optimalParName_declare = new string ( " optimal_policy_discount_factor " ) ;
string * optimalParName_init = new string ( " optimal_policy_discount_factor " ) ;
declare_parameter ( optimalParName_declare , NULL ) ;
init_param ( optimalParName_init , exprnode ) ;
2011-03-29 18:18:32 +02:00
}
2010-10-15 19:05:16 +02:00
void
ParsingDriver : : begin_trend ( )
{
set_current_data_tree ( & mod_file - > dynamic_model ) ;
}
void
2013-03-26 16:46:18 +01:00
ParsingDriver : : declare_trend_var ( bool log_trend , string * name , string * tex_name )
2010-10-15 19:05:16 +02:00
{
2013-11-15 09:46:18 +01:00
declare_symbol ( name , log_trend ? eLogTrend : eTrend , tex_name , NULL ) ;
2010-10-15 19:05:16 +02:00
declared_trend_vars . push_back ( mod_file - > symbol_table . getID ( * name ) ) ;
delete name ;
if ( tex_name ! = NULL )
delete tex_name ;
}
void
ParsingDriver : : end_trend_var ( expr_t growth_factor )
{
try
{
dynamic_model - > addTrendVariables ( declared_trend_vars , growth_factor ) ;
}
catch ( DataTree : : TrendException & e )
{
error ( " Trend variable " + e . name + " was declared twice. " ) ;
}
declared_trend_vars . clear ( ) ;
reset_data_tree ( ) ;
}
2009-11-07 19:37:11 +01:00
void
ParsingDriver : : add_predetermined_variable ( string * name )
{
2009-11-09 12:03:18 +01:00
try
{
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
if ( mod_file - > symbol_table . getType ( symb_id ) ! = eEndogenous )
error ( " Predetermined variables must be endogenous variables " ) ;
mod_file - > symbol_table . markPredetermined ( symb_id ) ;
}
2009-12-16 18:13:23 +01:00
catch ( SymbolTable : : UnknownSymbolNameException & e )
2009-11-09 12:03:18 +01:00
{
error ( " Undeclared symbol name: " + * name ) ;
}
2009-11-07 19:37:11 +01:00
delete name ;
}
2009-09-02 16:37:59 +02:00
void
ParsingDriver : : add_equation_tags ( string * key , string * value )
{
2013-04-11 17:07:39 +02:00
eq_tags . push_back ( make_pair ( * key , * value ) ) ;
2009-09-02 16:37:59 +02:00
delete key ;
delete value ;
}
2010-09-16 19:18:45 +02:00
expr_t
2010-11-25 13:45:35 +01:00
ParsingDriver : : add_non_negative_constant ( string * constant )
2008-02-03 11:28:36 +01:00
{
2012-07-12 12:46:22 +02:00
expr_t id = data_tree - > AddNonNegativeConstant ( * constant ) ;
2008-02-03 11:28:36 +01:00
delete constant ;
return id ;
}
2010-09-16 19:18:45 +02:00
expr_t
2009-01-22 16:05:38 +01:00
ParsingDriver : : add_nan_constant ( )
{
return data_tree - > NaN ;
}
2010-09-16 19:18:45 +02:00
expr_t
2009-01-22 16:05:38 +01:00
ParsingDriver : : add_inf_constant ( )
{
return data_tree - > Infinity ;
}
2010-09-16 19:18:45 +02:00
expr_t
2008-02-03 11:28:36 +01:00
ParsingDriver : : add_model_variable ( string * name )
{
2016-09-23 15:22:25 +02:00
check_symbol_existence_in_model_block ( * name ) ;
int symb_id ;
try
{
symb_id = mod_file - > symbol_table . getID ( * name ) ;
2016-09-23 15:22:25 +02:00
if ( undeclared_model_vars . find ( * name ) ! = undeclared_model_vars . end ( ) )
model_error ( " Unknown symbol: " + * name ) ;
2016-09-23 15:22:25 +02:00
}
catch ( SymbolTable : : UnknownSymbolNameException & e )
{
2016-10-07 15:02:42 +02:00
// This could be endog or param too. Just declare something to continue parsing,
// knowing that processing will end at the end of parsing of the model block
2017-06-01 19:58:32 +02:00
declare_exogenous ( new string ( * name ) ) ;
2016-09-23 15:22:25 +02:00
undeclared_model_vars . insert ( * name ) ;
2016-09-23 15:22:25 +02:00
symb_id = mod_file - > symbol_table . getID ( * name ) ;
}
2010-02-22 17:33:38 +01:00
delete name ;
return add_model_variable ( symb_id , 0 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
2010-02-22 17:33:38 +01:00
ParsingDriver : : add_model_variable ( int symb_id , int lag )
2008-02-03 11:28:36 +01:00
{
2010-02-22 17:33:38 +01:00
assert ( symb_id > = 0 ) ;
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
2008-02-03 11:28:36 +01:00
if ( type = = eModFileLocalVariable )
2010-02-22 17:33:38 +01:00
error ( " Variable " + mod_file - > symbol_table . getName ( symb_id ) + " not allowed inside model declaration. Its scope is only outside model. " ) ;
2008-02-03 11:28:36 +01:00
2010-02-22 17:33:38 +01:00
if ( type = = eExternalFunction )
2014-07-15 16:54:30 +02:00
error ( " Symbol " + mod_file - > symbol_table . getName ( symb_id ) + " is a function name external to Dynare. It cannot be used like a variable without input argument inside model. " ) ;
2008-10-13 18:44:20 +02:00
if ( type = = eModelLocalVariable & & lag ! = 0 )
2010-02-22 17:33:38 +01:00
error ( " Model local variable " + mod_file - > symbol_table . getName ( symb_id ) + " cannot be given a lead or a lag. " ) ;
2008-10-13 18:44:20 +02:00
2010-10-11 14:49:23 +02:00
if ( dynamic_cast < StaticModel * > ( model_tree ) ! = NULL & & lag ! = 0 )
error ( " Leads and lags on variables are forbidden in 'planner_objective'. " ) ;
2014-05-13 11:46:19 +02:00
if ( dynamic_cast < StaticModel * > ( model_tree ) ! = NULL & & type = = eModelLocalVariable )
error ( " Model local variable " + mod_file - > symbol_table . getName ( symb_id ) + " cannot be used in 'planner_objective'. " ) ;
2008-10-13 18:44:20 +02:00
// It makes sense to allow a lead/lag on parameters: during steady state calibration, endogenous and parameters can be swapped
2010-02-22 17:33:38 +01:00
return model_tree - > AddVariable ( symb_id , lag ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
2008-02-03 11:28:36 +01:00
ParsingDriver : : add_expression_variable ( string * name )
{
// If symbol doesn't exist, then declare it as a mod file local variable
if ( ! mod_file - > symbol_table . exists ( * name ) )
mod_file - > symbol_table . addSymbol ( * name , eModFileLocalVariable ) ;
2008-10-17 14:22:35 +02:00
// This check must come after the previous one!
if ( mod_file - > symbol_table . getType ( * name ) = = eModelLocalVariable )
error ( " Variable " + * name + " not allowed outside model declaration. Its scope is only inside model. " ) ;
2013-11-29 16:29:25 +01:00
if ( mod_file - > symbol_table . getType ( * name ) = = eTrend
| | mod_file - > symbol_table . getType ( * name ) = = eLogTrend )
error ( " Variable " + * name + " not allowed outside model declaration, because it is a trend variable. " ) ;
2014-02-03 16:22:42 +01:00
if ( mod_file - > symbol_table . getType ( * name ) = = eExternalFunction )
error ( " Symbol ' " + * name + " ' is the name of a MATLAB/Octave function, and cannot be used as a variable. " ) ;
2010-03-16 12:23:59 +01:00
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
2010-09-16 19:18:45 +02:00
expr_t id = data_tree - > AddVariable ( symb_id ) ;
2008-02-03 11:28:36 +01:00
delete name ;
return id ;
}
2010-10-15 19:05:16 +02:00
void
2016-06-24 17:38:54 +02:00
ParsingDriver : : declare_nonstationary_var ( string * name , string * tex_name , vector < pair < string * , string * > * > * partition_value )
2010-10-15 19:05:16 +02:00
{
2016-02-26 16:23:39 +01:00
if ( tex_name = = NULL & & partition_value = = NULL )
2013-11-15 09:46:18 +01:00
declare_endogenous ( new string ( * name ) ) ;
2013-12-09 15:51:27 +01:00
else
if ( tex_name = = NULL )
2016-05-09 16:00:18 +02:00
declare_endogenous ( new string ( * name ) , NULL , partition_value ) ;
2016-02-26 16:23:39 +01:00
else if ( partition_value = = NULL )
2016-05-09 16:00:18 +02:00
declare_endogenous ( new string ( * name ) , tex_name ) ;
2013-12-09 15:51:27 +01:00
else
2016-05-09 16:00:18 +02:00
declare_endogenous ( new string ( * name ) , tex_name , partition_value ) ;
2013-12-09 15:51:27 +01:00
2010-10-15 19:05:16 +02:00
declared_nonstationary_vars . push_back ( mod_file - > symbol_table . getID ( * name ) ) ;
mod_file - > nonstationary_variables = true ;
delete name ;
}
void
2013-03-26 16:46:18 +01:00
ParsingDriver : : end_nonstationary_var ( bool log_deflator , expr_t deflator )
2010-10-15 19:05:16 +02:00
{
try
{
2013-03-26 16:46:18 +01:00
dynamic_model - > addNonstationaryVariables ( declared_nonstationary_vars , log_deflator , deflator ) ;
2010-10-15 19:05:16 +02:00
}
catch ( DataTree : : TrendException & e )
{
error ( " Variable " + e . name + " was listed more than once as following a trend. " ) ;
}
2013-10-29 11:47:59 +01:00
2013-11-29 15:32:49 +01:00
set < int > r ;
2013-10-29 11:47:59 +01:00
deflator - > collectVariables ( eEndogenous , r ) ;
2013-11-29 15:32:49 +01:00
for ( set < int > : : const_iterator it = r . begin ( ) ; it ! = r . end ( ) ; + + it )
if ( dynamic_model - > isNonstationary ( * it ) )
2013-10-29 11:47:59 +01:00
error ( " The deflator contains a non-stationary endogenous variable. This is not allowed. Please use only stationary endogenous and/or {log_}trend_vars. " ) ;
2010-10-15 19:05:16 +02:00
declared_nonstationary_vars . clear ( ) ;
reset_data_tree ( ) ;
}
2017-05-04 18:06:50 +02:00
void
ParsingDriver : : begin_VAR_restrictions ( )
{
clear_VAR_storage ( ) ;
}
void
ParsingDriver : : end_VAR_restrictions ( string * var_model_name )
{
mod_file - > addStatement ( new VarRestrictionsStatement ( * var_model_name ,
2017-05-18 17:50:58 +02:00
var_map ,
2017-05-04 18:06:50 +02:00
exclusion_restrictions ,
equation_restrictions ,
crossequation_restrictions ,
covariance_number_restriction ,
2017-05-16 10:09:48 +02:00
covariance_pair_restriction ,
mod_file - > symbol_table ) ) ;
2017-05-04 18:06:50 +02:00
clear_VAR_storage ( ) ;
}
void
ParsingDriver : : clear_VAR_storage ( )
{
exclusion_restriction . clear ( ) ;
exclusion_restrictions . clear ( ) ;
symbol_list . clear ( ) ;
var_restriction_eq_or_crosseq . clear ( ) ;
equation_restrictions . clear ( ) ;
crossequation_restrictions . clear ( ) ;
covariance_number_restriction . clear ( ) ;
covariance_pair_restriction . clear ( ) ;
}
void
ParsingDriver : : add_VAR_exclusion_restriction ( string * lagstr )
{
int lag = atoi ( lagstr - > c_str ( ) ) ;
map < int , map < int , SymbolList > > : : iterator it = exclusion_restrictions . find ( lag ) ;
if ( it = = exclusion_restrictions . end ( ) )
exclusion_restrictions [ lag ] = exclusion_restriction ;
else
for ( map < int , SymbolList > : : const_iterator it1 = exclusion_restriction . begin ( ) ;
it1 ! = exclusion_restriction . end ( ) ; it1 + + )
it - > second [ it1 - > first ] = it1 - > second ;
exclusion_restriction . clear ( ) ;
delete lagstr ;
}
void
ParsingDriver : : add_VAR_restriction_coeff ( string * name1 , string * name2 , string * lagstr )
{
int symb_id1 = mod_file - > symbol_table . getID ( * name1 ) ;
int symb_id2 = name2 = = NULL ? - 1 : mod_file - > symbol_table . getID ( * name2 ) ;
int lag = atoi ( lagstr - > c_str ( ) ) ;
var_restriction_coeff = make_pair ( symb_id1 , make_pair ( symb_id2 , lag ) ) ;
delete name1 ;
if ( name2 ! = NULL )
delete name2 ;
delete lagstr ;
}
void
ParsingDriver : : add_VAR_restriction_eq_or_crosseq ( expr_t expr )
{
var_restriction_eq_or_crosseq . push_back ( make_pair ( var_restriction_coeff , expr ) ) ;
}
void
ParsingDriver : : add_VAR_restriction_equation_or_crossequation ( string * numberstr )
{
assert ( var_restriction_eq_or_crosseq . size ( ) > 0 & & var_restriction_eq_or_crosseq . size ( ) < 3 ) ;
double number = atof ( numberstr - > c_str ( ) ) ;
if ( var_restriction_eq_or_crosseq . size ( ) = = 1 )
var_restriction_equation_or_crossequation = make_pair ( make_pair ( var_restriction_eq_or_crosseq [ 0 ] ,
2017-06-01 19:58:32 +02:00
make_pair ( make_pair ( - 1 , make_pair ( - 1 , - 1 ) ) , ( expr_t ) NULL ) ) ,
2017-05-04 18:06:50 +02:00
number ) ;
else
var_restriction_equation_or_crossequation = make_pair ( make_pair ( var_restriction_eq_or_crosseq [ 0 ] ,
var_restriction_eq_or_crosseq [ 1 ] ) ,
number ) ;
var_restriction_eq_or_crosseq . clear ( ) ;
}
void
ParsingDriver : : multiply_arg2_by_neg_one ( )
{
assert ( var_restriction_eq_or_crosseq . size ( ) = = 2 ) ;
expr_t exprtm1 = add_times ( var_restriction_eq_or_crosseq [ 1 ] . second ,
add_uminus ( add_non_negative_constant ( new string ( " -1 " ) ) ) ) ;
var_restriction_eq_or_crosseq [ 1 ] = make_pair ( var_restriction_eq_or_crosseq [ 1 ] . first , exprtm1 ) ;
}
void
2017-05-19 14:20:26 +02:00
ParsingDriver : : add_VAR_restriction_equation_or_crossequation_final ( string * name )
2017-05-04 18:06:50 +02:00
{
2017-05-19 14:20:26 +02:00
if ( name ! = NULL )
2017-05-04 18:06:50 +02:00
{
2017-05-19 14:20:26 +02:00
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
equation_restrictions [ symb_id ] = var_restriction_equation_or_crossequation ;
delete name ;
2017-05-04 18:06:50 +02:00
}
2017-05-19 14:20:26 +02:00
else
crossequation_restrictions . push_back ( var_restriction_equation_or_crossequation ) ;
2017-05-04 18:06:50 +02:00
}
void
ParsingDriver : : add_VAR_restriction_exclusion_equation ( string * name )
{
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
exclusion_restriction [ symb_id ] = symbol_list ;
symbol_list . clear ( ) ;
delete name ;
}
void
ParsingDriver : : add_VAR_covariance_number_restriction ( string * name1 , string * name2 , string * valuestr )
{
int symb_id1 = mod_file - > symbol_table . getID ( * name1 ) ;
int symb_id2 = mod_file - > symbol_table . getID ( * name2 ) ;
double value = atof ( valuestr - > c_str ( ) ) ;
covariance_number_restriction [ make_pair ( symb_id1 , symb_id2 ) ] = value ;
delete name1 ;
delete name2 ;
delete valuestr ;
}
void
ParsingDriver : : add_VAR_covariance_pair_restriction ( string * name11 , string * name12 , string * name21 , string * name22 )
{
int symb_id11 = mod_file - > symbol_table . getID ( * name11 ) ;
int symb_id12 = mod_file - > symbol_table . getID ( * name12 ) ;
int symb_id21 = mod_file - > symbol_table . getID ( * name21 ) ;
int symb_id22 = mod_file - > symbol_table . getID ( * name22 ) ;
covariance_pair_restriction [ make_pair ( symb_id11 , symb_id12 ) ] = make_pair ( symb_id21 , symb_id22 ) ;
delete name11 ;
delete name12 ;
delete name21 ;
delete name22 ;
}
2017-05-10 17:21:38 +02:00
void
2017-05-11 12:14:45 +02:00
ParsingDriver : : run_var_estimation ( )
2017-05-10 17:21:38 +02:00
{
2017-05-11 12:14:45 +02:00
mod_file - > addStatement ( new VarEstimationStatement ( options_list ) ) ;
2017-05-10 17:21:38 +02:00
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : periods ( string * periods )
{
2012-02-10 16:59:47 +01:00
warning ( " periods: this command is now deprecated and may be removed in a future version of Dynare. Please use the ''periods'' option of the ''simul'' command instead. " ) ;
2009-10-29 18:16:10 +01:00
2008-02-03 11:28:36 +01:00
int periods_val = atoi ( periods - > c_str ( ) ) ;
mod_file - > addStatement ( new PeriodsStatement ( periods_val ) ) ;
delete periods ;
}
void
ParsingDriver : : dsample ( string * arg1 )
{
int arg1_val = atoi ( arg1 - > c_str ( ) ) ;
mod_file - > addStatement ( new DsampleStatement ( arg1_val ) ) ;
delete arg1 ;
}
void
ParsingDriver : : dsample ( string * arg1 , string * arg2 )
{
int arg1_val = atoi ( arg1 - > c_str ( ) ) ;
int arg2_val = atoi ( arg2 - > c_str ( ) ) ;
mod_file - > addStatement ( new DsampleStatement ( arg1_val , arg2_val ) ) ;
delete arg1 ;
delete arg2 ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : init_param ( string * name , expr_t rhs )
2008-02-03 11:28:36 +01:00
{
2011-12-11 15:35:26 +01:00
check_symbol_is_parameter ( name ) ;
2009-02-27 13:19:25 +01:00
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
mod_file - > addStatement ( new InitParamStatement ( symb_id , rhs , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
delete name ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : init_val ( string * name , expr_t rhs )
2008-02-03 11:28:36 +01:00
{
2013-09-16 22:13:56 +02:00
if ( nostrict )
if ( ! mod_file - > symbol_table . exists ( * name ) )
{
2016-10-07 14:40:10 +02:00
warning ( " discarding ' " + * name + " ' as it was not recognized in the initval or endval statement " ) ;
2013-09-16 22:13:56 +02:00
delete name ;
return ;
}
2008-02-03 11:28:36 +01:00
check_symbol_existence ( * name ) ;
2009-02-27 13:19:25 +01:00
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
2008-02-03 11:28:36 +01:00
if ( type ! = eEndogenous
& & type ! = eExogenous
& & type ! = eExogenousDet )
error ( " initval/endval: " + * name + " should be an endogenous or exogenous variable " ) ;
2009-02-27 13:19:25 +01:00
init_values . push_back ( make_pair ( symb_id , rhs ) ) ;
2008-02-03 11:28:36 +01:00
delete name ;
}
void
2008-04-14 09:22:10 +02:00
ParsingDriver : : initval_file ( string * filename )
2008-02-03 11:28:36 +01:00
{
2008-04-14 11:17:15 +02:00
mod_file - > addStatement ( new InitvalFileStatement ( * filename ) ) ;
2008-02-03 11:28:36 +01:00
delete filename ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : hist_val ( string * name , string * lag , expr_t rhs )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * name ) ;
2009-02-27 13:19:25 +01:00
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
2008-02-03 11:28:36 +01:00
if ( type ! = eEndogenous
& & type ! = eExogenous
& & type ! = eExogenousDet )
2010-10-20 14:47:03 +02:00
error ( " histval: " + * name + " should be an endogenous or exogenous variable " ) ;
2008-02-03 11:28:36 +01:00
int ilag = atoi ( lag - > c_str ( ) ) ;
2017-09-13 10:16:19 +02:00
if ( ilag > 0 )
error ( " histval: the lag on " + * name + " should be less than or equal to 0 " ) ;
2009-02-27 13:19:25 +01:00
pair < int , int > key ( symb_id , ilag ) ;
2008-02-03 11:28:36 +01:00
2010-10-20 14:47:03 +02:00
if ( mod_file - > dynamic_model . minLagForSymbol ( symb_id ) > ilag - 1 )
2017-09-13 11:36:14 +02:00
hist_vals_wrong_lag [ symb_id ] = ilag ;
2010-10-20 14:47:03 +02:00
2008-02-03 11:28:36 +01:00
if ( hist_values . find ( key ) ! = hist_values . end ( ) )
error ( " hist_val: ( " + * name + " , " + * lag + " ) declared twice " ) ;
hist_values [ key ] = rhs ;
delete name ;
delete lag ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : homotopy_val ( string * name , expr_t val1 , expr_t val2 )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * name ) ;
2009-02-27 13:19:25 +01:00
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
2008-02-03 11:28:36 +01:00
if ( type ! = eParameter
& & type ! = eExogenous
& & type ! = eExogenousDet )
error ( " homotopy_val: " + * name + " should be a parameter or exogenous variable " ) ;
2009-02-27 13:19:25 +01:00
homotopy_values . push_back ( make_pair ( symb_id , make_pair ( val1 , val2 ) ) ) ;
2008-02-03 11:28:36 +01:00
delete name ;
}
2017-10-06 14:49:14 +02:00
void
ParsingDriver : : end_generate_irfs ( )
{
mod_file - > addStatement ( new GenerateIRFsStatement ( options_list , generate_irf_names , generate_irf_elements ) ) ;
2017-10-09 11:18:42 +02:00
2017-10-06 14:49:14 +02:00
generate_irf_elements . clear ( ) ;
generate_irf_names . clear ( ) ;
options_list . clear ( ) ;
}
void
2017-10-09 11:18:42 +02:00
ParsingDriver : : add_generate_irfs_element ( string * name )
2017-10-06 14:49:14 +02:00
{
for ( vector < string > : : const_iterator it = generate_irf_names . begin ( ) ;
it ! = generate_irf_names . end ( ) ; it + + )
if ( * it = = * name )
2017-10-09 11:18:42 +02:00
error ( " Names in the generate_irfs block must be unique but you entered ' "
+ * name + " ' more than once. " ) ;
2017-10-06 14:49:14 +02:00
generate_irf_names . push_back ( * name ) ;
2017-10-09 11:18:42 +02:00
generate_irf_elements . push_back ( generate_irf_exos ) ;
generate_irf_exos . clear ( ) ;
2017-10-06 14:49:14 +02:00
delete name ;
2017-10-09 11:18:42 +02:00
}
void
ParsingDriver : : add_generate_irfs_exog_element ( string * exo , string * value )
{
check_symbol_is_exogenous ( exo ) ;
if ( generate_irf_exos . find ( * exo ) ! = generate_irf_exos . end ( ) )
error ( " You have set the exogenous variable " + * exo + " twice. " ) ;
generate_irf_exos [ * exo ] = atof ( value - > c_str ( ) ) ;
delete exo ;
delete value ;
2017-10-06 14:49:14 +02:00
}
2008-05-01 14:04:48 +02:00
void
ParsingDriver : : forecast ( )
{
mod_file - > addStatement ( new ForecastStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : use_dll ( )
{
2009-09-02 15:36:56 +02:00
mod_file - > use_dll = true ;
2008-02-03 11:28:36 +01:00
}
void
2009-08-29 17:04:11 +02:00
ParsingDriver : : block ( )
2008-02-03 11:28:36 +01:00
{
2009-08-29 17:04:11 +02:00
mod_file - > block = true ;
2008-02-03 11:28:36 +01:00
}
2010-01-08 12:06:25 +01:00
void
ParsingDriver : : no_static ( )
{
mod_file - > no_static = true ;
}
2008-02-03 11:28:36 +01:00
void
2009-08-29 17:04:11 +02:00
ParsingDriver : : byte_code ( )
2008-02-03 11:28:36 +01:00
{
2009-08-29 17:04:11 +02:00
mod_file - > byte_code = true ;
2008-02-03 11:28:36 +01:00
}
2013-04-25 18:09:31 +02:00
void
2013-05-17 16:51:34 +02:00
ParsingDriver : : differentiate_forward_vars_all ( )
2013-04-25 18:09:31 +02:00
{
mod_file - > differentiate_forward_vars = true ;
}
2013-05-17 16:51:34 +02:00
void
ParsingDriver : : differentiate_forward_vars_some ( )
{
mod_file - > differentiate_forward_vars = true ;
mod_file - > differentiate_forward_vars_subset = symbol_list . get_symbols ( ) ;
for ( vector < string > : : const_iterator it = mod_file - > differentiate_forward_vars_subset . begin ( ) ;
it ! = mod_file - > differentiate_forward_vars_subset . end ( ) ; + + it )
{
check_symbol_existence ( * it ) ;
if ( mod_file - > symbol_table . getType ( * it ) ! = eEndogenous )
error ( " Symbol " + * it + " is not an endogenous " ) ;
}
symbol_list . clear ( ) ;
}
2009-09-03 12:10:06 +02:00
void
ParsingDriver : : cutoff ( string * value )
{
double val = atof ( value - > c_str ( ) ) ;
mod_file - > dynamic_model . cutoff = val ;
2009-12-16 14:21:31 +01:00
mod_file - > static_model . cutoff = val ;
2009-09-03 12:10:06 +02:00
delete value ;
}
void
ParsingDriver : : mfs ( string * value )
{
int val = atoi ( value - > c_str ( ) ) ;
mod_file - > dynamic_model . mfs = val ;
2009-12-16 14:21:31 +01:00
mod_file - > static_model . mfs = val ;
2009-09-03 12:10:06 +02:00
delete value ;
}
2008-02-03 11:28:36 +01:00
void
2012-10-31 15:23:02 +01:00
ParsingDriver : : end_initval ( bool all_values_required )
2008-02-03 11:28:36 +01:00
{
2012-10-31 15:23:02 +01:00
mod_file - > addStatement ( new InitValStatement ( init_values , mod_file - > symbol_table , all_values_required ) ) ;
2009-02-27 13:19:25 +01:00
init_values . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
void
2012-10-31 15:23:02 +01:00
ParsingDriver : : end_endval ( bool all_values_required )
2008-02-03 11:28:36 +01:00
{
2012-10-31 15:23:02 +01:00
mod_file - > addStatement ( new EndValStatement ( init_values , mod_file - > symbol_table , all_values_required ) ) ;
2009-02-27 13:19:25 +01:00
init_values . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
void
2016-06-02 12:57:11 +02:00
ParsingDriver : : end_histval ( bool all_values_required )
2008-02-03 11:28:36 +01:00
{
2017-09-11 18:14:56 +02:00
mod_file - > addStatement ( new HistValStatement ( hist_values , hist_vals_wrong_lag , mod_file - > symbol_table , all_values_required ) ) ;
2008-02-03 11:28:36 +01:00
hist_values . clear ( ) ;
}
void
ParsingDriver : : end_homotopy ( )
{
mod_file - > addStatement ( new HomotopyStatement ( homotopy_values , mod_file - > symbol_table ) ) ;
homotopy_values . clear ( ) ;
}
void
ParsingDriver : : begin_model ( )
{
2009-04-14 16:39:53 +02:00
set_current_data_tree ( & mod_file - > dynamic_model ) ;
2008-02-03 11:28:36 +01:00
}
2016-09-23 15:22:25 +02:00
void
ParsingDriver : : end_model ( )
{
if ( model_error_encountered )
{
cerr < < model_errors . str ( ) ;
exit ( EXIT_FAILURE ) ;
}
reset_data_tree ( ) ;
}
2008-02-03 11:28:36 +01:00
void
2014-04-10 11:54:49 +02:00
ParsingDriver : : end_shocks ( bool overwrite )
2008-02-03 11:28:36 +01:00
{
2014-04-10 11:54:49 +02:00
mod_file - > addStatement ( new ShocksStatement ( overwrite , det_shocks , var_shocks , std_shocks ,
2008-02-03 11:28:36 +01:00
covar_shocks , corr_shocks , mod_file - > symbol_table ) ) ;
det_shocks . clear ( ) ;
var_shocks . clear ( ) ;
std_shocks . clear ( ) ;
covar_shocks . clear ( ) ;
corr_shocks . clear ( ) ;
}
void
2014-04-10 11:54:49 +02:00
ParsingDriver : : end_mshocks ( bool overwrite )
2008-02-03 11:28:36 +01:00
{
2014-04-10 11:54:49 +02:00
mod_file - > addStatement ( new MShocksStatement ( overwrite , det_shocks , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
det_shocks . clear ( ) ;
}
void
2009-10-16 19:23:57 +02:00
ParsingDriver : : add_det_shock ( string * var , bool conditional_forecast )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * var ) ;
2010-04-14 15:03:41 +02:00
int symb_id = mod_file - > symbol_table . getID ( * var ) ;
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
2009-10-16 19:23:57 +02:00
if ( conditional_forecast )
{
if ( type ! = eEndogenous )
2011-02-07 11:51:13 +01:00
error ( " conditional_forecast_paths: shocks can only be applied to endogenous variables " ) ;
2009-10-16 19:23:57 +02:00
}
else
{
if ( type ! = eExogenous & & type ! = eExogenousDet )
error ( " shocks: shocks can only be applied to exogenous variables " ) ;
}
2008-02-03 11:28:36 +01:00
2010-04-14 15:03:41 +02:00
if ( det_shocks . find ( symb_id ) ! = det_shocks . end ( ) )
2009-10-16 19:23:57 +02:00
error ( " shocks/conditional_forecast_paths: variable " + * var + " declared twice " ) ;
2008-02-03 11:28:36 +01:00
if ( det_shocks_periods . size ( ) ! = det_shocks_values . size ( ) )
2009-10-16 19:23:57 +02:00
error ( " shocks/conditional_forecast_paths: variable " + * var + " : number of periods is different from number of shock values " ) ;
2008-02-03 11:28:36 +01:00
vector < ShocksStatement : : DetShockElement > v ;
2010-06-14 12:24:04 +02:00
for ( size_t i = 0 ; i < det_shocks_periods . size ( ) ; i + + )
2008-02-03 11:28:36 +01:00
{
ShocksStatement : : DetShockElement dse ;
dse . period1 = det_shocks_periods [ i ] . first ;
dse . period2 = det_shocks_periods [ i ] . second ;
dse . value = det_shocks_values [ i ] ;
v . push_back ( dse ) ;
}
2013-12-31 01:57:30 +01:00
det_shocks [ symb_id ] = v ;
2017-06-01 19:58:32 +02:00
2008-02-03 11:28:36 +01:00
det_shocks_periods . clear ( ) ;
det_shocks_values . clear ( ) ;
delete var ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_stderr_shock ( string * var , expr_t value )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * var ) ;
2010-04-14 15:03:41 +02:00
int symb_id = mod_file - > symbol_table . getID ( * var ) ;
if ( var_shocks . find ( symb_id ) ! = var_shocks . end ( )
| | std_shocks . find ( symb_id ) ! = std_shocks . end ( ) )
2008-02-03 11:28:36 +01:00
error ( " shocks: variance or stderr of shock on " + * var + " declared twice " ) ;
2010-04-14 15:03:41 +02:00
std_shocks [ symb_id ] = value ;
2008-02-03 11:28:36 +01:00
delete var ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_var_shock ( string * var , expr_t value )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * var ) ;
2010-04-14 15:03:41 +02:00
int symb_id = mod_file - > symbol_table . getID ( * var ) ;
if ( var_shocks . find ( symb_id ) ! = var_shocks . end ( )
| | std_shocks . find ( symb_id ) ! = std_shocks . end ( ) )
2008-02-03 11:28:36 +01:00
error ( " shocks: variance or stderr of shock on " + * var + " declared twice " ) ;
2010-04-14 15:03:41 +02:00
var_shocks [ symb_id ] = value ;
2008-02-03 11:28:36 +01:00
delete var ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_covar_shock ( string * var1 , string * var2 , expr_t value )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * var1 ) ;
check_symbol_existence ( * var2 ) ;
2010-04-14 15:03:41 +02:00
int symb_id1 = mod_file - > symbol_table . getID ( * var1 ) ;
int symb_id2 = mod_file - > symbol_table . getID ( * var2 ) ;
2008-02-03 11:28:36 +01:00
2010-04-14 15:03:41 +02:00
pair < int , int > key ( symb_id1 , symb_id2 ) , key_inv ( symb_id2 , symb_id1 ) ;
2008-02-03 11:28:36 +01:00
if ( covar_shocks . find ( key ) ! = covar_shocks . end ( )
| | covar_shocks . find ( key_inv ) ! = covar_shocks . end ( )
| | corr_shocks . find ( key ) ! = corr_shocks . end ( )
| | corr_shocks . find ( key_inv ) ! = corr_shocks . end ( ) )
error ( " shocks: covariance or correlation shock on variable pair ( " + * var1 + " , "
+ * var2 + " ) declared twice " ) ;
covar_shocks [ key ] = value ;
delete var1 ;
delete var2 ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_correl_shock ( string * var1 , string * var2 , expr_t value )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * var1 ) ;
check_symbol_existence ( * var2 ) ;
2010-04-14 15:03:41 +02:00
int symb_id1 = mod_file - > symbol_table . getID ( * var1 ) ;
int symb_id2 = mod_file - > symbol_table . getID ( * var2 ) ;
pair < int , int > key ( symb_id1 , symb_id2 ) , key_inv ( symb_id2 , symb_id1 ) ;
2008-02-03 11:28:36 +01:00
if ( covar_shocks . find ( key ) ! = covar_shocks . end ( )
| | covar_shocks . find ( key_inv ) ! = covar_shocks . end ( )
| | corr_shocks . find ( key ) ! = corr_shocks . end ( )
| | corr_shocks . find ( key_inv ) ! = corr_shocks . end ( ) )
error ( " shocks: covariance or correlation shock on variable pair ( " + * var1 + " , "
+ * var2 + " ) declared twice " ) ;
corr_shocks [ key ] = value ;
delete var1 ;
delete var2 ;
}
void
ParsingDriver : : add_period ( string * p1 , string * p2 )
{
int p1_val = atoi ( p1 - > c_str ( ) ) ;
int p2_val = atoi ( p2 - > c_str ( ) ) ;
2009-10-16 19:23:57 +02:00
if ( p1_val > p2_val )
error ( " shocks/conditional_forecast_paths: can't have first period index greater than second index in range specification " ) ;
2008-02-03 11:28:36 +01:00
det_shocks_periods . push_back ( make_pair ( p1_val , p2_val ) ) ;
delete p1 ;
delete p2 ;
}
void
ParsingDriver : : add_period ( string * p1 )
{
int p1_val = atoi ( p1 - > c_str ( ) ) ;
det_shocks_periods . push_back ( make_pair ( p1_val , p1_val ) ) ;
delete p1 ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_value ( expr_t value )
2008-02-03 11:28:36 +01:00
{
det_shocks_values . push_back ( value ) ;
}
void
2010-11-24 18:26:43 +01:00
ParsingDriver : : add_value ( string * v )
2008-02-03 11:28:36 +01:00
{
2010-11-24 18:26:43 +01:00
expr_t id ;
2012-07-12 12:46:22 +02:00
if ( v - > at ( 0 ) = = ' - ' )
id = data_tree - > AddUMinus ( data_tree - > AddNonNegativeConstant ( v - > substr ( 1 , string : : npos ) ) ) ;
else
id = data_tree - > AddNonNegativeConstant ( * v ) ;
2011-02-16 11:08:40 +01:00
2010-11-24 18:26:43 +01:00
delete v ;
det_shocks_values . push_back ( id ) ;
2008-02-03 11:28:36 +01:00
}
2011-08-03 11:00:11 +02:00
void
ParsingDriver : : begin_svar_identification ( )
{
svar_upper_cholesky = false ;
svar_lower_cholesky = false ;
svar_constants_exclusion = false ;
}
2009-12-04 22:32:19 +01:00
void
ParsingDriver : : end_svar_identification ( )
{
2011-10-10 11:45:55 +02:00
mod_file - > addStatement ( new SvarIdentificationStatement ( svar_ident_restrictions ,
2009-12-04 22:32:19 +01:00
svar_upper_cholesky ,
svar_lower_cholesky ,
2017-06-01 19:58:32 +02:00
svar_constants_exclusion ,
2009-12-04 22:32:19 +01:00
mod_file - > symbol_table ) ) ;
svar_restriction_symbols . clear ( ) ;
svar_equation_restrictions . clear ( ) ;
2011-10-10 11:45:55 +02:00
svar_ident_restrictions . clear ( ) ;
2011-11-06 17:44:50 +01:00
svar_Qi_restriction_nbr . clear ( ) ;
svar_Ri_restriction_nbr . clear ( ) ;
2009-12-04 22:32:19 +01:00
}
void
ParsingDriver : : combine_lag_and_restriction ( string * lag )
{
int current_lag = atoi ( lag - > c_str ( ) ) ;
2011-10-10 11:45:55 +02:00
for ( SvarIdentificationStatement : : svar_identification_restrictions_t : : const_iterator it = svar_ident_restrictions . begin ( ) ;
it ! = svar_ident_restrictions . end ( ) ; it + + )
if ( it - > lag = = current_lag )
2009-12-04 22:32:19 +01:00
error ( " lag " + * lag + " used more than once. " ) ;
2009-12-16 18:13:23 +01:00
for ( map < int , vector < int > > : : const_iterator it = svar_equation_restrictions . begin ( ) ;
it ! = svar_equation_restrictions . end ( ) ; it + + )
2011-10-10 11:45:55 +02:00
for ( vector < int > : : const_iterator it1 = it - > second . begin ( ) ;
2017-06-01 19:58:32 +02:00
it1 ! = it - > second . end ( ) ; it1 + + )
2011-10-10 11:45:55 +02:00
{
2017-06-01 19:58:32 +02:00
SvarIdentificationStatement : : svar_identification_restriction new_restriction ;
new_restriction . equation = it - > first ;
if ( current_lag > 0 )
new_restriction . restriction_nbr = + + svar_Ri_restriction_nbr [ it - > first ] ;
else
new_restriction . restriction_nbr = + + svar_Qi_restriction_nbr [ it - > first ] ;
new_restriction . lag = current_lag ;
new_restriction . variable = * it1 ;
new_restriction . value = data_tree - > One ;
svar_ident_restrictions . push_back ( new_restriction ) ;
}
2011-10-10 11:45:55 +02:00
// svar_ident_exclusion_values[make_pair(current_lag, it->first)] = it->second;
2009-12-04 22:32:19 +01:00
svar_upper_cholesky = false ;
svar_lower_cholesky = false ;
svar_equation_restrictions . clear ( ) ;
delete lag ;
}
void
ParsingDriver : : add_restriction_in_equation ( string * equation )
{
int eqn = atoi ( equation - > c_str ( ) ) ;
if ( eqn < 1 )
error ( " equation numbers must be greater than or equal to 1. " ) ;
if ( svar_equation_restrictions . count ( eqn ) > 0 )
error ( " equation number " + * equation + " referenced more than once under a single lag. " ) ;
svar_equation_restrictions [ eqn ] = svar_restriction_symbols ;
svar_restriction_symbols . clear ( ) ;
delete equation ;
}
void
ParsingDriver : : add_in_svar_restriction_symbols ( string * tmp_var )
{
check_symbol_existence ( * tmp_var ) ;
2009-12-14 16:54:00 +01:00
int symb_id = mod_file - > symbol_table . getID ( * tmp_var ) ;
2009-12-16 18:13:23 +01:00
for ( vector < int > : : const_iterator viit = svar_restriction_symbols . begin ( ) ;
viit ! = svar_restriction_symbols . end ( ) ; viit + + )
if ( symb_id = = * viit )
2009-12-04 22:32:19 +01:00
error ( * tmp_var + " restriction added twice. " ) ;
2009-12-14 16:54:00 +01:00
svar_restriction_symbols . push_back ( symb_id ) ;
2009-12-04 22:32:19 +01:00
delete tmp_var ;
}
2017-06-01 19:58:32 +02:00
void
2011-10-10 11:45:55 +02:00
ParsingDriver : : add_restriction_equation_nbr ( string * eq_nbr )
{
svar_equation_nbr = atoi ( eq_nbr - > c_str ( ) ) ;
svar_left_handside = true ;
2011-11-07 12:26:20 +01:00
// reinitialize restriction type that must be set from the first restriction element
svar_restriction_type = ParsingDriver : : NOT_SET ;
2011-10-10 11:45:55 +02:00
}
void
ParsingDriver : : add_restriction_equal ( )
{
if ( svar_left_handside )
svar_left_handside = false ;
else
error ( " svar_identification: there are more than one EQUAL sign in a restriction equation " ) ;
}
void
ParsingDriver : : add_positive_restriction_element ( expr_t value , string * variable , string * lag )
{
// if the expression is not on the left handside, change its sign
if ( ! svar_left_handside )
value = add_uminus ( value ) ;
2017-06-01 19:58:32 +02:00
2011-11-07 12:26:20 +01:00
add_restriction_element ( value , variable , lag ) ;
2011-10-10 11:45:55 +02:00
}
void
ParsingDriver : : add_positive_restriction_element ( string * variable , string * lag )
{
2017-06-01 19:58:32 +02:00
expr_t value ( data_tree - > One ) ;
2011-10-10 11:45:55 +02:00
// if the expression is not on the left handside, change its sign
if ( ! svar_left_handside )
value = add_uminus ( value ) ;
2011-11-07 12:26:20 +01:00
add_restriction_element ( value , variable , lag ) ;
2011-10-10 11:45:55 +02:00
}
void
ParsingDriver : : add_negative_restriction_element ( expr_t value , string * variable , string * lag )
{
// if the expression is on the left handside, change its sign
if ( svar_left_handside )
value = add_uminus ( value ) ;
2011-11-07 12:26:20 +01:00
add_restriction_element ( value , variable , lag ) ;
2011-10-10 11:45:55 +02:00
}
void
ParsingDriver : : add_negative_restriction_element ( string * variable , string * lag )
{
2017-06-01 19:58:32 +02:00
expr_t value ( data_tree - > One ) ;
2011-10-10 11:45:55 +02:00
// if the expression is on the left handside, change its sign
if ( svar_left_handside )
value = add_uminus ( value ) ;
2011-11-07 12:26:20 +01:00
add_restriction_element ( value , variable , lag ) ;
}
void
ParsingDriver : : add_restriction_element ( expr_t value , string * variable , string * lag )
{
check_symbol_existence ( * variable ) ;
int symb_id = mod_file - > symbol_table . getID ( * variable ) ;
2011-11-06 17:44:50 +01:00
int current_lag = atoi ( lag - > c_str ( ) ) ;
2011-11-07 12:26:20 +01:00
if ( svar_restriction_type = = ParsingDriver : : NOT_SET )
{
if ( current_lag = = 0 )
2017-06-01 19:58:32 +02:00
{
svar_restriction_type = ParsingDriver : : Qi_TYPE ;
+ + svar_Qi_restriction_nbr [ svar_equation_nbr ] ;
}
2011-11-07 12:26:20 +01:00
else
2017-06-01 19:58:32 +02:00
{
svar_restriction_type = ParsingDriver : : Ri_TYPE ;
+ + svar_Ri_restriction_nbr [ svar_equation_nbr ] ;
}
2011-11-07 12:26:20 +01:00
}
else
{
if ( ( svar_restriction_type = = Qi_TYPE & & current_lag > 0 )
2017-06-01 19:58:32 +02:00
| | ( svar_restriction_type = = Ri_TYPE & & current_lag = = 0 ) )
error ( " SVAR_IDENTIFICATION: a single restrictions must affect either Qi or Ri, but not both " ) ;
2011-11-07 12:26:20 +01:00
}
2011-10-10 11:45:55 +02:00
SvarIdentificationStatement : : svar_identification_restriction new_restriction ;
new_restriction . equation = svar_equation_nbr ;
2011-11-06 17:44:50 +01:00
if ( current_lag > 0 )
2011-11-07 12:26:20 +01:00
new_restriction . restriction_nbr = svar_Ri_restriction_nbr [ svar_equation_nbr ] ;
2011-11-06 17:44:50 +01:00
else
2011-11-07 12:26:20 +01:00
new_restriction . restriction_nbr = svar_Qi_restriction_nbr [ svar_equation_nbr ] ;
2011-11-06 17:44:50 +01:00
new_restriction . lag = current_lag ;
2011-10-10 11:45:55 +02:00
new_restriction . variable = symb_id ;
new_restriction . value = value ;
svar_ident_restrictions . push_back ( new_restriction ) ;
}
2011-11-06 17:44:50 +01:00
void
ParsingDriver : : check_restriction_expression_constant ( expr_t value )
{
if ( value - > eval ( eval_context_t ( ) ) ! = 0 )
error ( " SVAR_INDENTIFICATION restrictions must be homogenous " ) ;
}
2009-12-04 22:32:19 +01:00
void
ParsingDriver : : add_upper_cholesky ( )
{
svar_upper_cholesky = true ;
}
void
ParsingDriver : : add_lower_cholesky ( )
{
svar_lower_cholesky = true ;
}
2011-08-03 11:00:11 +02:00
void
ParsingDriver : : add_constants_exclusion ( )
{
svar_constants_exclusion = true ;
}
2015-08-24 11:21:06 +02:00
void
ParsingDriver : : add_svar_global_identification_check ( )
{
mod_file - > addStatement ( new SvarGlobalIdentificationCheckStatement ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : do_sigma_e ( )
{
2012-02-10 16:59:47 +01:00
warning ( " Sigma_e: this command is now deprecated and may be removed in a future version of Dynare. Please use the ''shocks'' command instead. " ) ;
2009-10-29 18:16:10 +01:00
2008-02-03 11:28:36 +01:00
try
{
mod_file - > addStatement ( new SigmaeStatement ( sigmae_matrix ) ) ;
}
2009-12-16 18:13:23 +01:00
catch ( SigmaeStatement : : MatrixFormException & e )
2008-02-03 11:28:36 +01:00
{
error ( " Sigma_e: matrix is neither upper triangular nor lower triangular " ) ;
}
sigmae_matrix . clear ( ) ;
}
void
ParsingDriver : : end_of_row ( )
{
sigmae_matrix . push_back ( sigmae_row ) ;
sigmae_row . clear ( ) ;
}
void
2010-11-25 13:45:35 +01:00
ParsingDriver : : add_to_row_const ( string * v )
2008-02-03 11:28:36 +01:00
{
2010-11-25 13:45:35 +01:00
expr_t id ;
2012-07-12 12:46:22 +02:00
if ( v - > at ( 0 ) = = ' - ' )
id = data_tree - > AddUMinus ( data_tree - > AddNonNegativeConstant ( v - > substr ( 1 , string : : npos ) ) ) ;
else
id = data_tree - > AddNonNegativeConstant ( * v ) ;
2011-02-16 11:08:40 +01:00
2010-11-25 13:45:35 +01:00
delete v ;
sigmae_row . push_back ( id ) ;
2008-02-03 11:28:36 +01:00
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_to_row ( expr_t v )
2008-02-03 11:28:36 +01:00
{
sigmae_row . push_back ( v ) ;
}
void
ParsingDriver : : steady ( )
{
2009-09-02 15:36:56 +02:00
mod_file - > addStatement ( new SteadyStatement ( options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
void
ParsingDriver : : option_num ( const string & name_option , string * opt1 , string * opt2 )
{
if ( options_list . paired_num_options . find ( name_option )
! = options_list . paired_num_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
options_list . paired_num_options [ name_option ] = make_pair ( * opt1 , * opt2 ) ;
delete opt1 ;
delete opt2 ;
}
void
ParsingDriver : : option_num ( const string & name_option , string * opt )
{
option_num ( name_option , * opt ) ;
delete opt ;
}
void
ParsingDriver : : option_num ( const string & name_option , const string & opt )
{
2009-12-01 18:51:47 +01:00
if ( options_list . num_options . find ( name_option ) ! = options_list . num_options . end ( ) )
2008-02-03 11:28:36 +01:00
error ( " option " + name_option + " declared twice " ) ;
options_list . num_options [ name_option ] = opt ;
}
void
ParsingDriver : : option_str ( const string & name_option , string * opt )
{
option_str ( name_option , * opt ) ;
delete opt ;
}
void
ParsingDriver : : option_str ( const string & name_option , const string & opt )
{
if ( options_list . string_options . find ( name_option )
! = options_list . string_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
options_list . string_options [ name_option ] = opt ;
}
2011-11-29 17:14:26 +01:00
void
ParsingDriver : : option_date ( const string & name_option , string * opt )
{
option_date ( name_option , * opt ) ;
delete opt ;
}
void
ParsingDriver : : option_date ( const string & name_option , const string & opt )
{
if ( options_list . date_options . find ( name_option )
! = options_list . date_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
options_list . date_options [ name_option ] = opt ;
}
2008-04-04 20:40:20 +02:00
void
2008-04-07 15:14:40 +02:00
ParsingDriver : : option_symbol_list ( const string & name_option )
2008-04-04 20:40:20 +02:00
{
2008-04-07 15:14:40 +02:00
if ( options_list . symbol_list_options . find ( name_option )
! = options_list . symbol_list_options . end ( ) )
2008-04-04 20:40:20 +02:00
error ( " option " + name_option + " declared twice " ) ;
2017-06-01 19:58:32 +02:00
if ( name_option . compare ( " irf_shocks " ) = = 0 )
2011-03-31 16:33:47 +02:00
{
vector < string > shocks = symbol_list . get_symbols ( ) ;
for ( vector < string > : : const_iterator it = shocks . begin ( ) ;
it ! = shocks . end ( ) ; it + + )
if ( mod_file - > symbol_table . getType ( * it ) ! = eExogenous )
2011-07-07 15:15:44 +02:00
error ( " Variables passed to irf_shocks must be exogenous. Caused by: " + * it ) ;
2011-03-31 16:33:47 +02:00
}
2017-06-01 19:58:32 +02:00
if ( name_option . compare ( " ms.parameters " ) = = 0 )
2011-12-24 16:58:16 +01:00
{
vector < string > parameters = symbol_list . get_symbols ( ) ;
for ( vector < string > : : const_iterator it = parameters . begin ( ) ;
it ! = parameters . end ( ) ; it + + )
if ( mod_file - > symbol_table . getType ( * it ) ! = eParameter )
error ( " Variables passed to the parameters option of the markov_switching statement must be parameters. Caused by: " + * it ) ;
}
2008-04-07 15:14:40 +02:00
options_list . symbol_list_options [ name_option ] = symbol_list ;
symbol_list . clear ( ) ;
2008-04-04 20:40:20 +02:00
}
2009-12-10 23:49:50 +01:00
void
ParsingDriver : : option_vec_int ( const string & name_option , const vector < int > * opt )
{
if ( options_list . vector_int_options . find ( name_option )
! = options_list . vector_int_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
2009-12-14 16:54:00 +01:00
if ( ( * opt ) . empty ( ) )
error ( " option " + name_option + " was passed an empty vector. " ) ;
2009-12-10 23:49:50 +01:00
options_list . vector_int_options [ name_option ] = * opt ;
2009-12-14 16:54:00 +01:00
delete opt ;
2009-12-10 23:49:50 +01:00
}
2018-01-12 16:54:17 +01:00
void
ParsingDriver : : option_vec_str ( const string & name_option , const vector < string > * opt )
{
if ( options_list . vector_str_options . find ( name_option )
! = options_list . vector_str_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
if ( ( * opt ) . empty ( ) )
error ( " option " + name_option + " was passed an empty vector. " ) ;
options_list . vector_str_options [ name_option ] = * opt ;
delete opt ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : linear ( )
{
mod_file - > linear = true ;
}
void
2008-04-07 15:14:40 +02:00
ParsingDriver : : add_in_symbol_list ( string * tmp_var )
2008-02-03 11:28:36 +01:00
{
2008-04-11 16:41:52 +02:00
if ( * tmp_var ! = " : " )
check_symbol_existence ( * tmp_var ) ;
2008-04-07 15:14:40 +02:00
symbol_list . addSymbol ( * tmp_var ) ;
2008-02-03 11:28:36 +01:00
delete tmp_var ;
}
2009-12-16 18:13:23 +01:00
void
ParsingDriver : : rplot ( )
2008-02-03 11:28:36 +01:00
{
2015-04-01 15:17:08 +02:00
mod_file - > addStatement ( new RplotStatement ( symbol_list ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
2009-12-16 18:13:23 +01:00
void
ParsingDriver : : stoch_simul ( )
2008-02-03 11:28:36 +01:00
{
2009-09-02 18:44:15 +02:00
mod_file - > addStatement ( new StochSimulStatement ( symbol_list , options_list ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
2016-10-26 18:19:33 +02:00
void
ParsingDriver : : var_model ( )
{
2016-11-03 12:56:54 +01:00
OptionsList : : string_options_t : : const_iterator it = options_list . string_options . find ( " var.model_name " ) ;
if ( it = = options_list . string_options . end ( ) )
error ( " You must pass the model_name option to the var_model statement. " ) ;
const string * name = new string ( it - > second ) ;
2018-01-30 16:33:16 +01:00
if ( options_list . vector_str_options . find ( " var.eqtags " ) ! = options_list . vector_str_options . end ( ) )
if ( ! symbol_list . empty ( ) )
error ( " You cannot pass a symbol list when passing equation tags to the var_model statement " ) ;
else if ( options_list . num_options . find ( " var.order " ) ! = options_list . num_options . end ( ) )
error ( " You cannot pass the order option when passing equation tags to the var_model statement " ) ;
if ( ! symbol_list . empty ( ) )
if ( options_list . num_options . find ( " var.order " ) = = options_list . num_options . end ( ) )
error ( " You must pass the order option when passing a symbol list to the var_model statement " ) ;
2018-02-08 13:07:15 +01:00
mod_file - > addStatement ( new VarModelStatement ( symbol_list , options_list , * name , mod_file - > symbol_table ) ) ;
2017-05-18 17:50:58 +02:00
var_map [ it - > second ] = symbol_list . getSymbols ( ) ;
2016-10-26 18:19:33 +02:00
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : simul ( )
{
2009-09-02 18:44:15 +02:00
mod_file - > addStatement ( new SimulStatement ( options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
2008-08-25 17:06:36 +02:00
void
ParsingDriver : : model_info ( )
{
2008-08-29 14:31:25 +02:00
mod_file - > addStatement ( new ModelInfoStatement ( options_list ) ) ;
2008-08-25 17:06:36 +02:00
options_list . clear ( ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : check ( )
{
mod_file - > addStatement ( new CheckStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : add_estimated_params_element ( )
{
2010-06-21 18:40:36 +02:00
if ( estim_params . name ! = " dsge_prior_weight " )
{
check_symbol_existence ( estim_params . name ) ;
2014-02-28 18:01:03 +01:00
SymbolType type = mod_file - > symbol_table . getType ( estim_params . name ) ;
switch ( estim_params . type )
{
case 1 :
if ( type ! = eEndogenous & & type ! = eExogenous )
error ( estim_params . name + " must be an endogenous or an exogenous variable " ) ;
break ;
case 2 :
check_symbol_is_parameter ( & estim_params . name ) ;
break ;
case 3 :
check_symbol_existence ( estim_params . name2 ) ;
SymbolType type2 = mod_file - > symbol_table . getType ( estim_params . name2 ) ;
if ( ( type ! = eEndogenous & & type ! = eExogenous ) | | type ! = type2 )
error ( estim_params . name + " and " + estim_params . name2 + " must either be both endogenous variables or both exogenous " ) ;
break ;
}
2010-06-21 18:40:36 +02:00
}
2008-02-03 11:28:36 +01:00
estim_params_list . push_back ( estim_params ) ;
2009-01-22 16:05:38 +01:00
estim_params . init ( * data_tree ) ;
2008-02-03 11:28:36 +01:00
}
void
ParsingDriver : : estimated_params ( )
{
mod_file - > addStatement ( new EstimatedParamsStatement ( estim_params_list , mod_file - > symbol_table ) ) ;
estim_params_list . clear ( ) ;
}
void
2013-11-06 10:36:58 +01:00
ParsingDriver : : estimated_params_init ( bool use_calibration )
2008-02-03 11:28:36 +01:00
{
2013-11-06 10:36:58 +01:00
mod_file - > addStatement ( new EstimatedParamsInitStatement ( estim_params_list , mod_file - > symbol_table , use_calibration ) ) ;
2008-02-03 11:28:36 +01:00
estim_params_list . clear ( ) ;
}
void
ParsingDriver : : estimated_params_bounds ( )
{
mod_file - > addStatement ( new EstimatedParamsBoundsStatement ( estim_params_list , mod_file - > symbol_table ) ) ;
estim_params_list . clear ( ) ;
}
2016-05-10 18:01:00 +02:00
void
ParsingDriver : : add_osr_params_element ( )
{
check_symbol_existence ( osr_params . name ) ;
SymbolType type = mod_file - > symbol_table . getType ( osr_params . name ) ;
if ( type ! = eParameter )
error ( osr_params . name + " must be a parameter to be used in the osr_bounds block " ) ;
osr_params_list . push_back ( osr_params ) ;
osr_params . init ( * data_tree ) ;
}
void
ParsingDriver : : osr_params_bounds ( )
{
2016-05-20 15:35:09 +02:00
mod_file - > addStatement ( new OsrParamsBoundsStatement ( osr_params_list ) ) ;
2016-05-10 18:01:00 +02:00
osr_params_list . clear ( ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : set_unit_root_vars ( )
{
2011-11-20 20:16:02 +01:00
mod_file - > addStatement ( new UnitRootVarsStatement ( ) ) ;
2012-02-10 16:59:47 +01:00
warning ( " ''unit_root_vars'' is now obsolete; use the ''diffuse_filter'' option of ''estimation'' instead " ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
2011-11-29 17:14:26 +01:00
void
ParsingDriver : : set_time ( string * arg )
{
2013-10-11 16:28:14 +02:00
option_date ( " initial_period " , arg ) ;
2011-11-29 17:14:26 +01:00
mod_file - > addStatement ( new SetTimeStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
2011-12-06 15:42:57 +01:00
void
ParsingDriver : : estimation_data ( )
{
mod_file - > addStatement ( new EstimationDataStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
2011-12-15 11:49:04 +01:00
void
2012-03-26 16:46:44 +02:00
ParsingDriver : : set_subsamples ( string * name1 , string * name2 )
2011-12-15 11:49:04 +01:00
{
2012-03-26 16:46:44 +02:00
check_symbol_existence ( * name1 ) ;
if ( ! name2 - > empty ( ) )
check_symbol_existence ( * name2 ) ;
2012-04-02 18:06:19 +02:00
mod_file - > addStatement ( new SubsamplesStatement ( * name1 , * name2 , subsample_declaration_map ,
mod_file - > symbol_table ) ) ;
2012-03-26 16:46:44 +02:00
subsample_declarations [ make_pair ( * name1 , * name2 ) ] = subsample_declaration_map ;
subsample_declaration_map . clear ( ) ;
delete name1 ;
delete name2 ;
2011-12-15 11:49:04 +01:00
}
2011-12-14 13:58:21 +01:00
void
2012-03-26 16:46:44 +02:00
ParsingDriver : : copy_subsamples ( string * to_name1 , string * to_name2 , string * from_name1 , string * from_name2 )
2011-12-14 13:58:21 +01:00
{
2012-03-26 16:46:44 +02:00
check_symbol_existence ( * to_name1 ) ;
check_symbol_existence ( * from_name1 ) ;
if ( ! to_name2 - > empty ( ) )
check_symbol_existence ( * to_name2 ) ;
if ( ! from_name2 - > empty ( ) )
check_symbol_existence ( * from_name2 ) ;
2017-06-01 19:58:32 +02:00
if ( subsample_declarations . find ( make_pair ( * from_name1 , * from_name2 ) ) = = subsample_declarations . end ( ) )
2012-03-26 16:46:44 +02:00
{
string err = * from_name1 ;
if ( ! from_name2 - > empty ( ) )
err . append ( " , " ) . append ( * from_name2 ) ;
error ( err + " does not have an associated subsample statement. " ) ;
}
2012-04-02 18:06:19 +02:00
mod_file - > addStatement ( new SubsamplesEqualStatement ( * to_name1 , * to_name2 , * from_name1 , * from_name2 ,
mod_file - > symbol_table ) ) ;
2012-03-28 16:19:10 +02:00
2017-06-01 19:58:32 +02:00
subsample_declarations [ make_pair ( * to_name1 , * to_name2 ) ]
= subsample_declarations [ make_pair ( * from_name1 , * from_name2 ) ] ;
2012-03-26 16:46:44 +02:00
delete to_name1 ;
delete to_name2 ;
delete from_name1 ;
delete from_name2 ;
2011-12-14 13:58:21 +01:00
}
void
ParsingDriver : : check_symbol_is_statement_variable ( string * name )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
if ( mod_file - > symbol_table . getType ( symb_id ) ! = eStatementDeclaredVariable )
error ( * name + " is not a variable assigned in a statement " ) ;
}
void
ParsingDriver : : set_subsample_name_equal_to_date_range ( string * name , string * date1 , string * date2 )
{
if ( subsample_declaration_map . find ( * name ) ! = subsample_declaration_map . end ( ) )
error ( " Symbol " + * name + " may only be assigned once in a SUBSAMPLE statement " ) ;
subsample_declaration_map [ * name ] = make_pair ( * date1 , * date2 ) ;
delete name ;
delete date1 ;
delete date2 ;
}
void
2012-03-28 16:19:10 +02:00
ParsingDriver : : check_subsample_declaration_exists ( string * name1 , string * subsample_name )
2011-12-14 13:58:21 +01:00
{
2012-03-28 16:19:10 +02:00
if ( subsample_name - > empty ( ) )
return ;
2017-06-01 19:58:32 +02:00
string * str_empty = new string ( " " ) ;
2012-03-28 16:19:10 +02:00
check_subsample_declaration_exists ( name1 , str_empty , subsample_name ) ;
delete str_empty ;
}
void
ParsingDriver : : check_subsample_declaration_exists ( string * name1 , string * name2 , string * subsample_name )
{
if ( subsample_name - > empty ( ) )
return ;
2012-03-26 16:46:44 +02:00
check_symbol_existence ( * name1 ) ;
if ( ! name2 - > empty ( ) )
2017-06-01 19:58:32 +02:00
check_symbol_existence ( * name2 ) ;
2012-03-26 16:46:44 +02:00
subsample_declarations_t : : const_iterator it = subsample_declarations . find ( make_pair ( * name1 , * name2 ) ) ;
2011-12-14 13:58:21 +01:00
if ( it = = subsample_declarations . end ( ) )
2012-03-26 16:46:44 +02:00
{
2012-03-28 16:19:10 +02:00
it = subsample_declarations . find ( make_pair ( * name2 , * name1 ) ) ;
2017-06-01 19:58:32 +02:00
if ( it = = subsample_declarations . end ( ) )
2012-03-28 16:19:10 +02:00
{
string err = * name1 ;
if ( ! name2 - > empty ( ) )
err . append ( " , " ) . append ( * name2 ) ;
error ( " A subsample statement has not been issued for " + err ) ;
}
2012-03-26 16:46:44 +02:00
}
2012-03-28 16:19:10 +02:00
SubsamplesStatement : : subsample_declaration_map_t tmp_map = it - > second ;
2011-12-14 13:58:21 +01:00
if ( tmp_map . find ( * subsample_name ) = = tmp_map . end ( ) )
error ( " The subsample name " + * subsample_name + " was not previously declared in a subsample statement. " ) ;
}
2011-12-11 15:35:26 +01:00
void
2012-03-28 16:19:10 +02:00
ParsingDriver : : set_prior ( string * name , string * subsample_name )
2011-12-11 15:35:26 +01:00
{
check_symbol_is_parameter ( name ) ;
2012-03-28 16:19:10 +02:00
check_subsample_declaration_exists ( name , subsample_name ) ;
mod_file - > addStatement ( new PriorStatement ( * name , * subsample_name , prior_shape , prior_variance , options_list ) ) ;
2011-12-11 15:35:26 +01:00
options_list . clear ( ) ;
2011-12-22 15:14:00 +01:00
set_prior_variance ( ) ;
2011-12-29 18:43:21 +01:00
prior_shape = eNoShape ;
2011-12-11 15:35:26 +01:00
delete name ;
2012-03-28 16:19:10 +02:00
delete subsample_name ;
2011-12-11 15:35:26 +01:00
}
2015-03-03 15:08:33 +01:00
void
2017-06-01 19:58:32 +02:00
ParsingDriver : : set_joint_prior ( vector < string * > * symbol_vec )
2015-03-03 15:08:33 +01:00
{
2017-06-01 19:58:32 +02:00
for ( vector < string * > : : const_iterator it = symbol_vec - > begin ( ) ; it ! = symbol_vec - > end ( ) ; it + + )
2015-03-03 15:08:33 +01:00
add_joint_parameter ( * it ) ;
mod_file - > addStatement ( new JointPriorStatement ( joint_parameters , prior_shape , options_list ) ) ;
joint_parameters . clear ( ) ;
options_list . clear ( ) ;
prior_shape = eNoShape ;
delete symbol_vec ;
}
void
ParsingDriver : : add_joint_parameter ( string * name )
{
check_symbol_is_parameter ( name ) ;
joint_parameters . push_back ( * name ) ;
delete name ;
}
2011-12-11 15:35:26 +01:00
void
2011-12-22 15:14:00 +01:00
ParsingDriver : : set_prior_variance ( expr_t variance )
2011-12-11 15:35:26 +01:00
{
prior_variance = variance ;
}
2012-03-30 14:55:25 +02:00
void
ParsingDriver : : copy_prior ( string * to_declaration_type , string * to_name1 , string * to_name2 , string * to_subsample_name ,
string * from_declaration_type , string * from_name1 , string * from_name2 , string * from_subsample_name )
{
2012-04-04 10:43:29 +02:00
if ( strcmp ( to_declaration_type - > c_str ( ) , " par " ) = = 0 )
check_symbol_is_parameter ( to_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( to_name1 ) ;
if ( ! to_name2 - > empty ( ) )
check_symbol_is_endogenous_or_exogenous ( to_name2 ) ;
}
2012-03-30 14:55:25 +02:00
2012-04-04 10:43:29 +02:00
if ( strcmp ( from_declaration_type - > c_str ( ) , " par " ) = = 0 )
check_symbol_is_parameter ( from_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( from_name1 ) ;
if ( ! from_name2 - > empty ( ) )
check_symbol_is_endogenous_or_exogenous ( from_name2 ) ;
}
2012-03-30 14:55:25 +02:00
mod_file - > addStatement ( new PriorEqualStatement ( * to_declaration_type , * to_name1 , * to_name2 , * to_subsample_name ,
* from_declaration_type , * from_name1 , * from_name2 , * from_subsample_name ,
mod_file - > symbol_table ) ) ;
2012-04-04 10:43:29 +02:00
2012-03-30 14:55:25 +02:00
delete to_declaration_type ;
delete to_name1 ;
delete to_name2 ;
delete to_subsample_name ;
delete from_declaration_type ;
delete from_name1 ;
delete from_name2 ;
delete from_subsample_name ;
}
2011-12-14 17:19:14 +01:00
void
2012-03-28 16:19:10 +02:00
ParsingDriver : : set_options ( string * name , string * subsample_name )
2011-12-14 17:19:14 +01:00
{
check_symbol_is_parameter ( name ) ;
2012-03-28 16:19:10 +02:00
check_subsample_declaration_exists ( name , subsample_name ) ;
mod_file - > addStatement ( new OptionsStatement ( * name , * subsample_name , options_list ) ) ;
2011-12-14 17:19:14 +01:00
options_list . clear ( ) ;
delete name ;
2012-03-28 16:19:10 +02:00
delete subsample_name ;
2011-12-14 17:19:14 +01:00
}
2012-03-30 15:36:58 +02:00
void
ParsingDriver : : copy_options ( string * to_declaration_type , string * to_name1 , string * to_name2 , string * to_subsample_name ,
string * from_declaration_type , string * from_name1 , string * from_name2 , string * from_subsample_name )
{
2012-04-04 10:43:29 +02:00
if ( strcmp ( to_declaration_type - > c_str ( ) , " par " ) = = 0 )
check_symbol_is_parameter ( to_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( to_name1 ) ;
if ( ! to_name2 - > empty ( ) )
check_symbol_is_endogenous_or_exogenous ( to_name2 ) ;
}
2012-03-30 15:36:58 +02:00
2012-04-04 10:43:29 +02:00
if ( strcmp ( from_declaration_type - > c_str ( ) , " par " ) = = 0 )
check_symbol_is_parameter ( from_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( from_name1 ) ;
if ( ! from_name2 - > empty ( ) )
check_symbol_is_endogenous_or_exogenous ( from_name2 ) ;
}
2012-03-30 15:36:58 +02:00
mod_file - > addStatement ( new OptionsEqualStatement ( * to_declaration_type , * to_name1 , * to_name2 , * to_subsample_name ,
* from_declaration_type , * from_name1 , * from_name2 , * from_subsample_name ,
mod_file - > symbol_table ) ) ;
delete to_declaration_type ;
delete to_name1 ;
delete to_name2 ;
delete to_subsample_name ;
delete from_declaration_type ;
delete from_name1 ;
delete from_name2 ;
delete from_subsample_name ;
}
2011-12-11 15:35:26 +01:00
void
ParsingDriver : : check_symbol_is_endogenous_or_exogenous ( string * name )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
2017-06-01 19:58:32 +02:00
switch ( mod_file - > symbol_table . getType ( symb_id ) )
2011-12-11 15:35:26 +01:00
{
case eEndogenous :
case eExogenous :
case eExogenousDet :
break ;
default :
error ( * name + " is neither endogenous or exogenous. " ) ;
}
}
2017-10-06 14:49:14 +02:00
void
ParsingDriver : : check_symbol_is_exogenous ( string * name )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
switch ( mod_file - > symbol_table . getType ( symb_id ) )
{
case eExogenous :
case eExogenousDet :
break ;
default :
error ( * name + " is not exogenous. " ) ;
}
}
2011-12-11 15:35:26 +01:00
void
2012-03-28 16:19:10 +02:00
ParsingDriver : : set_std_prior ( string * name , string * subsample_name )
2011-12-11 15:35:26 +01:00
{
check_symbol_is_endogenous_or_exogenous ( name ) ;
2012-03-28 16:19:10 +02:00
check_subsample_declaration_exists ( name , subsample_name ) ;
mod_file - > addStatement ( new StdPriorStatement ( * name , * subsample_name , prior_shape , prior_variance ,
2011-12-29 18:43:21 +01:00
options_list , mod_file - > symbol_table ) ) ;
2011-12-11 15:35:26 +01:00
options_list . clear ( ) ;
2011-12-22 15:14:00 +01:00
set_prior_variance ( ) ;
2011-12-29 18:43:21 +01:00
prior_shape = eNoShape ;
2011-12-11 15:35:26 +01:00
delete name ;
2012-03-28 16:19:10 +02:00
delete subsample_name ;
2011-12-11 15:35:26 +01:00
}
2011-12-14 17:19:14 +01:00
void
2012-03-28 16:19:10 +02:00
ParsingDriver : : set_std_options ( string * name , string * subsample_name )
2011-12-14 17:19:14 +01:00
{
check_symbol_is_endogenous_or_exogenous ( name ) ;
2012-03-28 16:19:10 +02:00
check_subsample_declaration_exists ( name , subsample_name ) ;
mod_file - > addStatement ( new StdOptionsStatement ( * name , * subsample_name , options_list , mod_file - > symbol_table ) ) ;
2011-12-14 17:19:14 +01:00
options_list . clear ( ) ;
delete name ;
2012-03-28 16:19:10 +02:00
delete subsample_name ;
2011-12-14 17:19:14 +01:00
}
2011-12-11 15:35:26 +01:00
void
2012-03-28 16:19:10 +02:00
ParsingDriver : : set_corr_prior ( string * name1 , string * name2 , string * subsample_name )
2011-12-11 15:35:26 +01:00
{
check_symbol_is_endogenous_or_exogenous ( name1 ) ;
check_symbol_is_endogenous_or_exogenous ( name2 ) ;
2012-03-28 16:19:10 +02:00
check_subsample_declaration_exists ( name1 , name2 , subsample_name ) ;
mod_file - > addStatement ( new CorrPriorStatement ( * name1 , * name2 , * subsample_name , prior_shape , prior_variance ,
2011-12-29 18:43:21 +01:00
options_list , mod_file - > symbol_table ) ) ;
2011-12-11 15:35:26 +01:00
options_list . clear ( ) ;
2011-12-22 15:14:00 +01:00
set_prior_variance ( ) ;
2011-12-29 18:43:21 +01:00
prior_shape = eNoShape ;
2011-12-11 15:35:26 +01:00
delete name1 ;
delete name2 ;
2012-03-28 16:19:10 +02:00
delete subsample_name ;
2011-12-11 15:35:26 +01:00
}
2011-12-14 17:19:14 +01:00
void
2012-03-28 16:19:10 +02:00
ParsingDriver : : set_corr_options ( string * name1 , string * name2 , string * subsample_name )
2011-12-14 17:19:14 +01:00
{
check_symbol_is_endogenous_or_exogenous ( name1 ) ;
check_symbol_is_endogenous_or_exogenous ( name2 ) ;
2012-03-28 16:19:10 +02:00
check_subsample_declaration_exists ( name1 , name2 , subsample_name ) ;
mod_file - > addStatement ( new CorrOptionsStatement ( * name1 , * name2 , * subsample_name , options_list , mod_file - > symbol_table ) ) ;
2011-12-14 17:19:14 +01:00
options_list . clear ( ) ;
delete name1 ;
delete name2 ;
2012-03-28 16:19:10 +02:00
delete subsample_name ;
2011-12-14 17:19:14 +01:00
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : run_estimation ( )
{
2013-11-20 12:06:26 +01:00
mod_file - > addStatement ( new EstimationStatement ( symbol_list , options_list ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
void
ParsingDriver : : dynare_sensitivity ( )
{
mod_file - > addStatement ( new DynareSensitivityStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : optim_options_helper ( const string & name )
{
if ( options_list . string_options . find ( " optim_opt " ) = = options_list . string_options . end ( ) )
options_list . string_options [ " optim_opt " ] = " " ;
else
options_list . string_options [ " optim_opt " ] + = " , " ;
options_list . string_options [ " optim_opt " ] + = " '' " + name + " '', " ;
}
void
ParsingDriver : : optim_options_string ( string * name , string * value )
{
optim_options_helper ( * name ) ;
options_list . string_options [ " optim_opt " ] + = " '' " + * value + " '' " ;
delete name ;
delete value ;
}
void
ParsingDriver : : optim_options_num ( string * name , string * value )
{
optim_options_helper ( * name ) ;
options_list . string_options [ " optim_opt " ] + = * value ;
delete name ;
2015-05-13 16:09:50 +02:00
delete value ;
}
void
2016-05-04 13:22:56 +02:00
ParsingDriver : : sampling_options_helper ( const string & name )
2015-05-13 16:09:50 +02:00
{
2016-05-04 13:22:56 +02:00
if ( options_list . string_options . find ( " posterior_sampler_options.sampling_opt " ) = =
options_list . string_options . end ( ) )
options_list . string_options [ " posterior_sampler_options.sampling_opt " ] = " " ;
2015-05-13 16:09:50 +02:00
else
2016-05-04 13:22:56 +02:00
options_list . string_options [ " posterior_sampler_options.sampling_opt " ] + = " , " ;
options_list . string_options [ " posterior_sampler_options.sampling_opt " ] + = " '' " + name + " '', " ;
2015-05-13 16:09:50 +02:00
}
void
2016-05-04 13:22:56 +02:00
ParsingDriver : : sampling_options_string ( string * name , string * value )
2015-05-13 16:09:50 +02:00
{
2016-05-04 13:22:56 +02:00
sampling_options_helper ( * name ) ;
options_list . string_options [ " posterior_sampler_options.sampling_opt " ] + = " '' " + * value + " '' " ;
2015-05-13 16:09:50 +02:00
delete name ;
delete value ;
}
void
2016-05-04 13:22:56 +02:00
ParsingDriver : : sampling_options_num ( string * name , string * value )
2015-05-13 16:09:50 +02:00
{
2016-05-04 13:22:56 +02:00
sampling_options_helper ( * name ) ;
options_list . string_options [ " posterior_sampler_options.sampling_opt " ] + = * value ;
2015-05-13 16:09:50 +02:00
delete name ;
2008-02-03 11:28:36 +01:00
delete value ;
}
void
2010-04-14 15:03:41 +02:00
ParsingDriver : : check_varobs ( )
2008-02-03 11:28:36 +01:00
{
2010-04-14 15:03:41 +02:00
if ( mod_file - > symbol_table . observedVariablesNbr ( ) > 0 )
error ( " varobs: you cannot have several 'varobs' statements in the same MOD file " ) ;
}
void
ParsingDriver : : add_varobs ( string * name )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
if ( mod_file - > symbol_table . getType ( symb_id ) ! = eEndogenous )
error ( " varobs: " + * name + " is not an endogenous variable " ) ;
mod_file - > symbol_table . addObservedVariable ( symb_id ) ;
delete name ;
2008-02-03 11:28:36 +01:00
}
2016-10-13 18:19:38 +02:00
void
ParsingDriver : : check_varexobs ( )
{
if ( mod_file - > symbol_table . observedExogenousVariablesNbr ( ) > 0 )
error ( " varexobs: you cannot have several 'varexobs' statements in the same MOD file " ) ;
}
void
ParsingDriver : : add_varexobs ( string * name )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
if ( mod_file - > symbol_table . getType ( symb_id ) ! = eExogenous )
error ( " varexobs: " + * name + " is not an exogenous variable " ) ;
mod_file - > symbol_table . addObservedExogenousVariable ( symb_id ) ;
delete name ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : set_trends ( )
{
mod_file - > addStatement ( new ObservationTrendsStatement ( trend_elements , mod_file - > symbol_table ) ) ;
trend_elements . clear ( ) ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : set_trend_element ( string * arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * arg1 ) ;
if ( trend_elements . find ( * arg1 ) ! = trend_elements . end ( ) )
error ( " observation_trends: " + * arg1 + " declared twice " ) ;
trend_elements [ * arg1 ] = arg2 ;
delete arg1 ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : set_optim_weights ( string * name , expr_t value )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * name ) ;
if ( mod_file - > symbol_table . getType ( * name ) ! = eEndogenous )
error ( " optim_weights: " + * name + " isn't an endogenous variable " ) ;
if ( var_weights . find ( * name ) ! = var_weights . end ( ) )
error ( " optim_weights: " + * name + " declared twice " ) ;
var_weights [ * name ] = value ;
delete name ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : set_optim_weights ( string * name1 , string * name2 , expr_t value )
2008-02-03 11:28:36 +01:00
{
check_symbol_existence ( * name1 ) ;
if ( mod_file - > symbol_table . getType ( * name1 ) ! = eEndogenous )
error ( " optim_weights: " + * name1 + " isn't an endogenous variable " ) ;
check_symbol_existence ( * name2 ) ;
if ( mod_file - > symbol_table . getType ( * name2 ) ! = eEndogenous )
error ( " optim_weights: " + * name2 + " isn't an endogenous variable " ) ;
pair < string , string > covar_key ( * name1 , * name2 ) ;
if ( covar_weights . find ( covar_key ) ! = covar_weights . end ( ) )
error ( " optim_weights: pair of variables ( " + * name1 + " , " + * name2
+ " ) declared twice " ) ;
covar_weights [ covar_key ] = value ;
delete name1 ;
delete name2 ;
}
void
ParsingDriver : : optim_weights ( )
{
mod_file - > addStatement ( new OptimWeightsStatement ( var_weights , covar_weights , mod_file - > symbol_table ) ) ;
var_weights . clear ( ) ;
covar_weights . clear ( ) ;
}
void
ParsingDriver : : set_osr_params ( )
{
2016-05-20 15:35:09 +02:00
mod_file - > addStatement ( new OsrParamsStatement ( symbol_list , mod_file - > symbol_table ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
void
ParsingDriver : : run_osr ( )
{
2008-04-07 15:14:40 +02:00
mod_file - > addStatement ( new OsrStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
void
2008-10-13 18:06:07 +02:00
ParsingDriver : : run_dynatype ( string * filename )
2008-02-03 11:28:36 +01:00
{
2008-10-13 18:06:07 +02:00
mod_file - > addStatement ( new DynaTypeStatement ( symbol_list , * filename ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
delete filename ;
}
void
2008-10-13 18:06:07 +02:00
ParsingDriver : : run_dynasave ( string * filename )
2008-02-03 11:28:36 +01:00
{
2008-10-13 18:06:07 +02:00
mod_file - > addStatement ( new DynaSaveStatement ( symbol_list , * filename ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
delete filename ;
}
2008-12-31 20:29:17 +01:00
void
ParsingDriver : : run_load_params_and_steady_state ( string * filename )
{
2013-02-26 16:50:05 +01:00
mod_file - > addStatement ( new LoadParamsAndSteadyStateStatement ( * filename , mod_file - > symbol_table , warnings ) ) ;
2008-12-31 20:29:17 +01:00
delete filename ;
}
void
ParsingDriver : : run_save_params_and_steady_state ( string * filename )
{
mod_file - > addStatement ( new SaveParamsAndSteadyStateStatement ( * filename ) ) ;
delete filename ;
}
2009-04-20 15:58:15 +02:00
void
ParsingDriver : : run_identification ( )
{
2009-10-14 18:16:43 +02:00
mod_file - > addStatement ( new IdentificationStatement ( options_list ) ) ;
options_list . clear ( ) ;
2009-04-20 15:58:15 +02:00
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : add_mc_filename ( string * filename , string * prior )
{
2010-09-16 19:00:48 +02:00
for ( ModelComparisonStatement : : filename_list_t : : iterator it = filename_list . begin ( ) ;
2009-12-16 18:13:23 +01:00
it ! = filename_list . end ( ) ; it + + )
2008-09-26 18:24:13 +02:00
if ( ( * it ) . first = = * filename )
error ( " model_comparison: filename " + * filename + " declared twice " ) ;
filename_list . push_back ( make_pair ( * filename , * prior ) ) ;
2008-02-03 11:28:36 +01:00
delete filename ;
delete prior ;
}
void
ParsingDriver : : run_model_comparison ( )
{
mod_file - > addStatement ( new ModelComparisonStatement ( filename_list , options_list ) ) ;
filename_list . clear ( ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : begin_planner_objective ( )
{
2010-02-22 17:33:38 +01:00
set_current_data_tree ( new StaticModel ( mod_file - > symbol_table , mod_file - > num_constants , mod_file - > external_functions_table ) ) ;
2008-02-03 11:28:36 +01:00
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : end_planner_objective ( expr_t expr )
2008-02-03 11:28:36 +01:00
{
// Add equation corresponding to expression
2010-09-16 19:18:45 +02:00
expr_t eq = model_tree - > AddEqual ( expr , model_tree - > Zero ) ;
2014-01-27 16:41:43 +01:00
model_tree - > addEquation ( eq , location . begin . line ) ;
2008-02-03 11:28:36 +01:00
2009-04-14 16:39:53 +02:00
mod_file - > addStatement ( new PlannerObjectiveStatement ( dynamic_cast < StaticModel * > ( model_tree ) ) ) ;
2008-02-03 11:28:36 +01:00
reset_data_tree ( ) ;
}
2014-03-08 09:55:00 +01:00
void
ParsingDriver : : ramsey_model ( )
{
if ( ! mod_file - > symbol_table . exists ( " optimal_policy_discount_factor " ) )
declare_optimal_policy_discount_factor_parameter ( data_tree - > One ) ;
2017-08-24 16:43:36 +02:00
mod_file - > addStatement ( new RamseyModelStatement ( options_list ) ) ;
2014-03-08 09:55:00 +01:00
options_list . clear ( ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : ramsey_policy ( )
{
2011-05-24 15:34:03 +02:00
if ( ! mod_file - > symbol_table . exists ( " optimal_policy_discount_factor " ) )
declare_optimal_policy_discount_factor_parameter ( data_tree - > One ) ;
2016-12-27 13:46:01 +01:00
mod_file - > addStatement ( new RamseyPolicyStatement ( mod_file - > symbol_table , ramsey_policy_list , options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
2016-12-27 13:46:01 +01:00
ramsey_policy_list . clear ( ) ;
}
void
ParsingDriver : : add_to_ramsey_policy_list ( string * name )
{
ramsey_policy_list . push_back ( * name ) ;
delete name ;
2008-02-03 11:28:36 +01:00
}
2011-03-13 21:19:55 +01:00
void
ParsingDriver : : discretionary_policy ( )
{
2011-05-24 15:34:03 +02:00
if ( ! mod_file - > symbol_table . exists ( " optimal_policy_discount_factor " ) )
declare_optimal_policy_discount_factor_parameter ( data_tree - > One ) ;
2011-03-13 21:19:55 +01:00
mod_file - > addStatement ( new DiscretionaryPolicyStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2009-04-30 15:14:33 +02:00
void
2017-04-04 15:28:27 +02:00
ParsingDriver : : write_latex_dynamic_model ( bool write_equation_tags )
2009-04-30 15:14:33 +02:00
{
2017-04-04 15:28:27 +02:00
mod_file - > addStatement ( new WriteLatexDynamicModelStatement ( mod_file - > dynamic_model , write_equation_tags ) ) ;
2009-04-30 15:14:33 +02:00
}
void
2017-08-24 15:35:10 +02:00
ParsingDriver : : write_latex_static_model ( bool write_equation_tags )
2009-04-30 15:14:33 +02:00
{
2017-08-24 15:35:10 +02:00
mod_file - > addStatement ( new WriteLatexStaticModelStatement ( mod_file - > static_model , write_equation_tags ) ) ;
2009-04-30 15:14:33 +02:00
}
2015-02-16 08:31:30 +01:00
void
2017-08-24 15:35:10 +02:00
ParsingDriver : : write_latex_original_model ( bool write_equation_tags )
2015-02-16 08:31:30 +01:00
{
2017-08-24 15:35:10 +02:00
mod_file - > addStatement ( new WriteLatexOriginalModelStatement ( mod_file - > original_model , write_equation_tags ) ) ;
2015-02-16 08:31:30 +01:00
}
2017-08-30 11:32:01 +02:00
void
ParsingDriver : : write_latex_steady_state_model ( )
{
mod_file - > addStatement ( new WriteLatexSteadyStateModelStatement ( mod_file - > steady_state_model ) ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : bvar_density ( string * maxnlags )
{
mod_file - > addStatement ( new BVARDensityStatement ( atoi ( maxnlags - > c_str ( ) ) , options_list ) ) ;
options_list . clear ( ) ;
delete maxnlags ;
}
void
ParsingDriver : : bvar_forecast ( string * nlags )
{
mod_file - > addStatement ( new BVARForecastStatement ( atoi ( nlags - > c_str ( ) ) , options_list ) ) ;
options_list . clear ( ) ;
delete nlags ;
}
2009-07-26 19:07:07 +02:00
void
ParsingDriver : : sbvar ( )
{
mod_file - > addStatement ( new SBVARStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
2011-05-11 19:02:39 +02:00
ParsingDriver : : ms_estimation ( )
2009-07-26 19:07:07 +02:00
{
2011-05-11 19:02:39 +02:00
mod_file - > addStatement ( new MSSBVAREstimationStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_simulation ( )
{
mod_file - > addStatement ( new MSSBVARSimulationStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_compute_mdd ( )
{
mod_file - > addStatement ( new MSSBVARComputeMDDStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_compute_probabilities ( )
{
mod_file - > addStatement ( new MSSBVARComputeProbabilitiesStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_irf ( )
{
2017-06-01 19:58:32 +02:00
mod_file - > addStatement ( new MSSBVARIrfStatement ( symbol_list , options_list ) ) ;
2011-05-30 15:47:34 +02:00
symbol_list . clear ( ) ;
2011-05-11 19:02:39 +02:00
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_forecast ( )
{
mod_file - > addStatement ( new MSSBVARForecastStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_variance_decomposition ( )
{
mod_file - > addStatement ( new MSSBVARVarianceDecompositionStatement ( options_list ) ) ;
2009-07-26 19:07:07 +02:00
options_list . clear ( ) ;
}
2009-12-09 01:38:53 +01:00
void
ParsingDriver : : svar ( )
{
2016-11-04 14:44:45 +01:00
OptionsList : : string_options_t : : const_iterator it0 , it1 , it2 ;
OptionsList : : num_options_t : : const_iterator itn ;
2010-09-16 19:00:48 +02:00
OptionsList : : vec_int_options_t : : const_iterator itv ;
2009-12-09 01:38:53 +01:00
it0 = options_list . string_options . find ( " ms.coefficients " ) ;
it1 = options_list . string_options . find ( " ms.variances " ) ;
it2 = options_list . string_options . find ( " ms.constants " ) ;
2009-12-16 18:13:23 +01:00
if ( it0 = = options_list . string_options . end ( )
& & it1 = = options_list . string_options . end ( )
& & it2 = = options_list . string_options . end ( ) )
2009-12-09 01:38:53 +01:00
error ( " You must pass one of 'coefficients', 'variances', or 'constants'. " ) ;
2009-12-16 18:13:23 +01:00
if ( ( it0 ! = options_list . string_options . end ( )
& & it1 ! = options_list . string_options . end ( ) )
| | ( it1 ! = options_list . string_options . end ( )
& & it2 ! = options_list . string_options . end ( ) )
| | ( it0 ! = options_list . string_options . end ( )
& & it2 ! = options_list . string_options . end ( ) ) )
2011-09-15 20:18:37 +02:00
error ( " You may only pass one of 'coefficients', 'variances', or 'constants'. " ) ;
2009-12-09 01:38:53 +01:00
2016-11-04 14:44:45 +01:00
itn = options_list . num_options . find ( " ms.chain " ) ;
if ( itn = = options_list . num_options . end ( ) )
2009-12-09 01:38:53 +01:00
error ( " A chain option must be passed to the svar statement. " ) ;
2016-11-04 14:44:45 +01:00
else if ( atoi ( itn - > second . c_str ( ) ) < = 0 )
2009-12-09 01:38:53 +01:00
error ( " The value passed to the chain option must be greater than zero. " ) ;
2009-12-10 23:49:50 +01:00
itv = options_list . vector_int_options . find ( " ms.equations " ) ;
if ( itv ! = options_list . vector_int_options . end ( ) )
2009-12-16 18:13:23 +01:00
for ( vector < int > : : const_iterator viit = itv - > second . begin ( ) ; viit ! = itv - > second . end ( ) ; viit + + )
2009-12-14 16:54:00 +01:00
if ( * viit < = 0 )
error ( " The value(s) passed to the equation option must be greater than zero. " ) ;
2009-12-09 01:38:53 +01:00
mod_file - > addStatement ( new SvarStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
2009-12-08 17:46:13 +01:00
void
ParsingDriver : : markov_switching ( )
{
2011-12-19 15:57:28 +01:00
OptionsList : : num_options_t : : const_iterator it0 ;
2009-12-08 17:46:13 +01:00
it0 = options_list . num_options . find ( " ms.chain " ) ;
if ( it0 = = options_list . num_options . end ( ) )
error ( " A chain option must be passed to the markov_switching statement. " ) ;
else if ( atoi ( it0 - > second . c_str ( ) ) < = 0 )
error ( " The value passed to the chain option must be greater than zero. " ) ;
2011-12-19 15:57:28 +01:00
it0 = options_list . num_options . find ( " ms.number_of_regimes " ) ;
if ( it0 = = options_list . num_options . end ( ) )
error ( " A number_of_regimes option must be passed to the markov_switching statement. " ) ;
else if ( atoi ( it0 - > second . c_str ( ) ) < = 0 )
error ( " The value passed to the number_of_regimes option must be greater than zero. " ) ;
2009-12-08 17:46:13 +01:00
it0 = options_list . num_options . find ( " ms.duration " ) ;
if ( it0 = = options_list . num_options . end ( ) )
error ( " A duration option must be passed to the markov_switching statement. " ) ;
mod_file - > addStatement ( new MarkovSwitchingStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
2009-08-29 17:04:11 +02:00
void
2009-07-23 10:31:48 +02:00
ParsingDriver : : shock_decomposition ( )
{
mod_file - > addStatement ( new ShockDecompositionStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2009-08-29 17:04:11 +02:00
2017-03-21 14:58:15 +01:00
void
ParsingDriver : : realtime_shock_decomposition ( )
{
mod_file - > addStatement ( new RealtimeShockDecompositionStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2017-03-22 11:30:35 +01:00
void
ParsingDriver : : plot_shock_decomposition ( )
{
mod_file - > addStatement ( new PlotShockDecompositionStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2017-03-31 12:50:17 +02:00
void
ParsingDriver : : initial_condition_decomposition ( )
{
mod_file - > addStatement ( new InitialConditionDecompositionStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2009-10-16 19:23:57 +02:00
void
ParsingDriver : : conditional_forecast ( )
{
mod_file - > addStatement ( new ConditionalForecastStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : plot_conditional_forecast ( string * periods )
{
int nperiods ;
if ( periods = = NULL )
nperiods = - 1 ;
else
{
nperiods = atoi ( periods - > c_str ( ) ) ;
delete periods ;
}
mod_file - > addStatement ( new PlotConditionalForecastStatement ( nperiods , symbol_list ) ) ;
symbol_list . clear ( ) ;
}
void
ParsingDriver : : conditional_forecast_paths ( )
{
2016-09-06 14:43:06 +02:00
mod_file - > addStatement ( new ConditionalForecastPathsStatement ( det_shocks , mod_file - > symbol_table ) ) ;
2009-10-16 19:23:57 +02:00
det_shocks . clear ( ) ;
}
2012-05-30 16:28:00 +02:00
void
ParsingDriver : : calib_smoother ( )
{
mod_file - > addStatement ( new CalibSmootherStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2012-06-08 17:36:32 +02:00
void
ParsingDriver : : extended_path ( )
{
mod_file - > addStatement ( new ExtendedPathStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_model_equal ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
2010-09-16 19:18:45 +02:00
expr_t id = model_tree - > AddEqual ( arg1 , arg2 ) ;
2013-04-11 17:07:39 +02:00
// Detect if the equation is tagged [static]
2017-06-01 19:58:32 +02:00
bool is_static_only = false ;
2013-04-11 17:07:39 +02:00
for ( vector < pair < string , string > > : : const_iterator it = eq_tags . begin ( ) ;
it ! = eq_tags . end ( ) ; + + it )
if ( it - > first = = " static " )
{
is_static_only = true ;
break ;
}
if ( is_static_only )
{
if ( ! id - > isInStaticForm ( ) )
error ( " An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators " ) ;
2017-06-01 19:58:32 +02:00
2017-08-24 15:35:10 +02:00
dynamic_model - > addStaticOnlyEquation ( id , location . begin . line , eq_tags ) ;
2013-04-11 17:07:39 +02:00
}
else
2014-01-27 16:41:43 +01:00
model_tree - > addEquation ( id , location . begin . line , eq_tags ) ;
2013-04-11 17:07:39 +02:00
eq_tags . clear ( ) ;
2008-02-03 11:28:36 +01:00
return id ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_model_equal_with_zero_rhs ( expr_t arg )
2008-02-03 11:28:36 +01:00
{
return add_model_equal ( arg , model_tree - > Zero ) ;
}
void
2017-08-28 15:14:11 +02:00
ParsingDriver : : declare_model_local_variable ( string * name , string * tex_name )
{
declare_symbol ( name , eModelLocalVariable , tex_name , NULL ) ;
delete name ;
if ( tex_name ! = NULL )
delete tex_name ;
}
2008-02-03 11:28:36 +01:00
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : declare_and_init_model_local_variable ( string * name , expr_t rhs )
2008-02-03 11:28:36 +01:00
{
2010-04-23 18:39:07 +02:00
int symb_id ;
2008-02-03 11:28:36 +01:00
try
{
2010-04-23 18:39:07 +02:00
symb_id = mod_file - > symbol_table . addSymbol ( * name , eModelLocalVariable ) ;
2008-02-03 11:28:36 +01:00
}
2009-12-16 18:13:23 +01:00
catch ( SymbolTable : : AlreadyDeclaredException & e )
2008-02-03 11:28:36 +01:00
{
2010-04-23 18:39:07 +02:00
// It can have already been declared in a steady_state_model block, check that it is indeed a ModelLocalVariable
symb_id = mod_file - > symbol_table . getID ( * name ) ;
if ( mod_file - > symbol_table . getType ( symb_id ) ! = eModelLocalVariable )
2017-03-28 23:06:03 +02:00
error ( * name + " has wrong type or was already used on the right-hand side. You cannot use it on the left-hand side of a pound ('#') expression " ) ;
2008-02-03 11:28:36 +01:00
}
2010-04-23 18:39:07 +02:00
try
{
model_tree - > AddLocalVariable ( symb_id , rhs ) ;
}
catch ( DataTree : : LocalVariableException & e )
{
error ( " Local model variable " + * name + " declared twice. " ) ;
}
2008-02-03 11:28:36 +01:00
delete name ;
}
2009-03-11 12:43:18 +01:00
void
ParsingDriver : : change_type ( SymbolType new_type , vector < string * > * var_list )
{
2009-12-16 18:13:23 +01:00
for ( vector < string * > : : iterator it = var_list - > begin ( ) ;
it ! = var_list - > end ( ) ; it + + )
2009-03-11 12:43:18 +01:00
{
int id ;
try
{
id = mod_file - > symbol_table . getID ( * * it ) ;
}
2009-12-16 18:13:23 +01:00
catch ( SymbolTable : : UnknownSymbolNameException & e )
2009-03-11 12:43:18 +01:00
{
error ( " Unknown variable " + * * it ) ;
}
// Check if symbol already used in a VariableNode
if ( mod_file - > expressions_tree . isSymbolUsed ( id )
2009-04-14 16:39:53 +02:00
| | mod_file - > dynamic_model . isSymbolUsed ( id ) )
2009-03-11 12:43:18 +01:00
error ( " You cannot modify the type of symbol " + * * it + " after having used it in an expression " ) ;
mod_file - > symbol_table . changeType ( id , new_type ) ;
delete * it ;
}
delete var_list ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_plus ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddPlus ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_minus ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddMinus ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_uminus ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddUMinus ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_times ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddTimes ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_divide ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
2014-10-03 16:54:59 +02:00
try
{
return data_tree - > AddDivide ( arg1 , arg2 ) ;
}
catch ( DataTree : : DivisionByZeroException )
{
2017-11-07 12:02:31 +01:00
error ( " Division by zero error encountered when reading model from .mod file " ) ;
2014-10-03 16:54:59 +02:00
}
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_less ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddLess ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_greater ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddGreater ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_less_equal ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddLessEqual ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_greater_equal ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddGreaterEqual ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_equal_equal ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddEqualEqual ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_different ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddDifferent ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_power ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddPower ( arg1 , arg2 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_expectation ( string * arg1 , expr_t arg2 )
2009-10-29 18:16:10 +01:00
{
2010-09-16 19:18:45 +02:00
expr_t expectationNode ;
2011-10-25 16:46:12 +02:00
expectationNode = data_tree - > AddExpectation ( atoi ( arg1 - > c_str ( ) ) , arg2 ) ;
2009-10-29 18:16:10 +01:00
delete arg1 ;
return expectationNode ;
}
2016-11-03 17:08:06 +01:00
expr_t
2016-11-18 12:42:02 +01:00
ParsingDriver : : add_var_expectation ( string * arg1 , string * arg2 , string * arg3 )
2016-11-03 17:08:06 +01:00
{
2016-11-21 11:30:09 +01:00
stringstream ss ( * arg2 ) ;
int forecast_horizon ;
ss > > forecast_horizon ;
expr_t varExpectationNode = data_tree - > AddVarExpectation ( mod_file - > symbol_table . getID ( * arg1 ) , forecast_horizon , * arg3 ) ;
2016-11-18 12:42:02 +01:00
delete arg2 ;
2016-11-03 17:08:06 +01:00
return varExpectationNode ;
}
2018-01-30 16:33:16 +01:00
expr_t
2018-02-07 16:50:49 +01:00
ParsingDriver : : add_pac_expectation ( )
2018-01-30 16:33:16 +01:00
{
2018-02-07 16:50:49 +01:00
if ( pac_expectation_model_name . empty ( ) )
error ( " pac_expectation: you must pass the model_name option " ) ;
2018-02-08 17:51:31 +01:00
if ( pac_expectation_var_model_name . empty ( ) )
error ( " pac_expectation: you must pass the var_model_name option " ) ;
2018-02-07 16:50:49 +01:00
if ( pac_expectation_discount . empty ( ) )
error ( " pac_expectation: you must pass the discount option " ) ;
if ( pac_expectation_growth . empty ( ) )
error ( " pac_expectation: you must pass the growth option " ) ;
int pac_expectation_discount_id =
mod_file - > symbol_table . getID ( pac_expectation_discount ) ;
int pac_expectation_growth_id =
mod_file - > symbol_table . getID ( pac_expectation_growth ) ;
expr_t pac_exp_node = data_tree - > AddPacExpectation ( pac_expectation_model_name ,
2018-02-08 17:51:31 +01:00
pac_expectation_var_model_name ,
2018-02-07 16:50:49 +01:00
pac_expectation_discount_id ,
pac_expectation_growth_id ) ;
pac_expectation_model_name = pac_expectation_discount = pac_expectation_growth = " " ;
return pac_exp_node ;
}
void
ParsingDriver : : add_pac_expectation_model_name ( string * arg )
{
if ( ! pac_expectation_model_name . empty ( ) )
error ( " pac_expectation: you can only pass the model_name option once " ) ;
pac_expectation_model_name = * arg ;
delete arg ;
}
2018-02-08 17:51:31 +01:00
void
ParsingDriver : : add_pac_expectation_var_model_name ( string * arg )
{
if ( ! pac_expectation_var_model_name . empty ( ) )
error ( " pac_expectation: you can only pass the var_model_name option once " ) ;
pac_expectation_var_model_name = * arg ;
delete arg ;
}
2018-02-07 16:50:49 +01:00
void
ParsingDriver : : add_pac_expectation_discount ( string * arg )
{
if ( ! pac_expectation_discount . empty ( ) )
error ( " pac_expectation: you can only pass the discount option once " ) ;
check_symbol_is_parameter ( arg ) ;
pac_expectation_discount = * arg ;
delete arg ;
}
void
ParsingDriver : : add_pac_expectation_growth ( string * arg )
{
if ( ! pac_expectation_growth . empty ( ) )
error ( " pac_expectation: you can only pass the growth option once " ) ;
check_symbol_existence ( * arg ) ;
SymbolType type = mod_file - > symbol_table . getType ( mod_file - > symbol_table . getID ( * arg ) ) ;
if ( type ! = eParameter & & type ! = eEndogenous )
error ( " pac_expectation growth argument must either be a parameter or an endogenous variable. " ) ;
pac_expectation_growth = * arg ;
delete arg ;
2018-01-30 16:33:16 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_exp ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddExp ( arg1 ) ;
}
2017-06-12 14:56:44 +02:00
expr_t
ParsingDriver : : add_diff ( expr_t arg1 )
{
return data_tree - > AddDiff ( arg1 ) ;
}
expr_t
ParsingDriver : : add_adl ( expr_t arg1 , string * name , string * lag )
{
2017-07-03 16:38:44 +02:00
expr_t id = data_tree - > AddAdl ( arg1 , * name , atoi ( lag - > c_str ( ) ) ) ;
2017-06-30 15:56:56 +02:00
// Declare parameters here so that parameters can be initialized after the model block
2017-07-03 14:52:06 +02:00
int i = 0 ;
ostringstream inttostr ;
for ( ; i < atoi ( lag - > c_str ( ) ) ; i + + )
{
inttostr . clear ( ) ;
inttostr . str ( " " ) ;
inttostr < < i + 1 ;
declare_parameter ( new string ( * name + " _lag_ " + inttostr . str ( ) ) ) ;
}
2017-06-30 15:56:56 +02:00
2017-06-12 14:56:44 +02:00
delete name ;
delete lag ;
return id ;
}
2017-07-03 17:21:11 +02:00
expr_t
ParsingDriver : : add_adl ( expr_t arg1 , string * name , vector < int > * lags )
{
expr_t id = data_tree - > AddAdl ( arg1 , * name , * lags ) ;
// Declare parameters here so that parameters can be initialized after the model block
for ( vector < int > : : const_iterator it = lags - > begin ( ) ; it ! = lags - > end ( ) ; it + + )
{
ostringstream inttostr ;
inttostr < < * it ;
declare_parameter ( new string ( * name + " _lag_ " + inttostr . str ( ) ) ) ;
}
delete name ;
delete lags ;
return id ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_log ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddLog ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_log10 ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddLog10 ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_cos ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddCos ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_sin ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddSin ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_tan ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
return data_tree - > AddTan ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_acos ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddAcos ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_asin ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddAsin ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_atan ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddAtan ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_cosh ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddCosh ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_sinh ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddSinh ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_tanh ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddTanh ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_acosh ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddAcosh ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_asinh ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddAsinh ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_atanh ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddAtanh ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_sqrt ( expr_t arg1 )
2008-02-03 11:28:36 +01:00
{
2009-04-16 12:33:30 +02:00
return data_tree - > AddSqrt ( arg1 ) ;
2008-02-03 11:28:36 +01:00
}
2011-08-12 13:20:53 +02:00
expr_t
ParsingDriver : : add_abs ( expr_t arg1 )
{
return data_tree - > AddAbs ( arg1 ) ;
}
expr_t
ParsingDriver : : add_sign ( expr_t arg1 )
{
return data_tree - > AddSign ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_max ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
2009-12-16 18:13:23 +01:00
return data_tree - > AddMax ( arg1 , arg2 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_min ( expr_t arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
2009-12-16 18:13:23 +01:00
return data_tree - > AddMin ( arg1 , arg2 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_normcdf ( expr_t arg1 , expr_t arg2 , expr_t arg3 )
2008-02-03 11:28:36 +01:00
{
2009-12-16 18:13:23 +01:00
return data_tree - > AddNormcdf ( arg1 , arg2 , arg3 ) ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_normcdf ( expr_t arg )
2008-09-04 10:10:42 +02:00
{
return add_normcdf ( arg , data_tree - > Zero , data_tree - > One ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_normpdf ( expr_t arg1 , expr_t arg2 , expr_t arg3 )
2010-03-11 09:43:16 +01:00
{
return data_tree - > AddNormpdf ( arg1 , arg2 , arg3 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_normpdf ( expr_t arg )
2010-03-11 09:43:16 +01:00
{
return add_normpdf ( arg , data_tree - > Zero , data_tree - > One ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_erf ( expr_t arg1 )
2010-03-11 11:57:34 +01:00
{
return data_tree - > AddErf ( arg1 ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
ParsingDriver : : add_steady_state ( expr_t arg1 )
2009-09-10 22:09:16 +02:00
{
return data_tree - > AddSteadyState ( arg1 ) ;
}
2008-02-03 11:28:36 +01:00
void
2010-02-22 17:33:38 +01:00
ParsingDriver : : external_function_option ( const string & name_option , string * opt )
{
external_function_option ( name_option , * opt ) ;
2010-03-03 11:40:13 +01:00
delete opt ;
2010-02-22 17:33:38 +01:00
}
void
ParsingDriver : : external_function_option ( const string & name_option , const string & opt )
{
if ( name_option = = " name " )
{
if ( opt . empty ( ) )
error ( " An argument must be passed to the 'name' option of the external_function() statement. " ) ;
2013-11-15 09:46:18 +01:00
declare_symbol ( & opt , eExternalFunction , NULL , NULL ) ;
2010-02-24 15:10:11 +01:00
current_external_function_id = mod_file - > symbol_table . getID ( opt ) ;
2010-02-22 17:33:38 +01:00
}
else if ( name_option = = " first_deriv_provided " )
{
if ( opt . empty ( ) )
current_external_function_options . firstDerivSymbID = eExtFunSetButNoNameProvided ;
else
{
2013-11-15 09:46:18 +01:00
declare_symbol ( & opt , eExternalFunction , NULL , NULL ) ;
2010-02-22 17:33:38 +01:00
current_external_function_options . firstDerivSymbID = mod_file - > symbol_table . getID ( opt ) ;
}
}
else if ( name_option = = " second_deriv_provided " )
{
if ( opt . empty ( ) )
current_external_function_options . secondDerivSymbID = eExtFunSetButNoNameProvided ;
else
{
2013-11-15 09:46:18 +01:00
declare_symbol ( & opt , eExternalFunction , NULL , NULL ) ;
2010-02-22 17:33:38 +01:00
current_external_function_options . secondDerivSymbID = mod_file - > symbol_table . getID ( opt ) ;
}
}
else if ( name_option = = " nargs " )
current_external_function_options . nargs = atoi ( opt . c_str ( ) ) ;
else
error ( " Unexpected error in ParsingDriver::external_function_option(): Please inform Dynare Team. " ) ;
}
void
ParsingDriver : : external_function ( )
{
2010-02-24 15:10:11 +01:00
if ( current_external_function_id = = eExtFunNotSet )
2010-02-22 17:33:38 +01:00
error ( " The 'name' option must be passed to external_function(). " ) ;
2011-02-04 16:25:38 +01:00
if ( current_external_function_options . secondDerivSymbID > = 0
& & current_external_function_options . firstDerivSymbID = = eExtFunNotSet )
2010-02-22 17:33:38 +01:00
error ( " If the second derivative is provided to the external_function command, the first derivative must also be provided. " ) ;
2011-02-04 16:25:38 +01:00
if ( current_external_function_options . secondDerivSymbID = = eExtFunSetButNoNameProvided
& & current_external_function_options . firstDerivSymbID ! = eExtFunSetButNoNameProvided )
2010-02-24 15:10:11 +01:00
error ( " If the second derivative is provided in the top-level function, the first derivative must also be provided in that function. " ) ;
2010-03-03 11:40:13 +01:00
mod_file - > external_functions_table . addExternalFunction ( current_external_function_id , current_external_function_options , true ) ;
2010-02-22 17:33:38 +01:00
reset_current_external_function_options ( ) ;
}
void
ParsingDriver : : push_external_function_arg_vector_onto_stack ( )
2008-02-03 11:28:36 +01:00
{
2010-09-16 19:18:45 +02:00
vector < expr_t > emptyvec ;
2010-02-22 17:33:38 +01:00
stack_external_function_args . push ( emptyvec ) ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_external_function_arg ( expr_t arg )
2010-02-22 17:33:38 +01:00
{
stack_external_function_args . top ( ) . push_back ( arg ) ;
2008-02-03 11:28:36 +01:00
}
2016-10-07 15:02:42 +02:00
pair < bool , double >
ParsingDriver : : is_there_one_integer_argument ( ) const
{
if ( stack_external_function_args . top ( ) . size ( ) ! = 1 )
return make_pair ( false , 0 ) ;
NumConstNode * numNode = dynamic_cast < NumConstNode * > ( stack_external_function_args . top ( ) . front ( ) ) ;
UnaryOpNode * unaryNode = dynamic_cast < UnaryOpNode * > ( stack_external_function_args . top ( ) . front ( ) ) ;
if ( numNode = = NULL & & unaryNode = = NULL )
return make_pair ( false , 0 ) ;
eval_context_t ectmp ;
double model_var_arg ;
if ( unaryNode = = NULL )
{
try
{
model_var_arg = numNode - > eval ( ectmp ) ;
}
catch ( ExprNode : : EvalException & e )
{
return make_pair ( false , 0 ) ;
}
}
else
if ( unaryNode - > get_op_code ( ) ! = oUminus )
return make_pair ( false , 0 ) ;
else
{
try
{
model_var_arg = unaryNode - > eval ( ectmp ) ;
}
catch ( ExprNode : : EvalException & e )
{
return make_pair ( false , 0 ) ;
}
}
if ( model_var_arg ! = floor ( model_var_arg ) )
return make_pair ( false , 0 ) ;
return make_pair ( true , model_var_arg ) ;
}
2010-09-16 19:18:45 +02:00
expr_t
2010-03-03 11:40:13 +01:00
ParsingDriver : : add_model_var_or_external_function ( string * function_name , bool in_model_block )
2008-02-03 11:28:36 +01:00
{
2010-09-16 19:18:45 +02:00
expr_t nid ;
2008-02-03 11:28:36 +01:00
if ( mod_file - > symbol_table . exists ( * function_name ) )
{
2010-02-22 17:33:38 +01:00
if ( mod_file - > symbol_table . getType ( * function_name ) ! = eExternalFunction )
2010-03-15 10:47:44 +01:00
{
if ( ! in_model_block )
2010-02-22 17:33:38 +01:00
{
2011-01-13 19:10:16 +01:00
if ( stack_external_function_args . top ( ) . size ( ) > 0 )
error ( string ( " Symbol " ) + * function_name + string ( " cannot take arguments. " ) ) ;
2010-03-15 10:47:44 +01:00
else
return add_expression_variable ( function_name ) ;
}
else
{ // e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode)
2016-09-23 15:22:25 +02:00
if ( undeclared_model_vars . find ( * function_name ) ! = undeclared_model_vars . end ( ) )
model_error ( " Unknown symbol: " + * function_name ) ;
2016-10-07 15:02:42 +02:00
pair < bool , double > rv = is_there_one_integer_argument ( ) ;
if ( ! rv . first )
model_error ( string ( " Symbol " ) + * function_name + string ( " is being treated as if it were a function (i.e., takes an argument that is not an integer). " ) ) ;
nid = add_model_variable ( mod_file - > symbol_table . getID ( * function_name ) , ( int ) rv . second ) ;
2010-02-22 17:33:38 +01:00
stack_external_function_args . pop ( ) ;
delete function_name ;
return nid ;
}
}
else
{ // e.g. this function has already been referenced (either ad hoc or through the external_function() statement
// => check that the information matches previously declared info
int symb_id = mod_file - > symbol_table . getID ( * function_name ) ;
2014-07-01 17:41:37 +02:00
if ( ! mod_file - > external_functions_table . exists ( symb_id ) )
error ( " Using a derivative of an external function ( " + * function_name + " ) in the model block is currently not allowed. " ) ;
2010-02-22 17:33:38 +01:00
2010-03-03 11:40:13 +01:00
if ( in_model_block )
if ( mod_file - > external_functions_table . getNargs ( symb_id ) = = eExtFunNotSet )
2011-02-04 16:25:38 +01:00
error ( " Before using " + * function_name
+ " () in the model block, you must first declare it via the external_function() statement " ) ;
else if ( ( int ) ( stack_external_function_args . top ( ) . size ( ) ) ! = mod_file - > external_functions_table . getNargs ( symb_id ) )
error ( " The number of arguments passed to " + * function_name
+ " () does not match those of a previous call or declaration of this function. " ) ;
2010-02-22 17:33:38 +01:00
}
2008-02-03 11:28:36 +01:00
}
else
2010-02-22 17:33:38 +01:00
{ //First time encountering this external function i.e., not previously declared or encountered
2010-03-03 11:40:13 +01:00
if ( in_model_block )
2016-10-07 15:02:42 +02:00
{
// Continue processing, noting that it was not declared
// Paring will end at the end of the model block
undeclared_model_vars . insert ( * function_name ) ;
model_error ( " Unknown symbol: " + * function_name ) ;
pair < bool , double > rv = is_there_one_integer_argument ( ) ;
if ( rv . first )
{
// assume it's a lead/lagged variable
2017-06-01 19:58:32 +02:00
declare_exogenous ( new string ( * function_name ) ) ;
2016-10-07 15:02:42 +02:00
return add_model_variable ( mod_file - > symbol_table . getID ( * function_name ) , ( int ) rv . second ) ;
}
else
2016-10-07 15:48:18 +02:00
error ( " To use an external function ( " + * function_name + " ) within the model block, you must first declare it via the external_function() statement. " ) ;
2016-10-07 15:02:42 +02:00
}
2016-10-07 15:48:18 +02:00
declare_symbol ( function_name , eExternalFunction , NULL , NULL ) ;
current_external_function_options . nargs = stack_external_function_args . top ( ) . size ( ) ;
mod_file - > external_functions_table . addExternalFunction ( mod_file - > symbol_table . getID ( * function_name ) ,
current_external_function_options , in_model_block ) ;
reset_current_external_function_options ( ) ;
2010-02-22 17:33:38 +01:00
}
2008-02-03 11:28:36 +01:00
2010-02-22 17:33:38 +01:00
//By this point, we're sure that this function exists in the External Functions Table and is not a mod var
2010-03-16 12:17:17 +01:00
int symb_id = mod_file - > symbol_table . getID ( * function_name ) ;
nid = data_tree - > AddExternalFunction ( symb_id , stack_external_function_args . top ( ) ) ;
2010-02-22 17:33:38 +01:00
stack_external_function_args . pop ( ) ;
delete function_name ;
2010-03-03 11:40:13 +01:00
return nid ;
2008-02-03 11:28:36 +01:00
}
void
2010-06-18 12:39:29 +02:00
ParsingDriver : : add_native ( const string & s )
{
2013-10-10 11:04:56 +02:00
mod_file - > addStatement ( new NativeStatement ( s ) ) ;
2010-06-18 12:39:29 +02:00
}
void
ParsingDriver : : add_native_remove_charset ( const char * s , const string & token )
2008-02-03 11:28:36 +01:00
{
2010-06-17 12:47:38 +02:00
string str = string ( s ) ;
size_t found = str . find ( token ) ;
assert ( found ! = string : : npos ) ;
2010-06-18 12:39:29 +02:00
str . resize ( found ) ;
add_native ( str ) ;
2008-02-03 11:28:36 +01:00
}
2010-04-23 18:39:07 +02:00
2015-06-16 12:48:32 +02:00
void
ParsingDriver : : add_verbatim ( const string & s )
{
mod_file - > addStatement ( new VerbatimStatement ( s ) ) ;
}
void
ParsingDriver : : add_verbatim_remove_charset ( const char * s , const string & token )
{
string str = string ( s ) ;
size_t found = str . find ( token ) ;
assert ( found ! = string : : npos ) ;
str . resize ( found ) ;
add_verbatim ( str ) ;
}
2010-04-23 18:39:07 +02:00
void
ParsingDriver : : begin_steady_state_model ( )
{
set_current_data_tree ( & mod_file - > steady_state_model ) ;
}
void
2010-09-16 19:18:45 +02:00
ParsingDriver : : add_steady_state_model_equal ( string * varname , expr_t expr )
2010-04-23 18:39:07 +02:00
{
int id ;
try
{
id = mod_file - > symbol_table . getID ( * varname ) ;
}
catch ( SymbolTable : : UnknownSymbolNameException & e )
{
// Unknown symbol, declare it as a ModFileLocalVariable
id = mod_file - > symbol_table . addSymbol ( * varname , eModFileLocalVariable ) ;
}
SymbolType type = mod_file - > symbol_table . getType ( id ) ;
2010-06-03 15:59:35 +02:00
if ( type ! = eEndogenous & & type ! = eModFileLocalVariable & & type ! = eParameter )
2010-04-23 18:39:07 +02:00
error ( * varname + " has incorrect type " ) ;
2010-05-31 17:43:17 +02:00
mod_file - > steady_state_model . addDefinition ( id , expr ) ;
2010-04-23 18:39:07 +02:00
delete varname ;
}
2011-01-26 19:55:01 +01:00
void
ParsingDriver : : add_steady_state_model_equal_multiple ( expr_t expr )
{
const vector < string > & symbs = symbol_list . get_symbols ( ) ;
vector < int > ids ;
for ( size_t i = 0 ; i < symbs . size ( ) ; i + + )
{
int id ;
try
{
id = mod_file - > symbol_table . getID ( symbs [ i ] ) ;
}
catch ( SymbolTable : : UnknownSymbolNameException & e )
{
// Unknown symbol, declare it as a ModFileLocalVariable
id = mod_file - > symbol_table . addSymbol ( symbs [ i ] , eModFileLocalVariable ) ;
}
SymbolType type = mod_file - > symbol_table . getType ( id ) ;
if ( type ! = eEndogenous & & type ! = eModFileLocalVariable & & type ! = eParameter )
error ( symbs [ i ] + " has incorrect type " ) ;
ids . push_back ( id ) ;
}
mod_file - > steady_state_model . addMultipleDefinitions ( ids , expr ) ;
symbol_list . clear ( ) ;
}
2012-09-11 14:26:53 +02:00
void
ParsingDriver : : add_graph_format ( const string & name )
{
graph_formats . addSymbol ( name ) ;
}
void
ParsingDriver : : process_graph_format_option ( )
{
options_list . symbol_list_options [ " graph_format " ] = graph_formats ;
graph_formats . clear ( ) ;
}
2017-03-22 11:30:35 +01:00
void
ParsingDriver : : plot_shock_decomp_process_graph_format_option ( )
{
options_list . symbol_list_options [ " plot_shock_decomp.graph_format " ] = graph_formats ;
graph_formats . clear ( ) ;
}
2012-11-16 12:34:49 +01:00
void
ParsingDriver : : model_diagnostics ( )
{
mod_file - > addStatement ( new ModelDiagnosticsStatement ( ) ) ;
}
2013-05-31 14:47:28 +02:00
void
ParsingDriver : : add_parallel_local_file ( string * filename )
{
mod_file - > parallel_local_files . push_back ( * filename ) ;
delete filename ;
}
2014-02-10 19:22:54 +01:00
void
2014-03-17 18:10:44 +01:00
ParsingDriver : : add_moment_calibration_item ( string * endo1 , string * endo2 , string * lags , vector < string * > * range )
2014-02-10 19:22:54 +01:00
{
MomentCalibration : : Constraint c ;
check_symbol_existence ( * endo1 ) ;
c . endo1 = mod_file - > symbol_table . getID ( * endo1 ) ;
if ( mod_file - > symbol_table . getType ( * endo1 ) ! = eEndogenous )
error ( " Variable " + * endo1 + " is not an endogenous. " ) ;
delete endo1 ;
check_symbol_existence ( * endo2 ) ;
c . endo2 = mod_file - > symbol_table . getID ( * endo2 ) ;
if ( mod_file - > symbol_table . getType ( * endo2 ) ! = eEndogenous )
error ( " Variable " + * endo2 + " is not an endogenous. " ) ;
delete endo2 ;
2014-03-17 18:10:44 +01:00
c . lags = * lags ;
delete lags ;
2017-06-01 19:58:32 +02:00
2014-02-10 19:22:54 +01:00
assert ( range - > size ( ) = = 2 ) ;
c . lower_bound = * ( ( * range ) [ 0 ] ) ;
c . upper_bound = * ( ( * range ) [ 1 ] ) ;
delete ( * range ) [ 0 ] ;
delete ( * range ) [ 1 ] ;
delete range ;
2017-06-01 19:58:32 +02:00
2014-02-10 19:22:54 +01:00
moment_calibration_constraints . push_back ( c ) ;
}
2017-06-01 19:58:32 +02:00
void
ParsingDriver : : end_moment_calibration ( )
2014-02-10 19:22:54 +01:00
{
mod_file - > addStatement ( new MomentCalibration ( moment_calibration_constraints ,
mod_file - > symbol_table ) ) ;
moment_calibration_constraints . clear ( ) ;
}
void
2014-03-17 18:10:44 +01:00
ParsingDriver : : add_irf_calibration_item ( string * endo , string * periods , string * exo , vector < string * > * range )
2014-02-10 19:22:54 +01:00
{
IrfCalibration : : Constraint c ;
check_symbol_existence ( * endo ) ;
c . endo = mod_file - > symbol_table . getID ( * endo ) ;
if ( mod_file - > symbol_table . getType ( * endo ) ! = eEndogenous )
error ( " Variable " + * endo + " is not an endogenous. " ) ;
delete endo ;
2014-03-17 18:10:44 +01:00
c . periods = * periods ;
delete periods ;
2014-02-10 19:22:54 +01:00
check_symbol_existence ( * exo ) ;
c . exo = mod_file - > symbol_table . getID ( * exo ) ;
if ( mod_file - > symbol_table . getType ( * exo ) ! = eExogenous )
error ( " Variable " + * endo + " is not an exogenous. " ) ;
delete exo ;
2017-06-01 19:58:32 +02:00
2014-02-10 19:22:54 +01:00
assert ( range - > size ( ) = = 2 ) ;
c . lower_bound = * ( ( * range ) [ 0 ] ) ;
c . upper_bound = * ( ( * range ) [ 1 ] ) ;
delete ( * range ) [ 0 ] ;
delete ( * range ) [ 1 ] ;
delete range ;
2017-06-01 19:58:32 +02:00
2014-02-10 19:22:54 +01:00
irf_calibration_constraints . push_back ( c ) ;
}
2017-06-01 19:58:32 +02:00
void
ParsingDriver : : end_irf_calibration ( )
2014-02-10 19:22:54 +01:00
{
mod_file - > addStatement ( new IrfCalibration ( irf_calibration_constraints ,
2015-09-07 11:39:33 +02:00
mod_file - > symbol_table ,
options_list ) ) ;
2014-02-10 19:22:54 +01:00
irf_calibration_constraints . clear ( ) ;
}
2014-04-03 15:05:20 +02:00
void
ParsingDriver : : smoother2histval ( )
{
mod_file - > addStatement ( new Smoother2histvalStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : histval_file ( string * filename )
{
mod_file - > addStatement ( new HistvalFileStatement ( * filename ) ) ;
delete filename ;
}
2014-04-09 17:57:17 +02:00
void
ParsingDriver : : perfect_foresight_setup ( )
{
mod_file - > addStatement ( new PerfectForesightSetupStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : perfect_foresight_solver ( )
{
mod_file - > addStatement ( new PerfectForesightSolverStatement ( options_list ) ) ;
options_list . clear ( ) ;
}
2015-05-31 12:18:06 +02:00
2017-10-05 15:09:04 +02:00
void
ParsingDriver : : gmm_estimation ( )
{
mod_file - > addStatement ( new GMMEstimationStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : smm_estimation ( )
{
mod_file - > addStatement ( new SMMEstimationStatement ( symbol_list , options_list ) ) ;
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2015-10-13 17:16:10 +02:00
void
2015-10-14 11:02:35 +02:00
ParsingDriver : : prior_posterior_function ( bool prior_func )
2015-10-13 17:16:10 +02:00
{
2017-06-01 19:58:32 +02:00
mod_file - > addStatement ( new PriorPosteriorFunctionStatement ( ( bool ) prior_func , options_list ) ) ;
2015-10-13 17:16:10 +02:00
options_list . clear ( ) ;
}
2015-05-31 12:18:06 +02:00
void
ParsingDriver : : add_ramsey_constraints_statement ( )
{
2017-02-08 18:29:57 +01:00
mod_file - > addStatement ( new RamseyConstraintsStatement ( mod_file - > symbol_table , ramsey_constraints ) ) ;
2015-05-31 12:18:06 +02:00
ramsey_constraints . clear ( ) ;
}
void
ParsingDriver : : ramsey_constraint_add_less ( const string * name , const expr_t rhs )
{
2017-06-01 19:58:32 +02:00
add_ramsey_constraint ( name , oLess , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
ParsingDriver : : ramsey_constraint_add_greater ( const string * name , const expr_t rhs )
{
2017-06-01 19:58:32 +02:00
add_ramsey_constraint ( name , oGreater , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
ParsingDriver : : ramsey_constraint_add_less_equal ( const string * name , const expr_t rhs )
{
2017-06-01 19:58:32 +02:00
add_ramsey_constraint ( name , oLessEqual , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
ParsingDriver : : ramsey_constraint_add_greater_equal ( const string * name , const expr_t rhs )
{
2017-06-01 19:58:32 +02:00
add_ramsey_constraint ( name , oGreaterEqual , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
ParsingDriver : : add_ramsey_constraint ( const string * name , BinaryOpcode op_code , const expr_t rhs )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
if ( type ! = eEndogenous )
error ( " ramsey_constraints: " + * name + " should be an endogenous variable " ) ;
RamseyConstraintsStatement : : Constraint C ;
C . endo = symb_id ;
C . code = op_code ;
C . expression = rhs ;
ramsey_constraints . push_back ( C ) ;
delete name ;
}
2016-04-10 18:55:17 +02:00
void
ParsingDriver : : add_shock_group_element ( string * name )
{
check_symbol_existence ( * name ) ;
int symb_id = mod_file - > symbol_table . getID ( * name ) ;
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
if ( type ! = eExogenous )
error ( " shock_groups: " + * name + " should be an exogenous variable " ) ;
shock_group . push_back ( * name ) ;
delete name ;
}
void
ParsingDriver : : add_shock_group ( string * name )
{
ShockGroupsStatement : : Group G ;
G . name = * name ;
G . list = shock_group ;
shock_groups . push_back ( G ) ;
shock_group . clear ( ) ;
}
void
ParsingDriver : : end_shock_groups ( const string * name )
{
mod_file - > addStatement ( new ShockGroupsStatement ( shock_groups , * name ) ) ;
shock_groups . clear ( ) ;
}