DynareBison.yy 54.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (C) 2003-2008 Dynare Team
 *
 * This file is part of Dynare.
 *
 * Dynare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dynare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

%skeleton "lalr1.cc"
%require "2.3"
%defines

%{
using namespace std;

class ParsingDriver;

#include "ExprNode.hh"

/* 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)

%}

%name-prefix="Dynare"

%parse-param { ParsingDriver &driver }
%lex-param { ParsingDriver &driver }

%locations
56
57
58
59
60
%initial-action
{
  // Initialize the location filenames to NULL
  @$.begin.filename = @$.end.filename = NULL;
}
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

%debug
%error-verbose

%union
{
  string *string_val;
  NodeID node_val;
};

%{
#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
%}

%token AR AUTOCORR
%token BAYESIAN_IRF BETA_PDF BICGSTAB
%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
%token BVAR_REPLIC
%token CALIB CALIB_VAR CHECK CONF_SIG CONSTANT CORR COVAR CUTOFF
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
%token <string_val> FLOAT_NUMBER
%token FORECAST
%token GAMMA_PDF GAUSSIAN_ELIMINATION GCC_COMPILER GMRES GRAPH
%token HISTVAL HP_FILTER HP_NGRID
michel's avatar
michel committed
95
%token INITVAL INITVAL_FILE
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
%token <string_val> INT_NUMBER
%token INV_GAMMA_PDF IRF
%token KALMAN_ALGO KALMAN_TOL
%token LAPLACE LCC_COMPILER LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR LU MARKOWITZ MAX
%token METHOD MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MSHOCKS
%token MODEL_COMPARISON_APPROXIMATION MODIFIEDHARMONICMEAN MOMENTS_VARENDO
%token <string_val> NAME
%token NO_COMPILER NOBS NOCONSTANT NOCORR NODIAGNOSTIC NOFUNCTIONS
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS
%token PARAMETERS PERIODS PLANNER_OBJECTIVE PREFILTER PRESAMPLE
%token PRINT PRIOR_TRUNC PRIOR_ANALYSIS POSTERIOR_ANALYSIS
%token QZ_CRITERIUM
%token RELATIVE_IRF REPLIC RPLOT
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO
%token SPARSE SPARSE_DLL STDERR STEADY STOCH_SIMUL
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT
%token <string_val> TEX_NAME
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL
%token VALUES VAR VAREXO VAREXO_DET VAROBS
%token XLS_SHEET XLS_RANGE
%token NORMCDF
%token HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS
%left COMMA
121
122
%left EQUAL_EQUAL EXCLAMATION_EQUAL
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
123
124
%left PLUS MINUS
%left TIMES DIVIDE
125
%left UMINUS UPLUS
126
127
128
129
130
131
%nonassoc POWER
%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH ASINH ACOSH ATANH SQRT
/* GSA analysis */
%token DYNARE_SENSITIVITY IDENTIFICATION MORRIS STAB REDFORM PPRIOR PRIOR_RANGE PPOST ILPTAU GLUE MORRIS_NLIV
%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
michel's avatar
michel committed
132
%token ALPHA_RMSE ALPHA2_RMSE TRANS_IDENT
133
134
135
136
137
/* end of GSA analysis*/

%type <node_val> expression
%type <node_val> equation hand_side model_var
%type <string_val> signed_float signed_integer prior
138
139
%type <string_val> value value1 filename filename_elem vec_int_elem vec_int_1 vec_int
%type <string_val> vec_value_1 vec_value
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
%type <string_val> calib_arg2 range number

%%

%start statement_list;

statement_list : statement
               | statement_list statement
               ;

statement : declaration
          | periods
          | cutoff
          | markowitz
          | model
          | initval
michel's avatar
michel committed
156
          | initval_file
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
          | endval
          | histval
          | init_param
          | shocks
          | mshocks
          | sigma_e
          | steady
          | check
          | simul
          | stoch_simul
          | estimation
          | prior_analysis
          | posterior_analysis
          | estimated_params
          | estimated_params_bounds
          | estimated_params_init
          | varobs
          | observation_trends
          | unit_root_vars
          | dsample
          | rplot
          | optim_weights
          | osr_params
          | osr
          | calib_var
          | calib
          | dynatype
          | dynasave
          | model_comparison
          | planner_objective
          | ramsey_policy
          | bvar_density
          | bvar_forecast
          | dynare_sensitivity
          | homotopy_setup
192
          | forecast
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
          ;

declaration : parameters
            | var
            | varexo
            | varexo_det
            ;


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

208
rplot : RPLOT symbol_list ';' { driver.rplot(); };
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

var : VAR var_list ';';

varexo : VAREXO varexo_list ';';

varexo_det : VAREXO_DET varexo_det_list ';';

parameters : PARAMETERS parameter_list ';';

var_list : var_list NAME
           { driver.declare_endogenous($2); }
         | var_list COMMA NAME
           { driver.declare_endogenous($3); }
         | NAME
           { driver.declare_endogenous($1); }
         | var_list NAME TEX_NAME
           { driver.declare_endogenous($2, $3); }
         | var_list COMMA NAME TEX_NAME
           { driver.declare_endogenous($3, $4); }
         | NAME TEX_NAME
           { driver.declare_endogenous($1, $2); }
         ;

varexo_list : varexo_list NAME
              { driver.declare_exogenous($2); }
            | varexo_list COMMA NAME
              { driver.declare_exogenous($3); }
            | NAME
              { driver.declare_exogenous($1); }
            | varexo_list NAME TEX_NAME
              { driver.declare_exogenous($2, $3); }
            | varexo_list COMMA NAME TEX_NAME
              { driver.declare_exogenous($3, $4); }
            | NAME TEX_NAME
              { driver.declare_exogenous($1, $2); }
            ;

varexo_det_list : varexo_det_list NAME
                  { driver.declare_exogenous_det($2); }
                | varexo_det_list COMMA NAME
                  { driver.declare_exogenous_det($3); }
                | NAME
                  { driver.declare_exogenous_det($1); }
                | varexo_det_list NAME TEX_NAME
                  { driver.declare_exogenous_det($2, $3); }
                | varexo_det_list COMMA NAME TEX_NAME
                  { driver.declare_exogenous_det($3, $4); }
                | NAME TEX_NAME
                   { driver.declare_exogenous_det($1, $2); }
                ;

parameter_list : parameter_list NAME
                 { driver.declare_parameter($2); }
               | parameter_list COMMA NAME
                 { driver.declare_parameter($3); }
               | NAME
                 { driver.declare_parameter($1); }
               | parameter_list NAME TEX_NAME
                 { driver.declare_parameter($2, $3); }
               | parameter_list COMMA NAME TEX_NAME
                 { driver.declare_parameter($3, $4); }
               | NAME TEX_NAME
                 { driver.declare_parameter($1, $2); }
               ;

periods : PERIODS INT_NUMBER ';'
          { driver.periods($2); }
        | PERIODS EQUAL INT_NUMBER ';'
          { driver.periods($3); }
        ;

cutoff : CUTOFF FLOAT_NUMBER ';'
         { driver.cutoff($2); }
       | CUTOFF EQUAL FLOAT_NUMBER ';'
         { driver.cutoff($3); }
       ;

markowitz : MARKOWITZ FLOAT_NUMBER ';'
            { driver.markowitz($2); }
          | MARKOWITZ EQUAL FLOAT_NUMBER ';'
            { driver.markowitz($3); }
          ;


init_param : NAME EQUAL expression ';' { driver.init_param($1, $3); };

expression : '(' expression ')'
             { $$ = $2;}
           | NAME
             { $$ = driver.add_expression_variable($1); }
           | FLOAT_NUMBER
             { $$ = driver.add_constant($1); }
           | INT_NUMBER
             { $$ = driver.add_constant($1); }
           | 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); }
           | MINUS expression %prec UMINUS
             { $$ = driver.add_uminus($2); }
