DynareBison.yy 184 KB
Newer Older
1
// -*- C++ -*-
2
/*
3
 * Copyright © 2003-2021 Dynare Team
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/>.
 */

21
%language "c++"
22
%require "3.2"
23
%defines
24
%define api.value.type variant
25
%define api.namespace {Dynare}
26
%define parse.assert
27
28
%define parse.error verbose
%define parse.trace
29

30
%code top {
31
class ParsingDriver;
32
}
33

34
%code requires {
35
#include "ExprNode.hh"
36
#include "CodeInterpreter.hh"
37
}
38

39
%param { ParsingDriver &driver }
40
41

%locations
42
43
%initial-action
{
44
45
  // Initialize the locations' filenames to the filename maintained by the lexer
  @$.begin.filename = @$.end.filename = &(driver.lexer->filename);
46
}
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%code {
/* Little hack: we redefine the macro which computes the locations, because
   we need to access the location from within the parsing driver for error
   and warning messages. */
#define YYLLOC_DEFAULT(Current, Rhs, N)                         \
  do {                                                          \
    if (N)                                                      \
      {                                                         \
        (Current).begin = YYRHSLOC(Rhs, 1).begin;               \
        (Current).end   = YYRHSLOC(Rhs, N).end;                 \
      }                                                         \
    else                                                        \
      {                                                         \
        (Current).begin = (Current).end = YYRHSLOC(Rhs, 0).end;	\
      }                                                         \
    driver.location = (Current);                                \
  } while(false)

66
67
68
69
70
71
72
#include "ParsingDriver.hh"

/* this "connects" the bison parser in the driver to the flex scanner class
 * object. it defines the yylex() function call to pull the next token from the
 * current lexer object of the driver context. */
#undef yylex
#define yylex driver.lexer->lex
73
}
74

