/*
* Copyright (C) 2003-2018 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see .
*/
#ifndef _PARSING_DRIVER_HH
#define _PARSING_DRIVER_HH
#ifdef _MACRO_DRIVER_HH
# error Impossible to include both ParsingDriver.hh and MacroDriver.hh
#endif
#include
#include
#include
#include
#include "ModFile.hh"
#include "SymbolList.hh"
class ParsingDriver;
#include "ExprNode.hh"
#include "DynareBison.hh"
#include "ComputingTasks.hh"
#include "Shocks.hh"
#include "SigmaeInitialization.hh"
#include "NumericalInitialization.hh"
#include "DynamicModel.hh"
using namespace std;
// Declare DynareFlexLexer class
#ifndef __FLEX_LEXER_H
# define yyFlexLexer DynareFlexLexer
# include
# undef yyFlexLexer
#endif
//! The lexer class
/*! Actually it was necessary to subclass the DynareFlexLexer class generated by Flex,
since the prototype for DynareFlexLexer::yylex() was not convenient.
*/
class DynareFlex : public DynareFlexLexer
{
public:
DynareFlex(istream *in = 0, ostream *out = 0);
//! The main lexing function
Dynare::parser::token_type lex(Dynare::parser::semantic_type *yylval,
Dynare::parser::location_type *yylloc,
ParsingDriver &driver);
//! The filename being parsed
/*! The bison parser locations (begin and end) contain a pointer to that string */
string filename;
//! Increment the location counter given a token
void location_increment(Dynare::parser::location_type *yylloc, const char *yytext);
//! Count parens in dates statement
int dates_parens_nb;
};
//! Drives the scanning and parsing of the .mod file, and constructs its abstract representation
/*! It is built along the guidelines given in Bison 2.3 manual. */
class ParsingDriver
{
private:
//! Checks that a given symbol exists, and stops with an error message if it doesn't
void check_symbol_existence(const string &name);
//! Checks that a given symbol exists and is a parameter, and stops with an error message if it isn't
void check_symbol_is_parameter(string *name);
//! Checks that a given symbol was assigned within a Statement
void check_symbol_is_statement_variable(string *name);
//! Checks that a given symbol exists and is a endogenous or exogenous, and stops with an error message if it isn't
void check_symbol_is_endogenous_or_exogenous(string *name);
//! Checks that a given symbol exists and is a exogenous, and stops with an error message if it isn't
void check_symbol_is_exogenous(string *name);
//! Checks for symbol existence in model block. If it doesn't exist, an error message is stored to be printed at
//! the end of the model block
void check_symbol_existence_in_model_block(const string &name);
//! Helper to add a symbol declaration
void declare_symbol(const string *name, SymbolType type, const string *tex_name, const vector *> *partition_value);
//! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name
void optim_options_helper(const string &name);
void sampling_options_helper(const string &name);
//! Stores temporary symbol table
SymbolList symbol_list;
//! The data tree in which to add expressions currently parsed
DataTree *data_tree;
//! The model tree in which to add expressions currently parsed
/*! It is only a dynamic cast of data_tree pointer, and is therefore null if data_tree is not a ModelTree instance */
ModelTree *model_tree;
//! The dynamic model tree in which to add expressions currently parsed
/*! It is only a dynamic cast of data_tree pointer, and is therefore null if data_tree is not a DynamicModel instance */
DynamicModel *dynamic_model;
//! Sets data_tree and model_tree pointers
void set_current_data_tree(DataTree *data_tree_arg);
//! Stores options lists
OptionsList options_list;
//! Temporary storage for trend elements
ObservationTrendsStatement::trend_elements_t trend_elements;
//! Temporary storage for filename list of ModelComparison (contains weights)
ModelComparisonStatement::filename_list_t filename_list;
//! Temporary storage for list of EstimationParams (from estimated_params* statements)
vector estim_params_list;
//! Temporary storage for list of OsrParams (from osr_params_block statements)
vector osr_params_list;
//! Temporary storage of variances from optim_weights
OptimWeightsStatement::var_weights_t var_weights;
//! Temporary storage of covariances from optim_weights
OptimWeightsStatement::covar_weights_t covar_weights;
//! Temporary storage for deterministic shocks
ShocksStatement::det_shocks_t det_shocks;
//! Temporary storage for periods of deterministic shocks
vector > det_shocks_periods;
//! Temporary storage for values of deterministic shocks
vector det_shocks_values;
//! Temporary storage for variances of shocks
ShocksStatement::var_and_std_shocks_t var_shocks;
//! Temporary storage for standard errors of shocks
ShocksStatement::var_and_std_shocks_t std_shocks;
//! Temporary storage for covariances of shocks
ShocksStatement::covar_and_corr_shocks_t covar_shocks;
//! Temporary storage for correlations of shocks
ShocksStatement::covar_and_corr_shocks_t corr_shocks;
//! Temporary storage for Sigma_e rows
SigmaeStatement::row_t sigmae_row;
//! Temporary storage for Sigma_e matrix
SigmaeStatement::matrix_t sigmae_matrix;
//! Temporary storage for initval/endval blocks
InitOrEndValStatement::init_values_t init_values;
//! Temporary storage for histval blocks
HistValStatement::hist_values_t hist_values;
//! Temporary storage for histval blocks
HistValStatement::hist_vals_wrong_lag_t hist_vals_wrong_lag;
//! Temporary storage for homotopy_setup blocks
HomotopyStatement::homotopy_values_t homotopy_values;
//! Temporary storage for moment_calibration
MomentCalibration::constraints_t moment_calibration_constraints;
//! Temporary storage for irf_calibration
IrfCalibration::constraints_t irf_calibration_constraints;
//! Temporary storage for ramsey_constraints
RamseyConstraintsStatement::constraints_t ramsey_constraints;
//! Temporary storage for svar_identification blocks
SvarIdentificationStatement::svar_identification_restrictions_t svar_ident_restrictions;
//! Temporary storage for mapping the equation number to the restrictions within an svar_identification block
map > svar_equation_restrictions;
//! Temporary storage for restrictions in an equation within an svar_identification block
vector svar_restriction_symbols;
//! Temporary storage for constants exculsion within an svar_identification
bool svar_constants_exclusion;
//! Temporary storage for upper cholesky within an svar_identification block
bool svar_upper_cholesky;
//! Temporary storage for lower cholesky within an svar_identification block
bool svar_lower_cholesky;
//! Temporary storage for equation number for a restriction within an svar_identification block
int svar_equation_nbr;
//! Temporary storage for left/right handside of a restriction equation within an svar_identificaton block
bool svar_left_handside;
//! Temporary storage for current restriction number in svar_identification block
map svar_Qi_restriction_nbr;
map svar_Ri_restriction_nbr;
//! Stores undeclared model variables
set undeclared_model_vars;
//! Temporary storage for restriction type
enum SvarRestrictionType
{
NOT_SET,
Qi_TYPE,
Ri_TYPE
};
SvarRestrictionType svar_restriction_type;
//! Temporary storage for generate_irfs
vector generate_irf_names;
vector