Merge branch 'preprocessor-dates' into remove-dynDate-class

Conflicts:
	preprocessor/DynareBison.yy
	preprocessor/DynareFlex.ll
	preprocessor/macro/MacroFlex.ll
time-shift
Stéphane Adjemian (Penelope) 2013-11-14 15:50:20 +01:00
commit 7e22f43fe0
5 changed files with 50 additions and 24 deletions

View File

@ -99,14 +99,13 @@ class ParsingDriver;
%token DATAFILE FILE DETERMINISTIC DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS %token DATAFILE FILE DETERMINISTIC DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME %token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME
%token <string_val> FLOAT_NUMBER %token <string_val> FLOAT_NUMBER DATES
%token DEFAULT FIXED_POINT %token DEFAULT FIXED_POINT
%token FORECAST K_ORDER_SOLVER INSTRUMENTS SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN %token FORECAST K_ORDER_SOLVER INSTRUMENTS SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN
%token GAMMA_PDF GRAPH GRAPH_FORMAT CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK STD %token GAMMA_PDF GRAPH GRAPH_FORMAT CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK STD
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID HYBRID %token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID HYBRID
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT %token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT
%token <string_val> INT_NUMBER %token <string_val> INT_NUMBER
%token <string_val> DATE_NUMBER
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS %token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS
%token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF %token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LYAPUNOV %token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LYAPUNOV
@ -178,8 +177,8 @@ class ParsingDriver;
%type <node_val> expression expression_or_empty %type <node_val> expression expression_or_empty
%type <node_val> equation hand_side %type <node_val> equation hand_side
%type <string_val> non_negative_number signed_number signed_integer %type <string_val> non_negative_number signed_number signed_integer date_str
%type <string_val> filename symbol vec_of_vec_value vec_value_list %type <string_val> filename symbol vec_of_vec_value vec_value_list date_expr
%type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf %type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf
%type <string_val> range vec_value_w_inf vec_value_1_w_inf %type <string_val> range vec_value_w_inf vec_value_1_w_inf
%type <symbol_type_val> change_type_arg %type <symbol_type_val> change_type_arg
@ -1239,7 +1238,15 @@ prior_pdf : BETA_PDF
{ $$ = eInvGamma2; } { $$ = eInvGamma2; }
; ;
set_time : SET_TIME '(' DATE_NUMBER ')' ';' date_str : DATES { $$ = $1; }
date_expr : date_str
{ $$ = $1; }
| date_expr PLUS INT_NUMBER
{ $$ = $1; $$->append("+").append(*$3); }
;
set_time : SET_TIME '(' date_expr ')' ';'
{ driver.set_time($3); } { driver.set_time($3); }
; ;
@ -2293,10 +2300,10 @@ o_conditional_variance_decomposition : CONDITIONAL_VARIANCE_DECOMPOSITION EQUAL
{ driver.option_vec_int("conditional_variance_decomposition", $3); } { driver.option_vec_int("conditional_variance_decomposition", $3); }
; ;
o_first_obs : FIRST_OBS EQUAL INT_NUMBER { driver.option_num("first_obs", $3); }; o_first_obs : FIRST_OBS EQUAL INT_NUMBER { driver.option_num("first_obs", $3); };
o_new_estimation_data_first_obs : FIRST_OBS EQUAL DATE_NUMBER o_new_estimation_data_first_obs : FIRST_OBS EQUAL date_expr
{ driver.option_date("first_obs", $3); } { driver.option_date("first_obs", $3); }
; ;
o_last_obs : LAST_OBS EQUAL DATE_NUMBER o_last_obs : LAST_OBS EQUAL date_expr
{ driver.option_date("last_obs", $3); } { driver.option_date("last_obs", $3); }
; ;
o_shift : SHIFT EQUAL signed_number { driver.option_num("shift", $3); }; o_shift : SHIFT EQUAL signed_number { driver.option_num("shift", $3); };
@ -2340,7 +2347,7 @@ list_allowed_graph_formats : allowed_graph_formats
| list_allowed_graph_formats COMMA allowed_graph_formats | list_allowed_graph_formats COMMA allowed_graph_formats
; ;
o_subsample_name : symbol EQUAL DATE_NUMBER ':' DATE_NUMBER o_subsample_name : symbol EQUAL date_expr ':' date_expr
{ driver.set_subsample_name_equal_to_date_range($1, $3, $5); } { driver.set_subsample_name_equal_to_date_range($1, $3, $5); }
; ;
o_conf_sig : CONF_SIG EQUAL non_negative_number { driver.option_num("conf_sig", $3); }; o_conf_sig : CONF_SIG EQUAL non_negative_number { driver.option_num("conf_sig", $3); };

