DynareBison.yy 121 KB
Newer Older
sebastien's avatar
sebastien committed
1
/*
2
 * Copyright (C) 2003-2013 Dynare Team
sebastien's avatar
sebastien committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * 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/>.
 */

20
21
22
23
%skeleton "lalr1.cc"
%require "2.3"
%defines

24
25
26
27
28
29
/* Prologue:
   In Bison <= 2.3, it is inserted in both the .cc and .hh files.
   In Bison >= 2.3a, it is inserted only in the .cc file.
   Since Bison 2.4, the new %code directives provide a cleaner way of dealing
   with the prologue.
*/
30
%{
31
using namespace std;
32
33

class ParsingDriver;
34

sebastien's avatar
sebastien committed
35
#include "ExprNode.hh"
36
#include "CodeInterpreter.hh"
sebastien's avatar
sebastien committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

/* 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 = (Rhs)[1].begin;               \
        (Current).end   = (Rhs)[N].end;                 \
      }                                                 \
    else                                                \
      {                                                 \
        (Current).begin = (Current).end = (Rhs)[0].end;	\
      }                                                 \
    driver.location = (Current);                        \
  } while(false)

55
56
%}

57
58
%name-prefix="Dynare"

59
60
%parse-param { ParsingDriver &driver }
%lex-param { ParsingDriver &driver }
61
62

%locations
63
64
%initial-action
{
65
66
  // Initialize the locations' filenames to the filename maintained by the lexer
  @$.begin.filename = @$.end.filename = &(driver.lexer->filename);
67
}
68
69
70
71
72
73

%debug
%error-verbose

%union
{
74
  string *string_val;
75
  expr_t node_val;
76
77
  SymbolType symbol_type_val;
  vector<string *> *vector_string_val;
78
  vector<int> *vector_int_val;
79
  PriorDistributions prior_distributions_val;
80
81
};

michel's avatar
michel committed
82
%{
83
#include "ParsingDriver.hh"
84
85
86
87
88
89

/* 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
michel's avatar
michel committed
90
%}
91

92
%token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR
93
%token BAYESIAN_IRF BETA_PDF BLOCK
94
95
96
%token BVAR_DENSITY BVAR_FORECAST
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
97
%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED
98
%token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION
99
%token DATAFILE FILE DETERMINISTIC DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS
100
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR
101
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME
102
%token <string_val> FLOAT_NUMBER
103
%token DEFAULT FIXED_POINT
104
%token FORECAST K_ORDER_SOLVER INSTRUMENTS SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN
105
%token GAMMA_PDF GRAPH GRAPH_FORMAT CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK STD
106
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID HYBRID
107
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT
108
%token <string_val> INT_NUMBER
109
%token <string_val> DATE_NUMBER
110
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS
111
%token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF
112
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LYAPUNOV
113
%token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT
114
%token MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN MINIMAL_SOLVING_PERIODS
115
%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
116
%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL MCMC_JUMPING_COVARIANCE
117
%token <string_val> NAME
118
%token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS
119
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS
120
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED
121
%token PARALLEL_LOCAL_FILES PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERFECT_FORESIGHT PERIODS PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE
122
%token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN PRUNING
sebastien's avatar
trunk:    
sebastien committed
123
%token <string_val> QUOTED_STRING
124
%token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE
125
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY
126
127
128
%token SHOCKS SHOCK_DECOMPOSITION SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SIMULATION_TYPE
%token SMOOTHER SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL STOCHASTIC SOLVE_ALGO SOLVER_PERIODS
%token STDERR STEADY STOCH_SIMUL SURPRISE SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME
129
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL
130
%token <string_val> TEX_NAME
131
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED
132
%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES
133
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL
134
%token XLS_SHEET XLS_RANGE
135
%left COMMA
136
137
%left EQUAL_EQUAL EXCLAMATION_EQUAL
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
138
139
%left PLUS MINUS
%left TIMES DIVIDE
140
%left UMINUS UPLUS
141
%nonassoc POWER
142
%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH ERF
143
%token ASINH ACOSH ATANH SQRT NORMCDF NORMPDF STEADY_STATE EXPECTATION
144
/* GSA analysis */
145
%token DYNARE_SENSITIVITY MORRIS STAB REDFORM PPRIOR PRIOR_RANGE PPOST ILPTAU MORRIS_NLIV
146
147
%token MORRIS_NTRA NSAM LOAD_REDFORM LOAD_RMSE LOAD_STAB ALPHA2_STAB KSSTAT LOGTRANS_REDFORM THRESHOLD_REDFORM
%token KSSTAT_REDFORM ALPHA2_REDFORM NAMENDO NAMLAGENDO NAMEXO RMSE LIK_ONLY VAR_RMSE PFILT_RMSE ISTART_RMSE
148
%token ALPHA_RMSE ALPHA2_RMSE
149
/* end of GSA analysis*/
Houtan Bastani's avatar
Houtan Bastani committed
150
%token FREQ INITIAL_YEAR INITIAL_SUBPERIOD FINAL_YEAR FINAL_SUBPERIOD DATA VLIST LOG_VAR PERCENT_VAR
michel's avatar
michel committed
151
%token VLISTLOG VLISTPER
152
%token RESTRICTION RESTRICTION_FNAME CROSS_RESTRICTIONS NLAGS CONTEMP_REDUCED_FORM REAL_PSEUDO_FORECAST
153
%token DUMMY_OBS NSTATES INDXSCALESSTATES NO_BAYESIAN_PRIOR SPECIFICATION SIMS_ZHA
154
%token <string_val> 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
Houtan Bastani's avatar
Houtan Bastani committed
155
%token GSIG2_LMDM Q_DIAG FLAT_PRIOR NCSK NSTD
156
%token INDXPARR INDXOVR INDXAP APBAND INDXIMF IMFBAND INDXFORE FOREBAND INDXGFOREHAT INDXGIMFHAT
157
%token INDXESTIMA INDXGDLS EQ_MS FILTER_COVARIANCE FILTER_DECOMPOSITION
158
%token EQ_CMS TLINDX TLNUMBER BANACT RESTRICTIONS
159
%token OUTPUT_FILE_TAG DRAWS_NBR_BURN_IN_1 DRAWS_NBR_BURN_IN_2 HORIZON
Houtan Bastani's avatar
Houtan Bastani committed
160
161
%token SBVAR TREND_VAR DEFLATOR GROWTH_FACTOR MS_IRF MS_VARIANCE_DECOMPOSITION
%token MS_ESTIMATION MS_SIMULATION MS_COMPUTE_MDD MS_COMPUTE_PROBABILITIES MS_FORECAST
162
%token SVAR_IDENTIFICATION EQUATION EXCLUSION LAG UPPER_CHOLESKY LOWER_CHOLESKY MONTHLY QUARTERLY
163
%token MARKOV_SWITCHING CHAIN DURATION NUMBER_OF_REGIMES
164
%token SVAR COEFF COEFFICIENTS VARIANCES CONSTANTS EQUATIONS
165
%token EXTERNAL_FUNCTION EXT_FUNC_NAME EXT_FUNC_NARGS FIRST_DERIV_PROVIDED SECOND_DERIV_PROVIDED
166
%token SELECTED_VARIABLES_ONLY COVA_COMPUTE SIMULATION_FILE_TAG FILE_TAG
167
%token NO_ERROR_BANDS ERROR_BAND_PERCENTILES SHOCKS_PER_PARAMETER NO_CREATE_INIT
168
%token SHOCK_DRAWS FREE_PARAMETERS MEDIAN DATA_OBS_NBR NEIGHBORHOOD_WIDTH PVALUE_KS PVALUE_CORR
169
%token FILTERED_PROBABILITIES REAL_TIME_SMOOTHED
Houtan Bastani's avatar
Houtan Bastani committed
170
%token PROPOSAL_TYPE PROPOSAL_UPPER_BOUND PROPOSAL_LOWER_BOUND PROPOSAL_DRAWS USE_MEAN_CENTER
Houtan Bastani's avatar
Houtan Bastani committed
171
172
173
174
175
176
177
%token ADAPTIVE_MH_DRAWS THINNING_FACTOR COEFFICIENTS_PRIOR_HYPERPARAMETERS
%token CONVERGENCE_STARTING_VALUE CONVERGENCE_ENDING_VALUE CONVERGENCE_INCREMENT_VALUE
%token MAX_ITERATIONS_STARTING_VALUE MAX_ITERATIONS_INCREMENT_VALUE MAX_BLOCK_ITERATIONS
%token MAX_REPEATED_OPTIMIZATION_RUNS FUNCTION_CONVERGENCE_CRITERION
%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
178

michel's avatar
michel committed
179
%type <node_val> expression expression_or_empty
180
%type <node_val> equation hand_side
181
%type <string_val> non_negative_number signed_number signed_integer date_number
182
%type <string_val> filename symbol vec_of_vec_value vec_value_list
183
%type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf
184
%type <string_val> range vec_value_w_inf vec_value_1_w_inf
185
%type <symbol_type_val> change_type_arg
186
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt
187
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
188
%type <prior_distributions_val> prior_pdf prior_distribution
michel's avatar
michel committed
189
190
%%

191
192
%start statement_list;

193
194
195
196
statement_list : statement
               | statement_list statement
               ;

197
198
199
200
statement : parameters
          | var
          | varexo
          | varexo_det
201
          | predetermined_variables
202
          | change_type
203
204
205
          | periods
          | model
          | initval
michel's avatar
michel committed
206
          | initval_file
207
208
209
210
211
212
213
214
215
216
217
218
219
220
          | endval
          | histval
          | init_param
          | shocks
          | mshocks
          | sigma_e
          | steady
          | check
          | simul
          | stoch_simul
          | estimation
          | estimated_params
          | estimated_params_bounds
          | estimated_params_init
221
          | set_time
222
          | data
223
          | prior
224
          | prior_eq
225
          | subsamples
226
          | subsamples_eq
227
          | options
228
          | options_eq
229
230
231
232
233
234
235
236
237
238
239
          | varobs
          | observation_trends
          | unit_root_vars
          | dsample
          | rplot
          | optim_weights
          | osr_params
          | osr
          | dynatype
          | dynasave
          | model_comparison
240
          | model_info
241
242
          | planner_objective
          | ramsey_policy
243
          | discretionary_policy
244
245
          | bvar_density
          | bvar_forecast
246
          | sbvar
247
          | dynare_sensitivity
248
          | homotopy_setup
249
          | forecast
250
251
          | load_params_and_steady_state
          | save_params_and_steady_state
sebastien's avatar
sebastien committed
252
          | identification
253
254
          | write_latex_dynamic_model
          | write_latex_static_model
255
          | shock_decomposition
256
257
258
          | conditional_forecast
          | conditional_forecast_paths
          | plot_conditional_forecast
259
260
261
          | svar_identification
          | markov_switching
          | svar
262
          | external_function
263
          | steady_state_model
264
          | trend_var
265
          | log_trend_var
Houtan Bastani's avatar
Houtan Bastani committed
266
267
268
269
270
271
272
          | ms_estimation
          | ms_simulation
          | ms_compute_mdd
          | ms_compute_probabilities
          | ms_forecast
          | ms_irf
          | ms_variance_decomposition
273
          | calib_smoother
274
          | extended_path
275
          | model_diagnostics
276
277
278
279
280
281
          ;

dsample : DSAMPLE INT_NUMBER ';'
          { driver.dsample($2); }
        | DSAMPLE INT_NUMBER INT_NUMBER ';'
          { driver.dsample($2, $3); }
michel's avatar
michel committed
282
283
        ;

284
rplot : RPLOT symbol_list ';' { driver.rplot(); };
285

286
287
288
289
290
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
291
                 { driver.declare_trend_var(false, $2); }
292
               | trend_var_list COMMA symbol
293
                 { driver.declare_trend_var(false, $3); }
294
               | symbol
295
                 { driver.declare_trend_var(false, $1); }
296
               | trend_var_list symbol TEX_NAME
297
                 { driver.declare_trend_var(false, $2, $3); }
298
               | trend_var_list COMMA symbol TEX_NAME
299
                 { driver.declare_trend_var(false, $3, $4); }
300
               | symbol TEX_NAME
301
                 { driver.declare_trend_var(false, $1, $2); }
302
303
               ;

304
log_trend_var : LOG_TREND_VAR '(' LOG_GROWTH_FACTOR EQUAL { driver.begin_trend(); } hand_side ')' log_trend_var_list ';'
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
                { 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); }
                   ;

