DynareBison.yy 34 KB
Newer Older
1
2
3
4
5
%skeleton "lalr1.cc"
%require "2.3"
%defines

%{
6
using namespace std;
7
8

class ParsingDriver;
9

sebastien's avatar
sebastien committed
10
#include "ExprNode.hh"
11
12
%}

13
14
%parse-param { ParsingDriver &driver }
%lex-param { ParsingDriver &driver }
15
16
17
18
19
20
21
22
23
24
25
26
27

%locations
%initial-action
{
  // Initialize the location filenames
  @$.begin.filename = @$.end.filename = &driver.file;
};

%debug
%error-verbose

%union
{
28
  string *string_val;
sebastien's avatar
sebastien committed
29
  NodeID node_val;
30
31
};

michel's avatar
michel committed
32
%{
33
#include "ParsingDriver.hh"
michel's avatar
michel committed
34
%}
35

michel's avatar
michel committed
36
37
%token AR AUTOCORR
%token BAYESIAN_IRF BETA_PDF
sebastien's avatar
sebastien committed
38
%token CALIB CALIB_VAR CHECK CONF_SIG CONSTANT CORR COVAR CUTOFF
39
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE 
michel's avatar
michel committed
40
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
sebastien's avatar
sebastien committed
41
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
42
%token <string_val> FLOAT_NUMBER
43
%token FORECAST
sebastien's avatar
sebastien committed
44
%token GAMMA_PDF GCC_COMPILER GRAPH
45
46
%token HISTVAL HP_FILTER HP_NGRID
%token INITVAL
47
%token <string_val> INT_NUMBER
48
49
%token INV_GAMMA_PDF IRF
%token KALMAN_ALGO KALMAN_TOL
sebastien's avatar
sebastien committed
50
%token LAPLACE LCC_COMPILER LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR
michel's avatar
michel committed
51
52
53
%token MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MSHOCKS
%token MODEL_COMPARISON_APPROXIMATION MODIFIEDHARMONICMEAN MOMENTS_VARENDO 
54
%token <string_val> NAME
55
%token NOBS NOCONSTANT NOCORR NODIAGNOSTIC NOFUNCTIONS NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF
michel's avatar
michel committed
56
%token OBSERVATION_TRENDS OLR OLR_INST OLR_BETA OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS 
57
%token PARAMETERS PERIODS PLANNER_OBJECTIVE PREFILTER PRESAMPLE PRINT PRIOR_TRUNC PRIOR_ANALYSIS POSTERIOR_ANALYSIS
michel's avatar
michel committed
58
%token QZ_CRITERIUM
59
%token RELATIVE_IRF REPLIC RPLOT
sebastien's avatar
sebastien committed
60
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO SPARSE_DLL STDERR STEADY STOCH_SIMUL  
michel's avatar
michel committed
61
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT
62
%token <string_val> TEX_NAME
michel's avatar
michel committed
63
64
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL
%token VALUES VAR VAREXO VAREXO_DET VAROBS
65
%token XLS_SHEET XLS_RANGE
66
67
68
%left COMMA
%left PLUS MINUS
%left TIMES DIVIDE
michel's avatar
michel committed
69
%left UMINUS
70
%nonassoc POWER 
71
%token EXP LOG LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH ASINH ACOSH ATANH SQRT
72

sebastien's avatar
sebastien committed
73
74
%type <node_val> expression
%type <node_val> equation hand_side model_var
75
76
77
%type <string_val> signed_float signed_integer prior
%type <string_val> value filename filename_elem vec_int_elem vec_int_1 vec_int
%type <string_val> calib_arg2 range
78

michel's avatar
michel committed
79
80
%%

81
82
%start statement_list;

michel's avatar
michel committed
83
84
85
86
87
88
89
90
 statement_list
 	: statement
        | statement_list statement
        ;

 statement
  	: declaration
 	| periods
sebastien's avatar
sebastien committed
91
  | cutoff
michel's avatar
michel committed
92
93
94
95
 	| model
 	| initval
 	| endval
 	| histval
sebastien's avatar
sebastien committed
96
 	| init_param
michel's avatar
michel committed
97
98
99
100
101
102
103
104
 	| shocks
 	| mshocks
 	| sigma_e
 	| steady
 	| check
 	| simul
 	| stoch_simul
 	| estimation
michel's avatar
michel committed
105
106
        | prior_analysis
        | posterior_analysis
michel's avatar
michel committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
	| 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
	| olr
	| olr_inst
        | model_comparison
michel's avatar
michel committed
125
126
        | planner_objective
	| ramsey_policy
michel's avatar
michel committed
127
128
129
130
131
132
133
134
135
136
137
	;

    
 declaration
 	: parameters
 	| var
 	| varexo
 	| varexo_det
 	;

 	
sebastien's avatar
sebastien committed
138
139
 dsample : DSAMPLE INT_NUMBER ';' { driver.dsample($2);}
         | DSAMPLE INT_NUMBER INT_NUMBER ';' {driver.dsample($2, $3);}