75
%token AIM_SOLVER ANALYTIC_DERIVATION ANALYTIC_DERIVATION_MODE AR POSTERIOR_SAMPLING_METHOD
76
%token BALANCED_GROWTH_TEST_TOL BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION SILENT_OPTIMIZER
77
78
79
80
%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER FIG_NAME WRITE_XLS
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA INTERACTIVE SCREEN_SHOCKS STEADYSTATE
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN DETAIL_PLOT TYPE
%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED PROPOSAL_DISTRIBUTION REALTIME VINTAGE
81
%token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION
82
%token COMMA CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED INITIAL_CONDITION_DECOMPOSITION
83
%token DATAFILE FILE SERIES DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS
84
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR EXPRESSION
85
86
%token FILENAME DIRNAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS FIRST_SIMULATION_PERIOD LAST_OBS 
%token SET_TIME OSR_PARAMS_BOUNDS KEEP_KALMAN_ALGO_IF_SINGULARITY_IS_DETECTED
87
%token <string> FALSE FLOAT_NUMBER DATES
Houtan Bastani's avatar
Houtan Bastani committed
88
%token DEFAULT FIXED_POINT FLIP OPT_ALGO COMPILATION_SETUP COMPILER ADD_FLAGS SUBSTITUTE_FLAGS ADD_LIBS SUBSTITUTE_LIBS
89
%token FORECAST K_ORDER_SOLVER INSTRUMENTS SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN
90
%token GAMMA_PDF GRAPH GRAPH_FORMAT CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK STD
91
%token HISTVAL HISTVAL_FILE HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID FILTERED_THEORETICAL_MOMENTS_GRID HYBRID ONE_SIDED_HP_FILTER
92
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT INFILE INVARS
93
%token <string> INT_NUMBER
94
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION
95
%token FAST_KALMAN_FILTER KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SCHUR_VEC_TOL SUBSAMPLES OPTIONS TOLF TOLX PLOT_INIT_DATE PLOT_END_DATE
96
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LINEAR_DECOMPOSITION LOAD_IDENT_FILES LOAD_MH_FILE LOAD_RESULTS_AFTER_LOAD_MH LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV LINEAR_APPROXIMATION
97
98
%token LYAPUNOV_COMPLEX_THRESHOLD LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR
%token MATCHED_MOMENTS MARKOWITZ MARGINAL_DENSITY MAX MAXIT
Stéphane Adjemian's avatar
Stéphane Adjemian committed
99
%token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_TUNE_JSCALE MH_TUNE_GUESS MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS
100
%token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN
101
%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO CONTEMPORANEOUS_CORRELATION DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL RAFTERY_LEWIS_QRS RAFTERY_LEWIS_DIAGNOSTICS MCMC_JUMPING_COVARIANCE MOMENT_CALIBRATION
102
%token NUMBER_OF_PARTICLES RESAMPLING SYSTEMATIC GENERIC RESAMPLING_THRESHOLD RESAMPLING_METHOD KITAGAWA STRATIFIED SMOOTH
103
%token CPF_WEIGHTS AMISANOTRISTANI MURRAYJONESPARSLOW WRITE_EQUATION_TAGS FILTER_INITIAL_STATE
104
%token NONLINEAR_FILTER_INITIALIZATION FILTER_ALGORITHM PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION
105
%token <string> NAME
106
%token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE FAST_REALTIME RESCALE_PREDICTION_ERROR_COVARIANCE GENERATE_IRFS
Houtan Bastani's avatar
Houtan Bastani committed
107
%token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS NO_HOMOTOPY
108
%token NOGRAPH POSTERIOR_NOGRAPH POSTERIOR_GRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS MODEL_NAME STDERR_MULTIPLES DIAGONAL_ONLY
109
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED OUTFILE OUTVARS OVERWRITE DISCOUNT
110
%token PARALLEL_LOCAL_FILES PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERIODS PERIOD PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE
111
%token PERFECT_FORESIGHT_SETUP PERFECT_FORESIGHT_SOLVER NO_POSTERIOR_KERNEL_DENSITY FUNCTION
112
%token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN MLE_MODE PRUNING
113
%token <string> QUOTED_STRING
114
%token QZ_CRITERIUM QZ_ZERO_THRESHOLD DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE PIPE_E PIPE_X PIPE_P
115
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY TARGETS
116
%token SHOCKS SHOCK_DECOMPOSITION SHOCK_GROUPS USE_SHOCK_GROUPS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED ENDOGENOUS_TERMINAL_PERIOD
117
%token SMOOTHER SMOOTHER2HISTVAL SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL SOLVE_ALGO SOLVER_PERIODS ROBUST_LIN_SOLVE
118
%token STDERR STEADY STOCH_SIMUL SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME REALTIME_SHOCK_DECOMPOSITION CONDITIONAL UNCONDITIONAL
119
120
%token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT PLANNER_DISCOUNT_LATEX_NAME
%token DISCRETIONARY_POLICY DISCRETIONARY_TOL EVALUATE_PLANNER_OBJECTIVE
121
%token <string> TEX_NAME TRUE
122
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED
123
%token VALUES VAR VAREXO VAREXO_DET VARIABLE VAROBS VAREXOBS PREDETERMINED_VARIABLES VAR_EXPECTATION VAR_EXPECTATION_MODEL PLOT_SHOCK_DECOMPOSITION MODEL_LOCAL_VARIABLE
124
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL WRITE_LATEX_STEADY_STATE_MODEL
Houtan Bastani's avatar
Houtan Bastani committed
125
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP VAR_MODEL PAC_MODEL QOQ YOY AOA PAC_EXPECTATION TREND_COMPONENT_MODEL
126
127
%left EQUAL_EQUAL EXCLAMATION_EQUAL
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
128
129
%left PLUS MINUS
%left TIMES DIVIDE
130
%precedence UNARY
131
%nonassoc POWER
132
%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN ERF DIFF ADL AUXILIARY_MODEL_NAME
133
%token SQRT CBRT NORMCDF NORMPDF STEADY_STATE EXPECTATION OCCBIN_LIKELIHOOD OCCBIN_SMOOTHER
134
/* GSA analysis */
135
%token DYNARE_SENSITIVITY MORRIS STAB REDFORM PPRIOR PRIOR_RANGE PPOST ILPTAU MORRIS_NLIV
136
%token MORRIS_NTRA NSAM LOAD_REDFORM LOAD_RMSE LOAD_STAB ALPHA2_STAB LOGTRANS_REDFORM THRESHOLD_REDFORM
137
%token KSSTAT_REDFORM ALPHA2_REDFORM NAMENDO NAMLAGENDO NAMEXO RMSE LIK_ONLY VAR_RMSE PFILT_RMSE ISTART_RMSE
138
%token ALPHA_RMSE ALPHA2_RMSE
139
/* end of GSA analysis*/
140
%token FREQ INITIAL_YEAR INITIAL_SUBPERIOD FINAL_YEAR FINAL_SUBPERIOD DATA VLIST
Houtan Bastani's avatar
Houtan Bastani committed
141
%token VLISTLOG VLISTPER SPECTRAL_DENSITY INIT2SHOCKS
142
%token RESTRICTION RESTRICTION_FNAME CROSS_RESTRICTIONS NLAGS CONTEMP_REDUCED_FORM REAL_PSEUDO_FORECAST
143
%token DUMMY_OBS NSTATES INDXSCALESSTATES NO_BAYESIAN_PRIOR SPECIFICATION SIMS_ZHA
144
145
%token <string> ALPHA BETA ABAND NINV CMS NCMS CNUM GAMMA INV_GAMMA INV_GAMMA1 INV_GAMMA2 NORMAL UNIFORM EPS PDF FIG DR NONE PRIOR PRIOR_VARIANCE HESSIAN IDENTITY_MATRIX DIRICHLET DIAGONAL OPTIMAL
%token GSIG2_LMDM Q_DIAG FLAT_PRIOR NCSK NSTD WEIBULL WEIBULL_PDF GMM SMM
146
%token INDXPARR INDXOVR INDXAP APBAND INDXIMF INDXFORE FOREBAND INDXGFOREHAT INDXGIMFHAT
147
%token INDXESTIMA INDXGDLS EQ_MS FILTER_COVARIANCE FILTER_DECOMPOSITION SMOOTHED_STATE_UNCERTAINTY
148
149
%token EQ_CMS TLINDX TLNUMBER RESTRICTIONS POSTERIOR_SAMPLER_OPTIONS
%token OUTPUT_FILE_TAG HORIZON
150
%token SBVAR TREND_VAR DEFLATOR GROWTH_FACTOR MS_IRF MS_VARIANCE_DECOMPOSITION GROWTH
Houtan Bastani's avatar
Houtan Bastani committed
151
%token MS_ESTIMATION MS_SIMULATION MS_COMPUTE_MDD MS_COMPUTE_PROBABILITIES MS_FORECAST
152
%token SVAR_IDENTIFICATION EQUATION EXCLUSION LAG UPPER_CHOLESKY LOWER_CHOLESKY MONTHLY QUARTERLY
Houtan Bastani's avatar
Houtan Bastani committed
153
%token MARKOV_SWITCHING CHAIN DURATION NUMBER_OF_REGIMES NUMBER_OF_LAGS EPILOGUE
154
%token SVAR SVAR_GLOBAL_IDENTIFICATION_CHECK COEFF COEFFICIENTS VARIANCES CONSTANTS EQUATIONS
155
%token EXTERNAL_FUNCTION EXT_FUNC_NAME EXT_FUNC_NARGS FIRST_DERIV_PROVIDED SECOND_DERIV_PROVIDED
156
%token SELECTED_VARIABLES_ONLY COVA_COMPUTE SIMULATION_FILE_TAG FILE_TAG
157
%token NO_ERROR_BANDS ERROR_BAND_PERCENTILES SHOCKS_PER_PARAMETER NO_CREATE_INIT
158
%token SHOCK_DRAWS FREE_PARAMETERS MEDIAN DATA_OBS_NBR NEIGHBORHOOD_WIDTH PVALUE_KS PVALUE_CORR
159
%token FILTERED_PROBABILITIES REAL_TIME_SMOOTHED PRIOR_FUNCTION POSTERIOR_FUNCTION SAMPLING_DRAWS
Houtan Bastani's avatar
Houtan Bastani committed
160
%token PROPOSAL_TYPE PROPOSAL_UPPER_BOUND PROPOSAL_LOWER_BOUND PROPOSAL_DRAWS USE_MEAN_CENTER
161
%token ADAPTIVE_MH_DRAWS THINNING_FACTOR COEFFICIENTS_PRIOR_HYPERPARAMETERS
Houtan Bastani's avatar
Houtan Bastani committed
162
163
%token CONVERGENCE_STARTING_VALUE CONVERGENCE_ENDING_VALUE CONVERGENCE_INCREMENT_VALUE
%token MAX_ITERATIONS_STARTING_VALUE MAX_ITERATIONS_INCREMENT_VALUE MAX_BLOCK_ITERATIONS
164
%token MAX_REPEATED_OPTIMIZATION_RUNS FUNCTION_CONVERGENCE_CRITERION SAVE_REALTIME
Houtan Bastani's avatar
Houtan Bastani committed
165
166
167
%token PARAMETER_CONVERGENCE_CRITERION NUMBER_OF_LARGE_PERTURBATIONS NUMBER_OF_SMALL_PERTURBATIONS
%token NUMBER_OF_POSTERIOR_DRAWS_AFTER_PERTURBATION MAX_NUMBER_OF_STAGES
%token RANDOM_FUNCTION_CONVERGENCE_CRITERION RANDOM_PARAMETER_CONVERGENCE_CRITERION
168
169
/* Method of Moments */
%token METHOD_OF_MOMENTS MOM_METHOD
170
%token BARTLETT_KERNEL_LAG WEIGHTING_MATRIX WEIGHTING_MATRIX_SCALING_FACTOR ANALYTIC_STANDARD_ERRORS ANALYTIC_JACOBIAN PENALIZED_ESTIMATOR VERBOSE 
171
172
%token SIMULATION_MULTIPLE MOM_SEED SEED BOUNDED_SHOCK_SUPPORT ADDITIONAL_OPTIMIZER_STEPS MOM_SE_TOLX SE_TOLX MOM_BURNIN BURNIN 
%token EQTAGS STEADY_STATE_GROWTH
173
%token ANALYTICAL_GIRF IRF_IN_PERCENT EMAS_GIRF EMAS_DROP EMAS_TOLF EMAS_MAX_ITER
174
175
176
%token NO_IDENTIFICATION_STRENGTH NO_IDENTIFICATION_REDUCEDFORM NO_IDENTIFICATION_MOMENTS
%token NO_IDENTIFICATION_MINIMAL NO_IDENTIFICATION_SPECTRUM NORMALIZE_JACOBIANS GRID_NBR
%token TOL_RANK TOL_DERIV TOL_SV CHECKS_VIA_SUBSETS MAX_DIM_SUBSETS_GROUPS
177
%token MAX_NROWS SQUEEZE_SHOCK_DECOMPOSITION WITH_EPILOGUE
178

