Statement.cc 6.01 KB
Newer Older
1
/*
2
 * Copyright (C) 2006-2013 Dynare Team
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * This file is part of Dynare.
 *
 * Dynare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dynare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "Statement.hh"
21
#include <boost/xpressive/xpressive.hpp>
22
23
24

ModFileStructure::ModFileStructure() :
  check_present(false),
25
  steady_present(false),
26
  simul_present(false),
sebastien's avatar
sebastien committed
27
28
29
  stoch_simul_present(false),
  estimation_present(false),
  osr_present(false),
30
31
  osr_params_present(false),
  optim_weights_present(false),
32
  ramsey_model_present(false),
sebastien's avatar
sebastien committed
33
  ramsey_policy_present(false),
34
  discretionary_policy_present(false),
35
  planner_objective_present(false),
36
  extended_path_present(false),
37
  order_option(0),
38
  bvar_present(false),
houtanb's avatar
houtanb committed
39
  svar_identification_present(false),
40
  identification_present(false),
Sébastien Villemot's avatar
Sébastien Villemot committed
41
  estimation_analytic_derivation(false),
42
  partial_information(false),
43
  shocks_present_but_simul_not_yet(false),
44
  histval_present(false),
Sébastien Villemot's avatar
Sébastien Villemot committed
45
  k_order_solver(false),
46
47
48
49
  calibrated_measurement_errors(false),
  dsge_prior_weight_in_estimated_params(false),
  dsge_var_calibrated(""),
  dsge_var_estimated(false),
50
51
  bayesian_irf_present(false),
  estimation_data_statement_present(false),
52
  last_markov_switching_chain(0),
53
54
  calib_smoother_present(false),
  estim_params_use_calib(false)
55
56
57
58
59
60
61
62
{
}

Statement::~Statement()
{
}

void
63
Statement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
64
65
66
{
}

67
68
69
70
71
void
Statement::writeCOutput(ostream &output, const string &basename)
{
}

72
73
74
75
76
void
Statement::computingPass()
{
}

77
NativeStatement::NativeStatement(const string &native_statement_arg) :
78
79
80
81
82
83
84
  native_statement(native_statement_arg)
{
}

void
NativeStatement::writeOutput(ostream &output, const string &basename) const
{
85
86
87
88
89
90
91
92
  using namespace boost::xpressive;
  string date_regex = "(-?\\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4]\\d|5[0-2])))";
  sregex regex_lookbehind = sregex::compile("(?<!\\$|\\d|[a-zA-Z]|\\')" + date_regex);
  sregex regex_dollar = sregex::compile("(\\$)"+date_regex);

  string ns = regex_replace(native_statement, regex_lookbehind, "dates('$&')");
  ns = regex_replace(ns, regex_dollar, "$2" ); //replace $DATE with DATE
  output << ns << endl;
93
94
95
96
97
}

void
OptionsList::writeOutput(ostream &output) const
{
98
  for (num_options_t::const_iterator it = num_options.begin();
99
       it != num_options.end(); it++)
100
101
    output << "options_." << it->first << " = " << it->second << ";" << endl;

102
  for (paired_num_options_t::const_iterator it = paired_num_options.begin();
103
       it != paired_num_options.end(); it++)
104
105
106
    output << "options_." << it->first << " = [" << it->second.first << "; "
           << it->second.second << "];" << endl;

107
  for (string_options_t::const_iterator it = string_options.begin();
108
       it != string_options.end(); it++)
109
    output << "options_." << it->first << " = '" << it->second << "';" << endl;
110

111
112
  for (date_options_t::const_iterator it = date_options.begin();
       it != date_options.end(); it++)
113
    output << "options_." << it->first << " = " << it->second << ";" << endl;
114

115
  for (symbol_list_options_t::const_iterator it = symbol_list_options.begin();
116
       it != symbol_list_options.end(); it++)
sebastien's avatar
sebastien committed
117
    it->second.writeOutput("options_." + it->first, output);
118

119
  for (vec_int_options_t::const_iterator it = vector_int_options.begin();
120
       it != vector_int_options.end(); it++)
121
122
123
124
125
    {
      output << "options_." << it->first << " = ";
      if (it->second.size() > 1)
        {
          output << "[";
126
127
          for (vector<int>::const_iterator viit = it->second.begin();
               viit != it->second.end(); viit++)
128
129
130
131
132
133
            output << *viit << ";";
          output << "];" << endl;
        }
      else
        output << it->second.front() << ";" << endl;
    }
134
135
}

136
137
138
139
140
void
OptionsList::writeOutput(ostream &output, const string &option_group) const
{
  output << option_group << " = struct();" << endl;

141
  for (num_options_t::const_iterator it = num_options.begin();
142
       it != num_options.end(); it++)
143
144
    output << option_group << "." << it->first << " = " << it->second << ";" << endl;

145
  for (paired_num_options_t::const_iterator it = paired_num_options.begin();
146
       it != paired_num_options.end(); it++)
147
148
149
    output << option_group << "." << it->first << " = [" << it->second.first << "; "
           << it->second.second << "];" << endl;

150
  for (string_options_t::const_iterator it = string_options.begin();
151
       it != string_options.end(); it++)
152
153
    output << option_group << "." << it->first << " = '" << it->second << "';" << endl;

154
155
  for (date_options_t::const_iterator it = date_options.begin();
       it != date_options.end(); it++)
156
    output << option_group << "." << it->first << " = " << it->second << ";" << endl;
157

158
  for (symbol_list_options_t::const_iterator it = symbol_list_options.begin();
159
       it != symbol_list_options.end(); it++)
sebastien's avatar
sebastien committed
160
    it->second.writeOutput(option_group + "." + it->first, output);
161

162
  for (vec_int_options_t::const_iterator it = vector_int_options.begin();
163
       it != vector_int_options.end(); it++)
164
165
166
167
168
    {
      output << option_group << "." << it->first << " = ";
      if (it->second.size() > 1)
        {
          output << "[";
169
170
          for (vector<int>::const_iterator viit = it->second.begin();
               viit != it->second.end(); viit++)
171
172
173
174
175
176
            output << *viit << ";";
          output << "];" << endl;
        }
      else
        output <<  it->second.front() << ";" << endl;
    }
177
178
}

179
180
181
182
183
184
void
OptionsList::clear()
{
  num_options.clear();
  paired_num_options.clear();
  string_options.clear();
185
  date_options.clear();
sebastien's avatar
sebastien committed
186
  symbol_list_options.clear();
187
  vector_int_options.clear();
188
}