michel's avatar
michel committed
140
141
         ; 

142
 rplot : RPLOT tmp_var_list ';' {driver.rplot();}
michel's avatar
michel committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
      ; 
 var 
 	: VAR var_list ';' 
 	;

 varexo 
 	: VAREXO varexo_list ';'
	;

 varexo_det
 	: VAREXO_DET varexo_det_list ';'
	;
      	
 parameters
 	: PARAMETERS parameter_list ';'
 	;
 
 var_list
 	: var_list NAME  
162
 		{ driver.declare_endogenous($2); }
michel's avatar
michel committed
163
 	| var_list COMMA NAME  
164
 		{ driver.declare_endogenous($3); }
michel's avatar
michel committed
165
 	| NAME
166
167
168
169
170
 		{ 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); }
michel's avatar
michel committed
171
 	| NAME TEX_NAME
172
 		{ driver.declare_endogenous($1, $2); }
michel's avatar
michel committed
173
174
175
176
	; 
	
 varexo_list
 	: varexo_list NAME
177
 		{ driver.declare_exogenous($2); }
michel's avatar
michel committed
178
 	| varexo_list COMMA NAME
179
 		{ driver.declare_exogenous($3); }
michel's avatar
michel committed
180
 	| NAME
181
 		{ driver.declare_exogenous($1); }
michel's avatar
michel committed
182
 	| varexo_list NAME TEX_NAME
183
 		{ driver.declare_exogenous($2, $3); }
michel's avatar
michel committed
184
 	| varexo_list COMMA NAME TEX_NAME
185
 		{ driver.declare_exogenous($3, $4); }
michel's avatar
michel committed
186
 	| NAME TEX_NAME
187
 		{ driver.declare_exogenous($1, $2); }
michel's avatar
michel committed
188
189
190
191
	; 

 varexo_det_list
 	: varexo_det_list NAME
192
 		{ driver.declare_exogenous_det($2); }
michel's avatar
michel committed
193
 	| varexo_det_list COMMA NAME
194
 		{ driver.declare_exogenous_det($3); }
michel's avatar
michel committed
195
 	| NAME
196
 		{ driver.declare_exogenous_det($1); }
michel's avatar
michel committed
197
 	| varexo_det_list NAME TEX_NAME
198
 		{ driver.declare_exogenous_det($2, $3); }
michel's avatar
michel committed
199
 	| varexo_det_list COMMA NAME TEX_NAME
200
 		{ driver.declare_exogenous_det($3, $4); }
michel's avatar
michel committed
201
 	| NAME TEX_NAME
202
 		{ driver.declare_exogenous_det($1, $2); }
michel's avatar
michel committed
203
204
205
206
	; 

 parameter_list
 	: parameter_list NAME
207
 		{ driver.declare_parameter($2); }
michel's avatar
michel committed
208
 	| parameter_list COMMA NAME
209
 		{ driver.declare_parameter($3); }
michel's avatar
michel committed
210
 	| NAME
211
 		{ driver.declare_parameter($1); }
michel's avatar
michel committed
212
 	| parameter_list NAME TEX_NAME
213
 		{ driver.declare_parameter($2, $3); }
michel's avatar
michel committed
214
 	| parameter_list COMMA NAME TEX_NAME
215
 		{ driver.declare_parameter($3, $4); }
michel's avatar
michel committed
216
 	| NAME TEX_NAME
217
 		{ driver.declare_parameter($1, $2); }
michel's avatar
michel committed
218
219
220
221
222
	; 	

 periods 
 	: PERIODS INT_NUMBER ';'
 		{
sebastien's avatar
sebastien committed
223
      driver.periods($2);
michel's avatar
michel committed
224
225
226
		}
    | PERIODS EQUAL INT_NUMBER ';'
 		{
sebastien's avatar
sebastien committed
227
      driver.periods($3);
michel's avatar
michel committed
228
229
230
		}
    ;

sebastien's avatar
sebastien committed
231
232
233
234
235
236
237
238
239
240
cutoff
 	: CUTOFF FLOAT_NUMBER ';'
 		{
      driver.cutoff($2);
		}
    | CUTOFF EQUAL FLOAT_NUMBER ';'
 		{
      driver.cutoff($3);
		}
    ;
michel's avatar
michel committed
241
 		   
sebastien's avatar
sebastien committed
242
 init_param
243
244
 	: NAME EQUAL expression ';'
    {driver.init_param($1, $3);} 
michel's avatar
michel committed
245
246
247
248
249
250
	;
 	
 expression
	: '(' expression ')'
		{ $$ = $2;}
	| NAME
251
		{$$ = driver.add_expression_variable($1);}
michel's avatar
michel committed
252
	| FLOAT_NUMBER
sebastien's avatar
sebastien committed
253
		{$$ = driver.add_constant($1);}
michel's avatar
michel committed
254
	| INT_NUMBER
