Commit 7cfad8ee authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Merge branch 'master' into remove-dynDate-class

parents b99db457 ddf90fb7
......@@ -1020,9 +1020,9 @@ extension or if the filename contains a non-alphanumeric character;
Declarations of variables and parameters are made with the following commands:
@deffn Command var @var{VARIABLE_NAME} [$@var{LATEX_NAME}$]@dots{};
@deffnx Command var (deflator = @var{MODEL_EXPRESSION}) @var{VARIABLE_NAME} [$@var{LATEX_NAME}$]@dots{};
@deffnx Command var (log_deflator = @var{MODEL_EXPRESSION}) @var{VARIABLE_NAME} [$@var{LATEX_NAME}$]@dots{};
@deffn Command var @var{VARIABLE_NAME} [$@var{LATEX_NAME}$ [(long_name=@var{QUOTED_STRING})]]@dots{};
@deffnx Command var (deflator = @var{MODEL_EXPRESSION}) @var{VARIABLE_NAME} [$@var{LATEX_NAME}$ [(long_name=@var{QUOTED_STRING})]]@dots{};
@deffnx Command var (log_deflator = @var{MODEL_EXPRESSION}) @var{VARIABLE_NAME} [$@var{LATEX_NAME}$ [(long_name=@var{QUOTED_STRING})]]@dots{};
@descriptionhead
......@@ -1058,6 +1058,11 @@ Same as @code{deflator}, except that the deflator is assumed to be
additive instead of multiplicative (or, to put it otherwise, the
declared variable is equal to the log of a variable with a
multiplicative trend).
@anchor{long_name}
@item long_name = @var{QUOTED_STRING}
This is the long version of the variable name. Its value is stored in
@code{M_.endo_names_long}. Default: @var{VARIABLE_NAME}
@end table
@examplehead
......@@ -1065,11 +1070,12 @@ multiplicative trend).
@example
var c gnp q1 q2;
var(deflator=A) i b;
var c $C$ [long_name=`Consumption'];
@end example
@end deffn
@deffn Command varexo @var{VARIABLE_NAME} [$@var{LATEX_NAME}$]@dots{};
@deffn Command varexo @var{VARIABLE_NAME} [$@var{LATEX_NAME}$ [(long_name=@var{QUOTED_STRING})]]@dots{};
@descriptionhead
......@@ -1083,6 +1089,12 @@ shocks to her model.
@code{varexo} commands can appear several times in the file and Dynare
will concatenate them.
@optionshead
@table @code
@item long_name = @var{QUOTED_STRING}
Like @ref{long_name} but value stored in @code{M_.exo_names_long}.
@end table
@examplehead
@example
......@@ -1091,7 +1103,7 @@ varexo m gov;
@end deffn
@deffn Command varexo_det @var{VARIABLE_NAME} [$@var{LATEX_NAME}$]@dots{};
@deffn Command varexo_det @var{VARIABLE_NAME} [$@var{LATEX_NAME}$ [(long_name=@var{QUOTED_STRING})]]@dots{};
@descriptionhead
......@@ -1111,6 +1123,12 @@ conditions and future information.
@code{varexo_det} commands can appear several times in the file and
Dynare will concatenate them.
@optionshead
@table @code
@item long_name = @var{QUOTED_STRING}
Like @ref{long_name} but value stored in @code{M_.exo_det_names_long}.
@end table
@examplehead
@example
......@@ -1122,7 +1140,7 @@ varexo_det tau;
@end deffn
@deffn Command parameters @var{PARAMETER_NAME} [$@var{LATEX_NAME}$]@dots{};
@deffn Command parameters @var{PARAMETER_NAME} [$@var{LATEX_NAME}$ [(long_name=@var{QUOTED_STRING})]]@dots{};
@descriptionhead
......@@ -1137,6 +1155,12 @@ initialization}).
@code{parameters} commands can appear several times in the file and
Dynare will concatenate them.
@optionshead
@table @code
@item long_name = @var{QUOTED_STRING}
Like @ref{long_name} but value stored in @code{M_.param_names_long}.
@end table
@examplehead
@example
......
......@@ -32,7 +32,7 @@ end
rawdata = read_variables(datafile,varobs,[],xls.sheet,xls.range);
% Get the (default) number of observations.
if isempty(nobs)
if isempty(nobs) || rows(rawdata)<nobs+first-1 %case 2: dataset has changed
nobs = rows(rawdata)-first+1;
end
......
......@@ -130,7 +130,7 @@ class ParsingDriver;
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED
%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL
%token XLS_SHEET XLS_RANGE
%token XLS_SHEET XLS_RANGE LONG_NAME
%left COMMA
%left EQUAL_EQUAL EXCLAMATION_EQUAL
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
......@@ -180,7 +180,7 @@ class ParsingDriver;
%type <string_val> non_negative_number signed_number signed_integer date_str
%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> range vec_value_w_inf vec_value_1_w_inf
%type <string_val> range vec_value_w_inf vec_value_1_w_inf named_var
%type <symbol_type_val> change_type_arg
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
......@@ -337,6 +337,12 @@ nonstationary_var_list : nonstationary_var_list symbol
{ driver.declare_nonstationary_var($3, $4); }
| symbol TEX_NAME
{ driver.declare_nonstationary_var($1, $2); }
| nonstationary_var_list symbol TEX_NAME named_var
{ driver.declare_nonstationary_var($2, $3, $4); }
| nonstationary_var_list COMMA symbol TEX_NAME named_var
{ driver.declare_nonstationary_var($3, $4, $5); }
| symbol TEX_NAME named_var
{ driver.declare_nonstationary_var($1, $2, $3); }
;
varexo : VAREXO varexo_list ';';
......@@ -347,6 +353,10 @@ predetermined_variables : PREDETERMINED_VARIABLES predetermined_variables_list '
parameters : PARAMETERS parameter_list ';';
named_var : '(' LONG_NAME EQUAL QUOTED_STRING ')'
{ $$ = $4; }
;
var_list : var_list symbol
{ driver.declare_endogenous($2); }
| var_list COMMA symbol
......@@ -359,6 +369,12 @@ var_list : var_list symbol
{ driver.declare_endogenous($3, $4); }
| symbol TEX_NAME
{ driver.declare_endogenous($1, $2); }
| var_list symbol TEX_NAME named_var
{ driver.declare_endogenous($2, $3, $4); }
| var_list COMMA symbol TEX_NAME named_var
{ driver.declare_endogenous($3, $4, $5); }
| symbol TEX_NAME named_var
{ driver.declare_endogenous($1, $2, $3); }
;
varexo_list : varexo_list symbol
......@@ -373,6 +389,12 @@ varexo_list : varexo_list symbol
{ driver.declare_exogenous($3, $4); }
| symbol TEX_NAME
{ driver.declare_exogenous($1, $2); }
| varexo_list symbol TEX_NAME named_var
{ driver.declare_exogenous($2, $3, $4); }
| varexo_list COMMA symbol TEX_NAME named_var
{ driver.declare_exogenous($3, $4, $5); }
| symbol TEX_NAME named_var
{ driver.declare_exogenous($1, $2, $3); }
;
varexo_det_list : varexo_det_list symbol
......@@ -387,6 +409,12 @@ varexo_det_list : varexo_det_list symbol
{ driver.declare_exogenous_det($3, $4); }
| symbol TEX_NAME
{ driver.declare_exogenous_det($1, $2); }
| varexo_det_list symbol TEX_NAME named_var
{ driver.declare_exogenous_det($2, $3, $4); }
| varexo_det_list COMMA symbol TEX_NAME named_var
{ driver.declare_exogenous_det($3, $4, $5); }
| symbol TEX_NAME named_var
{ driver.declare_exogenous_det($1, $2, $3); }
;
parameter_list : parameter_list symbol
......@@ -401,6 +429,12 @@ parameter_list : parameter_list symbol
{ driver.declare_parameter($3, $4); }
| symbol TEX_NAME
{ driver.declare_parameter($1, $2); }
| parameter_list symbol TEX_NAME named_var
{ driver.declare_parameter($2, $3, $4); }
| parameter_list COMMA symbol TEX_NAME named_var
{ driver.declare_parameter($3, $4, $5); }
| symbol TEX_NAME named_var
{ driver.declare_parameter($1, $2, $3); }
;
predetermined_variables_list : predetermined_variables_list symbol
......
......@@ -501,6 +501,8 @@ string eofbuff;
<DYNARE_STATEMENT>analytic_derivation {return token::ANALYTIC_DERIVATION;}
<DYNARE_STATEMENT>solver_periods {return token::SOLVER_PERIODS;}
<DYNARE_STATEMENT>endogenous_prior {return token::ENDOGENOUS_PRIOR;}
<DYNARE_STATEMENT>long_name {return token::LONG_NAME;}
<DYNARE_STATEMENT>[\$][^$]*[\$] {
strtok(yytext+1, "$");
......
......@@ -131,14 +131,17 @@ ParsingDriver::warning(const string &m)
}
void
ParsingDriver::declare_symbol(const string *name, SymbolType type, const string *tex_name)
ParsingDriver::declare_symbol(const string *name, SymbolType type, const string *tex_name, const string *long_name)
{
try
{
if (tex_name == NULL)
if (tex_name == NULL && long_name == NULL)
mod_file->symbol_table.addSymbol(*name, type);
else
mod_file->symbol_table.addSymbol(*name, type, *tex_name);
if (long_name == NULL)
mod_file->symbol_table.addSymbol(*name, type, *tex_name);
else
mod_file->symbol_table.addSymbol(*name, type, *tex_name, *long_name);
}
catch (SymbolTable::AlreadyDeclaredException &e)
{
......@@ -150,39 +153,47 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string
}
void
ParsingDriver::declare_endogenous(string *name, string *tex_name)
ParsingDriver::declare_endogenous(string *name, string *tex_name, string *long_name)
{
declare_symbol(name, eEndogenous, tex_name);
declare_symbol(name, eEndogenous, tex_name, long_name);
delete name;
if (tex_name != NULL)
delete tex_name;
if (long_name != NULL)
delete long_name;
}
void
ParsingDriver::declare_exogenous(string *name, string *tex_name)
ParsingDriver::declare_exogenous(string *name, string *tex_name, string *long_name)
{
declare_symbol(name, eExogenous, tex_name);
declare_symbol(name, eExogenous, tex_name, long_name);
delete name;
if (tex_name != NULL)
delete tex_name;
if (long_name != NULL)
delete long_name;
}
void
ParsingDriver::declare_exogenous_det(string *name, string *tex_name)
ParsingDriver::declare_exogenous_det(string *name, string *tex_name, string *long_name)
{
declare_symbol(name, eExogenousDet, tex_name);
declare_symbol(name, eExogenousDet, tex_name, long_name);
delete name;
if (tex_name != NULL)
delete tex_name;
if (long_name != NULL)
delete long_name;
}
void
ParsingDriver::declare_parameter(string *name, string *tex_name)
ParsingDriver::declare_parameter(string *name, string *tex_name, string *long_name)
{
declare_symbol(name, eParameter, tex_name);
declare_symbol(name, eParameter, tex_name, long_name);
delete name;
if (tex_name != NULL)
delete tex_name;
if (long_name != NULL)
delete long_name;
}
void
......@@ -191,7 +202,7 @@ ParsingDriver::declare_statement_local_variable(string *name)
if (mod_file->symbol_table.exists(*name))
error("Symbol " + *name + " cannot be assigned within a statement " +
"while being assigned elsewhere in the modfile");
declare_symbol(name, eStatementDeclaredVariable, NULL);
declare_symbol(name, eStatementDeclaredVariable, NULL, NULL);
delete name;
}
......@@ -215,7 +226,7 @@ ParsingDriver::begin_trend()
void
ParsingDriver::declare_trend_var(bool log_trend, string *name, string *tex_name)
{
declare_symbol(name, log_trend ? eLogTrend : eTrend, tex_name);
declare_symbol(name, log_trend ? eLogTrend : eTrend, tex_name, NULL);
declared_trend_vars.push_back(mod_file->symbol_table.getID(*name));
delete name;
if (tex_name != NULL)
......@@ -333,17 +344,22 @@ ParsingDriver::add_expression_variable(string *name)
}
void
ParsingDriver::declare_nonstationary_var(string *name, string *tex_name)
ParsingDriver::declare_nonstationary_var(string *name, string *tex_name, string *long_name)
{
if (tex_name != NULL)
declare_endogenous(new string(*name), new string(*tex_name));
if (long_name != NULL)
declare_endogenous(new string(*name), new string(*tex_name), new string(*long_name));
else
declare_endogenous(new string(*name), new string(*tex_name));
else
declare_endogenous(new string(*name), tex_name);
declare_endogenous(new string(*name));
declared_nonstationary_vars.push_back(mod_file->symbol_table.getID(*name));
mod_file->nonstationary_variables = true;
delete name;
if (tex_name != NULL)
delete tex_name;
if (long_name != NULL)
delete long_name;
}
void
......@@ -2292,7 +2308,7 @@ ParsingDriver::external_function_option(const string &name_option, const string
{
if (opt.empty())
error("An argument must be passed to the 'name' option of the external_function() statement.");
declare_symbol(&opt, eExternalFunction, NULL);
declare_symbol(&opt, eExternalFunction, NULL, NULL);
current_external_function_id = mod_file->symbol_table.getID(opt);
}
else if (name_option == "first_deriv_provided")
......@@ -2301,7 +2317,7 @@ ParsingDriver::external_function_option(const string &name_option, const string
current_external_function_options.firstDerivSymbID = eExtFunSetButNoNameProvided;
else
{
declare_symbol(&opt, eExternalFunction, NULL);
declare_symbol(&opt, eExternalFunction, NULL, NULL);
current_external_function_options.firstDerivSymbID = mod_file->symbol_table.getID(opt);
}
}
......@@ -2311,7 +2327,7 @@ ParsingDriver::external_function_option(const string &name_option, const string
current_external_function_options.secondDerivSymbID = eExtFunSetButNoNameProvided;
else
{
declare_symbol(&opt, eExternalFunction, NULL);
declare_symbol(&opt, eExternalFunction, NULL, NULL);
current_external_function_options.secondDerivSymbID = mod_file->symbol_table.getID(opt);
}
}
......@@ -2435,7 +2451,7 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in
if (in_model_block)
error("To use an external function (" + *function_name + ") within the model block, you must first declare it via the external_function() statement.");
declare_symbol(function_name, eExternalFunction, NULL);
declare_symbol(function_name, eExternalFunction, NULL, NULL);
current_external_function_options.nargs = stack_external_function_args.top().size();
mod_file->external_functions_table.addExternalFunction(mod_file->symbol_table.getID(*function_name),
current_external_function_options, in_model_block);
......
......@@ -94,7 +94,7 @@ private:
void check_symbol_is_endogenous_or_exogenous(string *name);
//! Helper to add a symbol declaration
void declare_symbol(const string *name, SymbolType type, const string *tex_name);
void declare_symbol(const string *name, SymbolType type, const string *tex_name, const string *long_name);
//! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name
void optim_options_helper(const string &name);
......@@ -261,13 +261,13 @@ public:
//! Sets the FILENAME for the initial value in initval
void initval_file(string *filename);
//! Declares an endogenous variable
void declare_endogenous(string *name, string *tex_name = NULL);
void declare_endogenous(string *name, string *tex_name = NULL, string *long_name = NULL);
//! Declares an exogenous variable
void declare_exogenous(string *name, string *tex_name = NULL);
void declare_exogenous(string *name, string *tex_name = NULL, string *long_name = NULL);
//! Declares an exogenous deterministic variable
void declare_exogenous_det(string *name, string *tex_name = NULL);
void declare_exogenous_det(string *name, string *tex_name = NULL, string *long_name = NULL);
//! Declares a parameter
void declare_parameter(string *name, string *tex_name = NULL);
void declare_parameter(string *name, string *tex_name = NULL, string *long_name = NULL);
//! Declares a statement local variable
void declare_statement_local_variable(string *name);
//! Completes a subsample statement
......@@ -644,7 +644,7 @@ public:
//! Ends declaration of trend variable
void end_trend_var(expr_t growth_factor);
//! Declares a nonstationary variable with its deflator
void declare_nonstationary_var(string *name, string *tex_name = NULL);
void declare_nonstationary_var(string *name, string *tex_name = NULL, string *long_name = NULL);
//! Ends declaration of nonstationary variable
void end_nonstationary_var(bool log_deflator, expr_t deflator);
//! Add a graph format to the list of formats requested
......
......@@ -39,7 +39,7 @@ SymbolTable::SymbolTable() : frozen(false), size(0)
}
int
SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name) throw (AlreadyDeclaredException, FrozenException)
SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const string &long_name) throw (AlreadyDeclaredException, FrozenException)
{
if (frozen)
throw FrozenException();
......@@ -58,10 +58,17 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
type_table.push_back(type);
name_table.push_back(name);
tex_name_table.push_back(tex_name);
long_name_table.push_back(long_name);
return id;
}
int
SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name) throw (AlreadyDeclaredException, FrozenException)
{
return addSymbol(name, type, tex_name, name);
}
int
SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException)
{
......@@ -168,40 +175,48 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
{
output << "M_.exo_names = '" << getName(exo_ids[0]) << "';" << endl;
output << "M_.exo_names_tex = '" << getTeXName(exo_ids[0]) << "';" << endl;
output << "M_.exo_names_long = '" << getLongName(exo_ids[0]) << "';" << endl;
for (int id = 1; id < exo_nbr(); id++)
{
output << "M_.exo_names = char(M_.exo_names, '" << getName(exo_ids[id]) << "');" << endl
<< "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl;
<< "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl
<< "M_.exo_names_long = char(M_.exo_names_long, '" << getLongName(exo_ids[id]) << "');" << endl;
}
}
if (exo_det_nbr() > 0)
{
output << "M_.exo_det_names = '" << getName(exo_det_ids[0]) << "';" << endl;
output << "M_.exo_det_names_tex = '" << getTeXName(exo_det_ids[0]) << "';" << endl;
output << "M_.exo_det_names_long = '" << getLongName(exo_det_ids[0]) << "';" << endl;
for (int id = 1; id < exo_det_nbr(); id++)
{
output << "M_.exo_det_names = char(M_.exo_det_names, '" << getName(exo_det_ids[id]) << "');" << endl
<< "M_.exo_det_names_tex = char(M_.exo_det_names_tex, '" << getTeXName(exo_det_ids[id]) << "');" << endl;
<< "M_.exo_det_names_tex = char(M_.exo_det_names_tex, '" << getTeXName(exo_det_ids[id]) << "');" << endl
<< "M_.exo_det_names_long = char(M_.exo_det_names_long, '" << getLongName(exo_det_ids[id]) << "');" << endl;
}
}
if (endo_nbr() > 0)
{
output << "M_.endo_names = '" << getName(endo_ids[0]) << "';" << endl;
output << "M_.endo_names_tex = '" << getTeXName(endo_ids[0]) << "';" << endl;
output << "M_.endo_names_long = '" << getLongName(endo_ids[0]) << "';" << endl;
for (int id = 1; id < endo_nbr(); id++)
{
output << "M_.endo_names = char(M_.endo_names, '" << getName(endo_ids[id]) << "');" << endl
<< "M_.endo_names_tex = char(M_.endo_names_tex, '" << getTeXName(endo_ids[id]) << "');" << endl;
<< "M_.endo_names_tex = char(M_.endo_names_tex, '" << getTeXName(endo_ids[id]) << "');" << endl
<< "M_.endo_names_long = char(M_.endo_names_long, '" << getLongName(endo_ids[id]) << "');" << endl;
}
}
if (param_nbr() > 0)
{
output << "M_.param_names = '" << getName(param_ids[0]) << "';" << endl;
output << "M_.param_names_tex = '" << getTeXName(param_ids[0]) << "';" << endl;
output << "M_.param_names_long = '" << getLongName(param_ids[0]) << "';" << endl;
for (int id = 1; id < param_nbr(); id++)
{
output << "M_.param_names = char(M_.param_names, '" << getName(param_ids[id]) << "');" << endl
<< "M_.param_names_tex = char(M_.param_names_tex, '" << getTeXName(param_ids[id]) << "');" << endl;
<< "M_.param_names_tex = char(M_.param_names_tex, '" << getTeXName(param_ids[id]) << "');" << endl
<< "M_.param_names_long = char(M_.param_names_long, '" << getLongName(param_ids[id]) << "');" << endl;
if (getName(param_ids[id]) == "dsge_prior_weight")
output << "options_.dsge_var = 1;" << endl;
......
......@@ -87,6 +87,8 @@ private:
vector<string> name_table;
//! Maps IDs to TeX names
vector<string> tex_name_table;
//! Maps IDs to string names of variables
vector<string> long_name_table;
//! Maps IDs to types
vector<SymbolType> type_table;
......@@ -182,6 +184,9 @@ private:
public:
//! Add a symbol
/*! Returns the symbol ID */
int addSymbol(const string &name, SymbolType type, const string &tex_name, const string &long_name) throw (AlreadyDeclaredException, FrozenException);
//! Add a symbol without its long name (will be equal to its name)
/*! Returns the symbol ID */
int addSymbol(const string &name, SymbolType type, const string &tex_name) throw (AlreadyDeclaredException, FrozenException);
//! Add a symbol without its TeX name (will be equal to its name)
/*! Returns the symbol ID */
......@@ -242,6 +247,8 @@ public:
inline string getName(int id) const throw (UnknownSymbolIDException);
//! Get TeX name
inline string getTeXName(int id) const throw (UnknownSymbolIDException);
//! Get long name
inline string getLongName(int id) const throw (UnknownSymbolIDException);
//! Get type (by ID)
inline SymbolType getType(int id) const throw (UnknownSymbolIDException);
//! Get type (by name)
......@@ -318,6 +325,15 @@ SymbolTable::getTeXName(int id) const throw (UnknownSymbolIDException)
return tex_name_table[id];
}
inline string
SymbolTable::getLongName(int id) const throw (UnknownSymbolIDException)
{
if (id < 0 || id >= size)
throw UnknownSymbolIDException(id);
else
return long_name_table[id];
}
inline SymbolType
SymbolTable::getType(int id) const throw (UnknownSymbolIDException)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment