%{ #include #include "d_tab.h" #include "d.h" int previous_state; int comment_level = 0; int lineno = 1; void yyerror(char *); int name_var(char *); %} %option stack %option yylineno %x CMT %x DYNARE1 %x DYNARE2 %x DYNARE3 %x DYNARE4 %x THRU %% /* literal keywords token */ _longnames {BEGIN DYNARE1; return LONGNAMES;} initvalf {BEGIN THRU; ECHO;} endval {BEGIN DYNARE2; return ENDVAL;} initval {BEGIN DYNARE2; return INITVAL;} histval {BEGIN DYNARE2; return HISTVAL;} model {BEGIN DYNARE2; return MODEL;} periods {BEGIN DYNARE1; return PERIODS;} shocks {BEGIN DYNARE2; return SHOCKS;} mshocks {BEGIN DYNARE2; return MSHOCKS;} var {BEGIN DYNARE1; return VAR;} varexo {BEGIN DYNARE1; return VAREXO;} varexo_stochastic {BEGIN DYNARE1; return VAREXO_ST;} varrecur {BEGIN DYNARE1; return VARRECUR;} parameters {BEGIN DYNARE1; return PARAMETERS;} dyn2vec {BEGIN DYNARE1; return DYN2VEC;} dyn2gau {BEGIN DYNARE1; return DYN2VEC;} rplot {BEGIN DYNARE1; return RPLOT;} steady {BEGIN DYNARE1; return STEADY;} stoch_simul {BEGIN DYNARE1; return STOCH_SIMUL;} resol {BEGIN DYNARE1; return RESOL;} disp_dr {BEGIN DYNARE1; return DISP_DR;} disp_moments {BEGIN DYNARE1; return DISP_MOMENTS;} irf {BEGIN DYNARE1; return IRF;} d_corr {BEGIN DYNARE1; return D_CORR;} simul {BEGIN DYNARE1; return SIMUL;} dsample {BEGIN DYNARE1; return DSAMPLE;} check {BEGIN DYNARE1; yylval.string=strdup(yytext); return CHECK;} optim_weights {BEGIN DYNARE2; return OPTIM_WEIGHTS;} osr_params {BEGIN DYNARE1; return OSR_PARAMS;} osr {BEGIN DYNARE1; return OSR;} calib_var {BEGIN DYNARE2; return CALIB_VAR;} calib {BEGIN DYNARE1; return CALIB;} dynatype {BEGIN DYNARE1; return DYNATYPE;} dynasave {BEGIN DYNARE1; return DYNASAVE;} sigma_e_ {BEGIN THRU; ECHO;} sigma_e {BEGIN DYNARE3; return SIGMA_E;} olr {BEGIN DYNARE1; return OLR;} olr_inst {BEGIN DYNARE1; return OLR_INST;} estimated_params {BEGIN DYNARE2; return ESTIMATED_PARAMS;} estimation {BEGIN DYNARE1; return ESTIMATION;} varobs {BEGIN DYNARE1; return VAROBS;} /* \r is always ignored */ <*>\r ; /* comments */ <*>[/][/].* ; <*>"/*" {yy_push_state(CMT); ECHO;} [^*\n]* {ECHO;} "*"+[^*/\n]* {ECHO;} "*"+"/" {yy_pop_state(); ECHO;} [\n] {ECHO;} /* a semicolon in INITIAL state doesn't modify this state */ ; ECHO; /* initial spaces or tabs are ignored */ [ \t] ; /* everything which is not a DYNARE command or a comment is ECHOED*/ [^ \t\n;] {BEGIN THRU;ECHO;} [^;\n] ECHO; [;\n] {BEGIN INITIAL; ECHO;} ; {BEGIN INITIAL; return yytext[0];} ; {return yytext[0];} [\(\)] {return yytext[0];} /* var, periods and values in shock statements */ var {return VAR;} periods {return PERIODS;} values {return VALUES;} stderr {return STDERR;} varexo {return VAREXO;} end[ \t\n]*; {BEGIN INITIAL; return END;} /* lines starting with '#' */ ^# {BEGIN DYNARE4; return POUND;} [\n] {BEGIN DYNARE2; return EOL;} /* do loops in models */ do {return DO;} to {return TO;} by {return BY;} endo {return ENDO;} sum {return SUM;} prod {return PROD;} /* options */ dr_algo {return DR_ALGO;} simul_algo {return SIMUL_ALGO;} drop {return DROP;} linear {return LINEAR;} order {return ORDER;} replic {return REPLIC;} shock_size {return SHOCK_SIZE;} nomoments {return NOMOMENTS;} nocorr {return NOCORR;} ar {return AR;} nofunctions {return NOFUNCTIONS;} irf {return IRF;} hp_filter {return HP_FILTER;} hp_ngrid {return HP_NGRID;} simul_seed {return SIMUL_SEED;} simul {return SIMUL;} periods {return PERIODS;} qz_criterium {return QZ_CRITERIUM;} /* calib options */ autocorr {return AUTOCORR;} /* olr options */ olr_beta {return OLR_BETA;} /* estimation options */ datafile {return DATAFILE;} nobs {return NOBS;} first_obs {return FIRST_OBS;} /* estimated_params priors */ gamma_pdf {return GAMMA_PDF;} beta_pdf {return BETA_PDF;} normal_pdf {return NORMAL_PDF;} inv_gamma_pdf {return INV_GAMMA_PDF;} corr {return CORR;} /* spaces, tabs and EOL are ignored */ [ \t\n] ; /* names */ [A-Za-z_][A-Za-z0-9_]* { yylval.string=strdup(yytext); return NAME;} [A-Za-z_][A-Za-z0-9_]* { return name_var(strdup(yytext));} /* floating-point numbers */ -?(([0-9]*\.[0-9]+)|([0-9]+\.))([edED][-+]?[0-9]+)? { yylval.string=strdup(yytext); return DNUMBER;} /* integer number */ -?[0-9]+ { yylval.string=strdup(yytext); return INUMBER;} : {return yytext[0];} = {return EQUAL;} , {return yytext[0];} \$ {return DOLLAR;} = {return yytext[0];} ] {BEGIN DYNARE1; return yytext[0];} \[ {return yytext[0];} ] {BEGIN DYNARE1; return yytext[0];} . {yylval.string=strdup(yytext); return OPERATORS;} <*>. {return yytext[0];} %% int yywrap() { return 1; } int name_var(char *s) { struct var *p; p=var_search(s); if (p == NULL){ yylval.string=s; return NAME; } else if (p->endo_exo == 2){ yylval.string=s; return INDEX; } else{ yylval.p_tok=create_var(p); return VAR_ID; } } /* 01/01/03 MJ added DYNASAVE 12/31/02 MJ corrected THRU mode to permit native lines without a final ; MJ put back CMT mode for Gauss style comments (/ *...* /) 04/06/02 MJ added OPTIM_WEIGHTS OSR_PARAMS OSR */