sebastien's avatar
sebastien committed
255
		{$$ = driver.add_constant($1);}
michel's avatar
michel committed
256
	| expression PLUS expression 
sebastien's avatar
sebastien committed
257
    {$$ = driver.add_plus($1, $3);}
michel's avatar
michel committed
258
	| expression MINUS expression
sebastien's avatar
sebastien committed
259
    {$$ = driver.add_minus($1, $3);}
michel's avatar
michel committed
260
	| expression DIVIDE expression	 
sebastien's avatar
sebastien committed
261
    {$$ = driver.add_divide($1, $3);}
michel's avatar
michel committed
262
	| expression TIMES expression 
sebastien's avatar
sebastien committed
263
    {$$ = driver.add_times($1, $3);}
michel's avatar
michel committed
264
	| expression POWER expression 
sebastien's avatar
sebastien committed
265
    {$$ = driver.add_power($1, $3);}
michel's avatar
michel committed
266
	| MINUS expression %prec UMINUS
sebastien's avatar
sebastien committed
267
    {$$ = driver.add_uminus($2);}
michel's avatar
michel committed
268
	| PLUS expression
269
	  {$$ = $2;}
michel's avatar
michel committed
270
	| EXP '(' expression ')'
sebastien's avatar
sebastien committed
271
    {$$ = driver.add_exp($3);}
michel's avatar
michel committed
272
	| LOG '(' expression ')'
sebastien's avatar
sebastien committed
273
    {$$ = driver.add_log($3);}
michel's avatar
michel committed
274
	| LOG10 '(' expression ')'
sebastien's avatar
sebastien committed
275
    {$$ = driver.add_log10($3);}
michel's avatar
michel committed
276
	| SIN '(' expression ')'
sebastien's avatar
sebastien committed
277
    {$$ = driver.add_sin($3);}
michel's avatar
michel committed
278
	| COS '(' expression ')'
sebastien's avatar
sebastien committed
279
    {$$ = driver.add_cos($3);}
michel's avatar
michel committed
280
	| TAN '(' expression ')'
sebastien's avatar
sebastien committed
281
    {$$ = driver.add_tan($3);}
michel's avatar
michel committed
282
	| ASIN '(' expression ')'
sebastien's avatar
sebastien committed
283
    {$$ = driver.add_asin($3);}
michel's avatar
michel committed
284
	| ACOS '(' expression ')'
sebastien's avatar
sebastien committed
285
    {$$ = driver.add_acos($3);}
michel's avatar
michel committed
286
	| ATAN '(' expression ')'
sebastien's avatar
sebastien committed
287
    {$$ = driver.add_atan($3);}
michel's avatar
michel committed
288
	| SQRT '(' expression ')'
sebastien's avatar
sebastien committed
289
    {$$ = driver.add_sqrt($3);}
290
  | NAME '(' comma_expression ')' 
sebastien's avatar
sebastien committed
291
    {$$ = driver.add_unknown_function($1);}
michel's avatar
michel committed
292
293
	; 

294
 comma_expression :
sebastien's avatar
sebastien committed
295
296
          expression
          { driver.add_unknown_function_arg($1); }
297
        | comma_expression COMMA expression
sebastien's avatar
sebastien committed
298
          { driver.add_unknown_function_arg($3); }
michel's avatar
michel committed
299
300

 initval
sebastien's avatar
sebastien committed
301
 	: INITVAL ';' initval_list END
302
 		{driver.end_initval();}
sebastien's avatar
sebastien committed
303
304
 	|	INITVAL '(' initval_option ')' ';' initval_list END
 		{driver.end_initval();}
michel's avatar
michel committed
305
 	;
sebastien's avatar
sebastien committed
306
307
308
309

 initval_option
  : FILENAME EQUAL NAME {driver.init_val_filename($3);}
  ;
michel's avatar
michel committed
310
311
 	
 endval
sebastien's avatar
sebastien committed
312
 	: ENDVAL ';' initval_list END
313
 		{driver.end_endval();}
michel's avatar
michel committed
314
315
316
317
318
319
320
321
 	; 	

 initval_list
 	: initval_list initval_elem
	| initval_elem
	;

 initval_elem 
322
323
 	: NAME EQUAL expression ';'
    {driver.init_val($1, $3);}
michel's avatar
michel committed
324
325
326
 	; 	
 	
 histval
sebastien's avatar
sebastien committed
327
328
329
  : HISTVAL ';' histval_list END
    { driver.end_histval(); }
  ;
michel's avatar
michel committed
330
331
332
333
334
335
336

 histval_list
 	: histval_list histval_elem
	| histval_elem
	;
	
 histval_elem
337
338
 	: NAME '(' signed_integer ')' EQUAL expression ';'
    {driver.hist_val($1, $3, $6);}
michel's avatar
michel committed
339
 	;