View File

@ -60,6 +60,7 @@ string eofbuff;
%x VERBATIM_BLOCK %x VERBATIM_BLOCK
%x NATIVE %x NATIVE
%x NATIVE_COMMENT %x NATIVE_COMMENT
%x DATES_STATEMENT
%x LINE1 %x LINE1
%x LINE2 %x LINE2
%x LINE3 %x LINE3
@ -88,13 +89,13 @@ string eofbuff;
} }
/* spaces, tabs and carriage returns are ignored */ /* spaces, tabs and carriage returns are ignored */
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3>[ \t\r\f]+ { yylloc->step(); } <INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,DATES_STATEMENT,LINE1,LINE2,LINE3>[ \t\r\f]+ { yylloc->step(); }
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3>[\n]+ { yylloc->step(); } <INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,DATES_STATEMENT,LINE1,LINE2,LINE3>[\n]+ { yylloc->step(); }
/* Comments */ /* Comments */
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK>["%"].* <INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,DATES_STATEMENT>["%"].*
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK>["/"]["/"].* <INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,DATES_STATEMENT>["/"]["/"].*
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK>"/*" {comment_caller = YY_START; BEGIN COMMENT;} <INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,DATES_STATEMENT>"/*" {comment_caller = YY_START; BEGIN COMMENT;}
<COMMENT>"*/" {BEGIN comment_caller;} <COMMENT>"*/" {BEGIN comment_caller;}
<COMMENT>. <COMMENT>.
@ -204,6 +205,7 @@ string eofbuff;
<INITIAL>corr {BEGIN DYNARE_STATEMENT; return token::CORR;} <INITIAL>corr {BEGIN DYNARE_STATEMENT; return token::CORR;}
/* Inside of a Dynare statement */ /* Inside of a Dynare statement */
<DYNARE_STATEMENT>dates {dates_parens_nb=0; BEGIN DATES_STATEMENT; yylval->string_val = new string("dates");}
<DYNARE_STATEMENT>file {return token::FILE;} <DYNARE_STATEMENT>file {return token::FILE;}
<DYNARE_STATEMENT>datafile {return token::DATAFILE;} <DYNARE_STATEMENT>datafile {return token::DATAFILE;}
<DYNARE_STATEMENT>nobs {return token::NOBS;} <DYNARE_STATEMENT>nobs {return token::NOBS;}
@ -707,10 +709,16 @@ string eofbuff;
return token::INT_NUMBER; return token::INT_NUMBER;
} }
<DYNARE_STATEMENT,DYNARE_BLOCK>dates[[:space:]]*\([[:space:]]*\'[[:space:]]*(-[1-9][0-9]*|[0-9]+)([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2]))[[:space:]]*\'[[:space:]]*\) { <DATES_STATEMENT>\( { yylval->string_val->append(yytext); dates_parens_nb++; }
yylval->string_val = new string(yytext); <DATES_STATEMENT>\) {
return token::DATE_NUMBER; yylval->string_val->append(yytext);
} if (--dates_parens_nb == 0)
{
BEGIN DYNARE_STATEMENT;
return token::DATES;
}
}
<DATES_STATEMENT>. { yylval->string_val->append(yytext); }
<DYNARE_STATEMENT,DYNARE_BLOCK>\'[^\']+\' { <DYNARE_STATEMENT,DYNARE_BLOCK>\'[^\']+\' {
yylval->string_val = new string(yytext + 1); yylval->string_val = new string(yytext + 1);
@ -803,7 +811,7 @@ string eofbuff;
<NATIVE_COMMENT>"*/"[[:space:]]*\n { BEGIN NATIVE; } <NATIVE_COMMENT>"*/"[[:space:]]*\n { BEGIN NATIVE; }
<NATIVE_COMMENT>. <NATIVE_COMMENT>.
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3,NATIVE_COMMENT><<EOF>> { yyterminate(); } <INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,DATES_STATEMENT,LINE1,LINE2,LINE3,NATIVE_COMMENT><<EOF>> { yyterminate(); }
<*>. { driver.error(*yylloc, "character unrecognized by lexer"); } <*>. { driver.error(*yylloc, "character unrecognized by lexer"); }
%% %%

