2008-02-03 11:28:36 +01:00
/*
2021-01-22 11:59:44 +01:00
* Copyright © 2003 - 2021 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
2021-06-09 16:52:20 +02:00
* along with Dynare . If not , see < https : //www.gnu.org/licenses/>.
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : symbol_exists_and_is_not_modfile_local_or_external_function ( const string & 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 ) ;
2019-12-16 19:42:59 +01:00
return type ! = SymbolType : : modFileLocalVariable & & type ! = SymbolType : : externalFunction ;
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 )
{
2018-03-20 09:56:22 +01:00
if ( ! mod_file - > symbol_table . exists ( name )
| | undeclared_model_vars . find ( name ) ! = undeclared_model_vars . end ( ) )
undeclared_model_variable_error ( " Unknown symbol: " + name , name ) ;
2016-09-23 15:22:25 +02:00
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : check_symbol_existence ( const string & name )
{
if ( ! mod_file - > symbol_table . exists ( name ) )
2017-04-03 18:06:15 +02:00
error ( " Unknown symbol: " + name + " . \n If referenced from the 'initval', 'endval', 'histval', or 'shocks' block, you can pass the 'nostrict' option to dynare to have this line ignored. " ) ;
2008-02-03 11:28:36 +01:00
}
2011-12-11 15:35:26 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : check_symbol_is_parameter ( const string & name )
2011-12-11 15:35:26 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name ) ;
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2018-07-17 18:34:07 +02:00
if ( mod_file - > symbol_table . getType ( symb_id ) ! = SymbolType : : parameter )
2018-07-31 11:48:08 +02:00
error ( name + " is not a parameter " ) ;
2011-12-11 15:35:26 +01:00
}
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 ( )
{
2018-10-02 18:10:12 +02:00
current_external_function_options . nargs = ExternalFunctionsTable : : defaultNargs ;
current_external_function_options . firstDerivSymbID = ExternalFunctionsTable : : IDNotSet ;
current_external_function_options . secondDerivSymbID = ExternalFunctionsTable : : IDNotSet ;
current_external_function_id = ExternalFunctionsTable : : IDNotSet ;
2010-02-22 17:33:38 +01:00
}
2018-07-31 12:23:56 +02:00
unique_ptr < ModFile >
2008-03-28 18:38:10 +01:00
ParsingDriver : : parse ( istream & in , bool debug )
2008-02-03 11:28:36 +01:00
{
2018-07-31 12:23:56 +02:00
mod_file = make_unique < ModFile > ( warnings ) ;
2008-02-03 11:28:36 +01:00
2019-12-19 14:48:55 +01:00
symbol_list . setSymbolTable ( mod_file - > symbol_table ) ;
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
2018-07-31 12:23:56 +02:00
lexer = make_unique < 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 ( ) ;
2018-07-31 12:23:56 +02:00
return move ( mod_file ) ;
2008-02-03 11:28:36 +01:00
}
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
2017-03-27 16:20:50 +02:00
ParsingDriver : : create_error_string ( const Dynare : : parser : : location_type & l , const string & m , const string & var )
2008-02-03 11:28:36 +01:00
{
2017-03-27 16:20:50 +02:00
ostringstream stream ;
create_error_string ( l , m , stream ) ;
2018-06-04 12:48:09 +02:00
model_errors . emplace_back ( var , stream . str ( ) ) ;
2017-03-27 16:20:50 +02:00
}
void
ParsingDriver : : model_error ( const string & m , const string & var )
{
create_error_string ( location , m , var ) ;
2008-02-03 11:28:36 +01:00
}
2018-03-20 09:56:22 +01:00
void
ParsingDriver : : undeclared_model_variable_error ( const string & m , const string & var )
{
ostringstream stream ;
if ( ! nostrict )
{
stream < < " ERROR: " < < * location . begin . filename < < " : line " < < location . begin . line ;
if ( location . begin . line = = location . end . line )
if ( location . begin . column = = location . end . column - 1 )
stream < < " , col " < < location . begin . column ;
else
stream < < " , cols " < < location . begin . column < < " - " < < location . end . column - 1 ;
else
stream < < " , col " < < location . begin . column < < " - "
< < " line " < < location . end . line < < " , col " < < location . end . column - 1 ;
stream < < " : " ;
}
stream < < m ;
if ( nostrict )
stream < < " automatically declared exogenous. " ;
2018-06-04 12:48:09 +02:00
undeclared_model_variable_errors . emplace_back ( var , stream . str ( ) ) ;
2018-03-20 09:56:22 +01:00
}
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
2018-07-31 11:48:08 +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
{
2018-07-31 11:48:08 +02: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 )
2018-07-31 11:48:08 +02:00
warning ( " Symbol " + name + " declared twice. " ) ;
2008-02-03 11:28:36 +01:00
else
2018-07-31 11:48:08 +02:00
error ( " Symbol " + name + " declared twice with different types! " ) ;
2008-02-03 11:28:36 +01:00
}
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_endogenous ( const string & name , const string & tex_name , const vector < pair < string , string > > & partition_value )
2008-02-03 11:28:36 +01:00
{
2018-07-17 18:34:07 +02:00
declare_symbol ( name , SymbolType : : endogenous , tex_name , partition_value ) ;
2008-02-03 11:28:36 +01:00
}
2017-05-04 15:50:33 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_var_endogenous ( const string & name )
2017-05-04 15:50:33 +02:00
{
2018-07-31 11:48:08 +02:00
if ( mod_file - > symbol_table . exists ( name ) )
2017-05-04 15:50:33 +02:00
{
2018-07-31 11:48:08 +02:00
SymbolType type = mod_file - > symbol_table . getType ( name ) ;
2018-07-17 18:34:07 +02:00
if ( type ! = SymbolType : : endogenous & & type ! = SymbolType : : exogenous & & type ! = SymbolType : : exogenousDet )
2018-07-31 11:48:08 +02:00
error ( " Symbol " + name + " used in a VAR must be either endogenous or "
2017-06-01 19:58:32 +02:00
+ " 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 ;
}
2018-07-31 11:48:08 +02:00
declare_symbol ( name , SymbolType : : endogenousVAR , " " , { } ) ;
2017-05-04 15:50:33 +02:00
add_in_symbol_list ( name ) ;
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_exogenous ( const string & name , const string & tex_name , const vector < pair < string , string > > & partition_value )
2008-02-03 11:28:36 +01:00
{
2018-07-17 18:34:07 +02:00
declare_symbol ( name , SymbolType : : exogenous , tex_name , partition_value ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_exogenous_det ( const string & name , const string & tex_name , const vector < pair < string , string > > & partition_value )
2008-02-03 11:28:36 +01:00
{
2018-07-17 18:34:07 +02:00
declare_symbol ( name , SymbolType : : exogenousDet , tex_name , partition_value ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_parameter ( const string & name , const string & tex_name , const vector < pair < string , string > > & partition_value )
2008-02-03 11:28:36 +01:00
{
2018-07-17 18:34:07 +02:00
declare_symbol ( name , SymbolType : : parameter , tex_name , partition_value ) ;
2008-02-03 11:28:36 +01:00
}
2011-12-14 13:58:21 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_statement_local_variable ( const string & name )
2011-12-14 13:58:21 +01:00
{
2018-07-31 11:48:08 +02:00
if ( mod_file - > symbol_table . exists ( name ) )
error ( " Symbol " + name + " cannot be assigned within a statement "
2017-06-01 19:58:32 +02:00
+ " while being assigned elsewhere in the modfile " ) ;
2018-07-31 11:48:08 +02:00
declare_symbol ( name , SymbolType : : statementDeclaredVariable , " " , { } ) ;
2011-12-14 13:58:21 +01:00
}
2011-03-29 18:18:32 +02:00
void
2019-12-18 17:32:41 +01:00
ParsingDriver : : set_planner_discount ( expr_t value )
2011-03-29 18:18:32 +02:00
{
2019-12-18 17:32:41 +01:00
planner_discount = value ;
}
void
ParsingDriver : : set_planner_discount_latex_name ( string tex_name )
{
planner_discount_latex_name = move ( tex_name ) ;
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_trend_var ( bool log_trend , const string & name , const string & tex_name )
2010-10-15 19:05:16 +02:00
{
2018-07-31 11:48:08 +02:00
declare_symbol ( name , log_trend ? SymbolType : : logTrend : SymbolType : : trend , tex_name , { } ) ;
declared_trend_vars . push_back ( mod_file - > symbol_table . getID ( name ) ) ;
2010-10-15 19:05:16 +02:00
}
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_predetermined_variable ( const string & name )
2009-11-07 19:37:11 +01:00
{
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( name ) ;
int symb_id = mod_file - > symbol_table . getID ( name ) ;
mod_file - > symbol_table . markPredetermined ( symb_id ) ;
2009-11-07 19:37:11 +01:00
}
2009-09-02 16:37:59 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_equation_tags ( string key , string value )
2009-09-02 16:37:59 +02:00
{
2020-02-20 15:29:10 +01:00
eq_tags [ key ] = value ;
2018-07-09 14:39:13 +02:00
2018-07-31 11:48:08 +02:00
transform ( key . begin ( ) , key . end ( ) , key . begin ( ) , : : tolower ) ;
if ( key . compare ( " endogenous " ) = = 0 )
2018-07-17 18:34:07 +02:00
declare_or_change_type ( SymbolType : : endogenous , value ) ;
2009-09-02 16:37:59 +02:00
}
2010-09-16 19:18:45 +02:00
expr_t
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_non_negative_constant ( const string & constant )
2008-02-03 11:28:36 +01:00
{
2018-07-31 11:48:08 +02:00
return data_tree - > AddNonNegativeConstant ( constant ) ;
2008-02-03 11:28:36 +01:00
}
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_model_variable ( const string & name )
2008-02-03 11:28:36 +01:00
{
2019-10-08 16:06:01 +02:00
if ( name . find ( " . " ) ! = string : : npos )
error ( name + " treated as a variable, but it contains a '.' " ) ;
2018-07-31 11:48:08 +02:00
check_symbol_existence_in_model_block ( name ) ;
2016-09-23 15:22:25 +02:00
int symb_id ;
try
{
2018-07-31 11:48:08 +02:00
symb_id = mod_file - > symbol_table . getID ( name ) ;
2016-09-23 15:22:25 +02:00
}
catch ( SymbolTable : : UnknownSymbolNameException & e )
{
2018-03-20 09:56:22 +01:00
// Declare variable as exogenous to continue parsing
// processing will end at end of model block if nostrict option was not passed
2018-07-31 11:48:08 +02:00
declare_exogenous ( name ) ;
undeclared_model_vars . insert ( name ) ;
symb_id = mod_file - > symbol_table . getID ( name ) ;
2016-09-23 15:22:25 +02:00
}
2010-02-22 17:33:38 +01:00
return add_model_variable ( symb_id , 0 ) ;
2008-02-03 11:28:36 +01:00
}
2017-03-27 16:20:50 +02:00
expr_t
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_or_change_type ( SymbolType new_type , const string & name )
2017-03-27 16:20:50 +02:00
{
int symb_id ;
try
{
2018-07-31 11:48:08 +02:00
symb_id = mod_file - > symbol_table . getID ( name ) ;
2017-03-27 16:20:50 +02:00
mod_file - > symbol_table . changeType ( symb_id , new_type ) ;
// remove error messages
2018-07-31 11:48:08 +02:00
undeclared_model_vars . erase ( name ) ;
2018-06-04 15:03:26 +02:00
for ( auto it = undeclared_model_variable_errors . begin ( ) ;
2018-03-20 09:56:22 +01:00
it ! = undeclared_model_variable_errors . end ( ) ; )
2018-07-31 11:48:08 +02:00
if ( it - > first = = name )
2018-03-20 09:56:22 +01:00
it = undeclared_model_variable_errors . erase ( it ) ;
2017-03-27 16:20:50 +02:00
else
2019-12-16 19:42:59 +01:00
+ + it ;
2017-03-27 16:20:50 +02:00
}
catch ( SymbolTable : : UnknownSymbolNameException & e )
{
switch ( new_type )
{
2018-07-17 18:34:07 +02:00
case SymbolType : : endogenous :
2018-07-31 11:48:08 +02:00
declare_endogenous ( name ) ;
2017-03-27 16:20:50 +02:00
break ;
2018-07-17 18:34:07 +02:00
case SymbolType : : exogenous :
2018-07-31 11:48:08 +02:00
declare_exogenous ( name ) ;
2017-03-27 16:20:50 +02:00
break ;
2018-07-17 18:34:07 +02:00
case SymbolType : : parameter :
2018-07-31 11:48:08 +02:00
declare_parameter ( name ) ;
2017-03-27 16:20:50 +02:00
break ;
default :
error ( " Type not yet supported " ) ;
}
2018-07-31 11:48:08 +02:00
symb_id = mod_file - > symbol_table . getID ( name ) ;
2017-03-27 16:20:50 +02:00
}
return add_model_variable ( symb_id , 0 ) ;
}
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
2018-07-17 18:34:07 +02:00
if ( type = = SymbolType : : modFileLocalVariable )
2019-12-20 16:59:30 +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
2018-07-17 18:34:07 +02:00
if ( type = = SymbolType : : externalFunction )
2019-12-20 16:59:30 +01: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
2021-01-22 11:59:44 +01:00
// See dynare#1765
if ( type = = SymbolType : : exogenousDet & & lag ! = 0 )
error ( " Exogenous deterministic variable " + mod_file - > symbol_table . getName ( symb_id ) + " cannot be given a lead or a lag. " ) ;
2018-07-17 18:34:07 +02:00
if ( type = = SymbolType : : modelLocalVariable & & 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
2019-12-16 19:42:59 +01:00
if ( dynamic_cast < StaticModel * > ( model_tree ) & & lag ! = 0 )
2010-10-11 14:49:23 +02:00
error ( " Leads and lags on variables are forbidden in 'planner_objective'. " ) ;
2019-12-16 19:42:59 +01:00
if ( dynamic_cast < StaticModel * > ( model_tree ) & & type = = SymbolType : : modelLocalVariable )
2014-05-13 11:46:19 +02:00
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_expression_variable ( const string & name )
2008-02-03 11:28:36 +01:00
{
2019-10-08 16:06:01 +02:00
if ( name . find ( " . " ) ! = string : : npos )
error ( name + " treated as a variable, but it contains a '.' " ) ;
2018-09-03 17:16:28 +02:00
if ( parsing_epilogue & & ! mod_file - > symbol_table . exists ( name ) )
error ( " Variable " + name + " used in the epilogue block but was not declared. " ) ;
2008-02-03 11:28:36 +01:00
// If symbol doesn't exist, then declare it as a mod file local variable
2018-07-31 11:48:08 +02:00
if ( ! mod_file - > symbol_table . exists ( name ) )
mod_file - > symbol_table . addSymbol ( name , SymbolType : : modFileLocalVariable ) ;
2008-02-03 11:28:36 +01:00
2008-10-17 14:22:35 +02:00
// This check must come after the previous one!
2018-07-31 11:48:08 +02:00
if ( mod_file - > symbol_table . getType ( name ) = = SymbolType : : modelLocalVariable )
error ( " Variable " + name + " not allowed outside model declaration. Its scope is only inside model. " ) ;
2013-11-29 16:29:25 +01:00
2018-07-31 11:48:08 +02:00
if ( mod_file - > symbol_table . getType ( name ) = = SymbolType : : trend
| | mod_file - > symbol_table . getType ( name ) = = SymbolType : : logTrend )
error ( " Variable " + name + " not allowed outside model declaration, because it is a trend variable. " ) ;
2014-02-03 16:22:42 +01:00
2018-07-31 11:48:08 +02:00
if ( mod_file - > symbol_table . getType ( name ) = = SymbolType : : externalFunction )
error ( " Symbol ' " + name + " ' is the name of a MATLAB/Octave function, and cannot be used as a variable. " ) ;
2008-02-03 11:28:36 +01:00
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( name ) ;
return data_tree - > AddVariable ( symb_id ) ;
2008-02-03 11:28:36 +01:00
}
2010-10-15 19:05:16 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_nonstationary_var ( const string & name , const string & tex_name , const vector < pair < string , string > > & partition_value )
2010-10-15 19:05:16 +02:00
{
2018-07-31 11:48:08 +02:00
declare_endogenous ( name , tex_name , partition_value ) ;
2013-12-09 15:51:27 +01:00
2018-07-31 11:48:08 +02:00
declared_nonstationary_vars . push_back ( mod_file - > symbol_table . getID ( name ) ) ;
2010-10-15 19:05:16 +02:00
mod_file - > nonstationary_variables = true ;
}
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 ;
2018-07-17 18:34:07 +02:00
deflator - > collectVariables ( SymbolType : : endogenous , r ) ;
2018-06-04 12:26:16 +02:00
for ( int it : r )
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 ( ) ;
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : periods ( const string & periods )
2008-02-03 11:28:36 +01:00
{
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
2018-07-31 11:48:08 +02:00
int periods_val = stoi ( periods ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < PeriodsStatement > ( periods_val ) ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : dsample ( const string & arg1 )
2008-02-03 11:28:36 +01:00
{
2018-07-31 11:48:08 +02:00
int arg1_val = stoi ( arg1 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < DsampleStatement > ( arg1_val ) ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : dsample ( const string & arg1 , const string & arg2 )
2008-02-03 11:28:36 +01:00
{
2018-07-31 11:48:08 +02:00
int arg1_val = stoi ( arg1 ) ;
int arg2_val = stoi ( arg2 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < DsampleStatement > ( arg1_val , arg2_val ) ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : init_param ( const 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 ) ;
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < InitParamStatement > ( symb_id , rhs , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : init_val ( const string & name , expr_t rhs )
2008-02-03 11:28:36 +01:00
{
2013-09-16 22:13:56 +02:00
if ( nostrict )
2018-07-31 11:48:08 +02:00
if ( ! mod_file - > symbol_table . exists ( name ) )
2013-09-16 22:13:56 +02:00
{
2018-07-31 11:48:08 +02:00
warning ( " discarding ' " + name + " ' as it was not recognized in the initval or endval statement " ) ;
2013-09-16 22:13:56 +02:00
return ;
}
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous_or_exogenous ( name ) ;
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2018-06-04 16:36:46 +02:00
init_values . emplace_back ( symb_id , rhs ) ;
2008-02-03 11:28:36 +01:00
}
void
2020-05-14 16:36:35 +02:00
ParsingDriver : : initval_file ( )
2008-02-03 11:28:36 +01:00
{
2020-05-14 16:36:35 +02:00
mod_file - > addStatement ( make_unique < InitvalFileStatement > ( options_list ) ) ;
options_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : hist_val ( const string & name , const string & lag , expr_t rhs )
2008-02-03 11:28:36 +01:00
{
2017-04-03 16:44:31 +02:00
if ( nostrict )
2018-07-31 11:48:08 +02:00
if ( ! mod_file - > symbol_table . exists ( name ) )
2017-04-03 17:18:46 +02:00
{
2018-12-03 17:29:53 +01:00
warning ( " discarding ' " + name + " ' as it was not recognized in the histval block " ) ;
2017-04-03 17:18:46 +02:00
return ;
}
2017-04-03 16:44:31 +02:00
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous_or_exogenous ( name ) ;
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2008-02-03 11:28:36 +01:00
2018-07-31 11:48:08 +02:00
int ilag = stoi ( lag ) ;
2017-09-13 10:16:19 +02:00
if ( ilag > 0 )
2018-07-31 11:48:08 +02:00
error ( " histval: the lag on " + name + " should be less than or equal to 0 " ) ;
2017-09-13 10:16:19 +02:00
2009-02-27 13:19:25 +01:00
pair < int , int > key ( symb_id , ilag ) ;
2008-02-03 11:28:36 +01:00
if ( hist_values . find ( key ) ! = hist_values . end ( ) )
2018-07-31 11:48:08 +02:00
error ( " hist_val: ( " + name + " , " + lag + " ) declared twice " ) ;
2008-02-03 11:28:36 +01:00
hist_values [ key ] = rhs ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : homotopy_val ( const string & name , expr_t val1 , expr_t val2 )
2008-02-03 11:28:36 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name ) ;
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2009-02-27 13:19:25 +01:00
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
2008-02-03 11:28:36 +01:00
2018-07-17 18:34:07 +02:00
if ( type ! = SymbolType : : parameter
& & type ! = SymbolType : : exogenous
& & type ! = SymbolType : : exogenousDet )
2018-07-31 11:48:08 +02:00
error ( " homotopy_val: " + name + " should be a parameter or exogenous variable " ) ;
2008-02-03 11:28:36 +01:00
2018-12-03 15:05:49 +01:00
homotopy_values . emplace_back ( symb_id , val1 , val2 ) ;
2008-02-03 11:28:36 +01:00
}
2017-10-06 14:49:14 +02:00
void
ParsingDriver : : end_generate_irfs ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_generate_irfs_element ( string name )
2017-10-06 14:49:14 +02:00
{
2018-07-31 11:48:08 +02:00
for ( const auto & it : generate_irf_names )
if ( it = = name )
2017-10-09 11:18:42 +02:00
error ( " Names in the generate_irfs block must be unique but you entered ' "
2018-07-31 11:48:08 +02:00
+ name + " ' more than once. " ) ;
2017-10-06 14:49:14 +02:00
2018-07-31 11:48:08 +02:00
generate_irf_names . push_back ( move ( name ) ) ;
2017-10-09 11:18:42 +02:00
generate_irf_elements . push_back ( generate_irf_exos ) ;
generate_irf_exos . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_generate_irfs_exog_element ( string exo , const string & value )
2017-10-09 11:18:42 +02:00
{
check_symbol_is_exogenous ( exo ) ;
2018-07-31 11:48:08 +02:00
if ( generate_irf_exos . find ( exo ) ! = generate_irf_exos . end ( ) )
error ( " You have set the exogenous variable " + exo + " twice. " ) ;
2017-10-09 11:18:42 +02:00
2018-07-31 11:48:08 +02:00
generate_irf_exos [ move ( exo ) ] = stod ( value ) ;
2017-10-06 14:49:14 +02:00
}
2008-05-01 14:04:48 +02:00
void
ParsingDriver : : forecast ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ForecastStatement > ( symbol_list , options_list ) ) ;
2008-05-01 14:04:48 +02:00
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
2020-05-20 11:39:59 +02:00
ParsingDriver : : bytecode ( )
2008-02-03 11:28:36 +01:00
{
2020-05-20 11:39:59 +02:00
mod_file - > bytecode = true ;
2008-02-03 11:28:36 +01:00
}
2021-02-22 18:26:21 +01:00
void
ParsingDriver : : occbin ( )
{
mod_file - > occbin = true ;
}
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 ( ) ;
2019-12-20 16:59:30 +01:00
for ( auto & it : mod_file - > differentiate_forward_vars_subset )
2019-12-16 19:42:59 +01:00
check_symbol_is_endogenous ( it ) ;
2013-05-17 16:51:34 +02:00
symbol_list . clear ( ) ;
}
2009-09-03 12:10:06 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : cutoff ( const string & value )
2009-09-03 12:10:06 +02:00
{
2018-07-31 11:48:08 +02:00
double val = stod ( value ) ;
2009-09-03 12:10:06 +02:00
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
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : mfs ( const string & value )
2009-09-03 12:10:06 +02:00
{
2018-07-31 11:48:08 +02:00
int val = stoi ( value ) ;
2009-09-03 12:10:06 +02:00
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
}
2019-12-02 19:21:14 +01:00
void
2019-12-20 16:59:30 +01:00
ParsingDriver : : compilation_setup_substitute_flags ( const string & flags )
2019-12-02 19:21:14 +01:00
{
mod_file - > dynamic_model . user_set_subst_flags = flags ;
}
void
2019-12-20 16:59:30 +01:00
ParsingDriver : : compilation_setup_add_flags ( const string & flags )
2019-12-02 19:21:14 +01:00
{
mod_file - > dynamic_model . user_set_add_flags = flags ;
}
void
2019-12-20 16:59:30 +01:00
ParsingDriver : : compilation_setup_substitute_libs ( const string & libs )
2019-12-02 19:21:14 +01:00
{
mod_file - > dynamic_model . user_set_subst_libs = libs ;
}
void
2019-12-20 16:59:30 +01:00
ParsingDriver : : compilation_setup_add_libs ( const string & libs )
2019-12-02 19:21:14 +01:00
{
mod_file - > dynamic_model . user_set_add_libs = libs ;
}
void
2019-12-20 16:59:30 +01:00
ParsingDriver : : compilation_setup_compiler ( const string & compiler )
2019-12-02 19:21:14 +01:00
{
mod_file - > dynamic_model . user_set_compiler = compiler ;
}
2019-11-14 17:51:16 +01:00
void
ParsingDriver : : balanced_growth_test_tol ( const string & value )
{
mod_file - > dynamic_model . balanced_growth_test_tol = stod ( 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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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
{
2018-12-11 17:26:50 +01:00
mod_file - > addStatement ( make_unique < HistValStatement > ( hist_values , mod_file - > symbol_table , all_values_required ) ) ;
2008-02-03 11:28:36 +01:00
hist_values . clear ( ) ;
}
void
ParsingDriver : : end_homotopy ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < HomotopyStatement > ( homotopy_values , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
homotopy_values . clear ( ) ;
}
2018-09-03 17:16:28 +02:00
void
ParsingDriver : : begin_epilogue ( )
{
parsing_epilogue = true ;
set_current_data_tree ( & mod_file - > epilogue ) ;
}
void
ParsingDriver : : end_epilogue ( )
{
parsing_epilogue = false ;
reset_data_tree ( ) ;
}
void
2018-12-19 16:09:30 +01:00
ParsingDriver : : add_epilogue_variable ( const string & name )
2018-09-03 17:16:28 +02:00
{
2018-12-10 16:11:21 +01:00
declare_symbol ( name , SymbolType : : epilogue , " " , { } ) ;
2018-12-19 16:09:30 +01:00
}
void
ParsingDriver : : add_epilogue_equal ( const string & name , expr_t expr )
{
2018-12-10 16:11:21 +01:00
mod_file - > epilogue . addDefinition ( mod_file - > symbol_table . getID ( name ) , expr ) ;
2018-09-03 17:16:28 +02:00
}
2008-02-03 11:28:36 +01:00
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 ( )
{
2018-03-20 09:56:22 +01:00
bool exit_after_write = false ;
2017-03-27 16:20:50 +02:00
if ( model_errors . size ( ) > 0 )
2019-12-20 16:59:30 +01:00
for ( auto & it : model_errors )
2018-03-20 09:56:22 +01:00
{
2019-12-16 19:42:59 +01:00
if ( it . first . empty ( ) )
2018-03-20 09:56:22 +01:00
exit_after_write = true ;
2019-12-16 19:42:59 +01:00
cerr < < it . second ;
2018-03-20 09:56:22 +01:00
}
2017-04-03 14:52:20 +02:00
2018-03-20 09:56:22 +01:00
if ( undeclared_model_variable_errors . size ( ) > 0 )
2019-12-20 16:59:30 +01:00
for ( auto & it : undeclared_model_variable_errors )
2018-03-20 09:56:22 +01:00
if ( nostrict )
2019-12-16 19:42:59 +01:00
warning ( it . second ) ;
2018-03-20 09:56:22 +01:00
else
{
exit_after_write = true ;
2019-12-16 19:42:59 +01:00
cerr < < it . second < < endl ;
2017-04-03 14:52:20 +02:00
}
2018-03-20 09:56:22 +01:00
if ( exit_after_write )
exit ( EXIT_FAILURE ) ;
2016-09-23 15:22:25 +02:00
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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ShocksStatement > ( overwrite , det_shocks , var_shocks , std_shocks ,
covar_shocks , corr_shocks , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MShocksStatement > ( overwrite , det_shocks , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
det_shocks . clear ( ) ;
}
2021-05-26 18:00:06 +02:00
void
ParsingDriver : : end_heteroskedastic_shocks ( bool overwrite )
{
mod_file - > addStatement ( make_unique < HeteroskedasticShocksStatement > ( overwrite , heteroskedastic_shocks_values ,
heteroskedastic_shocks_scales , mod_file - > symbol_table ) ) ;
heteroskedastic_shocks_values . clear ( ) ;
heteroskedastic_shocks_scales . clear ( ) ;
}
2008-02-03 11:28:36 +01:00
void
2021-05-26 17:00:07 +02:00
ParsingDriver : : add_det_shock ( const string & var , const vector < pair < int , int > > & periods , const vector < expr_t > & values , bool conditional_forecast )
2008-02-03 11:28:36 +01:00
{
2009-10-16 19:23:57 +02:00
if ( conditional_forecast )
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( var ) ;
2009-10-16 19:23:57 +02:00
else
2018-08-01 10:47:09 +02:00
check_symbol_is_exogenous ( var ) ;
int symb_id = mod_file - > symbol_table . getID ( var ) ;
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 ( ) )
2018-07-31 11:48:08 +02:00
error ( " shocks/conditional_forecast_paths: variable " + var + " declared twice " ) ;
2008-02-03 11:28:36 +01:00
2021-05-26 17:00:07 +02:00
if ( periods . size ( ) ! = values . size ( ) )
2018-07-31 11:48:08 +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 ;
2021-05-26 17:00:07 +02:00
for ( size_t i = 0 ; i < periods . size ( ) ; i + + )
2008-02-03 11:28:36 +01:00
{
ShocksStatement : : DetShockElement dse ;
2021-05-26 17:00:07 +02:00
dse . period1 = periods [ i ] . first ;
dse . period2 = periods [ i ] . second ;
dse . value = values [ i ] ;
2008-02-03 11:28:36 +01:00
v . push_back ( dse ) ;
}
2013-12-31 01:57:30 +01:00
det_shocks [ symb_id ] = v ;
2008-02-03 11:28:36 +01:00
}
2021-05-26 18:00:06 +02:00
void
ParsingDriver : : add_heteroskedastic_shock ( const string & var , const vector < pair < int , int > > & periods , const vector < expr_t > & values , bool scales )
{
check_symbol_is_exogenous ( var ) ;
int symb_id = mod_file - > symbol_table . getID ( var ) ;
if ( ( ! scales & & heteroskedastic_shocks_values . find ( symb_id ) ! = heteroskedastic_shocks_values . end ( ) )
| | ( scales & & heteroskedastic_shocks_scales . find ( symb_id ) ! = heteroskedastic_shocks_scales . end ( ) ) )
error ( " heteroskedastic_shocks: variable " + var + " declared twice " ) ;
if ( periods . size ( ) ! = values . size ( ) )
error ( " heteroskedastic_shocks: variable " + var + " : number of periods is different from number of shock values " ) ;
vector < tuple < int , int , expr_t > > v ;
for ( size_t i = 0 ; i < periods . size ( ) ; i + + )
v . push_back ( { periods [ i ] . first , periods [ i ] . second , values [ i ] } ) ;
if ( scales )
heteroskedastic_shocks_scales [ symb_id ] = v ;
else
heteroskedastic_shocks_values [ symb_id ] = v ;
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_stderr_shock ( const string & var , expr_t value )
2008-02-03 11:28:36 +01:00
{
2017-04-03 16:44:31 +02:00
if ( nostrict )
2018-07-31 11:48:08 +02:00
if ( ! mod_file - > symbol_table . exists ( var ) )
2017-04-03 17:18:46 +02:00
{
2018-07-31 11:48:08 +02:00
warning ( " discarding shocks block declaration of the standard error of ' " + var + " ' as it was not declared " ) ;
2017-04-03 17:18:46 +02:00
return ;
}
2017-04-03 16:44:31 +02:00
2018-07-31 11:48:08 +02:00
check_symbol_existence ( var ) ;
int symb_id = mod_file - > symbol_table . getID ( var ) ;
2010-04-14 15:03:41 +02:00
if ( var_shocks . find ( symb_id ) ! = var_shocks . end ( )
| | std_shocks . find ( symb_id ) ! = std_shocks . end ( ) )
2018-07-31 11:48:08 +02:00
error ( " shocks: variance or stderr of shock on " + var + " declared twice " ) ;
2008-02-03 11:28:36 +01:00
2010-04-14 15:03:41 +02:00
std_shocks [ symb_id ] = value ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_var_shock ( const string & var , expr_t value )
2008-02-03 11:28:36 +01:00
{
2017-04-03 16:44:31 +02:00
if ( nostrict )
2018-07-31 11:48:08 +02:00
if ( ! mod_file - > symbol_table . exists ( var ) )
2017-04-03 17:18:46 +02:00
{
2018-07-31 11:48:08 +02:00
warning ( " discarding shocks block declaration of the variance of ' " + var + " ' as it was not declared " ) ;
2017-04-03 17:18:46 +02:00
return ;
}
2017-04-03 16:44:31 +02:00
2018-07-31 11:48:08 +02:00
check_symbol_existence ( var ) ;
int symb_id = mod_file - > symbol_table . getID ( var ) ;
2010-04-14 15:03:41 +02:00
if ( var_shocks . find ( symb_id ) ! = var_shocks . end ( )
| | std_shocks . find ( symb_id ) ! = std_shocks . end ( ) )
2018-07-31 11:48:08 +02:00
error ( " shocks: variance or stderr of shock on " + var + " declared twice " ) ;
2008-02-03 11:28:36 +01:00
2010-04-14 15:03:41 +02:00
var_shocks [ symb_id ] = value ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_covar_shock ( const string & var1 , const string & var2 , expr_t value )
2008-02-03 11:28:36 +01:00
{
2017-04-03 16:44:31 +02:00
if ( nostrict )
2018-07-31 11:48:08 +02:00
if ( ! mod_file - > symbol_table . exists ( var1 ) | | ! mod_file - > symbol_table . exists ( var2 ) )
2017-04-03 17:18:46 +02:00
{
2018-07-31 11:48:08 +02:00
warning ( " discarding shocks block declaration of the covariance of ' " + var1 + " ' and ' " + var2 + " ' as at least one was not declared " ) ;
2017-04-03 17:18:46 +02:00
return ;
}
2017-04-03 16:44:31 +02:00
2018-07-31 11:48:08 +02:00
check_symbol_existence ( var1 ) ;
check_symbol_existence ( var2 ) ;
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 ( ) )
2018-07-31 11:48:08 +02:00
error ( " shocks: covariance or correlation shock on variable pair ( " + var1 + " , "
+ var2 + " ) declared twice " ) ;
2008-02-03 11:28:36 +01:00
covar_shocks [ key ] = value ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_correl_shock ( const string & var1 , const string & var2 , expr_t value )
2008-02-03 11:28:36 +01:00
{
2017-04-03 16:44:31 +02:00
if ( nostrict )
2018-07-31 11:48:08 +02:00
if ( ! mod_file - > symbol_table . exists ( var1 ) | | ! mod_file - > symbol_table . exists ( var2 ) )
2017-04-03 17:18:46 +02:00
{
2018-07-31 11:48:08 +02:00
warning ( " discarding shocks block declaration of the correlation of ' " + var1 + " ' and ' " + var2 + " ' as at least one was not declared " ) ;
2017-04-03 17:18:46 +02:00
return ;
}
2017-04-03 16:44:31 +02:00
2018-07-31 11:48:08 +02:00
check_symbol_existence ( var1 ) ;
check_symbol_existence ( var2 ) ;
int symb_id1 = mod_file - > symbol_table . getID ( var1 ) ;
int symb_id2 = mod_file - > symbol_table . getID ( var2 ) ;
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 ( ) )
2018-07-31 11:48:08 +02:00
error ( " shocks: covariance or correlation shock on variable pair ( " + var1 + " , "
+ var2 + " ) declared twice " ) ;
2008-02-03 11:28:36 +01:00
corr_shocks [ key ] = value ;
}
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SvarIdentificationStatement > ( svar_ident_restrictions ,
svar_upper_cholesky ,
svar_lower_cholesky ,
svar_constants_exclusion ,
mod_file - > symbol_table ) ) ;
2009-12-04 22:32:19 +01:00
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : combine_lag_and_restriction ( const string & lag )
2009-12-04 22:32:19 +01:00
{
2018-07-31 11:48:08 +02:00
int current_lag = stoi ( lag ) ;
2009-12-04 22:32:19 +01:00
2018-07-31 11:48:08 +02:00
for ( const auto & it : svar_ident_restrictions )
if ( it . lag = = current_lag )
error ( " lag " + lag + " used more than once. " ) ;
2009-12-04 22:32:19 +01:00
2018-07-31 11:48:08 +02:00
for ( const auto & it : svar_equation_restrictions )
for ( auto it1 : it . second )
2011-10-10 11:45:55 +02:00
{
2017-06-01 19:58:32 +02:00
SvarIdentificationStatement : : svar_identification_restriction new_restriction ;
2018-07-31 11:48:08 +02:00
new_restriction . equation = it . first ;
2017-06-01 19:58:32 +02:00
if ( current_lag > 0 )
2018-07-31 11:48:08 +02:00
new_restriction . restriction_nbr = + + svar_Ri_restriction_nbr [ it . first ] ;
2017-06-01 19:58:32 +02:00
else
2018-07-31 11:48:08 +02:00
new_restriction . restriction_nbr = + + svar_Qi_restriction_nbr [ it . first ] ;
2017-06-01 19:58:32 +02:00
new_restriction . lag = current_lag ;
2018-07-31 11:48:08 +02:00
new_restriction . variable = it1 ;
2017-06-01 19:58:32 +02:00
new_restriction . value = data_tree - > One ;
svar_ident_restrictions . push_back ( new_restriction ) ;
}
2009-12-04 22:32:19 +01:00
svar_upper_cholesky = false ;
svar_lower_cholesky = false ;
svar_equation_restrictions . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_restriction_in_equation ( const string & equation )
2009-12-04 22:32:19 +01:00
{
2018-07-31 11:48:08 +02:00
int eqn = stoi ( equation ) ;
2009-12-04 22:32:19 +01:00
if ( eqn < 1 )
error ( " equation numbers must be greater than or equal to 1. " ) ;
if ( svar_equation_restrictions . count ( eqn ) > 0 )
2018-07-31 11:48:08 +02:00
error ( " equation number " + equation + " referenced more than once under a single lag. " ) ;
2009-12-04 22:32:19 +01:00
svar_equation_restrictions [ eqn ] = svar_restriction_symbols ;
svar_restriction_symbols . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_in_svar_restriction_symbols ( const string & tmp_var )
2009-12-04 22:32:19 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( tmp_var ) ;
int symb_id = mod_file - > symbol_table . getID ( tmp_var ) ;
2009-12-14 16:54:00 +01:00
2018-07-31 11:48:08 +02:00
for ( const auto & viit : svar_restriction_symbols )
if ( symb_id = = viit )
error ( tmp_var + " restriction added twice. " ) ;
2009-12-04 22:32:19 +01:00
2009-12-14 16:54:00 +01:00
svar_restriction_symbols . push_back ( symb_id ) ;
2009-12-04 22:32:19 +01:00
}
2017-06-01 19:58:32 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_restriction_equation_nbr ( const string & eq_nbr )
2011-10-10 11:45:55 +02:00
{
2018-07-31 11:48:08 +02:00
svar_equation_nbr = stoi ( eq_nbr ) ;
2011-10-10 11:45:55 +02:00
svar_left_handside = true ;
2011-11-07 12:26:20 +01:00
// reinitialize restriction type that must be set from the first restriction element
2018-10-02 18:15:31 +02:00
svar_restriction_type = SvarRestrictionType : : 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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_positive_restriction_element ( expr_t value , const string & variable , const string & lag )
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 ) ;
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_positive_restriction_element ( const string & variable , const string & lag )
2011-10-10 11:45:55 +02:00
{
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_negative_restriction_element ( expr_t value , const string & variable , const string & lag )
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 ) ;
2011-10-10 11:45:55 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_negative_restriction_element ( const string & variable , const string & lag )
2011-10-10 11:45:55 +02:00
{
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_restriction_element ( expr_t value , const string & variable , const string & lag )
2011-11-07 12:26:20 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( variable ) ;
int symb_id = mod_file - > symbol_table . getID ( variable ) ;
2011-11-07 12:26:20 +01:00
2018-07-31 11:48:08 +02:00
int current_lag = stoi ( lag ) ;
2018-10-02 18:15:31 +02:00
if ( svar_restriction_type = = SvarRestrictionType : : NOT_SET )
2011-11-07 12:26:20 +01:00
{
if ( current_lag = = 0 )
2017-06-01 19:58:32 +02:00
{
2018-10-02 18:15:31 +02:00
svar_restriction_type = SvarRestrictionType : : Qi_TYPE ;
2017-06-01 19:58:32 +02:00
+ + svar_Qi_restriction_nbr [ svar_equation_nbr ] ;
}
2011-11-07 12:26:20 +01:00
else
2017-06-01 19:58:32 +02:00
{
2018-10-02 18:15:31 +02:00
svar_restriction_type = SvarRestrictionType : : Ri_TYPE ;
2017-06-01 19:58:32 +02:00
+ + svar_Ri_restriction_nbr [ svar_equation_nbr ] ;
}
2011-11-07 12:26:20 +01:00
}
else
{
2018-10-02 18:15:31 +02:00
if ( ( svar_restriction_type = = SvarRestrictionType : : Qi_TYPE & & current_lag > 0 )
| | ( svar_restriction_type = = SvarRestrictionType : : Ri_TYPE & & current_lag = = 0 ) )
2017-06-01 19:58:32 +02:00
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 )
{
2019-12-16 19:42:59 +01:00
if ( value - > eval ( { } ) ! = 0 )
2011-11-06 17:44:50 +01:00
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SvarGlobalIdentificationCheckStatement > ( ) ) ;
2015-08-24 11:21:06 +02:00
}
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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SigmaeStatement > ( sigmae_matrix ) ) ;
2008-02-03 11:28:36 +01:00
}
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_to_row_const ( 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
2018-07-31 11:48:08 +02:00
if ( v . at ( 0 ) = = ' - ' )
id = data_tree - > AddUMinus ( data_tree - > AddNonNegativeConstant ( v . substr ( 1 , string : : npos ) ) ) ;
2012-07-12 12:46:22 +02:00
else
2018-07-31 11:48:08 +02:00
id = data_tree - > AddNonNegativeConstant ( v ) ;
2011-02-16 11:08:40 +01:00
2010-11-25 13:45:35 +01:00
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SteadyStatement > ( options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : option_num ( string name_option , string opt1 , string opt2 )
2008-02-03 11:28:36 +01:00
{
if ( options_list . paired_num_options . find ( name_option )
! = options_list . paired_num_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
2018-07-31 11:48:08 +02:00
options_list . paired_num_options [ move ( name_option ) ] = { move ( opt1 ) , move ( opt2 ) } ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : option_num ( string name_option , string opt )
2008-02-03 11:28:36 +01:00
{
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 " ) ;
2018-07-31 11:48:08 +02:00
options_list . num_options [ move ( name_option ) ] = move ( opt ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : option_str ( string name_option , string opt )
2008-02-03 11:28:36 +01:00
{
if ( options_list . string_options . find ( name_option )
! = options_list . string_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
2018-07-31 11:48:08 +02:00
options_list . string_options [ move ( name_option ) ] = move ( opt ) ;
2011-11-29 17:14:26 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : option_date ( string name_option , string opt )
2011-11-29 17:14:26 +01:00
{
if ( options_list . date_options . find ( name_option )
! = options_list . date_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
2018-07-31 11:48:08 +02:00
options_list . date_options [ move ( name_option ) ] = move ( opt ) ;
2011-11-29 17:14:26 +01:00
}
2008-04-04 20:40:20 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : option_symbol_list ( 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 ( ) ;
2019-12-20 16:59:30 +01:00
for ( auto & shock : shocks )
2020-11-18 17:47:37 +01:00
{
if ( ! mod_file - > symbol_table . exists ( shock ) )
error ( " Unknown symbol: " + shock ) ;
if ( mod_file - > symbol_table . getType ( shock ) ! = SymbolType : : exogenous )
error ( " Variables passed to irf_shocks must be exogenous. Caused by: " + shock ) ;
}
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 ( ) ;
2019-12-20 16:59:30 +01:00
for ( auto & it : parameters )
2019-12-16 19:42:59 +01:00
if ( mod_file - > symbol_table . getType ( it ) ! = SymbolType : : parameter )
error ( " Variables passed to the parameters option of the markov_switching statement must be parameters. Caused by: " + it ) ;
2011-12-24 16:58:16 +01:00
}
2018-07-31 11:48:08 +02:00
options_list . symbol_list_options [ move ( name_option ) ] = symbol_list ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-04-04 20:40:20 +02:00
}
2009-12-10 23:49:50 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : option_vec_int ( string name_option , vector < int > opt )
2009-12-10 23:49:50 +01:00
{
if ( options_list . vector_int_options . find ( name_option )
! = options_list . vector_int_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
2018-07-31 11:48:08 +02:00
if ( opt . empty ( ) )
2009-12-14 16:54:00 +01:00
error ( " option " + name_option + " was passed an empty vector. " ) ;
2018-07-31 11:48:08 +02:00
options_list . vector_int_options [ move ( name_option ) ] = move ( opt ) ;
2009-12-10 23:49:50 +01:00
}
2018-01-12 16:54:17 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : option_vec_str ( string name_option , vector < string > opt )
2018-01-12 16:54:17 +01:00
{
if ( options_list . vector_str_options . find ( name_option )
! = options_list . vector_str_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
2018-07-31 11:48:08 +02:00
if ( opt . empty ( ) )
2018-01-12 16:54:17 +01:00
error ( " option " + name_option + " was passed an empty vector. " ) ;
2018-07-31 11:48:08 +02:00
options_list . vector_str_options [ move ( name_option ) ] = move ( opt ) ;
2018-01-12 16:54:17 +01:00
}
2020-07-08 18:42:14 +02:00
void
ParsingDriver : : option_vec_cellstr ( string name_option , vector < string > opt )
{
if ( options_list . vector_cellstr_options . find ( name_option )
! = options_list . vector_cellstr_options . end ( ) )
error ( " option " + name_option + " declared twice " ) ;
if ( opt . empty ( ) )
error ( " option " + name_option + " was passed an empty vector. " ) ;
options_list . vector_cellstr_options [ move ( name_option ) ] = move ( opt ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : linear ( )
{
mod_file - > linear = true ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_in_symbol_list ( const string & tmp_var )
2008-02-03 11:28:36 +01:00
{
2018-07-31 11:48:08 +02:00
symbol_list . addSymbol ( tmp_var ) ;
2008-02-03 11:28:36 +01:00
}
2009-12-16 18:13:23 +01:00
void
ParsingDriver : : rplot ( )
2008-02-03 11:28:36 +01:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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
{
2020-07-17 09:43:28 +02:00
//make sure default order is known to preprocessor, see #49
if ( options_list . num_options . find ( " order " ) = = options_list . num_options . end ( ) )
options_list . num_options [ " order " ] = " 2 " ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( ) ;
}
2018-08-14 14:23:21 +02:00
void
ParsingDriver : : trend_component_model ( )
{
2019-12-16 19:42:59 +01:00
auto its = options_list . string_options . find ( " trend_component.name " ) ;
2018-08-22 09:15:00 +02:00
if ( its = = options_list . string_options . end ( ) )
2018-08-14 14:23:21 +02:00
error ( " You must pass the model_name option to the trend_component_model statement. " ) ;
2018-08-22 09:15:00 +02:00
auto name = its - > second ;
2018-08-14 14:23:21 +02:00
2019-12-16 19:42:59 +01:00
auto itvs = options_list . vector_str_options . find ( " trend_component.eqtags " ) ;
2018-08-22 09:15:00 +02:00
if ( itvs = = options_list . vector_str_options . end ( ) )
2018-08-14 14:23:21 +02:00
error ( " You must pass the eqtags option to the trend_component_model statement. " ) ;
2018-08-22 09:15:00 +02:00
auto eqtags = itvs - > second ;
2018-08-14 14:23:21 +02:00
2019-12-16 19:42:59 +01:00
auto itvs1 = options_list . vector_str_options . find ( " trend_component.targets " ) ;
2018-08-22 09:15:00 +02:00
if ( itvs1 = = options_list . vector_str_options . end ( ) )
2018-09-13 12:21:23 +02:00
error ( " You must pass the targets option to the trend_component_model statement. " ) ;
auto targets = itvs1 - > second ;
2018-08-14 14:23:21 +02:00
2018-09-13 12:21:23 +02:00
mod_file - > trend_component_model_table . addTrendComponentModel ( name , eqtags , targets ) ;
2018-08-14 14:23:21 +02:00
options_list . clear ( ) ;
}
2016-10-26 18:19:33 +02:00
void
ParsingDriver : : var_model ( )
{
2019-12-16 19:42:59 +01:00
auto its = options_list . string_options . find ( " var.model_name " ) ;
2018-08-21 11:46:59 +02:00
if ( its = = options_list . string_options . end ( ) )
2016-11-03 12:56:54 +01:00
error ( " You must pass the model_name option to the var_model statement. " ) ;
2018-08-21 11:46:59 +02:00
auto name = its - > second ;
2018-01-30 16:33:16 +01:00
2018-08-21 11:46:59 +02:00
int order = 0 ;
2019-12-16 19:42:59 +01:00
auto itn = options_list . num_options . find ( " var.order " ) ;
2018-08-21 11:46:59 +02:00
if ( itn ! = options_list . num_options . end ( ) )
order = stoi ( itn - > second ) ;
else
2019-12-20 16:59:30 +01:00
if ( ! symbol_list . empty ( ) )
error ( " You must pass the order option when passing a symbol list to the var_model statement " ) ;
2018-01-30 16:33:16 +01:00
2018-08-21 11:46:59 +02:00
vector < string > eqtags ;
2019-12-16 19:42:59 +01:00
auto itvs = options_list . vector_str_options . find ( " var.eqtags " ) ;
2018-08-21 11:46:59 +02:00
if ( itvs ! = options_list . vector_str_options . end ( ) )
{
eqtags = itvs - > second ;
if ( ! symbol_list . empty ( ) )
error ( " You cannot pass a symbol list when passing equation tags to the var_model statement " ) ;
else if ( itn ! = options_list . num_options . end ( ) )
error ( " You cannot pass the order option when passing equation tags to the var_model statement " ) ;
}
2019-02-21 10:30:25 +01:00
mod_file - > var_model_table . addVarModel ( name , eqtags , { symbol_list , order } ) ;
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 ( )
{
2019-12-13 15:54:38 +01:00
warning ( " The 'simul' statement is deprecated. Please use 'perfect_foresight_setup' and 'perfect_foresight_solver' instead. " ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < CheckStatement > ( options_list ) ) ;
2008-02-03 11:28:36 +01:00
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 :
2018-07-17 18:34:07 +02:00
if ( type ! = SymbolType : : endogenous & & type ! = SymbolType : : exogenous )
2014-02-28 18:01:03 +01:00
error ( estim_params . name + " must be an endogenous or an exogenous variable " ) ;
break ;
case 2 :
2018-07-31 11:48:08 +02:00
check_symbol_is_parameter ( estim_params . name ) ;
2014-02-28 18:01:03 +01:00
break ;
case 3 :
check_symbol_existence ( estim_params . name2 ) ;
SymbolType type2 = mod_file - > symbol_table . getType ( estim_params . name2 ) ;
2018-07-17 18:34:07 +02:00
if ( ( type ! = SymbolType : : endogenous & & type ! = SymbolType : : exogenous ) | | type ! = type2 )
2014-02-28 18:01:03 +01:00
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < EstimatedParamsStatement > ( estim_params_list , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < EstimatedParamsBoundsStatement > ( estim_params_list , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
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 ) ;
2018-07-17 18:34:07 +02:00
if ( type ! = SymbolType : : parameter )
2016-05-10 18:01:00 +02:00
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_time ( const string & arg )
2011-11-29 17:14:26 +01:00
{
2013-10-11 16:28:14 +02:00
option_date ( " initial_period " , arg ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SetTimeStatement > ( options_list ) ) ;
2011-11-29 17:14:26 +01:00
options_list . clear ( ) ;
}
2011-12-06 15:42:57 +01:00
void
ParsingDriver : : estimation_data ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < EstimationDataStatement > ( options_list ) ) ;
2011-12-06 15:42:57 +01:00
options_list . clear ( ) ;
}
2011-12-15 11:49:04 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_subsamples ( string name1 , string name2 )
2011-12-15 11:49:04 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name1 ) ;
if ( ! name2 . empty ( ) )
check_symbol_existence ( name2 ) ;
2012-03-26 16:46:44 +02:00
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SubsamplesStatement > ( name1 , name2 , subsample_declaration_map ,
mod_file - > symbol_table ) ) ;
2018-07-31 11:48:08 +02:00
subsample_declarations [ { move ( name1 ) , move ( name2 ) } ] = subsample_declaration_map ;
2012-03-26 16:46:44 +02:00
subsample_declaration_map . clear ( ) ;
2011-12-15 11:49:04 +01:00
}
2011-12-14 13:58:21 +01:00
void
2018-07-31 11:48:08 +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
{
2018-07-31 11:48:08 +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 ) ;
2012-03-26 16:46:44 +02:00
2018-07-31 11:48:08 +02:00
if ( subsample_declarations . find ( { from_name1 , from_name2 } ) = = subsample_declarations . end ( ) )
2012-03-26 16:46:44 +02:00
{
2018-07-31 11:48:08 +02:00
string err { from_name1 } ;
if ( ! from_name2 . empty ( ) )
err . append ( " , " ) . append ( from_name2 ) ;
2012-03-26 16:46:44 +02:00
error ( err + " does not have an associated subsample statement. " ) ;
}
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SubsamplesEqualStatement > ( to_name1 , to_name2 , from_name1 , from_name2 ,
mod_file - > symbol_table ) ) ;
2012-03-28 16:19:10 +02:00
2018-07-31 11:48:08 +02:00
subsample_declarations [ { move ( to_name1 ) , move ( to_name2 ) } ]
= subsample_declarations [ { move ( from_name1 ) , move ( from_name2 ) } ] ;
2011-12-14 13:58:21 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : check_symbol_is_statement_variable ( const string & name )
2011-12-14 13:58:21 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name ) ;
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2018-07-17 18:34:07 +02:00
if ( mod_file - > symbol_table . getType ( symb_id ) ! = SymbolType : : statementDeclaredVariable )
2018-07-31 11:48:08 +02:00
error ( name + " is not a variable assigned in a statement " ) ;
2011-12-14 13:58:21 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_subsample_name_equal_to_date_range ( string name , string date1 , string date2 )
2011-12-14 13:58:21 +01:00
{
2018-07-31 11:48:08 +02:00
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 [ move ( name ) ] = { move ( date1 ) , move ( date2 ) } ;
2011-12-14 13:58:21 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : check_subsample_declaration_exists ( const string & name1 , const string & subsample_name )
2011-12-14 13:58:21 +01:00
{
2018-07-31 11:48:08 +02:00
if ( subsample_name . empty ( ) )
2012-03-28 16:19:10 +02:00
return ;
2018-07-31 11:48:08 +02:00
check_subsample_declaration_exists ( name1 , " " , subsample_name ) ;
2012-03-28 16:19:10 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : check_subsample_declaration_exists ( const string & name1 , const string & name2 , const string & subsample_name )
2012-03-28 16:19:10 +02:00
{
2018-07-31 11:48:08 +02:00
if ( subsample_name . empty ( ) )
2012-03-28 16:19:10 +02:00
return ;
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name1 ) ;
if ( ! name2 . empty ( ) )
check_symbol_existence ( name2 ) ;
2012-03-26 16:46:44 +02:00
2018-07-31 11:48:08 +02:00
auto it = subsample_declarations . find ( { name1 , name2 } ) ;
2011-12-14 13:58:21 +01:00
if ( it = = subsample_declarations . end ( ) )
2012-03-26 16:46:44 +02:00
{
2018-07-31 11:48:08 +02:00
it = subsample_declarations . find ( { name2 , name1 } ) ;
2017-06-01 19:58:32 +02:00
if ( it = = subsample_declarations . end ( ) )
2012-03-28 16:19:10 +02:00
{
2018-07-31 11:48:08 +02:00
string err { name1 } ;
if ( ! name2 . empty ( ) )
err . append ( " , " ) . append ( name2 ) ;
2012-03-28 16:19:10 +02:00
error ( " A subsample statement has not been issued for " + err ) ;
}
2012-03-26 16:46:44 +02:00
}
2018-07-31 11:48:08 +02:00
auto tmp_map = it - > second ;
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-14 13:58:21 +01:00
}
2011-12-11 15:35:26 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_prior ( const string & name , const 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 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( ) ;
2018-07-18 16:52:12 +02:00
prior_shape = PriorDistributions : : noShape ;
2011-12-11 15:35:26 +01:00
}
2015-03-03 15:08:33 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_joint_prior ( const vector < string > & symbol_vec )
2015-03-03 15:08:33 +01:00
{
2018-07-31 11:48:08 +02:00
for ( auto & it : symbol_vec )
add_joint_parameter ( it ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < JointPriorStatement > ( joint_parameters , prior_shape , options_list ) ) ;
2015-03-03 15:08:33 +01:00
joint_parameters . clear ( ) ;
options_list . clear ( ) ;
2018-07-18 16:52:12 +02:00
prior_shape = PriorDistributions : : noShape ;
2015-03-03 15:08:33 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_joint_parameter ( string name )
2015-03-03 15:08:33 +01:00
{
check_symbol_is_parameter ( name ) ;
2018-07-31 11:48:08 +02:00
joint_parameters . push_back ( move ( name ) ) ;
2015-03-03 15:08:33 +01:00
}
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : copy_prior ( const string & to_declaration_type , const string & to_name1 ,
const string & to_name2 , const string & to_subsample_name ,
const string & from_declaration_type , const string & from_name1 ,
const string & from_name2 , const string & from_subsample_name )
2012-03-30 14:55:25 +02:00
{
2018-07-31 11:48:08 +02:00
if ( to_declaration_type = = " par " )
2012-04-04 10:43:29 +02:00
check_symbol_is_parameter ( to_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( to_name1 ) ;
2018-07-31 11:48:08 +02:00
if ( ! to_name2 . empty ( ) )
2012-04-04 10:43:29 +02:00
check_symbol_is_endogenous_or_exogenous ( to_name2 ) ;
}
2012-03-30 14:55:25 +02:00
2018-07-31 11:48:08 +02:00
if ( from_declaration_type = = " par " )
2012-04-04 10:43:29 +02:00
check_symbol_is_parameter ( from_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( from_name1 ) ;
2018-07-31 11:48:08 +02:00
if ( ! from_name2 . empty ( ) )
2012-04-04 10:43:29 +02:00
check_symbol_is_endogenous_or_exogenous ( from_name2 ) ;
}
2012-03-30 14:55:25 +02:00
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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-03-30 14:55:25 +02:00
}
2011-12-14 17:19:14 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_options ( const string & name , const 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 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < OptionsStatement > ( name , subsample_name , options_list ) ) ;
2011-12-14 17:19:14 +01:00
options_list . clear ( ) ;
}
2012-03-30 15:36:58 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : copy_options ( const string & to_declaration_type , const string & to_name1 ,
const string & to_name2 , const string & to_subsample_name ,
const string & from_declaration_type , const string & from_name1 ,
const string & from_name2 , const string & from_subsample_name )
2012-03-30 15:36:58 +02:00
{
2018-07-31 11:48:08 +02:00
if ( to_declaration_type = = " par " )
2012-04-04 10:43:29 +02:00
check_symbol_is_parameter ( to_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( to_name1 ) ;
2018-07-31 11:48:08 +02:00
if ( ! to_name2 . empty ( ) )
2012-04-04 10:43:29 +02:00
check_symbol_is_endogenous_or_exogenous ( to_name2 ) ;
}
2012-03-30 15:36:58 +02:00
2018-07-31 11:48:08 +02:00
if ( from_declaration_type = = " par " )
2012-04-04 10:43:29 +02:00
check_symbol_is_parameter ( from_name1 ) ;
else
{
check_symbol_is_endogenous_or_exogenous ( from_name1 ) ;
2018-07-31 11:48:08 +02:00
if ( ! from_name2 . empty ( ) )
2012-04-04 10:43:29 +02:00
check_symbol_is_endogenous_or_exogenous ( from_name2 ) ;
}
2012-03-30 15:36:58 +02:00
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ) ) ;
2012-03-30 15:36:58 +02:00
}
2011-12-11 15:35:26 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : check_symbol_is_endogenous_or_exogenous ( const string & name )
2011-12-11 15:35:26 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name ) ;
2018-08-01 10:47:09 +02:00
switch ( mod_file - > symbol_table . getType ( name ) )
2011-12-11 15:35:26 +01:00
{
2018-07-17 18:34:07 +02:00
case SymbolType : : endogenous :
case SymbolType : : exogenous :
case SymbolType : : exogenousDet :
2011-12-11 15:35:26 +01:00
break ;
default :
2018-07-31 11:48:08 +02:00
error ( name + " is neither endogenous or exogenous. " ) ;
2011-12-11 15:35:26 +01:00
}
}
2018-08-01 10:47:09 +02:00
void
ParsingDriver : : check_symbol_is_endogenous ( const string & name )
{
check_symbol_existence ( name ) ;
if ( mod_file - > symbol_table . getType ( name ) ! = SymbolType : : endogenous )
error ( name + " is not endogenous. " ) ;
}
2017-10-06 14:49:14 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : check_symbol_is_exogenous ( const string & name )
2017-10-06 14:49:14 +02:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name ) ;
2018-08-01 10:47:09 +02:00
switch ( mod_file - > symbol_table . getType ( name ) )
2017-10-06 14:49:14 +02:00
{
2018-07-17 18:34:07 +02:00
case SymbolType : : exogenous :
case SymbolType : : exogenousDet :
2017-10-06 14:49:14 +02:00
break ;
default :
2018-07-31 11:48:08 +02:00
error ( name + " is not exogenous. " ) ;
2017-10-06 14:49:14 +02:00
}
}
2011-12-11 15:35:26 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_std_prior ( const string & name , const 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 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < StdPriorStatement > ( name , subsample_name , prior_shape , prior_variance ,
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 ( ) ;
2018-07-18 16:52:12 +02:00
prior_shape = PriorDistributions : : noShape ;
2011-12-11 15:35:26 +01:00
}
2011-12-14 17:19:14 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_std_options ( const string & name , const 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 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < StdOptionsStatement > ( name , subsample_name , options_list , mod_file - > symbol_table ) ) ;
2011-12-14 17:19:14 +01:00
options_list . clear ( ) ;
}
2011-12-11 15:35:26 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_corr_prior ( const string & name1 , const string & name2 , const 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 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < CorrPriorStatement > ( name1 , name2 , subsample_name , prior_shape , prior_variance ,
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 ( ) ;
2018-07-18 16:52:12 +02:00
prior_shape = PriorDistributions : : noShape ;
2011-12-11 15:35:26 +01:00
}
2011-12-14 17:19:14 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_corr_options ( const string & name1 , const string & name2 , const 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 ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < CorrOptionsStatement > ( name1 , name2 , subsample_name , options_list , mod_file - > symbol_table ) ) ;
2011-12-14 17:19:14 +01:00
options_list . clear ( ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : run_estimation ( )
{
2020-02-04 17:48:37 +01:00
mod_file - > addStatement ( make_unique < EstimationStatement > ( mod_file - > symbol_table , 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < DynareSensitivityStatement > ( options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_varobs ( const string & name )
2010-04-14 15:03:41 +02:00
{
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( name ) ;
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2010-04-14 15:03:41 +02:00
mod_file - > symbol_table . addObservedVariable ( symb_id ) ;
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_varexobs ( const string & name )
2016-10-13 18:19:38 +02:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name ) ;
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2018-07-17 18:34:07 +02:00
if ( mod_file - > symbol_table . getType ( symb_id ) ! = SymbolType : : exogenous )
2018-07-31 11:48:08 +02:00
error ( " varexobs: " + name + " is not an exogenous variable " ) ;
2016-10-13 18:19:38 +02:00
mod_file - > symbol_table . addObservedExogenousVariable ( symb_id ) ;
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : set_trends ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ObservationTrendsStatement > ( trend_elements , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
trend_elements . clear ( ) ;
}
2021-01-18 16:42:20 +01:00
void
2020-06-29 11:38:41 +02:00
ParsingDriver : : set_deterministic_trends ( )
2021-01-18 16:42:20 +01:00
{
2020-06-29 11:38:41 +02:00
mod_file - > addStatement ( make_unique < DeterministicTrendsStatement > ( trend_elements , mod_file - > symbol_table ) ) ;
trend_elements . clear ( ) ;
2021-01-18 16:42:20 +01:00
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_trend_element ( string arg1 , expr_t arg2 )
2008-02-03 11:28:36 +01:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( arg1 ) ;
if ( trend_elements . find ( arg1 ) ! = trend_elements . end ( ) )
error ( " observation_trends: " + arg1 + " declared twice " ) ;
trend_elements [ move ( arg1 ) ] = arg2 ;
2008-02-03 11:28:36 +01:00
}
2020-06-29 11:38:41 +02:00
void
ParsingDriver : : set_filter_initial_state ( )
{
mod_file - > addStatement ( make_unique < FilterInitialStateStatement > ( filter_initial_state_elements , mod_file - > symbol_table ) ) ;
filter_initial_state_elements . clear ( ) ;
}
2021-01-18 16:42:20 +01:00
void
ParsingDriver : : set_filter_initial_state_element ( const string & name , const string & lag , 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 ) ;
int ilag = stoi ( lag ) ;
if ( type ! = SymbolType : : endogenous
& & type ! = SymbolType : : exogenous
& & type ! = SymbolType : : exogenousDet )
error ( " filter_initial_state: " + name + " should be an endogenous or exogenous variable " ) ;
if ( ( type = = SymbolType : : exogenous | | type = = SymbolType : : exogenousDet ) & & ilag = = 0 )
error ( " filter_initial_state: exogenous variable " + name + " must be provided with a lag " ) ;
if ( filter_initial_state_elements . find ( { symb_id , ilag } ) ! = filter_initial_state_elements . end ( ) )
error ( " filter_initial_state: ( " + name + " , " + lag + " ) declared twice " ) ;
if ( mod_file - > dynamic_model . minLagForSymbol ( symb_id ) > ilag - 1 )
error ( " filter_initial_state: variable " + name + " does not appear in the model with the lag " + to_string ( ilag - 1 ) + " (see the reference manual for the timing convention in 'filter_initial_state') " ) ;
filter_initial_state_elements [ { symb_id , ilag } ] = rhs ;
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_optim_weights ( string name , expr_t value )
2008-02-03 11:28:36 +01:00
{
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( name ) ;
2018-07-31 11:48:08 +02:00
if ( var_weights . find ( name ) ! = var_weights . end ( ) )
error ( " optim_weights: " + name + " declared twice " ) ;
var_weights [ move ( name ) ] = move ( value ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : set_optim_weights ( const string & name1 , const string & name2 , expr_t value )
2008-02-03 11:28:36 +01:00
{
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( name1 ) ;
check_symbol_is_endogenous ( name2 ) ;
2008-02-03 11:28:36 +01:00
2018-07-31 11:48:08 +02:00
pair < string , string > covar_key { name1 , name2 } ;
2008-02-03 11:28:36 +01:00
if ( covar_weights . find ( covar_key ) ! = covar_weights . end ( ) )
2018-07-31 11:48:08 +02:00
error ( " optim_weights: pair of variables ( " + name1 + " , " + name2
2008-02-03 11:28:36 +01:00
+ " ) declared twice " ) ;
covar_weights [ covar_key ] = value ;
}
void
ParsingDriver : : optim_weights ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < OptimWeightsStatement > ( var_weights , covar_weights , mod_file - > symbol_table ) ) ;
2008-02-03 11:28:36 +01:00
var_weights . clear ( ) ;
covar_weights . clear ( ) ;
}
void
ParsingDriver : : set_osr_params ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < OsrStatement > ( 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
2018-07-31 11:48:08 +02:00
ParsingDriver : : run_dynatype ( const string & filename )
2008-02-03 11:28:36 +01:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < DynaTypeStatement > ( symbol_list , filename ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : run_dynasave ( const string & filename )
2008-02-03 11:28:36 +01:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < DynaSaveStatement > ( symbol_list , filename ) ) ;
2008-04-07 15:14:40 +02:00
symbol_list . clear ( ) ;
2008-02-03 11:28:36 +01:00
}
2008-12-31 20:29:17 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : run_load_params_and_steady_state ( const string & filename )
2008-12-31 20:29:17 +01:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < LoadParamsAndSteadyStateStatement > ( filename , mod_file - > symbol_table , warnings ) ) ;
2008-12-31 20:29:17 +01:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : run_save_params_and_steady_state ( const string & filename )
2008-12-31 20:29:17 +01:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SaveParamsAndSteadyStateStatement > ( filename ) ) ;
2008-12-31 20:29:17 +01:00
}
2009-04-20 15:58:15 +02:00
void
ParsingDriver : : run_identification ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < IdentificationStatement > ( options_list ) ) ;
2009-10-14 18:16:43 +02:00
options_list . clear ( ) ;
2009-04-20 15:58:15 +02:00
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_mc_filename ( string filename , string prior )
2008-02-03 11:28:36 +01:00
{
2019-12-20 16:59:30 +01:00
for ( auto & it : filename_list )
2018-07-31 11:48:08 +02:00
if ( it . first = = filename )
error ( " model_comparison: filename " + filename + " declared twice " ) ;
filename_list . emplace_back ( move ( filename ) , move ( prior ) ) ;
2008-02-03 11:28:36 +01:00
}
void
ParsingDriver : : run_model_comparison ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ModelComparisonStatement > ( filename_list , options_list ) ) ;
2008-02-03 11:28:36 +01:00
filename_list . clear ( ) ;
options_list . clear ( ) ;
}
void
ParsingDriver : : begin_planner_objective ( )
{
2018-10-09 18:27:19 +02:00
planner_objective = make_unique < StaticModel > ( mod_file - > symbol_table ,
mod_file - > num_constants ,
mod_file - > external_functions_table ) ;
set_current_data_tree ( planner_objective . get ( ) ) ;
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
2018-10-09 18:27:19 +02:00
mod_file - > addStatement ( make_unique < PlannerObjectiveStatement > ( * planner_objective ) ) ;
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 " ) )
2019-12-18 17:32:41 +01:00
{
if ( ! planner_discount )
planner_discount = data_tree - > One ;
declare_parameter ( " optimal_policy_discount_factor " , planner_discount_latex_name ) ;
init_param ( " optimal_policy_discount_factor " , planner_discount ) ;
}
else if ( planner_discount )
error ( " ramsey_model: the 'planner_discount' option cannot be used when the 'optimal_policy_discount_factor' parameter is explicitly declared. " ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < RamseyModelStatement > ( options_list ) ) ;
2014-03-08 09:55:00 +01:00
options_list . clear ( ) ;
2019-12-18 17:32:41 +01:00
planner_discount = nullptr ;
planner_discount_latex_name . clear ( ) ;
2014-03-08 09:55:00 +01:00
}
2008-02-03 11:28:36 +01:00
void
ParsingDriver : : ramsey_policy ( )
{
2019-12-13 16:03:37 +01:00
warning ( " The 'ramsey_policy' statement is deprecated. Please use 'ramsey_model', 'stoch_simul', and 'evaluate_planner_objective' instead. " ) ;
2019-12-18 17:32:41 +01:00
2011-05-24 15:34:03 +02:00
if ( ! mod_file - > symbol_table . exists ( " optimal_policy_discount_factor " ) )
2019-12-18 17:32:41 +01:00
{
if ( ! planner_discount )
planner_discount = data_tree - > One ;
declare_parameter ( " optimal_policy_discount_factor " ) ;
init_param ( " optimal_policy_discount_factor " , planner_discount ) ;
}
else if ( planner_discount )
error ( " ramsey_policy: the 'planner_discount' option cannot be used when the 'optimal_policy_discount_factor' parameter is explicitly declared. " ) ;
2019-12-19 14:48:55 +01:00
mod_file - > addStatement ( make_unique < RamseyPolicyStatement > ( mod_file - > symbol_table ,
symbol_list , options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
2019-12-19 14:48:55 +01:00
symbol_list . clear ( ) ;
2019-12-18 17:32:41 +01:00
planner_discount = nullptr ;
2016-12-27 13:46:01 +01:00
}
2019-12-12 11:28:07 +01:00
void
ParsingDriver : : evaluate_planner_objective ( )
{
mod_file - > addStatement ( make_unique < EvaluatePlannerObjective > ( ) ) ;
}
2011-03-13 21:19:55 +01:00
void
ParsingDriver : : discretionary_policy ( )
{
2020-01-30 15:42:39 +01:00
/* The logic here is different from “ramsey_policy” and “ramsey_model”,
because we want to allow several instances of “ discretionary_policy ” in
the same . mod file . */
2011-05-24 15:34:03 +02:00
if ( ! mod_file - > symbol_table . exists ( " optimal_policy_discount_factor " ) )
2020-01-30 15:42:39 +01:00
declare_parameter ( " optimal_policy_discount_factor " ) ;
if ( ! planner_discount )
planner_discount = data_tree - > One ;
init_param ( " optimal_policy_discount_factor " , planner_discount ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < DiscretionaryPolicyStatement > ( symbol_list , options_list ) ) ;
2011-03-13 21:19:55 +01:00
symbol_list . clear ( ) ;
options_list . clear ( ) ;
2020-01-30 15:42:39 +01:00
planner_discount = nullptr ;
2011-03-13 21:19:55 +01:00
}
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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < WriteLatexSteadyStateModelStatement > ( mod_file - > steady_state_model ) ) ;
2017-08-30 11:32:01 +02:00
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : bvar_density ( const string & maxnlags )
2008-02-03 11:28:36 +01:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < BVARDensityStatement > ( stoi ( maxnlags ) , options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : bvar_forecast ( const string & nlags )
2008-02-03 11:28:36 +01:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < BVARForecastStatement > ( stoi ( nlags ) , options_list ) ) ;
2008-02-03 11:28:36 +01:00
options_list . clear ( ) ;
}
2009-07-26 19:07:07 +02:00
void
ParsingDriver : : sbvar ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SBVARStatement > ( options_list ) ) ;
2009-07-26 19:07:07 +02:00
options_list . clear ( ) ;
}
void
2011-05-11 19:02:39 +02:00
ParsingDriver : : ms_estimation ( )
2009-07-26 19:07:07 +02:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MSSBVAREstimationStatement > ( options_list ) ) ;
2011-05-11 19:02:39 +02:00
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_simulation ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MSSBVARSimulationStatement > ( options_list ) ) ;
2011-05-11 19:02:39 +02:00
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_compute_mdd ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MSSBVARComputeMDDStatement > ( options_list ) ) ;
2011-05-11 19:02:39 +02:00
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_compute_probabilities ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MSSBVARComputeProbabilitiesStatement > ( options_list ) ) ;
2011-05-11 19:02:39 +02:00
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_irf ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MSSBVARForecastStatement > ( options_list ) ) ;
2011-05-11 19:02:39 +02:00
options_list . clear ( ) ;
}
void
ParsingDriver : : ms_variance_decomposition ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2019-12-16 19:42:59 +01:00
auto 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
2019-12-16 19:42:59 +01:00
if ( auto itn = options_list . num_options . find ( " ms.chain " ) ;
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. " ) ;
2018-07-04 12:40:57 +02:00
else if ( stoi ( itn - > second ) < = 0 )
2009-12-09 01:38:53 +01:00
error ( " The value passed to the chain option must be greater than zero. " ) ;
2019-12-16 19:42:59 +01:00
if ( auto itv = options_list . vector_int_options . find ( " ms.equations " ) ;
itv ! = options_list . vector_int_options . end ( ) )
2018-06-04 12:26:16 +02:00
for ( int viit : itv - > second )
if ( viit < = 0 )
2009-12-14 16:54:00 +01:00
error ( " The value(s) passed to the equation option must be greater than zero. " ) ;
2009-12-09 01:38:53 +01:00
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < SvarStatement > ( options_list ) ) ;
2009-12-09 01:38:53 +01:00
options_list . clear ( ) ;
}
2009-12-08 17:46:13 +01:00
void
ParsingDriver : : markov_switching ( )
{
2019-12-16 19:42:59 +01:00
auto it0 = options_list . num_options . find ( " ms.chain " ) ;
2009-12-08 17:46:13 +01:00
if ( it0 = = options_list . num_options . end ( ) )
error ( " A chain option must be passed to the markov_switching statement. " ) ;
2018-07-04 12:40:57 +02:00
else if ( stoi ( it0 - > second ) < = 0 )
2009-12-08 17:46:13 +01:00
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. " ) ;
2018-07-04 12:40:57 +02:00
else if ( stoi ( it0 - > second ) < = 0 )
2011-12-19 15:57:28 +01:00
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. " ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MarkovSwitchingStatement > ( options_list ) ) ;
2009-12-08 17:46:13 +01:00
options_list . clear ( ) ;
}
2009-08-29 17:04:11 +02:00
void
2009-07-23 10:31:48 +02:00
ParsingDriver : : shock_decomposition ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ShockDecompositionStatement > ( symbol_list , options_list ) ) ;
2009-07-23 10:31:48 +02:00
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < RealtimeShockDecompositionStatement > ( symbol_list , options_list ) ) ;
2017-03-21 14:58:15 +01:00
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2017-03-22 11:30:35 +01:00
void
ParsingDriver : : plot_shock_decomposition ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < PlotShockDecompositionStatement > ( symbol_list , options_list ) ) ;
2017-03-22 11:30:35 +01:00
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2017-03-31 12:50:17 +02:00
void
ParsingDriver : : initial_condition_decomposition ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < InitialConditionDecompositionStatement > ( symbol_list , options_list ) ) ;
2017-03-31 12:50:17 +02:00
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2019-12-14 08:42:09 +01:00
void
ParsingDriver : : squeeze_shock_decomposition ( )
{
mod_file - > addStatement ( make_unique < SqueezeShockDecompositionStatement > ( symbol_list ) ) ;
symbol_list . clear ( ) ;
}
2009-10-16 19:23:57 +02:00
void
ParsingDriver : : conditional_forecast ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ConditionalForecastStatement > ( options_list ) ) ;
2009-10-16 19:23:57 +02:00
options_list . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : plot_conditional_forecast ( const string & periods )
2009-10-16 19:23:57 +02:00
{
2019-12-16 19:42:59 +01:00
int nperiods = periods . empty ( ) ? - 1 : stoi ( periods ) ;
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < PlotConditionalForecastStatement > ( nperiods , symbol_list ) ) ;
2009-10-16 19:23:57 +02:00
symbol_list . clear ( ) ;
}
void
ParsingDriver : : conditional_forecast_paths ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < CalibSmootherStatement > ( symbol_list , options_list ) ) ;
2012-05-30 16:28:00 +02:00
symbol_list . clear ( ) ;
options_list . clear ( ) ;
}
2012-06-08 17:36:32 +02:00
void
ParsingDriver : : extended_path ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ExtendedPathStatement > ( options_list ) ) ;
2012-06-08 17:36:32 +02:00
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]
2020-02-20 15:29:10 +01:00
if ( eq_tags . find ( " static " ) ! = eq_tags . end ( ) )
2013-04-11 17:07:39 +02:00
{
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_model_local_variable ( const string & name , const string & tex_name )
2017-08-28 15:14:11 +02:00
{
2018-07-31 11:48:08 +02:00
declare_symbol ( name , SymbolType : : modelLocalVariable , tex_name , { } ) ;
2017-08-28 15:14:11 +02:00
}
2008-02-03 11:28:36 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : declare_and_init_model_local_variable ( const 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
{
2018-07-31 11:48:08 +02:00
symb_id = mod_file - > symbol_table . addSymbol ( name , SymbolType : : modelLocalVariable ) ;
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
{
2021-04-16 17:34:13 +02:00
/* It can have already been declared in a steady_state_model block or
model_local_variable statement , check that it is indeed a
ModelLocalVariable */
2018-07-31 11:48:08 +02:00
symb_id = mod_file - > symbol_table . getID ( name ) ;
2018-07-17 18:34:07 +02:00
if ( mod_file - > symbol_table . getType ( symb_id ) ! = SymbolType : : modelLocalVariable )
2018-07-31 11:48:08 +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 )
{
2018-07-31 11:48:08 +02:00
error ( " Local model variable " + name + " declared twice. " ) ;
2010-04-23 18:39:07 +02:00
}
2008-02-03 11:28:36 +01:00
}
2009-03-11 12:43:18 +01:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : change_type ( SymbolType new_type , const vector < string > & var_list )
2009-03-11 12:43:18 +01:00
{
2019-12-20 16:59:30 +01:00
for ( auto & it : var_list )
2009-03-11 12:43:18 +01:00
{
int id ;
try
{
2018-07-31 11:48:08 +02:00
id = mod_file - > symbol_table . getID ( it ) ;
2009-03-11 12:43:18 +01:00
}
2009-12-16 18:13:23 +01:00
catch ( SymbolTable : : UnknownSymbolNameException & e )
2009-03-11 12:43:18 +01:00
{
2018-07-31 11:48:08 +02:00
error ( " Unknown variable " + it ) ;
2009-03-11 12:43:18 +01:00
}
// 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 ) )
2018-07-31 11:48:08 +02:00
error ( " You cannot modify the type of symbol " + it + " after having used it in an expression " ) ;
2009-03-11 12:43:18 +01:00
mod_file - > symbol_table . changeType ( id , new_type ) ;
}
}
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_expectation ( const string & arg1 , expr_t arg2 )
2009-10-29 18:16:10 +01:00
{
2018-07-31 11:48:08 +02:00
return data_tree - > AddExpectation ( stoi ( arg1 ) , arg2 ) ;
2009-10-29 18:16:10 +01:00
}
2016-11-03 17:08:06 +01:00
expr_t
2018-08-01 19:41:44 +02:00
ParsingDriver : : add_var_expectation ( const string & model_name )
2016-11-03 17:08:06 +01:00
{
2018-08-01 19:41:44 +02:00
return data_tree - > AddVarExpectation ( model_name ) ;
2016-11-03 17:08:06 +01:00
}
2018-01-30 16:33:16 +01:00
expr_t
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_pac_expectation ( const string & var_model_name )
2018-01-30 16:33:16 +01:00
{
2018-07-31 11:48:08 +02:00
return data_tree - > AddPacExpectation ( var_model_name ) ;
2018-02-07 16:50:49 +01:00
}
2019-02-28 19:22:34 +01:00
void
ParsingDriver : : begin_pac_growth ( )
{
set_current_data_tree ( & mod_file - > dynamic_model ) ;
}
void
ParsingDriver : : begin_pac_model ( )
{
parsing_pac_model = true ;
pac_growth = nullptr ;
pac_steady_state_growth_rate_number = - 1 ;
pac_steady_state_growth_rate_symb_id = - 1 ;
options_list . clear ( ) ;
}
2018-02-07 16:50:49 +01:00
void
2018-03-28 18:46:15 +02:00
ParsingDriver : : pac_model ( )
2018-02-07 16:50:49 +01:00
{
2019-12-16 19:42:59 +01:00
auto it = options_list . string_options . find ( " pac.model_name " ) ;
2018-03-28 18:46:15 +02:00
if ( it = = options_list . string_options . end ( ) )
error ( " You must pass the model_name option to the pac_model statement. " ) ;
2018-07-31 11:48:08 +02:00
auto name = it - > second ;
2018-02-07 16:50:49 +01:00
2019-03-04 11:06:19 +01:00
bool pac_growth_is_param = false ;
2019-12-16 19:42:59 +01:00
if ( pac_growth & & dynamic_cast < VariableNode * > ( pac_growth ) )
2019-03-04 11:06:19 +01:00
{
set < int > params ;
pac_growth - > collectVariables ( SymbolType : : parameter , params ) ;
if ( params . size ( ) = = 1 )
pac_growth_is_param = true ;
pac_growth - > collectVariables ( SymbolType : : endogenous , params ) ;
pac_growth - > collectVariables ( SymbolType : : exogenous , params ) ;
if ( params . size ( ) ! = 1 )
pac_growth_is_param = false ;
}
2019-12-16 19:42:59 +01:00
string aux_model_name ;
2018-08-14 14:23:21 +02:00
it = options_list . string_options . find ( " pac.aux_model_name " ) ;
2019-02-15 12:52:46 +01:00
if ( it ! = options_list . string_options . end ( ) )
2019-03-02 16:37:00 +01:00
{
2019-02-15 12:52:46 +01:00
aux_model_name = it - > second ;
2019-03-02 16:37:00 +01:00
if ( pac_steady_state_growth_rate_number > = 0 | | pac_steady_state_growth_rate_symb_id > = 0 )
{
pac_steady_state_growth_rate_number = - 1 ;
pac_steady_state_growth_rate_symb_id = - 1 ;
warning ( " when aux_model_name is used in the pac_model statement, steady_state_growth is ignored " ) ;
}
}
2019-03-04 11:06:19 +01:00
else
if ( pac_growth_is_param
2019-12-20 16:59:30 +01:00
& & ( pac_steady_state_growth_rate_number > = 0 | | pac_steady_state_growth_rate_symb_id > = 0 ) )
2019-03-04 11:06:19 +01:00
warning ( " If growth option is constant, steady_state_growth is ignored " ) ;
2019-12-16 19:42:59 +01:00
else if ( pac_growth & & ! pac_growth_is_param
2020-06-30 14:09:28 +02:00
& & pac_steady_state_growth_rate_number < 0
& & pac_steady_state_growth_rate_symb_id < 0 )
2019-03-04 11:06:19 +01:00
error ( " The steady state growth rate of the target must be provided (steady_state_growth option) if option growth is not constant " ) ;
2018-02-08 17:51:31 +01:00
2019-02-19 12:58:37 +01:00
if ( pac_steady_state_growth_rate_symb_id > = 0
& & mod_file - > symbol_table . getType ( pac_steady_state_growth_rate_symb_id ) ! = SymbolType : : parameter )
error ( " pac_model: steady_state_growth accepts either a number or a parameter " ) ;
2018-03-28 18:46:15 +02:00
it = options_list . string_options . find ( " pac.discount " ) ;
if ( it = = options_list . string_options . end ( ) )
error ( " You must pass the discount option to the pac_model statement. " ) ;
2018-07-31 11:48:08 +02:00
auto discount = it - > second ;
2018-03-28 18:46:15 +02:00
2019-01-24 19:35:30 +01:00
mod_file - > addStatement ( make_unique < PacModelStatement > ( name , aux_model_name , discount ,
2019-02-28 19:22:34 +01:00
pac_growth ,
2019-02-15 12:52:46 +01:00
pac_steady_state_growth_rate_number ,
pac_steady_state_growth_rate_symb_id ,
2018-09-05 15:17:21 +02:00
mod_file - > symbol_table ) ) ;
2019-02-28 19:22:34 +01:00
parsing_pac_model = false ;
2018-01-30 16:33:16 +01:00
}
2019-01-24 19:35:30 +01:00
void
2019-02-28 19:22:34 +01:00
ParsingDriver : : set_pac_growth ( expr_t pac_growth_arg )
2019-01-24 19:35:30 +01:00
{
2019-02-28 19:22:34 +01:00
pac_growth = pac_growth_arg ;
reset_data_tree ( ) ;
2019-01-24 19:35:30 +01:00
}
2019-02-15 12:52:46 +01:00
void
ParsingDriver : : set_pac_steady_state_growth ( const string & name_or_number )
{
try
{
pac_steady_state_growth_rate_number = stod ( name_or_number ) ;
}
catch ( . . . )
{
if ( ! mod_file - > symbol_table . exists ( name_or_number ) )
error ( " Unknown symbol used in pac_steady_state_growth option: " + name_or_number + " \n " ) ;
pac_steady_state_growth_rate_symb_id = mod_file - > symbol_table . getID ( name_or_number ) ;
}
}
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_adl ( expr_t arg1 , const string & name , const string & lag )
2017-06-12 14:56:44 +02:00
{
2018-07-31 11:48:08 +02:00
vector < int > lags ;
for ( int i = 1 ; i < = stoi ( lag ) ; i + + )
lags . push_back ( i ) ;
2018-02-28 11:31:08 +01:00
return add_adl ( arg1 , name , lags ) ;
2017-06-12 14:56:44 +02:00
}
2017-07-03 17:21:11 +02:00
expr_t
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_adl ( expr_t arg1 , const string & name , const vector < int > & lags )
2017-07-03 17:21:11 +02:00
{
2018-07-31 11:48:08 +02:00
expr_t id = data_tree - > AddAdl ( arg1 , name , lags ) ;
2017-07-03 17:21:11 +02:00
// Declare parameters here so that parameters can be initialized after the model block
2018-07-31 11:48:08 +02:00
for ( auto i : lags )
declare_parameter ( name + " _lag_ " + to_string ( i ) ) ;
2017-07-03 17:21:11 +02:00
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
}
2019-07-15 18:18:26 +02:00
expr_t
ParsingDriver : : add_cbrt ( expr_t arg1 )
{
return data_tree - > AddCbrt ( arg1 ) ;
}
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
{
2019-11-27 17:26:16 +01:00
// Forbid exogenous variables, see dynare#825
set < int > r ;
arg1 - > collectVariables ( SymbolType : : exogenous , r ) ;
if ( r . size ( ) > 0 )
error ( " Exogenous variables are not allowed in the context of the STEADY_STATE() operator. " ) ;
arg1 - > collectVariables ( SymbolType : : exogenousDet , r ) ;
if ( r . size ( ) > 0 )
error ( " Exogenous deterministic variables are not allowed in the context of the STEADY_STATE() operator. " ) ;
2009-09-10 22:09:16 +02:00
return data_tree - > AddSteadyState ( arg1 ) ;
}
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. " ) ;
2018-07-31 11:48:08 +02:00
declare_symbol ( opt , SymbolType : : externalFunction , " " , { } ) ;
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 ( ) )
2018-10-02 18:10:12 +02:00
current_external_function_options . firstDerivSymbID = ExternalFunctionsTable : : IDSetButNoNameProvided ;
2010-02-22 17:33:38 +01:00
else
{
2018-07-31 11:48:08 +02:00
declare_symbol ( opt , SymbolType : : externalFunction , " " , { } ) ;
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 ( ) )
2018-10-02 18:10:12 +02:00
current_external_function_options . secondDerivSymbID = ExternalFunctionsTable : : IDSetButNoNameProvided ;
2010-02-22 17:33:38 +01:00
else
{
2018-07-31 11:48:08 +02:00
declare_symbol ( opt , SymbolType : : externalFunction , " " , { } ) ;
2010-02-22 17:33:38 +01:00
current_external_function_options . secondDerivSymbID = mod_file - > symbol_table . getID ( opt ) ;
}
}
else if ( name_option = = " nargs " )
2018-07-04 12:40:57 +02:00
current_external_function_options . nargs = stoi ( opt ) ;
2010-02-22 17:33:38 +01:00
else
error ( " Unexpected error in ParsingDriver::external_function_option(): Please inform Dynare Team. " ) ;
}
void
ParsingDriver : : external_function ( )
{
2018-10-02 18:10:12 +02:00
if ( current_external_function_id = = ExternalFunctionsTable : : IDNotSet )
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
2019-12-20 16:59:30 +01:00
& & current_external_function_options . firstDerivSymbID = = ExternalFunctionsTable : : IDNotSet )
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. " ) ;
2018-10-02 18:10:12 +02:00
if ( current_external_function_options . secondDerivSymbID = = ExternalFunctionsTable : : IDSetButNoNameProvided
2019-12-20 16:59:30 +01:00
& & current_external_function_options . firstDerivSymbID ! = ExternalFunctionsTable : : IDSetButNoNameProvided )
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 )
2018-06-04 16:36:46 +02:00
return { false , 0 } ;
2016-10-07 15:02:42 +02:00
2019-12-16 19:42:59 +01:00
auto numNode = dynamic_cast < NumConstNode * > ( stack_external_function_args . top ( ) . front ( ) ) ;
auto unaryNode = dynamic_cast < UnaryOpNode * > ( stack_external_function_args . top ( ) . front ( ) ) ;
2016-10-07 15:02:42 +02:00
2019-12-16 19:42:59 +01:00
if ( ! numNode & & ! unaryNode )
2018-06-04 16:36:46 +02:00
return { false , 0 } ;
2016-10-07 15:02:42 +02:00
eval_context_t ectmp ;
double model_var_arg ;
2019-12-16 19:42:59 +01:00
if ( ! unaryNode )
2016-10-07 15:02:42 +02:00
{
try
{
model_var_arg = numNode - > eval ( ectmp ) ;
}
catch ( ExprNode : : EvalException & e )
{
2018-06-04 16:36:46 +02:00
return { false , 0 } ;
2016-10-07 15:02:42 +02:00
}
}
else
2018-11-28 14:32:26 +01:00
if ( unaryNode - > op_code ! = UnaryOpcode : : uminus )
2018-06-04 16:36:46 +02:00
return { false , 0 } ;
2016-10-07 15:02:42 +02:00
else
{
try
{
model_var_arg = unaryNode - > eval ( ectmp ) ;
}
catch ( ExprNode : : EvalException & e )
{
2018-06-04 16:36:46 +02:00
return { false , 0 } ;
2016-10-07 15:02:42 +02:00
}
}
if ( model_var_arg ! = floor ( model_var_arg ) )
2018-06-04 16:36:46 +02:00
return { false , 0 } ;
return { true , model_var_arg } ;
2016-10-07 15:02:42 +02:00
}
2010-09-16 19:18:45 +02:00
expr_t
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_model_var_or_external_function ( const 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 ;
2018-07-31 11:48:08 +02:00
if ( mod_file - > symbol_table . exists ( function_name ) )
if ( mod_file - > symbol_table . getType ( function_name ) ! = SymbolType : : externalFunction )
2019-02-28 19:22:34 +01:00
if ( ! in_model_block & & ! parsing_epilogue & & ! parsing_pac_model )
2010-03-15 10:47:44 +01:00
{
2018-03-20 09:56:22 +01:00
if ( stack_external_function_args . top ( ) . size ( ) > 0 )
2018-07-31 11:48:08 +02:00
error ( string ( " Symbol " ) + function_name + string ( " cannot take arguments. " ) ) ;
2010-03-15 10:47:44 +01:00
else
2018-03-20 09:56:22 +01:00
return add_expression_variable ( function_name ) ;
2010-02-22 17:33:38 +01:00
}
else
2018-03-20 09:56:22 +01:00
{ // e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode)
2018-07-31 11:48:08 +02:00
if ( undeclared_model_vars . find ( function_name ) ! = undeclared_model_vars . end ( ) )
undeclared_model_variable_error ( " Unknown symbol: " + function_name , function_name ) ;
2018-03-20 09:56:22 +01:00
pair < bool , double > rv = is_there_one_integer_argument ( ) ;
if ( ! rv . first )
2019-12-20 16:59:30 +01:00
model_error ( " Symbol " + function_name
+ " is being treated as if it were a function (i.e., takes an argument that is not an integer). " , " " ) ;
2018-03-20 09:56:22 +01:00
2019-04-23 11:07:32 +02:00
nid = add_model_variable ( mod_file - > symbol_table . getID ( function_name ) , static_cast < int > ( rv . second ) ) ;
2018-03-20 09:56:22 +01:00
stack_external_function_args . pop ( ) ;
return nid ;
2019-12-16 19:42:59 +01:00
}
2018-03-20 09:56:22 +01:00
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
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( function_name ) ;
2018-03-20 09:56:22 +01:00
if ( ! mod_file - > external_functions_table . exists ( symb_id ) )
2018-07-31 11:48:08 +02:00
error ( " Using a derivative of an external function ( " + function_name + " ) in the model block is currently not allowed. " ) ;
2018-03-20 09:56:22 +01:00
2018-09-03 17:16:28 +02:00
if ( in_model_block | | parsing_epilogue )
2018-10-02 18:10:12 +02:00
if ( mod_file - > external_functions_table . getNargs ( symb_id ) = = ExternalFunctionsTable : : IDNotSet )
2018-07-31 11:48:08 +02:00
error ( " Before using " + function_name
2018-03-20 09:56:22 +01:00
+ " () in the model block, you must first declare it via the external_function() statement " ) ;
2019-04-23 11:07:32 +02:00
else if ( static_cast < int > ( stack_external_function_args . top ( ) . size ( ) ) ! = mod_file - > external_functions_table . getNargs ( symb_id ) )
2018-07-31 11:48:08 +02:00
error ( " The number of arguments passed to " + function_name
2018-03-20 09:56:22 +01:00
+ " () does not match those of a previous call or declaration of this function. " ) ;
}
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
2018-09-03 17:16:28 +02:00
if ( parsing_epilogue )
error ( " Variable " + function_name + " used in the epilogue block but was not declared. " ) ;
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
2018-03-20 09:56:22 +01:00
// Processing will end at the end of the model block if nostrict was not passed
2018-07-31 11:48:08 +02:00
undeclared_model_vars . insert ( function_name ) ;
undeclared_model_variable_error ( " Unknown symbol: " + function_name , function_name ) ;
2018-03-20 09:56:22 +01:00
2016-10-07 15:02:42 +02:00
pair < bool , double > rv = is_there_one_integer_argument ( ) ;
if ( rv . first )
{
// assume it's a lead/lagged variable
2018-07-31 11:48:08 +02:00
declare_exogenous ( function_name ) ;
2019-04-23 11:07:32 +02:00
return add_model_variable ( mod_file - > symbol_table . getID ( function_name ) , static_cast < int > ( rv . second ) ) ;
2016-10-07 15:02:42 +02:00
}
else
2019-12-20 16:59:30 +01: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
}
2018-07-31 11:48:08 +02:00
declare_symbol ( function_name , SymbolType : : externalFunction , " " , { } ) ;
2016-10-07 15:48:18 +02:00
current_external_function_options . nargs = stack_external_function_args . top ( ) . size ( ) ;
2018-07-31 11:48:08 +02:00
mod_file - > external_functions_table . addExternalFunction ( mod_file - > symbol_table . getID ( function_name ) ,
2016-10-07 15:48:18 +02:00
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
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( function_name ) ;
2010-03-16 12:17:17 +01:00
nid = data_tree - > AddExternalFunction ( symb_id , stack_external_function_args . top ( ) ) ;
2010-02-22 17:33:38 +01:00
stack_external_function_args . pop ( ) ;
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 )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < NativeStatement > ( s ) ) ;
2010-06-18 12:39:29 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_native_remove_charset ( string str , const string & token )
2008-02-03 11:28:36 +01:00
{
2010-06-17 12:47:38 +02:00
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 )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < VerbatimStatement > ( s ) ) ;
2015-06-16 12:48:32 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_verbatim_remove_charset ( string str , const string & token )
2015-06-16 12:48:32 +02:00
{
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
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_steady_state_model_equal ( const string & varname , expr_t expr )
2010-04-23 18:39:07 +02:00
{
int id ;
try
{
2018-07-31 11:48:08 +02:00
id = mod_file - > symbol_table . getID ( varname ) ;
2010-04-23 18:39:07 +02:00
}
catch ( SymbolTable : : UnknownSymbolNameException & e )
{
// Unknown symbol, declare it as a ModFileLocalVariable
2018-07-31 11:48:08 +02:00
id = mod_file - > symbol_table . addSymbol ( varname , SymbolType : : modFileLocalVariable ) ;
2010-04-23 18:39:07 +02:00
}
SymbolType type = mod_file - > symbol_table . getType ( id ) ;
2018-07-17 18:34:07 +02:00
if ( type ! = SymbolType : : endogenous & & type ! = SymbolType : : modFileLocalVariable & & type ! = SymbolType : : parameter )
2018-07-31 11:48:08 +02:00
error ( varname + " has incorrect type " ) ;
2010-04-23 18:39:07 +02:00
2010-05-31 17:43:17 +02:00
mod_file - > steady_state_model . addDefinition ( id , expr ) ;
2010-04-23 18:39:07 +02:00
}
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 ;
2019-12-20 16:59:30 +01:00
for ( const auto & symb : symbs )
2011-01-26 19:55:01 +01:00
{
int id ;
try
{
2018-06-04 12:26:16 +02:00
id = mod_file - > symbol_table . getID ( symb ) ;
2011-01-26 19:55:01 +01:00
}
catch ( SymbolTable : : UnknownSymbolNameException & e )
{
// Unknown symbol, declare it as a ModFileLocalVariable
2018-07-17 18:34:07 +02:00
id = mod_file - > symbol_table . addSymbol ( symb , SymbolType : : modFileLocalVariable ) ;
2011-01-26 19:55:01 +01:00
}
SymbolType type = mod_file - > symbol_table . getType ( id ) ;
2018-07-17 18:34:07 +02:00
if ( type ! = SymbolType : : endogenous & & type ! = SymbolType : : modFileLocalVariable & & type ! = SymbolType : : parameter )
2018-06-04 12:26:16 +02:00
error ( symb + " has incorrect type " ) ;
2011-01-26 19:55:01 +01:00
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 ( ) ;
2019-12-06 10:40:44 +01:00
}
void
ParsingDriver : : initial_condition_decomp_process_graph_format_option ( )
{
options_list . symbol_list_options [ " initial_condition_decomp.graph_format " ] = graph_formats ;
graph_formats . clear ( ) ;
2012-09-11 14:26:53 +02:00
}
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ModelDiagnosticsStatement > ( ) ) ;
2012-11-16 12:34:49 +01:00
}
2013-05-31 14:47:28 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_parallel_local_file ( string filename )
2013-05-31 14:47:28 +02:00
{
2018-07-31 11:48:08 +02:00
mod_file - > parallel_local_files . push_back ( move ( filename ) ) ;
2013-05-31 14:47:28 +02:00
}
2014-02-10 19:22:54 +01:00
void
2019-09-25 12:02:44 +02:00
ParsingDriver : : add_moment_calibration_item ( const string & endo1 , const string & endo2 , string lags , const pair < expr_t , expr_t > & range )
2014-02-10 19:22:54 +01:00
{
MomentCalibration : : Constraint c ;
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( endo1 ) ;
2018-07-31 11:48:08 +02:00
c . endo1 = mod_file - > symbol_table . getID ( endo1 ) ;
2014-02-10 19:22:54 +01:00
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( endo2 ) ;
2018-07-31 11:48:08 +02:00
c . endo2 = mod_file - > symbol_table . getID ( endo2 ) ;
2014-02-10 19:22:54 +01:00
2018-07-31 11:48:08 +02:00
c . lags = move ( lags ) ;
2017-06-01 19:58:32 +02:00
2018-07-31 11:48:08 +02:00
c . lower_bound = range . first ;
c . upper_bound = range . second ;
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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < MomentCalibration > ( moment_calibration_constraints ,
mod_file - > symbol_table ) ) ;
2014-02-10 19:22:54 +01:00
moment_calibration_constraints . clear ( ) ;
}
void
2019-09-25 12:02:44 +02:00
ParsingDriver : : add_irf_calibration_item ( const string & endo , string periods , const string & exo , const pair < expr_t , expr_t > & range )
2014-02-10 19:22:54 +01:00
{
IrfCalibration : : Constraint c ;
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( endo ) ;
2018-07-31 11:48:08 +02:00
c . endo = mod_file - > symbol_table . getID ( endo ) ;
2014-02-10 19:22:54 +01:00
2018-07-31 11:48:08 +02:00
c . periods = move ( periods ) ;
2014-02-10 19:22:54 +01:00
2018-07-31 11:48:08 +02:00
check_symbol_existence ( exo ) ;
c . exo = mod_file - > symbol_table . getID ( exo ) ;
if ( mod_file - > symbol_table . getType ( exo ) ! = SymbolType : : exogenous )
error ( " Variable " + endo + " is not an exogenous. " ) ;
2017-06-01 19:58:32 +02:00
2018-07-31 11:48:08 +02:00
c . lower_bound = range . first ;
c . upper_bound = range . second ;
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
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < IrfCalibration > ( irf_calibration_constraints ,
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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < Smoother2histvalStatement > ( options_list ) ) ;
2014-04-03 15:05:20 +02:00
options_list . clear ( ) ;
}
void
2020-05-14 16:36:35 +02:00
ParsingDriver : : histval_file ( )
2014-04-03 15:05:20 +02:00
{
2020-05-14 16:36:35 +02:00
mod_file - > addStatement ( make_unique < HistvalFileStatement > ( options_list ) ) ;
options_list . clear ( ) ;
2014-04-03 15:05:20 +02:00
}
2014-04-09 17:57:17 +02:00
void
ParsingDriver : : perfect_foresight_setup ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < PerfectForesightSetupStatement > ( options_list ) ) ;
2014-04-09 17:57:17 +02:00
options_list . clear ( ) ;
}
void
ParsingDriver : : perfect_foresight_solver ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < PerfectForesightSolverStatement > ( options_list ) ) ;
2014-04-09 17:57:17 +02:00
options_list . clear ( ) ;
}
2015-05-31 12:18:06 +02:00
2017-10-05 15:09:04 +02:00
void
2020-07-08 18:42:14 +02:00
ParsingDriver : : method_of_moments ( )
2017-10-05 15:09:04 +02:00
{
2020-07-08 18:42:14 +02:00
mod_file - > addStatement ( make_unique < MethodOfMomentsStatement > ( symbol_list , options_list ) ) ;
2017-10-05 15:09:04 +02:00
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
{
2019-04-23 11:07:32 +02:00
mod_file - > addStatement ( make_unique < PriorPosteriorFunctionStatement > ( static_cast < 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 ( )
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < RamseyConstraintsStatement > ( mod_file - > symbol_table , ramsey_constraints ) ) ;
2015-05-31 12:18:06 +02:00
ramsey_constraints . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : ramsey_constraint_add_less ( const string & name , const expr_t rhs )
2015-05-31 12:18:06 +02:00
{
2018-07-18 16:18:26 +02:00
add_ramsey_constraint ( name , BinaryOpcode : : less , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : ramsey_constraint_add_greater ( const string & name , const expr_t rhs )
2015-05-31 12:18:06 +02:00
{
2018-07-18 16:18:26 +02:00
add_ramsey_constraint ( name , BinaryOpcode : : greater , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : ramsey_constraint_add_less_equal ( const string & name , const expr_t rhs )
2015-05-31 12:18:06 +02:00
{
2018-07-18 16:18:26 +02:00
add_ramsey_constraint ( name , BinaryOpcode : : lessEqual , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : ramsey_constraint_add_greater_equal ( const string & name , const expr_t rhs )
2015-05-31 12:18:06 +02:00
{
2018-07-18 16:18:26 +02:00
add_ramsey_constraint ( name , BinaryOpcode : : greaterEqual , rhs ) ;
2015-05-31 12:18:06 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_ramsey_constraint ( const string & name , BinaryOpcode op_code , const expr_t rhs )
2015-05-31 12:18:06 +02:00
{
2018-08-01 10:47:09 +02:00
check_symbol_is_endogenous ( name ) ;
2018-07-31 11:48:08 +02:00
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2015-05-31 12:18:06 +02:00
RamseyConstraintsStatement : : Constraint C ;
C . endo = symb_id ;
C . code = op_code ;
C . expression = rhs ;
ramsey_constraints . push_back ( C ) ;
}
2016-04-10 18:55:17 +02:00
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_shock_group_element ( string name )
2016-04-10 18:55:17 +02:00
{
2018-07-31 11:48:08 +02:00
check_symbol_existence ( name ) ;
int symb_id = mod_file - > symbol_table . getID ( name ) ;
2016-04-10 18:55:17 +02:00
SymbolType type = mod_file - > symbol_table . getType ( symb_id ) ;
2018-07-17 18:34:07 +02:00
if ( type ! = SymbolType : : exogenous )
2018-07-31 11:48:08 +02:00
error ( " shock_groups: " + name + " should be an exogenous variable " ) ;
2016-04-10 18:55:17 +02:00
2018-07-31 11:48:08 +02:00
shock_group . push_back ( move ( name ) ) ;
2016-04-10 18:55:17 +02:00
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : add_shock_group ( string name )
2016-04-10 18:55:17 +02:00
{
ShockGroupsStatement : : Group G ;
2018-07-31 11:48:08 +02:00
G . name = move ( name ) ;
2016-04-10 18:55:17 +02:00
G . list = shock_group ;
shock_groups . push_back ( G ) ;
shock_group . clear ( ) ;
}
void
2018-07-31 11:48:08 +02:00
ParsingDriver : : end_shock_groups ( const string & name )
2016-04-10 18:55:17 +02:00
{
2018-09-05 15:17:21 +02:00
mod_file - > addStatement ( make_unique < ShockGroupsStatement > ( shock_groups , name ) ) ;
2016-04-10 18:55:17 +02:00
shock_groups . clear ( ) ;
}
2018-08-01 19:41:44 +02:00
2019-12-02 11:18:21 +01:00
void
ParsingDriver : : add_init2shocks ( const string & endo_name , const string & exo_name )
{
check_symbol_existence ( endo_name ) ;
check_symbol_existence ( exo_name ) ;
int symb_id_endo = mod_file - > symbol_table . getID ( endo_name ) ;
if ( mod_file - > symbol_table . getType ( symb_id_endo ) ! = SymbolType : : endogenous )
error ( " init2shocks: " + endo_name + " should be an endogenous variable " ) ;
int symb_id_exo = mod_file - > symbol_table . getID ( exo_name ) ;
if ( mod_file - > symbol_table . getType ( symb_id_exo ) ! = SymbolType : : exogenous )
error ( " init2shocks: " + exo_name + " should be an exogenous variable " ) ;
2019-12-16 19:42:59 +01:00
init2shocks . emplace_back ( symb_id_endo , symb_id_exo ) ;
2019-12-02 11:18:21 +01:00
}
void
ParsingDriver : : end_init2shocks ( const string & name )
{
mod_file - > addStatement ( make_unique < Init2shocksStatement > ( init2shocks , name , mod_file - > symbol_table ) ) ;
init2shocks . clear ( ) ;
}
2018-08-01 19:41:44 +02:00
void
ParsingDriver : : var_expectation_model ( )
{
auto it = options_list . string_options . find ( " variable " ) ;
2018-11-28 17:32:55 +01:00
if ( it = = options_list . string_options . end ( ) & & ! var_expectation_model_expression )
error ( " You must pass either the 'variable' or the 'expression' option to the var_expectation_model statement. " ) ;
if ( it ! = options_list . string_options . end ( ) )
{
if ( var_expectation_model_expression )
error ( " You can't pass both the 'variable' or the 'expression' options to the var_expectation_model statement. " ) ;
var_expectation_model_expression = data_tree - > AddVariable ( mod_file - > symbol_table . getID ( it - > second ) ) ;
}
2018-08-01 19:41:44 +02:00
2018-08-22 16:50:01 +02:00
it = options_list . string_options . find ( " auxiliary_model_name " ) ;
2018-08-01 19:41:44 +02:00
if ( it = = options_list . string_options . end ( ) )
2018-08-22 16:50:01 +02:00
error ( " You must pass the auxiliary_model_name option to the var_expectation_model statement. " ) ;
2018-08-01 19:41:44 +02:00
auto var_model_name = it - > second ;
it = options_list . string_options . find ( " model_name " ) ;
if ( it = = options_list . string_options . end ( ) )
error ( " You must pass the model_name option to the var_expectation_model statement. " ) ;
auto model_name = it - > second ;
it = options_list . num_options . find ( " horizon " ) ;
if ( it = = options_list . num_options . end ( ) )
error ( " You must pass the horizon option to the var_expectation_model statement. " ) ;
auto horizon = it - > second ;
if ( var_expectation_model_discount )
{
VariableNode * var ;
if ( ! dynamic_cast < NumConstNode * > ( var_expectation_model_discount )
& & ! ( ( var = dynamic_cast < VariableNode * > ( var_expectation_model_discount ) )
& & var - > get_type ( ) = = SymbolType : : parameter ) )
error ( " The discount factor must be a constant expression or a parameter " ) ;
}
else
var_expectation_model_discount = data_tree - > One ;
2018-11-29 16:01:49 +01:00
mod_file - > addStatement ( make_unique < VarExpectationModelStatement > ( model_name , var_expectation_model_expression ,
var_model_name , horizon ,
var_expectation_model_discount , mod_file - > symbol_table ) ) ;
2018-08-01 19:41:44 +02:00
options_list . clear ( ) ;
var_expectation_model_discount = nullptr ;
2018-11-28 17:32:55 +01:00
var_expectation_model_expression = nullptr ;
2018-08-01 19:41:44 +02:00
}
2020-07-28 18:29:45 +02:00
void
ParsingDriver : : begin_matched_moments ( )
{
set_current_data_tree ( & mod_file - > dynamic_model ) ;
}
void
ParsingDriver : : end_matched_moments ( const vector < expr_t > & moments )
{
vector < tuple < vector < int > , vector < int > , vector < int > > > parsed_moments ;
for ( auto m : moments )
try
{
vector < int > symb_ids , lags , powers ;
m - > matchMatchedMoment ( symb_ids , lags , powers ) ;
parsed_moments . emplace_back ( symb_ids , lags , powers ) ;
}
catch ( ExprNode : : MatchFailureException & e )
{
error ( " Matched moment expression has incorrect format: " + e . message ) ;
}
mod_file - > addStatement ( make_unique < MatchedMomentsStatement > ( mod_file - > symbol_table , parsed_moments ) ) ;
reset_data_tree ( ) ;
}