322
323
var : VAR var_list ';'
    | VAR '(' DEFLATOR EQUAL { driver.begin_trend(); } hand_side ')' nonstationary_var_list ';'
324
325
326
      { driver.end_nonstationary_var(false, $6); }
    | VAR '(' LOG_DEFLATOR EQUAL { driver.begin_trend(); } hand_side ')' nonstationary_var_list ';'
      { driver.end_nonstationary_var(true, $6); }
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
    ;

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); }
                       | 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); }
                       ;
342
343
344
345
346

varexo : VAREXO varexo_list ';';

varexo_det : VAREXO_DET varexo_det_list ';';

347
348
predetermined_variables : PREDETERMINED_VARIABLES predetermined_variables_list ';';

349
350
parameters : PARAMETERS parameter_list ';';

351
var_list : var_list symbol
352
           { driver.declare_endogenous($2); }
353
         | var_list COMMA symbol
354
           { driver.declare_endogenous($3); }
355
         | symbol
356
           { driver.declare_endogenous($1); }
357
         | var_list symbol TEX_NAME
358
           { driver.declare_endogenous($2, $3); }
359
         | var_list COMMA symbol TEX_NAME
360
           { driver.declare_endogenous($3, $4); }
361
         | symbol TEX_NAME
362
           { driver.declare_endogenous($1, $2); }