179
180
181
182
183
%token <vector<string>> SYMBOL_VEC

%type <expr_t> expression expression_or_empty
%type <expr_t> equation hand_side
%type <string> non_negative_number signed_number signed_integer date_str
184
%type <string> filename symbol namespace_qualified_filename namespace_qualified_symbol
185
%type <string> vec_of_vec_value vec_value_list date_expr
186
187
%type <string> vec_value_1 vec_value signed_inf signed_number_w_inf
%type <string> range vec_value_w_inf vec_value_1_w_inf
188
%type <string> integer_range signed_integer_range boolean
189
%type <string> sub_sampling_options list_sub_sampling_option
190
191
192
193
194
%type <SymbolType> change_type_arg
%type <vector<string>> vec_str vec_str_1
%type <vector<string>> change_type_var_list
%type <vector<int>> vec_int_elem vec_int_1 vec_int vec_int_number
%type <PriorDistributions> prior_pdf prior_distribution
195
196
%type <pair<expr_t,expr_t>> calibration_range
%type <pair<string,string>> named_var_elem subsamples_eq_opt integer_range_w_inf
197
198
%type <vector<pair<string,string>>> named_var named_var_1
%type <tuple<string,string,string,string>> prior_eq_opt options_eq_opt
199
%type <vector<expr_t>> matched_moments_list
200
201
202
203
204
205
206
207
%%

%start statement_list;

statement_list : statement
               | statement_list statement
               ;

208
209
210
211
statement : parameters
          | var
          | varexo
          | varexo_det
212
          | predetermined_variables
213
          | model_local_variable
214
          | change_type
215
216
217
          | periods
          | model
          | initval
michel's avatar
michel committed
218
          | initval_file
219
220
221
222
223
224
225
226
227
228
229
230
231
232
          | endval
          | histval
          | init_param
          | shocks
          | mshocks
          | sigma_e
          | steady
          | check
          | simul
          | stoch_simul
          | estimation
          | estimated_params
          | estimated_params_bounds
          | estimated_params_init
233
          | set_time
234
          | data
Houtan Bastani's avatar
Houtan Bastani committed
235
          | epilogue
236
          | var_model
Houtan Bastani's avatar
Houtan Bastani committed
237
          | pac_model
238
          | trend_component_model
239
          | prior
240
          | prior_eq
241
          | subsamples
242
          | subsamples_eq
243
          | options
244
          | options_eq
245
246
          | varobs
          | observation_trends
247
          | filter_initial_state
248
          | varexobs
249
250
251
252
253
          | unit_root_vars
          | dsample
          | rplot
          | optim_weights
          | osr_params
254
          | osr_params_bounds
255
256
257
258
          | osr
          | dynatype
          | dynasave
          | model_comparison
259
          | model_info
260
          | planner_objective
261
          | ramsey_model
262
          | ramsey_policy
263
          | ramsey_constraints
264
          | evaluate_planner_objective
265
          | discretionary_policy
266
267
          | bvar_density
          | bvar_forecast
268
          | sbvar
269
270
          | dynare_sensitivity
          | homotopy_setup
271
          | forecast
272
273
          | load_params_and_steady_state
          | save_params_and_steady_state
sebastien's avatar
sebastien committed
274
          | identification
275
276
          | write_latex_dynamic_model
          | write_latex_static_model
277
          | write_latex_original_model
278
          | write_latex_steady_state_model
279
          | shock_decomposition
280
          | realtime_shock_decomposition
281
          | plot_shock_decomposition
282
          | initial_condition_decomposition
283
          | squeeze_shock_decomposition
284
285
286
          | conditional_forecast
          | conditional_forecast_paths
          | plot_conditional_forecast
287
          | svar_identification
288
          | svar_global_identification_check
