DynareBison.yy 118 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
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 PRIOR SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN
105
%token GAMMA_PDF GRAPH GRAPH_FORMAT CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK TRANSFORM_LOGPOW STD
106
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID
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
112
%token LABELS 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 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 SOLVE_MAXIT
115
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN
116
%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS
117
%token <string_val> NAME
118
%token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS
119
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF
120
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED
121
%token 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 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
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
154
%token DUMMY_OBS NSTATES INDXSCALESSTATES NO_BAYESIAN_PRIOR SPECIFICATION SIMS_ZHA
%token <string_val> ALPHA BETA ABAND NINV CMS NCMS CNUM GAMMA INV_GAMMA INV_GAMMA1 INV_GAMMA2 NORMAL UNIFORM EPS PDF FIG DR NONE
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
log_trend_var : LOG_TREND_VAR '(' GROWTH_FACTOR EQUAL { driver.begin_trend(); } hand_side ')' log_trend_var_list ';'
                { 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
              | o_linear
572
573
574
575
576
              ;

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

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

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

590
591
592
593
equation : hand_side EQUAL hand_side ';'
           { $$ = driver.add_model_equal($1, $3); }
         | hand_side ';'
           { $$ = driver.add_model_equal_with_zero_rhs($1); }
594
595
596
597
598
599
600
601
602
603
604
605
         | '[' 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); }
606
         ;
michel's avatar
michel committed
607

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

688
689
690
691
comma_hand_side : hand_side
                  { driver.add_external_function_arg($1); }
                | comma_hand_side COMMA hand_side
                  { driver.add_external_function_arg($3); }
692
                ;
693

694
pound_expression: '#' symbol EQUAL hand_side ';'
695
696
                  { driver.declare_and_init_model_local_variable($2, $4); };

697
shocks : SHOCKS ';' shock_list END ';' { driver.end_shocks(); };
698
699
700
701
702

shock_list : shock_list shock_elem
           | shock_elem
           ;

703
shock_elem : det_shock_elem
704
           | VAR symbol ';' STDERR expression ';'
705
             { driver.add_stderr_shock($2, $5); }
706
           | VAR symbol EQUAL expression ';'
707
             { driver.add_var_shock($2, $4); }
708
           | VAR symbol COMMA symbol EQUAL expression ';'
709
             { driver.add_covar_shock($2, $4, $6); }
710
           | CORR symbol COMMA symbol EQUAL expression ';'
711
712
713
             { driver.add_correl_shock($2, $4, $6); }
           ;

714
715
716
717
det_shock_elem : VAR symbol ';' PERIODS period_list ';' VALUES value_list ';'
                 { driver.add_det_shock($2, false); }
               ;

Houtan Bastani's avatar
Houtan Bastani committed
718
svar_identification : SVAR_IDENTIFICATION {driver.begin_svar_identification();} ';' svar_identification_list END ';'
houtanb's avatar
houtanb committed
719
                      { driver.end_svar_identification(); }
720
721
                    ;

722
723
724
725
726
727
728
729
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(); }
730
731
                         | RESTRICTION EQUATION INT_NUMBER COMMA
			 { driver.add_restriction_equation_nbr($3);}
732
733
                           restriction_expression EQUAL
                                {driver.add_restriction_equal();}
734
                           restriction_expression ';'
735
                         | UPPER_CHOLESKY ';'
houtanb's avatar
houtanb committed
736
                           { driver.add_upper_cholesky(); }
737
                         | LOWER_CHOLESKY ';'
houtanb's avatar
houtanb committed
738
                           { driver.add_lower_cholesky(); }
739
740
741
                         ;

svar_equation_list : svar_equation_list EQUATION INT_NUMBER COMMA svar_var_list ';'
houtanb's avatar
houtanb committed
742
                     { driver.add_restriction_in_equation($3); }
743
                   | EQUATION INT_NUMBER COMMA svar_var_list ';'
houtanb's avatar
houtanb committed
744
                     { driver.add_restriction_in_equation($2); }
745
746
747
                   ;

svar_var_list : svar_var_list COMMA symbol
houtanb's avatar
houtanb committed
748
                { driver.add_in_svar_restriction_symbols($3); }
749
              | symbol
houtanb's avatar
houtanb committed
750
                { driver.add_in_svar_restriction_symbols($1); }
751
752
              ;

753
restriction_expression : expression {driver.check_restriction_expression_constant($1);}
754
755
756
757
758
759
                       | restriction_expression_1
                       ;

restriction_expression_1 : restriction_elem_expression
                         | restriction_expression_1 restriction_elem_expression
                         ;   
760
761
762

restriction_elem_expression : COEFF '(' symbol COMMA INT_NUMBER ')'
                                 { driver.add_positive_restriction_element($3,$5);}
763
764
                            | PLUS COEFF '(' symbol COMMA INT_NUMBER ')'
		                 { driver.add_positive_restriction_element($4,$6);}
765
766
767
768
769
                            | 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);}
                            ;
770

771
markov_switching : MARKOV_SWITCHING '(' ms_options_list ')' ';'
houtanb's avatar
houtanb committed
772
                   { driver.markov_switching(); }
773
774
775
776
777
778
779
780
                 ;

ms_options_list : ms_options_list COMMA ms_options
                | ms_options
                ;

ms_options : o_chain
           | o_duration
781
           | o_restrictions
782
           | o_number_of_regimes
783
784
785
           ;

svar : SVAR '(' svar_options_list ')' ';'
houtanb's avatar
houtanb committed
786
       { driver.svar(); }
787
788
789
790
791
792
793
794
     ;

svar_options_list : svar_options_list COMMA svar_options
                  | svar_options
                  ;

svar_options : o_coefficients
             | o_variances
houtanb's avatar
houtanb committed
795
             | o_equations
796
797
798
             | o_chain
             ;

799
mshocks : MSHOCKS ';' mshock_list END ';' { driver.end_mshocks(); };
800
801
802
803
804

mshock_list : mshock_list det_shock_elem
            | det_shock_elem
            ;

805
period_list : period_list COMMA INT_NUMBER
806
              { driver.add_period($3); }
ferhat's avatar
ferhat committed
807
808
            | period_list INT_NUMBER
              { driver.add_period($2); }
809
810
            | period_list COMMA INT_NUMBER ':' INT_NUMBER
              { driver.add_period($3, $5); }
ferhat's avatar
ferhat committed
811
812
            | period_list INT_NUMBER ':' INT_NUMBER
              { driver.add_period($2, $4); }
813
814
815
816
817
818
            | INT_NUMBER ':' INT_NUMBER
              { driver.add_period($1, $3); }
            | INT_NUMBER
              { driver.add_period($1); }
            ;

819
820
821
822
823
824
expectation_type : PERFECT_FORESIGHT
                   { driver.add_expectation_pf(true); }
                 | SURPRISE
                   { driver.add_expectation_pf(false); }
                ;

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

827
828
829
830
831
832
value_list : value_list COMMA '(' expression ')'
             { driver.add_value($4); }
           | value_list '(' expression ')'
             { driver.add_value($3); }
           | '(' expression ')'
             { driver.add_value($2); }
833
           | value_list COMMA signed_number
834
             { driver.add_value($3); }
835
           | value_list signed_number
836
             { driver.add_value($2); }
837
           | signed_number
838
839
             { driver.add_value($1); }
           ;
840

841
842
843
844
845
846
847
848
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); }
849
               | triangular_row COMMA signed_number
850
851
852
                 { driver.add_to_row_const($3); }
               | triangular_row '(' expression ')'
                 { driver.add_to_row($3); }
853
               | triangular_row signed_number
854
855
856
                 { driver.add_to_row_const($2); }
               | '(' expression ')'
                 { driver.add_to_row($2); }