363
         ;
michel's avatar
michel committed
364

365
varexo_list : varexo_list symbol
366
              { driver.declare_exogenous($2); }
367
            | varexo_list COMMA symbol
368
              { driver.declare_exogenous($3); }
369
            | symbol
370
              { driver.declare_exogenous($1); }
371
            | varexo_list symbol TEX_NAME
372
              { driver.declare_exogenous($2, $3); }
373
            | varexo_list COMMA symbol TEX_NAME
374
              { driver.declare_exogenous($3, $4); }
375
            | symbol TEX_NAME
376
377
              { driver.declare_exogenous($1, $2); }
            ;
michel's avatar
michel committed
378

379
varexo_det_list : varexo_det_list symbol
380
                  { driver.declare_exogenous_det($2); }
381
                | varexo_det_list COMMA symbol
382
                  { driver.declare_exogenous_det($3); }
383
                | symbol
384
                  { driver.declare_exogenous_det($1); }
385
                | varexo_det_list symbol TEX_NAME
386
                  { driver.declare_exogenous_det($2, $3); }
387
                | varexo_det_list COMMA symbol TEX_NAME
388
                  { driver.declare_exogenous_det($3, $4); }
389
                | symbol TEX_NAME
390
391
                   { driver.declare_exogenous_det($1, $2); }
                ;