289
290
          | markov_switching
          | svar
291
          | external_function
292
          | steady_state_model
293
          | trend_var
294
          | generate_irfs
295
          | log_trend_var
Houtan Bastani's avatar
Houtan Bastani committed
296
297
298
299
300
301
302
          | ms_estimation
          | ms_simulation
          | ms_compute_mdd
          | ms_compute_probabilities
          | ms_forecast
          | ms_irf
          | ms_variance_decomposition
303
          | calib_smoother
304
          | extended_path
305
          | model_diagnostics
306
307
          | moment_calibration
          | irf_calibration
308
309
          | smoother2histval
          | histval_file
310
311
          | perfect_foresight_setup
          | perfect_foresight_solver
312
313
          | prior_function
          | posterior_function
314
          | method_of_moments
315
          | shock_groups
Houtan Bastani's avatar
Houtan Bastani committed
316
          | init2shocks
317
          | var_expectation_model
Houtan Bastani's avatar
Houtan Bastani committed
318
          | compilation_setup
319
          | matched_moments
320
321
322
323
324
325
326
327
          ;

dsample : DSAMPLE INT_NUMBER ';'
          { driver.dsample($2); }
        | DSAMPLE INT_NUMBER INT_NUMBER ';'
          { driver.dsample($2, $3); }
        ;

328
rplot : RPLOT symbol_list ';' { driver.rplot(); };
329

330
331
332
333
334
trend_var : TREND_VAR '(' GROWTH_FACTOR EQUAL { driver.begin_trend(); } hand_side ')' trend_var_list ';'
            { driver.end_trend_var($6); }
          ;

trend_var_list : trend_var_list symbol
335
                 { driver.declare_trend_var(false, $2); }
336
               | trend_var_list COMMA symbol
337
                 { driver.declare_trend_var(false, $3); }
338
               | symbol
339
                 { driver.declare_trend_var(false, $1); }
340
               | trend_var_list symbol TEX_NAME
341
                 { driver.declare_trend_var(false, $2, $3); }
342
               | trend_var_list COMMA symbol TEX_NAME
343
                 { driver.declare_trend_var(false, $3, $4); }
344
               | symbol TEX_NAME
345
                 { driver.declare_trend_var(false, $1, $2); }
346
347
               ;

348
log_trend_var : LOG_TREND_VAR '(' LOG_GROWTH_FACTOR EQUAL { driver.begin_trend(); } hand_side ')' log_trend_var_list ';'
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
                { driver.end_trend_var($6); }
              ;

log_trend_var_list : log_trend_var_list symbol
                     { driver.declare_trend_var(true, $2); }
                   | log_trend_var_list COMMA symbol
                     { driver.declare_trend_var(true, $3); }
                   | symbol
                     { driver.declare_trend_var(true, $1); }
                   | log_trend_var_list symbol TEX_NAME
                     { driver.declare_trend_var(true, $2, $3); }
                   | log_trend_var_list COMMA symbol TEX_NAME
                     { driver.declare_trend_var(true, $3, $4); }
                   | symbol TEX_NAME
                     { driver.declare_trend_var(true, $1, $2); }
                   ;

366
367
var : VAR var_list ';'
    | VAR '(' DEFLATOR EQUAL { driver.begin_trend(); } hand_side ')' nonstationary_var_list ';'
368
369
370
      { driver.end_nonstationary_var(false, $6); }
    | VAR '(' LOG_DEFLATOR EQUAL { driver.begin_trend(); } hand_side ')' nonstationary_var_list ';'
      { driver.end_nonstationary_var(true, $6); }
371
372
    ;

373
374
375
var_model : VAR_MODEL '(' var_model_options_list ')' ';' { driver.var_model(); }
          | VAR_MODEL '(' var_model_options_list ')' var_symbol_list ';' { driver.var_model(); } ;
          ;
376
377
378
379
380
381
382
383

var_symbol_list : var_symbol_list symbol
                  { driver.declare_var_endogenous($2); }
                | var_symbol_list COMMA symbol
                  { driver.declare_var_endogenous($3); }
                | symbol
                  { driver.declare_var_endogenous($1); }
                ;
384
385

var_model_options_list : var_model_options_list COMMA var_model_options
Houtan Bastani's avatar
Houtan Bastani committed
386
387
                       | var_model_options
                       ;
388
389
390

var_model_options : o_var_name
                  | o_var_order
391
                  | o_var_eq_tags
392
393
                  ;

394
395
396
397
398
399
400
401
trend_component_model : TREND_COMPONENT_MODEL '('  trend_component_model_options_list ')' ';' { driver.trend_component_model(); }
                      ;

trend_component_model_options_list : trend_component_model_options_list COMMA trend_component_model_options
                                   | trend_component_model_options
                                   ;

trend_component_model_options : o_trend_component_model_name
402
                              | o_trend_component_model_targets
403
404
405
                              | o_trend_component_model_eq_tags
                              ;

406
pac_model : PAC_MODEL '(' { driver.begin_pac_model(); } pac_model_options_list ')' ';' { driver.pac_model(); };
Houtan Bastani's avatar
Houtan Bastani committed
407
408
409
410
411
412

pac_model_options_list : pac_model_options_list COMMA pac_model_options
                       | pac_model_options
                       ;

pac_model_options : o_pac_name
413
                  | o_pac_aux_model_name
Houtan Bastani's avatar
Houtan Bastani committed
414
415
                  | o_pac_discount
                  | o_pac_growth
416
                  | o_pac_steady_state_growth
Houtan Bastani's avatar
Houtan Bastani committed
417
418
                  ;

419
420
421
422
423
424
425
426
427
428
429
var_expectation_model : VAR_EXPECTATION_MODEL '(' var_expectation_model_options_list ')' ';'
                        { driver.var_expectation_model(); }
                      ;

var_expectation_model_options_list : var_expectation_model_option
                                   | var_expectation_model_options_list COMMA var_expectation_model_option
                                   ;


var_expectation_model_option : VARIABLE EQUAL symbol
                               { driver.option_str("variable", $3); }
430
431
432
433
434
                             | EXPRESSION EQUAL { driver.begin_model(); } hand_side
                               {
                                 driver.var_expectation_model_expression = $4;
                                 driver.reset_data_tree();
                               }