327
           | PLUS expression %prec UPLUS
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
             { $$ = $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); }
           | MAX '(' expression COMMA expression ')'
             { $$ = driver.add_max($3 , $5); }
           | MIN '(' expression COMMA expression ')'
             { $$ = driver.add_min($3 , $5); }
           | NAME '(' comma_expression ')'
             { $$ = driver.add_unknown_function($1); }
           | NORMCDF '(' expression COMMA expression COMMA expression ')'
             { $$ = driver.add_normcdf($3,$5,$7);}
           ;

comma_expression : expression
                   { driver.add_unknown_function_arg($1); }
                   | comma_expression COMMA expression
                   { driver.add_unknown_function_arg($3); }
                 ;

initval : INITVAL ';' initval_list END
          { driver.end_initval(); }

michel's avatar
michel committed
370
371
372
initval_file : INITVAL_FILE '(' FILENAME EQUAL NAME ')' ';'
               { driver.initval_file($5); }
             ;
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

endval : ENDVAL ';' initval_list END { driver.end_endval(); };

initval_list : initval_list initval_elem
             | initval_elem
             ;

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

histval : HISTVAL ';' histval_list END { driver.end_histval(); };

histval_list : histval_list histval_elem
             | histval_elem
             ;

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

model_sparse_dll_options_list : model_sparse_dll_options_list COMMA model_sparse_dll_options
                          | model_sparse_dll_options
                          ;