392

393
parameter_list : parameter_list symbol
394
                 { driver.declare_parameter($2); }
395
               | parameter_list COMMA symbol
396
                 { driver.declare_parameter($3); }
397
               | symbol
398
                 { driver.declare_parameter($1); }
399
               | parameter_list symbol TEX_NAME
400
                 { driver.declare_parameter($2, $3); }
401
               | parameter_list COMMA symbol TEX_NAME
402
                 { driver.declare_parameter($3, $4); }
403
               | symbol TEX_NAME
404
405
                 { driver.declare_parameter($1, $2); }
               ;
406

407
408
409
410
411
412
413
414
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); }
                             ;

415
416
417
418
419
420
421
422
423
424
425
426
427
428
change_type : CHANGE_TYPE '(' change_type_arg ')' change_type_var_list ';'
              { driver.change_type($3, $5); }
            ;

change_type_arg : PARAMETERS
                  { $$ = eParameter; }
                | VAR
                  { $$ = eEndogenous; }
                | VAREXO
                  { $$ = eExogenous; }
                | VAREXO_DET
                  { $$ = eExogenousDet; }
                ;

429
change_type_var_list : symbol
430
                       { $$ = new vector<string *>(); $$->push_back($1); }
431
                     | change_type_var_list symbol
432
                       { $$ = $1; $1->push_back($2); }
433
                     | change_type_var_list COMMA symbol
434
435
436
                       { $$ = $1; $1->push_back($3); }
                     ;

437
438
439
440
441
periods : PERIODS INT_NUMBER ';'
          { driver.periods($2); }
        | PERIODS EQUAL INT_NUMBER ';'
          { driver.periods($3); }
        ;
442

443
init_param : symbol EQUAL expression ';' { driver.init_param($1, $3); };
444
445
446

expression : '(' expression ')'
             { $$ = $2;}
447
           | symbol
448
             { $$ = driver.add_expression_variable($1); }
449
450
           | non_negative_number
             { $$ = driver.add_non_negative_constant($1); }
451
452
453
454
455
456
457
458
459
460
           | 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); }
ferhat's avatar
ferhat committed
461
462
463
464
465
466
467
468
469
470
471
472
           | 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); }
473
474
           | MINUS expression %prec UMINUS
             { $$ = driver.add_uminus($2); }
475
           | PLUS expression %prec UPLUS