435
436
                             | AUXILIARY_MODEL_NAME EQUAL symbol
                               { driver.option_str("auxiliary_model_name", $3); }
437
438
439
440
441
442
443
444
445
446
                             | HORIZON EQUAL INT_NUMBER
                               { driver.option_num("horizon", $3); }
                             | HORIZON EQUAL integer_range_w_inf
                               { driver.option_num("horizon", "[ " + $3.first + ' ' + $3.second + " ]"); }
                             | MODEL_NAME EQUAL symbol
                               { driver.option_str("model_name", $3); }
                             | DISCOUNT EQUAL expression
                               { driver.var_expectation_model_discount = $3; }
                             ;

447
448
449
450
451
452
nonstationary_var_list : nonstationary_var_list symbol
                         { driver.declare_nonstationary_var($2); }
                       | nonstationary_var_list COMMA symbol
                         { driver.declare_nonstationary_var($3); }
                       | symbol
                         { driver.declare_nonstationary_var($1); }
453
                       |  nonstationary_var_list symbol named_var
454
                         { driver.declare_nonstationary_var($2, "", $3); }
455
                       | nonstationary_var_list COMMA symbol named_var
456
                         { driver.declare_nonstationary_var($3, "", $4); }
457
                       | symbol named_var
458
                         { driver.declare_nonstationary_var($1, "", $2); }
459
460
461
462
463
464
                       | nonstationary_var_list symbol TEX_NAME
                         { driver.declare_nonstationary_var($2, $3); }
                       | nonstationary_var_list COMMA symbol TEX_NAME
                         { driver.declare_nonstationary_var($3, $4); }
                       | symbol TEX_NAME
                         { driver.declare_nonstationary_var($1, $2); }
465
466
467
468
469
470
                       | nonstationary_var_list symbol TEX_NAME named_var
                         { driver.declare_nonstationary_var($2, $3, $4); }
                       | nonstationary_var_list COMMA symbol TEX_NAME named_var
                         { driver.declare_nonstationary_var($3, $4, $5); }
                       | symbol TEX_NAME named_var
                         { driver.declare_nonstationary_var($1, $2, $3); }
471
                       ;
472

Houtan Bastani's avatar
Houtan Bastani committed
473
474
varexo : VAREXO varexo_list ';'
       ;
475
476
477

varexo_det : VAREXO_DET varexo_det_list ';';

478
479
predetermined_variables : PREDETERMINED_VARIABLES predetermined_variables_list ';';

480
parameters : PARAMETERS parameter_list ';';
Houtan Bastani's avatar
Houtan Bastani committed
481
           ;
482

483
484
model_local_variable : MODEL_LOCAL_VARIABLE model_local_variable_list ';';

485
named_var_elem : symbol EQUAL QUOTED_STRING
486
                 { $$ = { $1, $3 }; }
487
488

named_var_1 : '(' named_var_elem
489
              { $$ = vector<pair<string, string>>{$2}; }
490
            | '(' COMMA named_var_elem
491
              { $$ = vector<pair<string, string>>{$3}; }
492
493
494
            | named_var_1 named_var_elem
              {
                $$ = $1;
495
                $$.push_back($2);
496
497
498
499
              }
            | named_var_1 COMMA named_var_elem
              {
                $$ = $1;
500
                $$.push_back($3);
501
502
503
              }
            ;

504
505
named_var : named_var_1 ')'
          | named_var_1 COMMA ')'
506
507
          ;

508
var_list : var_list symbol
509
           { driver.declare_endogenous($2); }
510
         | var_list COMMA symbol
511
           { driver.declare_endogenous($3); }
512
         | symbol
513
           { driver.declare_endogenous($1); }
514
         | var_list symbol named_var
515
           { driver.declare_endogenous($2, "", $3); }
516
         | var_list COMMA symbol named_var
517
           { driver.declare_endogenous($3, "", $4); }
518
         | symbol named_var
519
           { driver.declare_endogenous($1, "", $2); }
520
         | var_list symbol TEX_NAME
521
           { driver.declare_endogenous($2, $3); }
522
         | var_list COMMA symbol TEX_NAME
523
           { driver.declare_endogenous($3, $4); }
524
         | symbol TEX_NAME
525
           { driver.declare_endogenous($1, $2); }
526
527
528
529
530
531
         | var_list symbol TEX_NAME named_var
           { driver.declare_endogenous($2, $3, $4); }
         | var_list COMMA symbol TEX_NAME named_var
           { driver.declare_endogenous($3, $4, $5); }
         | symbol TEX_NAME named_var
           { driver.declare_endogenous($1, $2, $3); }
532
533
         ;

534
varexo_list : varexo_list symbol
535
              { driver.declare_exogenous($2); }
536
            | varexo_list COMMA symbol
537
              { driver.declare_exogenous($3); }
538
            | symbol
539
              { driver.declare_exogenous($1); }
540
            | varexo_list symbol named_var
541
              { driver.declare_exogenous($2, "", $3); }
542
            | varexo_list COMMA symbol named_var
543
              { driver.declare_exogenous($3, "", $4); }
544
            | symbol named_var
545
              { driver.declare_exogenous($1, "", $2); }
546
            | varexo_list symbol TEX_NAME
547
              { driver.declare_exogenous($2, $3); }
548
            | varexo_list COMMA symbol TEX_NAME
549
              { driver.declare_exogenous($3, $4); }
550
            | symbol TEX_NAME
551
              { driver.declare_exogenous($1, $2); }
552
553
554
555
556
557
            | varexo_list symbol TEX_NAME named_var
              { driver.declare_exogenous($2, $3, $4); }
            | varexo_list COMMA symbol TEX_NAME named_var
              { driver.declare_exogenous($3, $4, $5); }
            | symbol TEX_NAME named_var
              { driver.declare_exogenous($1, $2, $3); }
558
559
            ;

560
varexo_det_list : varexo_det_list symbol
561
                  { driver.declare_exogenous_det($2); }
562
                | varexo_det_list COMMA symbol
563
                  { driver.declare_exogenous_det($3); }
564
                | symbol
565
                  { driver.declare_exogenous_det($1); }
566
                | varexo_det_list symbol named_var
567
                  { driver.declare_exogenous_det($2, "", $3); }
568
                | varexo_det_list COMMA symbol named_var