View File

@ -71,6 +71,9 @@ public:
//! Increment the location counter given a token //! Increment the location counter given a token
void location_increment(Dynare::parser::location_type *yylloc, const char *yytext); void location_increment(Dynare::parser::location_type *yylloc, const char *yytext);
//! Count parens in dates statement
int dates_parens_nb;
}; };
//! Drives the scanning and parsing of the .mod file, and constructs its abstract representation //! Drives the scanning and parsing of the .mod file, and constructs its abstract representation

View File

@ -86,6 +86,8 @@ private:
//! If current context is the body of a loop, contains the location of the beginning of the body //! If current context is the body of a loop, contains the location of the beginning of the body
Macro::parser::location_type for_body_loc; Macro::parser::location_type for_body_loc;
//! Temporary variable used for counting parens in dates statement
int dates_parens_nb;
//! Temporary variable used in FOR_BODY mode //! Temporary variable used in FOR_BODY mode
string for_body_tmp; string for_body_tmp;
//! Temporary variable used in FOR_BODY mode //! Temporary variable used in FOR_BODY mode

View File

@ -51,8 +51,7 @@ typedef Macro::parser::token token;
%x FOR_BODY %x FOR_BODY
%x THEN_BODY %x THEN_BODY
%x ELSE_BODY %x ELSE_BODY
%x DATE_MATCH %x COPY_DATE_INFO
%x CLOSE_DATE
%{ %{
// Increments location counter for every token read // Increments location counter for every token read
@ -93,10 +92,17 @@ DATE (-[1-9][0-9]*|[0-9]+)([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-
<INITIAL>{DATE} { yylloc->step(); *yyout << "dates('" << yytext << "')"; } <INITIAL>{DATE} { yylloc->step(); *yyout << "dates('" << yytext << "')"; }
<INITIAL>${DATE} { yylloc->step(); *yyout << yytext + 1; } <INITIAL>${DATE} { yylloc->step(); *yyout << yytext + 1; }
<INITIAL>dates{SPC}*\({SPC}* { yylloc->step(); *yyout << "dates("; BEGIN(DATE_MATCH); } <INITIAL>dates{SPC}*\({SPC}* { yylloc->step(); *yyout << "dates("; dates_parens_nb=1; BEGIN(COPY_DATE_INFO); }
<DATE_MATCH>\'{SPC}*{DATE}{SPC}*\' { yylloc->step(); *yyout << yytext; BEGIN(CLOSE_DATE); } <COPY_DATE_INFO><<EOF>> { driver.error(*yylloc, "Unexpected end of file in dates statement"); }
<DATE_MATCH>{DATE} { yylloc->step(); *yyout << "'" << yytext << "'"; BEGIN(CLOSE_DATE); } <COPY_DATE_INFO>{EOL} { yylloc->lines(1); yylloc->step(); }
<CLOSE_DATE>{SPC}*\) { yylloc->step(); *yyout << ")"; BEGIN(INITIAL); } <COPY_DATE_INFO>\( { yylloc->step(); *yyout << yytext; dates_parens_nb++; }
<COPY_DATE_INFO>\) {
yylloc->step();
*yyout << yytext;
if (--dates_parens_nb == 0)
BEGIN(INITIAL);
}
<COPY_DATE_INFO>. { yylloc->step(); *yyout << yytext; }
<EXPR>\} { BEGIN(INITIAL); return token::EOL; } <EXPR>\} { BEGIN(INITIAL); return token::EOL; }