476
477
478
479
480
             { $$ = $2; }
           | EXP '(' expression ')'
             { $$ = driver.add_exp($3); }
           | LOG '(' expression ')'
             { $$ = driver.add_log($3); }
481
482
           | LN '(' expression ')'
             { $$ = driver.add_log($3); }
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
           | 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); }
499
500
501
502
           | ABS '(' expression ')'
             { $$ = driver.add_abs($3); }
           | SIGN '(' expression ')'
             { $$ = driver.add_sign($3); }
503
           | MAX '(' expression COMMA expression ')'
sebastien's avatar
sebastien committed
504
             { $$ = driver.add_max($3, $5); }
505
           | MIN '(' expression COMMA expression ')'
sebastien's avatar
sebastien committed
506
             { $$ = driver.add_min($3, $5); }
507
           | symbol { driver.push_external_function_arg_vector_onto_stack(); } '(' comma_expression ')'
508
             { $$ = driver.add_model_var_or_external_function($1, false); }
509
           | NORMCDF '(' expression COMMA expression COMMA expression ')'
sebastien's avatar
sebastien committed
510
             { $$ = driver.add_normcdf($3, $5, $7); }
511
           | NORMCDF '(' expression ')'
sebastien's avatar
sebastien committed
512
             { $$ = driver.add_normcdf($3); }
513
514
515
516
           | NORMPDF '(' expression COMMA expression COMMA expression ')'
             { $$ = driver.add_normpdf($3, $5, $7); }
           | NORMPDF '(' expression ')'
             { $$ = driver.add_normpdf($3); }
517
518
           | ERF '(' expression ')'
             { $$ = driver.add_erf($3); }
519
520
521
522
           | NAN_CONSTANT
             { $$ = driver.add_nan_constant(); }
           | INF_CONSTANT
             { $$ = driver.add_inf_constant(); }
523
           ;
524

525
comma_expression : expression
526
527
528
                   { driver.add_external_function_arg($1); }
                 | comma_expression COMMA expression
                   { driver.add_external_function_arg($3); }
529
                 ;
michel's avatar
michel committed
530

michel's avatar
michel committed
531
expression_or_empty : {$$ = driver.add_nan_constant();}
532
533
                    | expression
	            ;
michel's avatar
michel committed
534

535
initval : INITVAL ';' initval_list END ';'
536
537
538
539
          { driver.end_initval(false); }
        | INITVAL '(' ALL_VALUES_REQUIRED ')' ';' initval_list END ';'
          { driver.end_initval(true); }
        ;
michel's avatar
michel committed
540

sebastien's avatar
trunk:    
sebastien committed
541
initval_file : INITVAL_FILE '(' FILENAME EQUAL filename ')' ';'
michel's avatar
michel committed
542
543
               { driver.initval_file($5); }
             ;
544

545
546
547
548
549
endval : ENDVAL ';' initval_list END ';'
         { driver.end_endval(false); }
       | ENDVAL '(' ALL_VALUES_REQUIRED ')' ';' initval_list END ';'
         { driver.end_endval(true); }
       ;
550
551
552
553
554

initval_list : initval_list initval_elem
             | initval_elem
             ;

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

557
histval : HISTVAL ';' histval_list END ';' { driver.end_histval(); };
558
559
560
561
562

histval_list : histval_list histval_elem
             | histval_elem
             ;

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

565
566
model_options : BLOCK { driver.block(); }
              | o_cutoff
567
							| o_mfs
568
569
              | BYTECODE { driver.byte_code(); }
              | USE_DLL { driver.use_dll(); }
570
              | NO_STATIC { driver.no_static();}
571
572
              | DIFFERENTIATE_FORWARD_VARS { driver.differentiate_forward_vars_all(); }
              | DIFFERENTIATE_FORWARD_VARS EQUAL '(' symbol_list ')' { driver.differentiate_forward_vars_some(); }
573
              | o_linear
574
              | PARALLEL_LOCAL_FILES EQUAL '(' parallel_local_filename_list ')'
575
576
577
578
579
              ;

model_options_list : model_options_list COMMA model_options
                   | model_options
                   ;
michel's avatar
michel committed
580

581
model : MODEL ';' { driver.begin_model(); }
582
        equation_list END ';' { driver.reset_data_tree(); }
583
      | MODEL '(' model_options_list ')' ';' { driver.begin_model(); }
584
        equation_list END ';' { driver.reset_data_tree(); }
585
586
587
588
589
590
591
      ;