569
                  { driver.declare_exogenous_det($3, "", $4); }
570
                | symbol named_var
571
                  { driver.declare_exogenous_det($1, "", $2); }
572
                | varexo_det_list symbol TEX_NAME
573
                  { driver.declare_exogenous_det($2, $3); }
574
                | varexo_det_list COMMA symbol TEX_NAME
575
                  { driver.declare_exogenous_det($3, $4); }
576
                | symbol TEX_NAME
577
                   { driver.declare_exogenous_det($1, $2); }
578
579
580
581
582
583
                | varexo_det_list symbol TEX_NAME named_var
                  { driver.declare_exogenous_det($2, $3, $4); }
                | varexo_det_list COMMA symbol TEX_NAME named_var
                  { driver.declare_exogenous_det($3, $4, $5); }
                | symbol TEX_NAME named_var
                   { driver.declare_exogenous_det($1, $2, $3); }
584
585
                ;

586
parameter_list : parameter_list symbol
587
                 { driver.declare_parameter($2); }
588
               | parameter_list COMMA symbol
589
                 { driver.declare_parameter($3); }
590
               | symbol
591
                 { driver.declare_parameter($1); }
592
               | parameter_list symbol named_var
593
                 { driver.declare_parameter($2, "", $3); }
594
               | parameter_list COMMA symbol named_var
595
                 { driver.declare_parameter($3, "", $4); }
596
               | symbol named_var
597
                 { driver.declare_parameter($1, "", $2); }
598
               | parameter_list symbol TEX_NAME
599
                 { driver.declare_parameter($2, $3); }
600
               | parameter_list COMMA symbol TEX_NAME
601
                 { driver.declare_parameter($3, $4); }
602
               | symbol TEX_NAME
603
                 { driver.declare_parameter($1, $2); }
604
605
606
607
608
609
               | parameter_list symbol TEX_NAME named_var
                 { driver.declare_parameter($2, $3, $4); }
               | parameter_list COMMA symbol TEX_NAME named_var
                 { driver.declare_parameter($3, $4, $5); }
               | symbol TEX_NAME named_var
                 { driver.declare_parameter($1, $2, $3); }
610
611
               ;

612
613
614
615
616
617
618
619
predetermined_variables_list : predetermined_variables_list symbol
                               { driver.add_predetermined_variable($2); }
                             | predetermined_variables_list COMMA symbol
                               { driver.add_predetermined_variable($3); }
                             | symbol
                               { driver.add_predetermined_variable($1); }
                             ;

620
621
622
623
624
625
626
627
628
629
630
631
632
633
model_local_variable_list : model_local_variable_list symbol
                            { driver.declare_model_local_variable($2); }
                          | model_local_variable_list COMMA symbol
                            { driver.declare_model_local_variable($3); }
                          | symbol
                            { driver.declare_model_local_variable($1); }
                          | model_local_variable_list symbol TEX_NAME
                            { driver.declare_model_local_variable($2, $3); }
                          | model_local_variable_list COMMA symbol TEX_NAME
                            { driver.declare_model_local_variable($3, $4); }
                          | symbol TEX_NAME
                            { driver.declare_model_local_variable($1, $2); }
                          ;

634
635
636
637
638
change_type : CHANGE_TYPE '(' change_type_arg ')' change_type_var_list ';'
              { driver.change_type($3, $5); }
            ;

change_type_arg : PARAMETERS
639
                  { $$ = SymbolType::parameter; }
640
                | VAR
641
                  { $$ = SymbolType::endogenous; }
642
                | VAREXO
643
                  { $$ = SymbolType::exogenous; }
644
                | VAREXO_DET
645
                  { $$ = SymbolType::exogenousDet; }
646
647
                ;

648
change_type_var_list : symbol
649
                       { $$ = vector<string>{$1}; }
650
                     | change_type_var_list symbol
651
652
653
654
                       {
                         $$ = $1;
                         $$.push_back($2);
                       }
655
                     | change_type_var_list COMMA symbol
656
657
658
659
                       {
                         $$ = $1;
                         $$.push_back($3);
                       }
660
661
                     ;

662
663
664
665
666
667
periods : PERIODS INT_NUMBER ';'
          { driver.periods($2); }
        | PERIODS EQUAL INT_NUMBER ';'
          { driver.periods($3); }
        ;

668
init_param : symbol EQUAL expression ';' { driver.init_param($1, $3); };
669
670
671

expression : '(' expression ')'
             { $$ = $2;}
672
           | namespace_qualified_symbol
673
             { $$ = driver.add_expression_variable($1); }
674
675
           | non_negative_number
             { $$ = driver.add_non_negative_constant($1); }
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
           | expression PLUS expression
             { $$ = driver.add_plus($1, $3); }
           | expression MINUS expression
             { $$ = driver.add_minus($1, $3); }
           | expression DIVIDE expression
             { $$ = driver.add_divide($1, $3); }
           | expression TIMES expression
             { $$ = driver.add_times($1, $3); }
           | expression POWER expression
             { $$ = driver.add_power($1, $3); }
           | expression LESS expression
             { $$ = driver.add_less($1, $3); }
           | expression GREATER expression
             { $$ = driver.add_greater($1, $3); }
           | expression LESS_EQUAL expression
             { $$ = driver.add_less_equal($1, $3); }
           | expression GREATER_EQUAL expression
             { $$ = driver.add_greater_equal($1, $3); }
           | expression EQUAL_EQUAL expression
             { $$ = driver.add_equal_equal($1, $3); }
           | expression EXCLAMATION_EQUAL expression
             { $$ = driver.add_different($1, $3); }
698
           | MINUS expression %prec UNARY
699
             { $$ = driver.add_uminus($2); }
700
           | PLUS expression %prec UNARY
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
             { $$ = $2; }
           | EXP '(' expression ')'
             { $$ = driver.add_exp($3); }
           | LOG '(' expression ')'
             { $$ = driver.add_log($3); }
           | LN '(' expression ')'
             { $$ = driver.add_log($3); }
           | LOG10 '(' expression ')'
             { $$ = driver.add_log10($3); }
           | SIN '(' expression ')'
             { $$ = driver.add_sin($3); }
           | COS '(' expression ')'
             { $$ = driver.add_cos($3); }
           | TAN '(' expression ')'
             { $$ = driver.add_tan($3); }
           | ASIN '(' expression ')'
             { $$ = driver.add_asin($3); }
           | ACOS '(' expression ')'
             { $$ = driver.add_acos($3); }
           | ATAN '(' expression ')'
             { $$ = driver.add_atan($3); }
           | SQRT '(' expression ')'
             { $$ = driver.add_sqrt($3); }