model_sparse_options_list : model_sparse_options_list COMMA model_sparse_common_options
                          | model_sparse_common_options
                          ;

model_sparse_dll_options : model_compiler_options
                         | model_sparse_common_options
                         ;

model_compiler_options : LCC_COMPILER
                       { driver.init_compiler(0); }
                     | GCC_COMPILER
                       { driver.init_compiler(1); }
                     | NO_COMPILER
                       { driver.init_compiler(2); }
                      ;

model_sparse_common_options : o_cutoff
                     | o_markowitz
                     ;

model : MODEL ';' { driver.begin_model(); }
        equation_list END { driver.reset_data_tree(); }
      | MODEL '(' o_linear ')' ';' { driver.begin_model(); }
        equation_list END { driver.reset_data_tree(); }
      | MODEL '(' USE_DLL ')' ';' { driver.begin_model(); driver.use_dll(); }
        equation_list END { driver.reset_data_tree(); }
      | MODEL '(' SPARSE_DLL COMMA model_sparse_dll_options_list ')'
        { driver.begin_model(); driver.sparse_dll(); } ';'
        equation_list END { driver.reset_data_tree(); }
      | MODEL '(' SPARSE_DLL ')' { driver.begin_model(); driver.sparse_dll(); } ';'
        equation_list END { driver.reset_data_tree(); }
      | MODEL '(' SPARSE COMMA model_sparse_options_list ')'
        { driver.begin_model(); driver.sparse(); } ';'
        equation_list END { driver.reset_data_tree(); }
      | MODEL '(' SPARSE ')' { driver.begin_model(); driver.sparse(); } ';'
        equation_list END { driver.reset_data_tree(); }
      ;

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); }
         ;

hand_side : '(' hand_side ')'
            { $$ = $2;}
          | model_var
          | FLOAT_NUMBER
            { $$ = driver.add_constant($1); }
          | INT_NUMBER
            { $$ = driver.add_constant($1); }
          | 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); }
          | 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); }
          | 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); }
          | MAX '(' hand_side COMMA hand_side ')'
             { $$ = driver.add_max($3 , $5); }
          | MIN '(' hand_side COMMA hand_side ')'
             { $$ = driver.add_min($3 , $5); }
          | NORMCDF '(' hand_side COMMA hand_side COMMA hand_side ')'
             { $$ = driver.add_normcdf($3,$5,$7);}
          ;

pound_expression: '#' NAME EQUAL hand_side ';'
                  { driver.declare_and_init_model_local_variable($2, $4); };

model_var : NAME
            { $$ = driver.add_model_variable($1); }
          | NAME '(' signed_integer ')'
            { $$ = driver.add_model_variable($1, $3); }
          ;

shocks : SHOCKS ';' shock_list END { driver.end_shocks(); };

mshocks : MSHOCKS ';' shock_list END { driver.end_mshocks(); };

shock_list : shock_list shock_elem
           | shock_elem
           ;

shock_elem : VAR NAME ';' PERIODS period_list ';' VALUES value_list ';'
             { driver.add_det_shock($2); }
           | VAR NAME ';' STDERR expression ';'
             { driver.add_stderr_shock($2, $5); }
           | VAR NAME EQUAL expression ';'
             { driver.add_var_shock($2, $4); }
           | VAR NAME COMMA NAME EQUAL expression ';'
             { driver.add_covar_shock($2, $4, $6); }
           | CORR NAME COMMA NAME EQUAL expression ';'
             { driver.add_correl_shock($2, $4, $6); }
           ;

period_list : period_list COMMA INT_NUMBER
              { driver.add_period($3); }
            | period_list INT_NUMBER
              { driver.add_period($2); }
            | period_list COMMA INT_NUMBER ':' INT_NUMBER
              { driver.add_period($3, $5); }
            | period_list INT_NUMBER ':' INT_NUMBER
              { driver.add_period($2, $4); }
            | INT_NUMBER ':' INT_NUMBER
              { driver.add_period($1, $3); }
            | INT_NUMBER
              { driver.add_period($1); }
            ;