equation_list : equation_list equation
              | equation_list pound_expression
              | equation
              | pound_expression
              ;
michel's avatar
michel committed
592

593
594
595
596
equation : hand_side EQUAL hand_side ';'
           { $$ = driver.add_model_equal($1, $3); }
         | hand_side ';'
           { $$ = driver.add_model_equal_with_zero_rhs($1); }
597
598
599
600
601
602
603
604
605
606
607
608
         | '[' 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); }
609
610
         | NAME
           { driver.add_equation_tags($1, new string()); }
611
         ;
michel's avatar
michel committed
612

613
614
hand_side : '(' hand_side ')'
            { $$ = $2;}
615
616
          | symbol
            { $$ = driver.add_model_variable($1); }
617
618
          | non_negative_number
            { $$ = driver.add_non_negative_constant($1); }
619
620
621
622
623
624
625
626
          | 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); }
ferhat's avatar
ferhat committed
627
628
629
630
631
632
633
634
635
636
637
638
          | 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); }
639
640
          | hand_side POWER hand_side
            { $$ = driver.add_power($1, $3); }
641
          | EXPECTATION '(' signed_integer ')''(' hand_side ')'
642
	    { $$ = driver.add_expectation($3, $6); }
643
644
645
646
647
648
649
650
          | MINUS hand_side %prec UMINUS
            { $$ = driver.add_uminus($2); }
          | PLUS hand_side
            { $$ = $2; }
          | EXP '(' hand_side ')'
            { $$ = driver.add_exp($3); }
          | LOG '(' hand_side ')'
            { $$ = driver.add_log($3); }
651
652
          | LN '(' hand_side ')'
            { $$ = driver.add_log($3); }
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
          | 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); }
669
670
671
672
          | ABS '(' hand_side ')'
            { $$ = driver.add_abs($3); }
          | SIGN '(' hand_side ')'
            { $$ = driver.add_sign($3); }
673
          | MAX '(' hand_side COMMA hand_side ')'
674
            { $$ = driver.add_max($3, $5); }
675
          | MIN '(' hand_side COMMA hand_side ')'
676
            { $$ = driver.add_min($3, $5); }
677
          | symbol { driver.push_external_function_arg_vector_onto_stack(); } '(' comma_hand_side ')'
678
            { $$ = driver.add_model_var_or_external_function($1, true); }
679
          | NORMCDF '(' hand_side COMMA hand_side COMMA hand_side ')'
680
            { $$ = driver.add_normcdf($3, $5, $7); }
681
          | NORMCDF '(' hand_side ')'
682
            { $$ = driver.add_normcdf($3); }
683
684
685
686
          | NORMPDF '(' hand_side COMMA hand_side COMMA hand_side ')'
            { $$ = driver.add_normpdf($3, $5, $7); }
          | NORMPDF '(' hand_side ')'
            { $$ = driver.add_normpdf($3); }
687
688
          | ERF '(' hand_side ')'
            { $$ = driver.add_erf($3); }
689
          | STEADY_STATE '(' hand_side ')'
690
            { $$ = driver.add_steady_state($3); }
691
692
          ;

693
694
695
696
comma_hand_side : hand_side
                  { driver.add_external_function_arg($1); }
                | comma_hand_side COMMA hand_side
                  { driver.add_external_function_arg($3); }
697
                ;
698

699
pound_expression: '#' symbol EQUAL hand_side ';'
700
701
                  { driver.declare_and_init_model_local_variable($2, $4); };

702
shocks : SHOCKS ';' shock_list END ';' { driver.end_shocks(); };
703
704
705
706
707

shock_list : shock_list shock_elem
           | shock_elem
           ;

708
shock_elem : det_shock_elem
709
           | VAR symbol ';' STDERR expression ';'
710
             { driver.add_stderr_shock($2, $5); }
711
           | VAR symbol EQUAL expression ';'
712
             { driver.add_var_shock($2, $4); }
713
           | VAR symbol COMMA symbol EQUAL expression ';'
714
             { driver.add_covar_shock($2, $4, $6); }
715
           | CORR symbol COMMA symbol EQUAL expression ';'
716
717
718
             { driver.add_correl_shock($2, $4, $6); }
           ;

719
720
721
722
det_shock_elem : VAR symbol ';' PERIODS period_list ';' VALUES value_list ';'
                 { driver.add_det_shock($2, false); }
               ;