724
725
           | CBRT '(' expression ')'
             { $$ = driver.add_cbrt($3); }
726
727
728
729
           | ABS '(' expression ')'
             { $$ = driver.add_abs($3); }
           | SIGN '(' expression ')'
             { $$ = driver.add_sign($3); }
730
           | MAX '(' expression COMMA expression ')'
sebastien's avatar
sebastien committed
731
             { $$ = driver.add_max($3, $5); }
732
           | MIN '(' expression COMMA expression ')'
sebastien's avatar
sebastien committed
733
             { $$ = driver.add_min($3, $5); }
734
           | namespace_qualified_symbol { driver.push_external_function_arg_vector_onto_stack(); } '(' comma_expression ')'
735
             { $$ = driver.add_model_var_or_external_function($1, false); }
736
           | NORMCDF '(' expression COMMA expression COMMA expression ')'
sebastien's avatar
sebastien committed
737
             { $$ = driver.add_normcdf($3, $5, $7); }
738
           | NORMCDF '(' expression ')'
sebastien's avatar
sebastien committed
739
             { $$ = driver.add_normcdf($3); }
740
741
742
743
           | NORMPDF '(' expression COMMA expression COMMA expression ')'
             { $$ = driver.add_normpdf($3, $5, $7); }
           | NORMPDF '(' expression ')'
             { $$ = driver.add_normpdf($3); }
744
745
           | ERF '(' expression ')'
             { $$ = driver.add_erf($3); }
746
747
748
749
           | NAN_CONSTANT
             { $$ = driver.add_nan_constant(); }
           | INF_CONSTANT
             { $$ = driver.add_inf_constant(); }
750
751
752
           ;

comma_expression : expression
753
754
755
                   { driver.add_external_function_arg($1); }
                 | comma_expression COMMA expression
                   { driver.add_external_function_arg($3); }
756
757
                 ;

758
759
expression_or_empty : %empty
                      { $$ = driver.add_nan_constant(); }
760
761
                    | expression
	            ;
michel's avatar
michel committed
762

763
initval : INITVAL ';' initval_list END ';'
764
765
766
767
          { driver.end_initval(false); }
        | INITVAL '(' ALL_VALUES_REQUIRED ')' ';' initval_list END ';'
          { driver.end_initval(true); }
        ;
768

769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
histval_file : HISTVAL_FILE '(' h_options_list ')' ';'
              { driver.histval_file();};

initval_file : INITVAL_FILE '(' h_options_list ')' ';'
              { driver.initval_file();};

h_options_list: h_options_list COMMA h_options
               | h_options
               ;

h_options: o_filename
          | o_datafile
          | o_first_obs
          | o_data_first_obs
          | o_first_simulation_period
          | o_date_first_simulation_period
          | o_last_obs
          | o_data_last_obs
          | o_nobs
          | o_series2
          ;
790

791
792
793
794
795
endval : ENDVAL ';' initval_list END ';'
         { driver.end_endval(false); }
       | ENDVAL '(' ALL_VALUES_REQUIRED ')' ';' initval_list END ';'
         { driver.end_endval(true); }
       ;
796
797
798
799
800

initval_list : initval_list initval_elem
             | initval_elem
             ;

801
initval_elem : symbol EQUAL expression ';' { driver.init_val($1, $3); };
802

803
804
805
806
807
histval : HISTVAL ';' histval_list END ';'
          { driver.end_histval(false); };
        | HISTVAL '(' ALL_VALUES_REQUIRED ')' ';' histval_list END ';'
          { driver.end_histval(true); }
        ;
808
809
810
811
812

histval_list : histval_list histval_elem
             | histval_elem
             ;

813
histval_elem : symbol '(' signed_integer ')' EQUAL expression ';' { driver.hist_val($1, $3, $6); };
814

Houtan Bastani's avatar
Houtan Bastani committed
815
816
817
818
819
820
821
822
epilogue : EPILOGUE ';' { driver.begin_epilogue(); }
           epilogue_equation_list END ';' { driver.end_epilogue(); }
         ;

epilogue_equation_list : epilogue_equation_list epilogue_equation
                       | epilogue_equation
                       ;

823
824
epilogue_equation : NAME { driver.add_epilogue_variable($1); } EQUAL expression ';'
                    { driver.add_epilogue_equal($1, $4); }
Houtan Bastani's avatar
Houtan Bastani committed
825
826
                  ;

Houtan Bastani's avatar
Houtan Bastani committed
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
compilation_setup : COMPILATION_SETUP '(' compilation_setup_options_list ')' ';' { };

compilation_setup_options_list : compilation_setup_options_list COMMA compilation_setup_option
                               | compilation_setup_option
                               ;

compilation_setup_option : SUBSTITUTE_FLAGS EQUAL QUOTED_STRING
                           { driver.compilation_setup_substitute_flags($3); }
                         | ADD_FLAGS EQUAL QUOTED_STRING
                           { driver.compilation_setup_add_flags($3); }
                         | SUBSTITUTE_LIBS EQUAL QUOTED_STRING
                           { driver.compilation_setup_substitute_libs($3); }
                         | ADD_LIBS EQUAL QUOTED_STRING
                           { driver.compilation_setup_add_libs($3); }
                         | COMPILER EQUAL QUOTED_STRING
                           { driver.compilation_setup_compiler($3); }
                         ;

845
846
847
848
849
850
851
852
853
854
855
856
857
matched_moments : MATCHED_MOMENTS ';' { driver.begin_matched_moments(); }
                  matched_moments_list END ';' { driver.end_matched_moments($4); }
                ;

matched_moments_list : hand_side ';'
                       { $$ = { $1 }; }
                     | matched_moments_list hand_side ';'
                       {
                         $$ = $1;
                         $$.push_back($2);
                       }
                     ;

858
859
model_options : BLOCK { driver.block(); }
              | o_cutoff
860
              | o_mfs
861
              | BYTECODE { driver.bytecode(); }