sigma_e : SIGMA_E EQUAL '[' triangular_matrix ']' ';' { driver.do_sigma_e(); };

value_list
 	:  value_list COMMA expression
    {driver.add_value($3);}
  |  value_list number
    {driver.add_value($2);}
	| expression
    {driver.add_value($1);}
	;

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); }
               | triangular_row COMMA FLOAT_NUMBER
                 { driver.add_to_row_const($3); }
               | triangular_row COMMA INT_NUMBER
                 { driver.add_to_row_const($3); }
               | triangular_row '(' expression ')'
                 { driver.add_to_row($3); }
               | triangular_row FLOAT_NUMBER
                 { driver.add_to_row_const($2); }
               | triangular_row INT_NUMBER
                 { driver.add_to_row_const($2); }
               | '(' expression ')'
                 { driver.add_to_row($2); }
               | FLOAT_NUMBER
                 { driver.add_to_row_const($1); }
               | INT_NUMBER
                 { driver.add_to_row_const($1); }
               ;

steady : STEADY ';'
         { driver.steady(); }
       | STEADY '(' steady_options_list ')' ';'
         { driver.steady(); }
       ;

steady_options_list : steady_options_list COMMA steady_options
                    | steady_options
                    ;

steady_options : o_solve_algo
               | o_homotopy_mode
               | o_homotopy_steps
               ;

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

check_options_list : check_options_list COMMA check_options
                   | check_options
                   ;

check_options : o_solve_algo;

simul : SIMUL ';'
        { driver.simulate(); }
      | SIMUL '(' simul_options_list ')' ';'
        { driver.simulate(); }
      ;

simul_options_list : simul_options_list COMMA simul_options
                   | simul_options
                   ;

simul_options : o_periods
              | o_datafile
              | o_method
              ;

stoch_simul : STOCH_SIMUL ';'
              { driver.stoch_simul(); }
            | STOCH_SIMUL '(' stoch_simul_options_list ')' ';'
              { driver.stoch_simul(); }
634
            | STOCH_SIMUL symbol_list ';'
635
              { driver.stoch_simul(); }
636
            | STOCH_SIMUL '(' stoch_simul_options_list ')' symbol_list ';'
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
              { driver.stoch_simul(); }
            ;

stoch_simul_options_list : stoch_simul_options_list COMMA stoch_simul_options
                         | stoch_simul_options
                         ;

stoch_simul_options : o_dr_algo
                    | o_solve_algo
                    | o_simul_algo
                    | o_linear
                    | o_order
                    | o_replic
                    | o_drop
                    | o_ar
                    | o_nocorr
                    | o_nofunctions
                    | o_nomoments
                    | o_nograph
                    | o_irf
                    | o_relative_irf
                    | o_hp_filter
                    | o_hp_ngrid
                    | o_periods
                    | o_cutoff
                    | o_simul
                    | o_simul_seed
                    | o_qz_criterium
                    | o_print
                    | o_noprint
                    ;

669
symbol_list : symbol_list NAME
sebastien's avatar
sebastien committed
670
               { driver.add_in_symbol_list($2); }
671
             | symbol_list COMMA NAME
sebastien's avatar
sebastien committed
672
               { driver.add_in_symbol_list($3); }
673
             | NAME
sebastien's avatar
sebastien committed
674
               { driver.add_in_symbol_list($1); }
675
676
             ;

677
symbol_list_ext : symbol_list
sebastien's avatar
sebastien committed
678
679
680
681
682
                | ':'
                  {
                    string *colon = new string(":");
                    driver.add_in_symbol_list(colon);
                  }
683
684
                ;

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
signed_integer : PLUS INT_NUMBER
                 { $$ = $2; }
               | MINUS INT_NUMBER
                { $2->insert(0, "-"); $$ = $2; }
               | INT_NUMBER
                { $$ = $1; }
               ;

signed_float : PLUS FLOAT_NUMBER
               { $$ = $2; }
             | MINUS FLOAT_NUMBER
               { $2->insert(0, "-"); $$ = $2; }
             | FLOAT_NUMBER
               { $$ = $1; }
             ;

estimated_params : ESTIMATED_PARAMS ';' estimated_list END { driver.estimated_params(); };

estimated_list : estimated_list estimated_elem
                 { driver.add_estimated_params_element(); }
               | estimated_elem
                 { driver.add_estimated_params_element(); }
               ;