sebastien's avatar
sebastien committed
340
341
342
343
344
345
346
347
348
349

 model_sparse_options_list : model_sparse_options_list COMMA model_sparse_options
                     | model_sparse_options
                     ;

 model_sparse_options :
      LCC_COMPILER { driver.init_compiler(0); }
    | GCC_COMPILER { driver.init_compiler(1); }
    | o_cutoff
  ;
michel's avatar
michel committed
350
351
	
 model
sebastien's avatar
sebastien committed
352
  : MODEL ';' { driver.begin_model(); } equation_list END { driver.reset_data_tree(); }
sebastien's avatar
sebastien committed
353
 	| MODEL '(' o_linear ')' ';' { driver.begin_model(); } 
sebastien's avatar
sebastien committed
354
    equation_list END { driver.reset_data_tree(); }
sebastien's avatar
sebastien committed
355
  | MODEL '(' USE_DLL ')' ';' { driver.begin_model(); driver.use_dll(); }
sebastien's avatar
sebastien committed
356
357
358
359
360
    equation_list END { driver.reset_data_tree(); }
	| MODEL '(' SPARSE_DLL COMMA model_sparse_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(); }
michel's avatar
michel committed
361
362
363
364
365
366
367
368
369
370
371
 	;

 equation_list
    : equation_list equation     	
    | equation_list pound_expression
    | equation
    | pound_expression
    ;
    
 equation
 	: hand_side EQUAL hand_side ';'
372
 		{$$ = driver.add_model_equal($1, $3);}
michel's avatar
michel committed
373
 	| hand_side ';'
374
 		{$$ = driver.add_model_equal_with_zero_rhs($1);}
michel's avatar
michel committed
375
376
377
378
379
380
	;
 
 hand_side
	: '(' hand_side ')' {$$ = $2;}
	| model_var
	| FLOAT_NUMBER
sebastien's avatar
sebastien committed
381
		{$$ = driver.add_constant($1);}
michel's avatar
michel committed
382
	| INT_NUMBER
sebastien's avatar
sebastien committed
383
    {$1->append(".0"); $$ = driver.add_constant($1);}
michel's avatar
michel committed
384
	| hand_side PLUS hand_side 
sebastien's avatar
sebastien committed
385
    	{$$ = driver.add_plus($1, $3);}
michel's avatar
michel committed
386
	| hand_side MINUS hand_side
sebastien's avatar
sebastien committed
387
    	{$$ = driver.add_minus($1, $3);}
michel's avatar
michel committed
388
	| hand_side DIVIDE hand_side	 
sebastien's avatar
sebastien committed
389
    	{$$ = driver.add_divide($1, $3);}
michel's avatar
michel committed
390
	| hand_side TIMES hand_side 
sebastien's avatar
sebastien committed
391
    	{$$ = driver.add_times($1, $3);}
michel's avatar
michel committed
392
	| hand_side POWER hand_side 
sebastien's avatar
sebastien committed
393
    	{$$ = driver.add_power($1, $3);}	
michel's avatar
michel committed
394
        | MINUS hand_side %prec UMINUS
sebastien's avatar
sebastien committed
395
      { $$ = driver.add_uminus($2);}
michel's avatar
michel committed
396
397
398
	| PLUS hand_side
	{$$ = $2;}
	| EXP '(' hand_side ')'
sebastien's avatar
sebastien committed
399
    	{$$ = driver.add_exp($3);}
michel's avatar
michel committed
400
	| LOG '(' hand_side ')'
sebastien's avatar
sebastien committed
401
    	{$$ = driver.add_log($3);}
michel's avatar
michel committed
402
	| LOG10 '(' hand_side ')'
sebastien's avatar
sebastien committed
403
    	{$$ = driver.add_log10($3);}
michel's avatar
michel committed
404
	| SIN '(' hand_side ')'
sebastien's avatar
sebastien committed
405
    	{$$ = driver.add_sin($3);}
michel's avatar
michel committed
406
	| COS '(' hand_side ')'
sebastien's avatar
sebastien committed
407
    	{$$ = driver.add_cos($3);}
michel's avatar
michel committed
408
	| TAN '(' hand_side ')'
sebastien's avatar
sebastien committed
409
    	{$$ = driver.add_tan($3);}
michel's avatar
michel committed
410
	| ASIN '(' hand_side ')'
sebastien's avatar
sebastien committed
411
    	{$$ = driver.add_asin($3);}
michel's avatar
michel committed
412
	| ACOS '(' hand_side ')'
sebastien's avatar
sebastien committed
413
    	{$$ = driver.add_acos($3);}
michel's avatar
michel committed
414
	| ATAN '(' hand_side ')'
sebastien's avatar
sebastien committed
415
    	{$$ = driver.add_atan($3);}
michel's avatar
michel committed
416
	| SQRT '(' hand_side ')'
sebastien's avatar
sebastien committed
417
    	{$$ = driver.add_sqrt($3);}
michel's avatar
michel committed
418
419
	;
	
420
 pound_expression: '#' NAME EQUAL hand_side ';'
sebastien's avatar
sebastien committed
421
                   {driver.declare_and_init_model_local_variable($2, $4);}
michel's avatar
michel committed
422
423
424

 model_var
 	: NAME 
425
 		{$$ = driver.add_model_variable($1);}
michel's avatar
michel committed
426
	| NAME '(' signed_integer ')'
427
		{$$ = driver.add_model_variable($1, $3);}
michel's avatar
michel committed
428
429
430
	;
	
 shocks
sebastien's avatar
sebastien committed
431
 	: SHOCKS  ';' shock_list END {driver.end_shocks();}
michel's avatar
michel committed
432
433
434
 	;

 mshocks
sebastien's avatar
sebastien committed
435
  : MSHOCKS  ';' shock_list END {driver.end_mshocks();}
michel's avatar
michel committed
436
437
438
439
440
441
442
443
444
 	;

 shock_list 
 	: shock_list shock_elem
	| shock_elem
    ;

 shock_elem 
	: VAR NAME ';' PERIODS period_list ';' VALUES value_list ';'
445
		{driver.add_det_shock($2);}
446
447
448
449
450
451
452
453
	| 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);}
michel's avatar
michel committed
454
455
456
457
	;

 period_list
 	: period_list INT_NUMBER
458
 		{driver.add_period($2);}
michel's avatar
michel committed
459
	| period_list INT_NUMBER ':' INT_NUMBER 
460
 		{driver.add_period($2,$4);}
michel's avatar
michel committed
461
        | period_list COMMA INT_NUMBER
462
 		{driver.add_period($3);}
michel's avatar
michel committed
463
	| period_list COMMA INT_NUMBER ':' INT_NUMBER 
464
 		{driver.add_period($3, $5);}
michel's avatar
michel committed
465
	| INT_NUMBER ':' INT_NUMBER
466
 		{driver.add_period($1, $3);}
michel's avatar
michel committed
467
	| INT_NUMBER
468
 		{driver.add_period($1);}
michel's avatar
michel committed
469
470
471
472
473
	;


 value_list
 	: value_list signed_float  
sebastien's avatar
sebastien committed
474
		{driver.add_value_const($2);}
michel's avatar
michel committed
475
	| value_list signed_integer
sebastien's avatar
sebastien committed
476
		{driver.add_value_const($2);}
michel's avatar
michel committed
477
	| value_list NAME
sebastien's avatar
sebastien committed
478
		{driver.add_value_var($2);}
michel's avatar
michel committed
479
	| signed_float
sebastien's avatar
sebastien committed
480
		{driver.add_value_const($1);}
michel's avatar
michel committed
481
	| signed_integer
sebastien's avatar
sebastien committed
482
		{driver.add_value_const($1);}
michel's avatar
michel committed
483
	| NAME
sebastien's avatar
sebastien committed
484
		{driver.add_value_var($1);}
485
486
487
488
	| value_list '(' expression ')'
    {driver.add_value($3);}
	| '(' expression ')'
    {driver.add_value($2);}
michel's avatar
michel committed
489
490
491
492
	;
	
 sigma_e 
 	: SIGMA_E EQUAL '[' triangular_matrix ']' ';' 
493
 		{driver.do_sigma_e();}
michel's avatar
michel committed
494
495
496
497
    ;

 triangular_matrix 
 	: triangular_matrix ';' triangular_row 
498
 		{driver.end_of_row();}
michel's avatar
michel committed
499
    | triangular_row 
500
    	{driver.end_of_row();}
michel's avatar
michel committed
501
502
503
	;
	
 triangular_row 
504
505
 	: triangular_row COMMA '(' expression ')' 
    {driver.add_to_row($4);}
michel's avatar
michel committed
506
	| triangular_row COMMA FLOAT_NUMBER 
sebastien's avatar
sebastien committed
507
		{driver.add_to_row_const($3);}
michel's avatar
michel committed
508
	| triangular_row COMMA INT_NUMBER 
sebastien's avatar
sebastien committed
509
		{driver.add_to_row_const($3);}
510
511
	| triangular_row '(' expression ')'
    {driver.add_to_row($3);}
michel's avatar
michel committed
512
	| triangular_row FLOAT_NUMBER 
sebastien's avatar
sebastien committed
513
		{driver.add_to_row_const($2);}
michel's avatar
michel committed
514
	| triangular_row INT_NUMBER 
sebastien's avatar
sebastien committed
515
		{driver.add_to_row_const($2);}
516
517
	| '(' expression ')'
    {driver.add_to_row($2);}
michel's avatar
michel committed
518
	| FLOAT_NUMBER 
sebastien's avatar
sebastien committed
519
		{driver.add_to_row_const($1);}
michel's avatar
michel committed
520
	| INT_NUMBER 
sebastien's avatar
sebastien committed
521
		{driver.add_to_row_const($1);}
michel's avatar
michel committed
522
523
524
525
526
	;
	
 steady 
 	: STEADY ';' 
 		{
527
 			driver.steady();
michel's avatar
michel committed
528
529
 		}
    | STEADY '(' steady_options_list ')' ';'
530
    	 {driver.steady();}
michel's avatar
michel committed
531
532
533
534
535
536
537
538
539
540
541
    ;
    
 steady_options_list : steady_options_list COMMA steady_options
                     | steady_options
                     ;

 steady_options: o_solve_algo
               ;

 check 
 	: CHECK ';' 
542
 		{driver.check();}
michel's avatar
michel committed
543
	| CHECK '(' check_options_list ')' ';' 
544
		{driver.check();} 
michel's avatar
michel committed
545
546
547
548
549
550
551
552
553
554
555
	;

 check_options_list : check_options_list COMMA check_options
        | check_options
        ;

 check_options : o_solve_algo
               ;

 simul 
	: SIMUL ';' 
sebastien's avatar
sebastien committed
556
		{driver.simulate();}
michel's avatar
michel committed
557
	| SIMUL '(' simul_options_list ')' ';'
sebastien's avatar
sebastien committed
558
		{driver.simulate();}
michel's avatar
michel committed
559
560
561
562
563
564
565
566
567
568
569
        ;

 simul_options_list: simul_options_list COMMA simul_options
                   | simul_options
                   ;

 simul_options: o_periods
              ;

 stoch_simul
 	: STOCH_SIMUL ';'
570
 		{driver.stoch_simul();}
michel's avatar
michel committed
571
	| STOCH_SIMUL '(' stoch_simul_options_list ')' ';' 
572
		{driver.stoch_simul();}
michel's avatar
michel committed
573
	| STOCH_SIMUL tmp_var_list ';'
574
		{driver.stoch_simul();}
michel's avatar
michel committed
575
	| STOCH_SIMUL '(' stoch_simul_options_list ')' tmp_var_list ';' 
576
		{driver.stoch_simul();}
michel's avatar
michel committed
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
	;
	
 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
592
                     | o_nofunctions
michel's avatar
michel committed
593
594
595
596
597
598
                     | o_nomoments
                     | o_irf
                     | o_relative_irf
                     | o_hp_filter
                     | o_hp_ngrid
                     | o_periods
sebastien's avatar
sebastien committed
599
                     | o_cutoff
michel's avatar
michel committed
600
601
602
603
604
605
606
                     | o_simul
                     | o_simul_seed
                     | o_qz_criterium
                     ;

 tmp_var_list
	: tmp_var_list NAME
607
		{driver.add_tmp_var($2);}
michel's avatar
michel committed
608
	| tmp_var_list NAME EQUAL NAME
609
		{driver.add_tmp_var($2, $4);}
michel's avatar
michel committed
610
	| tmp_var_list COMMA NAME
611
		{driver.add_tmp_var($3);}
michel's avatar
michel committed
612
	| tmp_var_list COMMA NAME EQUAL NAME
613
		{driver.add_tmp_var($3, $5);}
michel's avatar
michel committed
614
	| NAME
615
		{driver.add_tmp_var($1);}
michel's avatar
michel committed
616
	| NAME EQUAL NAME
617
		{driver.add_tmp_var($1, $3);}
michel's avatar
michel committed
618
619
620
621
622
623
	;

 signed_integer
 	: PLUS INT_NUMBER
 		{$$ = $2;}
 	| MINUS INT_NUMBER
624
 		{$2->insert(0, "-"); $$ = $2;}
michel's avatar
michel committed
625
626
627
628
629
630
631
632
 	| INT_NUMBER
 		{$$ = $1;}
 	;
 	
 signed_float
 	: PLUS FLOAT_NUMBER
 		{$$ = $2;}
 	| MINUS FLOAT_NUMBER
633
 		{$2->insert(0, "-"); $$ = $2;}
michel's avatar
michel committed
634
635
636
637
638
 	| FLOAT_NUMBER
 		{$$ = $1;}
 	;

 estimated_params 
sebastien's avatar
sebastien committed
639
640
	: ESTIMATED_PARAMS ';' estimated_list END
    { driver.estimated_params(); }
michel's avatar
michel committed
641
642
643
644
	;
	
 estimated_list 
	: estimated_list estimated_elem 
sebastien's avatar
sebastien committed
645
		{driver.add_estimated_params_element();}
michel's avatar
michel committed
646
	| estimated_elem 
sebastien's avatar
sebastien committed
647
		{driver.add_estimated_params_element();}
michel's avatar
michel committed
648
649
650
651
652
653
654
655
	;

 estimated_elem 
	: estimated_elem1 COMMA estimated_elem2 ';'
	;

 estimated_elem1 
	: STDERR NAME 
656
657
		{driver.estim_params.type = 1;
		 driver.estim_params.name = *$2;
658
     delete $2;
michel's avatar
michel committed
659
660
		}
	| NAME
661
662
		{driver.estim_params.type = 2;
		 driver.estim_params.name = *$1;
663
     delete $1;
michel's avatar
michel committed
664
665
		}
	| CORR NAME COMMA NAME
666
667
668
		{driver.estim_params.type = 3;
		 driver.estim_params.name = *$2;
		 driver.estim_params.name2 = *$4;
669
670
     delete $2;
     delete $4;
michel's avatar
michel committed
671
672
673
674
675
		}
	;

 estimated_elem2 
	: prior COMMA estimated_elem3 
676
677
678
679
		{
      driver.estim_params.prior=*$1;
      delete $1;
    }
michel's avatar
michel committed
680
	| value COMMA prior COMMA estimated_elem3 
681
682
		{driver.estim_params.init_val=*$1;
		 driver.estim_params.prior=*$3;
683
684
     delete $1;
     delete $3;
michel's avatar
michel committed
685
686
		}
	| value COMMA value COMMA value COMMA prior COMMA estimated_elem3 
687
688
689
690
		{driver.estim_params.init_val=*$1;
		 driver.estim_params.low_bound=*$3;
		 driver.estim_params.up_bound=*$5;
		 driver.estim_params.prior=*$7;
691
692
693
694
     delete $1;
     delete $3;
     delete $5;
     delete $7;
michel's avatar
michel committed
695
696
		}
	| value 
697
698
699
700
		{
      driver.estim_params.init_val=*$1;
      delete $1;
    }
michel's avatar
michel committed
701
	| value COMMA value COMMA value 
702
703
704
		{driver.estim_params.init_val=*$1;
		 driver.estim_params.low_bound=*$3;
		 driver.estim_params.up_bound=*$5;
705
706
707
     delete $1;
     delete $3;
     delete $5;
michel's avatar
michel committed
708
709
710
711
712
		}
	;

 estimated_elem3 
 	: value COMMA value 
713
714
 		{driver.estim_params.mean=*$1;
 		 driver.estim_params.std=*$3;
715
716
     delete $1;
     delete $3;
michel's avatar
michel committed
717
718
 		}
	| value COMMA value COMMA value
719
720
721
		{driver.estim_params.mean=*$1;
		 driver.estim_params.std=*$3;
		 driver.estim_params.p3=*$5;
722
723
724
     delete $1;
     delete $3;
     delete $5;
michel's avatar
michel committed
725
726
		}	
	| value COMMA value COMMA value COMMA value 
727
728
729
730
		{driver.estim_params.mean=*$1;
		 driver.estim_params.std=*$3;
		 driver.estim_params.p3=*$5;
		 driver.estim_params.p4=*$7;
731
732
733
734
     delete $1;
     delete $3;
     delete $5;
     delete $7;
michel's avatar
michel committed
735
736
		}
	| value COMMA value COMMA value COMMA value COMMA value 
737
738
739
740
741
		{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;
742
743
744
745
746
     delete $1;
     delete $3;
     delete $5;
     delete $7;
     delete $9;
michel's avatar
michel committed
747
748
749
750
		}
	;

 estimated_params_init: ESTIMATED_PARAMS_INIT ';' estimated_init_list END
sebastien's avatar
sebastien committed
751
                        { driver.estimated_params_init(); }
michel's avatar
michel committed
752
753
754
                      ;

 estimated_init_list : estimated_init_list estimated_init_elem
sebastien's avatar
sebastien committed
755
                       {driver.add_estimated_params_element();}
michel's avatar
michel committed
756
                     | estimated_init_elem
sebastien's avatar
sebastien committed
757
                       {driver.add_estimated_params_element();}
michel's avatar
michel committed
758
759
760
                     ;

 estimated_init_elem : STDERR NAME COMMA value ';'
761
762
763
 		     		{driver.estim_params.type = 1;
				 driver.estim_params.name = *$2;
				 driver.estim_params.init_val=*$4;
764
765
         delete $2;
         delete $4;
michel's avatar
michel committed
766
767
				}
                     | CORR NAME COMMA NAME COMMA value ';'
768
769
770
771
 		     		{driver.estim_params.type = 3;
				 driver.estim_params.name = *$2;
				 driver.estim_params.name2 = *$4;
				 driver.estim_params.init_val=*$6;
772
773
774
         delete $2;
         delete $4;
         delete $6;
michel's avatar
michel committed
775
776
				}
                     | NAME COMMA value ';'
777
778
779
 		     		{driver.estim_params.type = 2;
				 driver.estim_params.name = *$1;
				 driver.estim_params.init_val=*$3;
780
781
         delete $1;
         delete $3;
michel's avatar
michel committed
782
783
784
785
				}
                     ;

 estimated_params_bounds: ESTIMATED_PARAMS_BOUNDS ';' estimated_bounds_list END
sebastien's avatar
sebastien committed
786
                          { driver.estimated_params_bounds(); }
michel's avatar
michel committed
787
788
789
                      ;

 estimated_bounds_list : estimated_bounds_list estimated_bounds_elem
sebastien's avatar
sebastien committed
790
                       {driver.add_estimated_params_element();}
michel's avatar
michel committed
791
                     | estimated_bounds_elem
sebastien's avatar
sebastien committed
792
                       {driver.add_estimated_params_element();}
michel's avatar
michel committed
793
794
795
                     ;

 estimated_bounds_elem : STDERR NAME COMMA value COMMA value ';'
796
797
798
799
 		     		{driver.estim_params.type = 1;
				 driver.estim_params.name = *$2;
				 driver.estim_params.low_bound=*$4;
				 driver.estim_params.up_bound=*$6;
800
801
802
         delete $2;
         delete $4;
         delete $6;
michel's avatar
michel committed
803
804
				}
                     | CORR NAME COMMA NAME COMMA value COMMA value ';'
805
806
807
808
809
 		     		{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;
810
811
812
813
         delete $2;
         delete $4;
         delete $6;
         delete $8;
michel's avatar
michel committed
814
815
				}
                     | NAME COMMA value COMMA value ';'
816
817
818
819
 		     		{driver.estim_params.type = 2;
				 driver.estim_params.name = *$1;
				 driver.estim_params.low_bound=*$3;
				 driver.estim_params.up_bound=*$5;
820
821
822
         delete $1;
         delete $3;
         delete $5;
michel's avatar
michel committed
823
824
825
826
827
				}
                     ;

 prior
	: BETA_PDF 
828
    {$$ = new string("1");}
michel's avatar
michel committed
829
	| GAMMA_PDF 
830
    {$$ = new string("2");}
michel's avatar
michel committed
831
	| NORMAL_PDF 
832
    {$$ = new string("3");}
michel's avatar
michel committed
833
	| INV_GAMMA_PDF 
834
    {$$ = new string("4");}
michel's avatar
michel committed
835
	| UNIFORM_PDF 
836
    {$$ = new string("5");}
michel's avatar
michel committed
837
838
839
	;

 value 
840
841
  : {$$ = new string("NaN");} 
  | INT_NUMBER
michel's avatar
michel committed
842
843
	| FLOAT_NUMBER
	| NAME
844
845
846
847
  | MINUS INT_NUMBER
    {$2->insert(0, "-"); $$ = $2;}
  | MINUS FLOAT_NUMBER
    {$2->insert(0, "-"); $$ = $2;}
michel's avatar
michel committed
848
849
850
851
852
853
	;

 
       
 estimation 
	: ESTIMATION ';'
854
		{driver.run_estimation();}
michel's avatar
michel committed
855
	| ESTIMATION '(' estimation_options_list ')' ';' 
856
		{driver.run_estimation();}
michel's avatar
michel committed
857
	| ESTIMATION tmp_var_list ';'
858
		{driver.run_estimation();}
michel's avatar
michel committed
859
	| ESTIMATION '(' estimation_options_list ')' tmp_var_list ';' 
860
		{driver.run_estimation();}
michel's avatar
michel committed
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
	;

 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
michel's avatar
michel committed
906
                   | o_mh_recover
michel's avatar
michel committed
907
908
                   ;
	
michel's avatar
michel committed
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
 prior_analysis 
	: PRIOR_ANALYSIS '(' prior_posterior_options_list ')' ';' 
                {driver.run_prior_analysis();}
	| PRIOR_ANALYSIS '(' prior_posterior_options_list ')' tmp_var_list ';' 
                {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();}
	| POSTERIOR_ANALYSIS '(' prior_posterior_options_list ')' tmp_var_list ';' 
		{driver.run_posterior_analysis();}
	;

michel's avatar
michel committed
944
 list_optim_option
sebastien's avatar
sebastien committed
945
946
 	: '\'' NAME '\'' COMMA '\'' NAME '\'' {driver.optim_options_string($2, $6);}
	| '\'' NAME '\'' COMMA value {driver.optim_options_num($2, $5);}
michel's avatar
michel committed
947
948
949
950
951
952
953
954
955
	;

 optim_options
	: list_optim_option
	| optim_options COMMA list_optim_option;
	;
	
 varobs 
 	: VAROBS tmp_var_list ';' 
956
 		{driver.set_varobs();}
michel's avatar
michel committed
957
958
959
	;

 observation_trends
sebastien's avatar
sebastien committed
960
961
        : OBSERVATION_TRENDS ';' trend_list END
{ driver.set_trends(); }
michel's avatar
michel committed
962
963
964
965
966
967
968
	;

 trend_list 
        : trend_list trend_element
	| trend_element
	;

969
970
 trend_element :  NAME '(' expression ')' ';' 
{driver.set_trend_element($1, $3);}
michel's avatar
michel committed
971
972
               ;

973
 unit_root_vars : UNIT_ROOT_VARS tmp_var_list ';' {driver.set_unit_root_vars();}
michel's avatar
michel committed
974
975
                ;