Houtan Bastani's avatar
Houtan Bastani committed
723
svar_identification : SVAR_IDENTIFICATION {driver.begin_svar_identification();} ';' svar_identification_list END ';'
houtanb's avatar
houtanb committed
724
                      { driver.end_svar_identification(); }
725
726
                    ;

727
728
729
730
731
732
733
734
svar_identification_list : svar_identification_list svar_identification_elem
                         | svar_identification_elem
                         ;

svar_identification_elem : EXCLUSION LAG INT_NUMBER ';' svar_equation_list
                           { driver.combine_lag_and_restriction($3); }
                         | EXCLUSION CONSTANTS ';'
                           { driver.add_constants_exclusion(); }
735
736
                         | RESTRICTION EQUATION INT_NUMBER COMMA
			 { driver.add_restriction_equation_nbr($3);}
737
738
                           restriction_expression EQUAL
                                {driver.add_restriction_equal();}
739
                           restriction_expression ';'
740
                         | UPPER_CHOLESKY ';'
houtanb's avatar
houtanb committed
741
                           { driver.add_upper_cholesky(); }
742
                         | LOWER_CHOLESKY ';'
houtanb's avatar
houtanb committed
743
                           { driver.add_lower_cholesky(); }
744
745
746
                         ;

svar_equation_list : svar_equation_list EQUATION INT_NUMBER COMMA svar_var_list ';'
houtanb's avatar
houtanb committed
747
                     { driver.add_restriction_in_equation($3); }
748
                   | EQUATION INT_NUMBER COMMA svar_var_list ';'
houtanb's avatar
houtanb committed
749
                     { driver.add_restriction_in_equation($2); }
750
751
752
                   ;

svar_var_list : svar_var_list COMMA symbol
houtanb's avatar
houtanb committed
753
                { driver.add_in_svar_restriction_symbols($3); }
754
              | symbol
houtanb's avatar
houtanb committed
755
                { driver.add_in_svar_restriction_symbols($1); }
756
757
              ;

758
restriction_expression : expression {driver.check_restriction_expression_constant($1);}
759
760
761
762
763
764
                       | restriction_expression_1
                       ;

restriction_expression_1 : restriction_elem_expression
                         | restriction_expression_1 restriction_elem_expression
                         ;   
765
766
767

restriction_elem_expression : COEFF '(' symbol COMMA INT_NUMBER ')'
                                 { driver.add_positive_restriction_element($3,$5);}
768
769
                            | PLUS COEFF '(' symbol COMMA INT_NUMBER ')'
		                 { driver.add_positive_restriction_element($4,$6);}
770
771
772
773
774
                            | MINUS COEFF '(' symbol COMMA INT_NUMBER ')'
		                 { driver.add_negative_restriction_element($4,$6);}
                            | expression TIMES COEFF '(' symbol COMMA INT_NUMBER ')'
                                 { driver.add_positive_restriction_element($1,$5,$7);}
                            ;
775

776
markov_switching : MARKOV_SWITCHING '(' ms_options_list ')' ';'
houtanb's avatar
houtanb committed
777
                   { driver.markov_switching(); }
778
779
780
781
782
783
784
785
                 ;

ms_options_list : ms_options_list COMMA ms_options
                | ms_options
                ;

ms_options : o_chain
           | o_duration
786
           | o_restrictions
787
           | o_number_of_regimes
788
789
790
           ;

svar : SVAR '(' svar_options_list ')' ';'
houtanb's avatar
houtanb committed
791
       { driver.svar(); }
792
793
794
795
796
797
798
799
     ;

svar_options_list : svar_options_list COMMA svar_options
                  | svar_options
                  ;

svar_options : o_coefficients
             | o_variances
houtanb's avatar
houtanb committed
800
             | o_equations
801
802
803
             | o_chain
             ;

804
mshocks : MSHOCKS ';' mshock_list END ';' { driver.end_mshocks(); };
805
806
807
808
809

mshock_list : mshock_list det_shock_elem
            | det_shock_elem
            ;

810
period_list : period_list COMMA INT_NUMBER
811
              { driver.add_period($3); }
ferhat's avatar
ferhat committed
812
813
            | period_list INT_NUMBER
              { driver.add_period($2); }
814
815
            | period_list COMMA INT_NUMBER ':' INT_NUMBER
              { driver.add_period($3, $5); }
ferhat's avatar
ferhat committed
816
817
            | period_list INT_NUMBER ':' INT_NUMBER
              { driver.add_period($2, $4); }