estimated_elem : estimated_elem1 COMMA estimated_elem2 ';';

estimated_elem1 : STDERR NAME
                  {
                    driver.estim_params.type = 1;
                    driver.estim_params.name = *$2;
                    delete $2;
                  }
                | NAME
                  {
                    driver.estim_params.type = 2;
                    driver.estim_params.name = *$1;
                    delete $1;
                  }
                | CORR NAME COMMA NAME
                  {
                    driver.estim_params.type = 3;
                    driver.estim_params.name = *$2;
                    driver.estim_params.name2 = *$4;
                    delete $2;
                    delete $4;
                  }
                ;

estimated_elem2 : prior COMMA estimated_elem3
                  {
                    driver.estim_params.prior = *$1;
                    delete $1;
                  }
                | value COMMA prior COMMA estimated_elem3
                  {
                    driver.estim_params.init_val = *$1;
                    driver.estim_params.prior = *$3;
                    delete $1;
                    delete $3;
                  }
                | value COMMA value COMMA value COMMA prior COMMA estimated_elem3
                  {
                    driver.estim_params.init_val = *$1;
                    driver.estim_params.low_bound = *$3;
                    driver.estim_params.up_bound = *$5;
                    driver.estim_params.prior = *$7;
                    delete $1;
                    delete $3;
                    delete $5;
                    delete $7;
                  }
                | value
                  {
                    driver.estim_params.init_val = *$1;
                    delete $1;
                  }
                | value COMMA value COMMA value
                  {
                    driver.estim_params.init_val = *$1;
                    driver.estim_params.low_bound = *$3;
                    driver.estim_params.up_bound = *$5;
                    delete $1;
                    delete $3;
                    delete $5;
                  }
                ;

estimated_elem3 : value COMMA value
                  {
                    driver.estim_params.mean = *$1;
                    driver.estim_params.std = *$3;
                    delete $1;
                    delete $3;
                  }
                | value COMMA value COMMA value
                  {
                    driver.estim_params.mean = *$1;
                    driver.estim_params.std = *$3;
                    driver.estim_params.p3 = *$5;
                    delete $1;
                    delete $3;
                    delete $5;
                  }
                | value COMMA value COMMA value COMMA value
                  {
                    driver.estim_params.mean = *$1;
                    driver.estim_params.std = *$3;
                    driver.estim_params.p3 = *$5;
                    driver.estim_params.p4 = *$7;
                    delete $1;
                    delete $3;
                    delete $5;
                    delete $7;
                  }
                | value COMMA value COMMA value COMMA value COMMA value
                  {
                    driver.estim_params.mean = *$1;
                    driver.estim_params.std = *$3;
                    driver.estim_params.p3 = *$5;
                    driver.estim_params.p4 = *$7;
                    driver.estim_params.jscale = *$9;
                    delete $1;
                    delete $3;
                    delete $5;
                    delete $7;
                    delete $9;
                  }
                ;

estimated_params_init : ESTIMATED_PARAMS_INIT ';' estimated_init_list END
                        { driver.estimated_params_init(); };

estimated_init_list : estimated_init_list estimated_init_elem
                      { driver.add_estimated_params_element(); }
                    | estimated_init_elem
                      { driver.add_estimated_params_element(); }
                    ;

estimated_init_elem : STDERR NAME COMMA value ';'
                      {
                        driver.estim_params.type = 1;
                        driver.estim_params.name = *$2;
                        driver.estim_params.init_val = *$4;
                        delete $2;
                        delete $4;
                      }
                    | CORR NAME COMMA NAME COMMA value ';'
                      {
                        driver.estim_params.type = 3;
                        driver.estim_params.name = *$2;
                        driver.estim_params.name2 = *$4;
                        driver.estim_params.init_val = *$6;
                        delete $2;
                        delete $4;
                        delete $6;
                      }
                    | NAME COMMA value ';'
                      {
                        driver.estim_params.type = 2;
                        driver.estim_params.name = *$1;
                        driver.estim_params.init_val = *$3;
                        delete $1;
                        delete $3;
                      }
                    ;

estimated_params_bounds : ESTIMATED_PARAMS_BOUNDS ';' estimated_bounds_list END
                          { driver.estimated_params_bounds(); };

estimated_bounds_list : estimated_bounds_list estimated_bounds_elem
                        { driver.add_estimated_params_element(); }
                      | estimated_bounds_elem
                        { driver.add_estimated_params_element(); }
                      ;