857
               | signed_number
858
                 { driver.add_to_row_const($1); }
michel's avatar
michel committed
859
860
               ;

861
862
863
864
865
866
867
868
869
870
steady : STEADY ';'
         { driver.steady(); }
       | STEADY '(' steady_options_list ')' ';'
         { driver.steady(); }
       ;

steady_options_list : steady_options_list COMMA steady_options
                    | steady_options
                    ;

871
872
873
steady_options : o_solve_algo
               | o_homotopy_mode
               | o_homotopy_steps
874
               | o_homotopy_force_continue
875
               | o_markowitz
876
               | o_maxit
877
               | o_nocheck
878
               | TRANSFORM_LOGPOW { driver.transform_logpow(); };
879
               ;
880
881
882
883
884
885
886
887
888
889

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
890

891
check_options : steady_options;
892

893
894
model_info : MODEL_INFO ';'
             { driver.model_info(); }
895
896
            | MODEL_INFO '(' model_info_options_list ')' ';'
              { driver.model_info(); }
sebastien's avatar
sebastien committed
897
           ;
898

899
900
901
902
903
model_info_options_list : model_info_options_list COMMA model_info_options
                   | model_info_options
                   ;
model_info_options :

904
simul : SIMUL ';'
905
        { driver.simul(); }
906
      | SIMUL '(' simul_options_list ')' ';'
907
        { driver.simul(); }
908
909
910
      ;

simul_options_list : simul_options_list COMMA simul_options
michel's avatar
michel committed
911
912
913
                   | simul_options
                   ;

914
simul_options : o_periods
915
              | o_datafile
916
              | o_stack_solve_algo
michel's avatar
michel committed
917
              | o_markowitz
918
              | o_minimal_solving_periods
919
              | o_maxit
michel's avatar
michel committed
920
921
              ;

922
923
924
925
926
927
928
929
930
931
932
933
934
935
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
                          ;

936
937
938
939
stoch_simul : STOCH_SIMUL ';'
              { driver.stoch_simul(); }
            | STOCH_SIMUL '(' stoch_simul_options_list ')' ';'
              { driver.stoch_simul(); }
940
            | STOCH_SIMUL symbol_list ';'
941
              { driver.stoch_simul(); }
942
            | STOCH_SIMUL '(' stoch_simul_options_list ')' symbol_list ';'
943
944
945
946
              { driver.stoch_simul(); }
            ;

stoch_simul_options_list : stoch_simul_options_list COMMA stoch_simul_options
michel's avatar
michel committed
947
948
949
                         | stoch_simul_options
                         ;

950
951
stoch_simul_options : o_dr_algo
                    | o_solve_algo
952
953
954
955
956
957
958
959
960
961
                    | o_simul_algo
                    | o_linear
                    | o_order
                    | o_replic
                    | o_drop
                    | o_ar
                    | o_nocorr
                    | o_nofunctions
                    | o_nomoments
                    | o_nograph
962
963
                    | o_nodisplay
                    | o_graph_format
964
                    | o_irf
965
                    | o_irf_shocks
966
967
968
969
970
971
                    | o_relative_irf
                    | o_hp_filter
                    | o_hp_ngrid
                    | o_periods
                    | o_simul
                    | o_simul_seed
972
                    | o_simul_replic
973
974
975
                    | o_qz_criterium
                    | o_print
                    | o_noprint
sebastien's avatar
sebastien committed
976
                    | o_aim_solver
977
                    | o_partial_information
978
                    | o_conditional_variance_decomposition
979
                    | o_k_order_solver
980
                    | o_pruning
981
                    | o_sylvester
982
                    | o_sylvester_fixed_point_tol
983
984
                    | o_dr
                    | o_dr_cycle_reduction_tol
985
986
                    | o_dr_logarithmic_reduction_tol
                    | o_dr_logarithmic_reduction_maxiter
987
<