818
819
820
821
822
823
            | INT_NUMBER ':' INT_NUMBER
              { driver.add_period($1, $3); }
            | INT_NUMBER
              { driver.add_period($1); }
            ;

824
825
826
827
828
829
expectation_type : PERFECT_FORESIGHT
                   { driver.add_expectation_pf(true); }
                 | SURPRISE
                   { driver.add_expectation_pf(false); }
                ;

830
sigma_e : SIGMA_E EQUAL '[' triangular_matrix ']' ';' { driver.do_sigma_e(); };
michel's avatar
michel committed
831

832
833
834
835
836
837
value_list : value_list COMMA '(' expression ')'
             { driver.add_value($4); }
           | value_list '(' expression ')'
             { driver.add_value($3); }
           | '(' expression ')'
             { driver.add_value($2); }
838
           | value_list COMMA signed_number
839
             { driver.add_value($3); }
840
           | value_list signed_number
841
             { driver.add_value($2); }
842
           | signed_number
843
844
             { driver.add_value($1); }
           ;
845

846
847
848
849
850
851
852
853
triangular_matrix : triangular_matrix ';' triangular_row
                    { driver.end_of_row(); }
                  | triangular_row
                    { driver.end_of_row(); }
                  ;

triangular_row : triangular_row COMMA '(' expression ')'
                 { driver.add_to_row($4); }
854
               | triangular_row COMMA signed_number
855
856
857
                 { driver.add_to_row_const($3); }
               | triangular_row '(' expression ')'
                 { driver.add_to_row($3); }
858
               | triangular_row signed_number
859
860
861
                 { driver.add_to_row_const($2); }
               | '(' expression ')'
                 { driver.add_to_row($2); }
862
               | signed_number
863
                 { driver.add_to_row_const($1); }
michel's avatar
michel committed
864
865
               ;

866
867
868
869
870
871
872
873
874
875
steady : STEADY ';'
         { driver.steady(); }
       | STEADY '(' steady_options_list ')' ';'
         { driver.steady(); }
       ;

steady_options_list : steady_options_list COMMA steady_options
                    | steady_options
                    ;

876
877
878
steady_options : o_solve_algo
               | o_homotopy_mode
               | o_homotopy_steps
879
               | o_homotopy_force_continue
880
               | o_markowitz
881
               | o_steady_maxit
882
               | o_nocheck
883
               ;
884
885
886
887
888
889
890
891
892
893

check : CHECK ';'
        { driver.check(); }
      | CHECK '(' check_options_list ')' ';'
        { driver.check(); }
      ;

check_options_list : check_options_list COMMA check_options
                   | check_options
                   ;
michel's avatar
michel committed
894

895
896
897
check_options : steady_options
	      | o_qz_zero_threshold
	      ;
898

899
900
model_info : MODEL_INFO ';'
             { driver.model_info(); }
901
902
            | MODEL_INFO '(' model_info_options_list ')' ';'
              { driver.model_info(); }
sebastien's avatar
sebastien committed
903
           ;
904

905
906
907
908
909
model_info_options_list : model_info_options_list COMMA model_info_options
                   | model_info_options
                   ;
model_info_options :

910
simul : SIMUL ';'
911
        { driver.simul(); }
912
      | SIMUL '(' simul_options_list ')' ';'
913
        { driver.simul(); }
914
915
916
      ;

simul_options_list : simul_options_list COMMA simul_options
michel's avatar
michel committed
917
918
919
                   | simul_options
                   ;

920
simul_options : o_periods
921
              | o_datafile
922
              | o_stack_solve_algo
michel's avatar
michel committed
923
              | o_markowitz
924
              | o_minimal_solving_periods
925
              | o_simul_maxit
michel's avatar
michel committed
926
927
              ;

928
929
930
931
932
933
934
935
936
937
938
939
940
941
external_function : EXTERNAL_FUNCTION '(' external_function_options_list ')' ';'
                    { driver.external_function(); }
                  ;

external_function_options_list : external_function_options_list COMMA external_function_options
                               | external_function_options
                               ;

external_function_options : o_ext_func_name
                          | o_ext_func_nargs
                          | o_first_deriv_provided
                          | o_second_deriv_provided
                          ;

942
943
944
945
stoch_simul : STOCH_SIMUL ';'
              { driver.stoch_simul(); }
            | STOCH_SIMUL '(' stoch_simul_options_list ')' ';'
              { driver.stoch_simul(); }
946
            | STOCH_SIMUL symbol_list ';'
947
              { driver.stoch_simul(); }