estimated_bounds_elem : STDERR NAME COMMA value COMMA value ';'
                        {
                          driver.estim_params.type = 1;
                          driver.estim_params.name = *$2;
                          driver.estim_params.low_bound = *$4;
                          driver.estim_params.up_bound = *$6;
                          delete $2;
                          delete $4;
                          delete $6;
                        }
                      | CORR NAME COMMA NAME COMMA value COMMA value ';'
                        {
                          driver.estim_params.type = 3;
                          driver.estim_params.name = *$2;
                          driver.estim_params.name2 = *$4;
                          driver.estim_params.low_bound = *$6;
                          driver.estim_params.up_bound = *$8;
                          delete $2;
                          delete $4;
                          delete $6;
                          delete $8;
                        }
                      | NAME COMMA value COMMA value ';'
                        {
                          driver.estim_params.type = 2;
                          driver.estim_params.name = *$1;
                          driver.estim_params.low_bound = *$3;
                          driver.estim_params.up_bound = *$5;
                          delete $1;
                          delete $3;
                          delete $5;
                        }
                      ;

prior : BETA_PDF
        { $$ = new string("1"); }
      | GAMMA_PDF
        { $$ = new string("2"); }
      | NORMAL_PDF
        { $$ = new string("3"); }
      | INV_GAMMA_PDF
        { $$ = new string("4"); }
      | UNIFORM_PDF
        { $$ = new string("5"); }
      ;

value : { $$ = new string("NaN"); }
907
      | value1
908
909
      ;

910
911
912
913
914
915
916
917
918
value1 : INT_NUMBER
       | FLOAT_NUMBER
       | NAME
       | MINUS INT_NUMBER
         { $2->insert(0, "-"); $$ = $2; }
       | MINUS FLOAT_NUMBER
         { $2->insert(0, "-"); $$ = $2; }
       ;

919
920
921
922
estimation : ESTIMATION ';'
             { driver.run_estimation(); }
           | ESTIMATION '(' estimation_options_list ')' ';'
             { driver.run_estimation(); }
923
           | ESTIMATION symbol_list ';'
924
             { driver.run_estimation(); }
925
           | ESTIMATION '(' estimation_options_list ')' symbol_list ';'
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
             { driver.run_estimation(); }
           ;

estimation_options_list : estimation_options_list COMMA estimation_options
                        | estimation_options
                        ;

estimation_options : o_datafile
                   | o_nobs
                   | o_first_obs
                   | o_prefilter
                   | o_presample
                   | o_lik_algo
                   | o_lik_init
                   | o_nograph
                   | o_conf_sig
                   | o_mh_replic
                   | o_mh_drop
                   | o_mh_jscale
                   | o_optim
                   | o_mh_init_scale
                   | o_mode_file
                   | o_mode_compute
                   | o_mode_check
                   | o_prior_trunc
                   | o_mh_mode
                   | o_mh_nblcks
                   | o_load_mh_file
                   | o_loglinear
                   | o_nodiagnostic
                   | o_bayesian_irf
                   | o_irf
                   | o_tex
                   | o_forecast
                   | o_smoother
                   | o_moments_varendo
                   | o_filtered_vars
                   | o_kalman_algo
                   | o_kalman_tol
                   | o_xls_sheet
                   | o_xls_range
                   | o_filter_step_ahead
                   | o_solve_algo
                   | o_constant
                   | o_noconstant
                   | o_mh_recover
                   ;

prior_analysis : PRIOR_ANALYSIS '(' prior_posterior_options_list ')' ';'
                 { driver.run_prior_analysis(); }
976
               | PRIOR_ANALYSIS '(' prior_posterior_options_list ')' symbol_list ';'
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
                 { driver.run_prior_analysis(); }
               ;

prior_posterior_options_list : prior_posterior_options_list COMMA prior_posterior_options
                             | prior_posterior_options
                             ;

prior_posterior_options : o_nograph
                        | o_conf_sig
                        | o_prior_trunc
                        | o_bayesian_irf
                        | o_irf
                        | o_tex
                        | o_forecast
                        | o_smoother
                        | o_moments_varendo
                        | o_filtered_vars
                        | o_xls_sheet
                        | o_xls_range
                        | o_filter_step_ahead
                        ;

posterior_analysis : POSTERIOR_ANALYSIS '(' prior_posterior_options_list ')' ';'
                     { driver.run_posterior_analysis(); }