862
              | USE_DLL { driver.use_dll(); }
863
              | NO_STATIC { driver.no_static();}
864
865
              | DIFFERENTIATE_FORWARD_VARS { driver.differentiate_forward_vars_all(); }
              | DIFFERENTIATE_FORWARD_VARS EQUAL '(' symbol_list ')' { driver.differentiate_forward_vars_some(); }
866
              | o_linear
867
              | PARALLEL_LOCAL_FILES EQUAL '(' parallel_local_filename_list ')'
868
              | BALANCED_GROWTH_TEST_TOL EQUAL non_negative_number { driver.balanced_growth_test_tol($3); }
869
870
871
872
873
              ;

model_options_list : model_options_list COMMA model_options
                   | model_options
                   ;
874
875

model : MODEL ';' { driver.begin_model(); }
876
        equation_list END ';' { driver.end_model(); }
877
      | MODEL '(' model_options_list ')' ';' { driver.begin_model(); }
878
        equation_list END ';' { driver.end_model(); }
879
880
881
882
883
884
885
886
887
888
889
890
      ;

equation_list : equation_list equation
              | equation_list pound_expression
              | equation
              | pound_expression
              ;

equation : hand_side EQUAL hand_side ';'
           { $$ = driver.add_model_equal($1, $3); }
         | hand_side ';'
           { $$ = driver.add_model_equal_with_zero_rhs($1); }
891
892
893
894
895
896
897
898
899
900
901
902
         | '[' tags_list ']' hand_side EQUAL hand_side ';'
           { $$ = driver.add_model_equal($4, $6); }
         | '[' tags_list ']' hand_side ';'
           { $$ = driver.add_model_equal_with_zero_rhs($4); }
         ;

tags_list : tags_list COMMA tag_pair
          | tag_pair
          ;

tag_pair : NAME EQUAL QUOTED_STRING
           { driver.add_equation_tags($1, $3); }
903
         | NAME
904
           { driver.add_equation_tags($1, ""); }
905
906
907
908
         ;

hand_side : '(' hand_side ')'
            { $$ = $2;}
909
          | namespace_qualified_symbol
910
            { $$ = driver.add_model_variable($1); }
911
          | symbol PIPE_E
912
            { $$ = driver.declare_or_change_type(SymbolType::endogenous, $1); }
913
          | symbol PIPE_X
914
            { $$ = driver.declare_or_change_type(SymbolType::exogenous, $1); }
915
          | symbol PIPE_P
916
            { $$ = driver.declare_or_change_type(SymbolType::parameter, $1); }
917
918
          | non_negative_number
            { $$ = driver.add_non_negative_constant($1); }
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
          | hand_side PLUS hand_side
            { $$ = driver.add_plus($1, $3); }
          | hand_side MINUS hand_side
            { $$ = driver.add_minus($1, $3); }
          | hand_side DIVIDE hand_side
            { $$ = driver.add_divide($1, $3); }
          | hand_side TIMES hand_side
            { $$ = driver.add_times($1, $3); }
          | hand_side LESS hand_side
            { $$ = driver.add_less($1, $3); }
          | hand_side GREATER hand_side
            { $$ = driver.add_greater($1, $3); }
          | hand_side LESS_EQUAL hand_side
            { $$ = driver.add_less_equal($1, $3); }
          | hand_side GREATER_EQUAL hand_side
            { $$ = driver.add_greater_equal($1, $3); }
          | hand_side EQUAL_EQUAL hand_side
            { $$ = driver.add_equal_equal($1, $3); }
          | hand_side EXCLAMATION_EQUAL hand_side
            { $$ = driver.add_different($1, $3); }
          | hand_side POWER hand_side
            { $$ = driver.add_power($1, $3); }
941
          | EXPECTATION '(' signed_integer ')''(' hand_side ')'
942
	    { $$ = driver.add_expectation($3, $6); }
943
944
          | VAR_EXPECTATION '(' symbol ')'
            { $$ = driver.add_var_expectation($3); }
Houtan Bastani's avatar
Houtan Bastani committed
945
946
          | PAC_EXPECTATION '(' symbol ')'
            { $$ = driver.add_pac_expectation($3); }
947
          | MINUS hand_side %prec UNARY
948
            { $$ = driver.add_uminus($2); }
949
          | PLUS hand_side %prec UNARY
950
951
952
            { $$ = $2; }
          | EXP '(' hand_side ')'
            { $$ = driver.add_exp($3); }
953
954
955
          | DIFF '(' hand_side ')'
            { $$ = driver.add_diff($3); }
          | ADL '(' hand_side COMMA QUOTED_STRING ')'
956
            { $$ = driver.add_adl($3, $5, "1"); }
957
958
          | ADL '(' hand_side COMMA QUOTED_STRING COMMA INT_NUMBER ')'
            { $$ = driver.add_adl($3, $5, $7); }
959
960
          | ADL '(' hand_side COMMA QUOTED_STRING COMMA vec_int ')'
            { $$ = driver.add_adl($3, $5, $7); }
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
          | LOG '(' hand_side ')'
            { $$ = driver.add_log($3); }
          | LN '(' hand_side ')'
            { $$ = driver.add_log($3); }
          | LOG10 '(' hand_side ')'
            { $$ = driver.add_log10($3); }
          | SIN '(' hand_side ')'
            { $$ = driver.add_sin($3); }
          | COS '(' hand_side ')'
            { $$ = driver.add_cos($3); }
          | TAN '(' hand_side ')'
            { $$ = driver.add_tan($3); }
          | ASIN '(' hand_side ')'
            { $$ = driver.add_asin($3); }
          | ACOS '(' hand_side ')'
            { $$ = driver.add_acos($3); }
          | ATAN '(' hand_side ')'
            { $$ = driver.add_atan($3); }
          | SQRT '(' hand_side ')'
            { $$ = driver.add_sqrt($3); }
Houtan Bastani's avatar
Houtan Bastani committed
981
982
          | CBRT '(' hand_side ')'
             { $$ = driver.add_cbrt($3); }
983
984
985
986
          | ABS '(' hand_side ')'
            { $$ = driver.add_abs($3); }
          | SIGN '(' hand_side ')'
            { $$ = driver.add_sign($3); }
987
          | MAX '(' hand_side COMMA hand_side ')'