Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
0f2bb4c5
Commit
0f2bb4c5
authored
Nov 15, 2013
by
Houtan Bastani
Browse files
preprocessor: support long name for endogenous, #478
parent
9a57698e
Changes
7
Hide whitespace changes
Inline
Side-by-side
doc/dynare.texi
View file @
0f2bb4c5
...
...
@@ -988,9 +988,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
...
...
@@ -1026,6 +1026,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
...
...
@@ -1033,6 +1038,7 @@ multiplicative trend).
@
example
var
c
gnp
q1
q2
;
var
(
deflator
=
A
)
i
b
;
var
c
$
C
$
[
long_name
=`
Consumption
'];
@end example
@end deffn
...
...
preprocessor/DynareBison.yy
View file @
0f2bb4c5
...
...
@@ -131,7 +131,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
...
...
@@ -181,7 +181,7 @@ class ParsingDriver;
%type <string_val> non_negative_number signed_number signed_integer date_number
%type <string_val> filename symbol vec_of_vec_value vec_value_list
%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
...
...
@@ -338,6 +338,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 '
;
';
...
...
@@ -348,6 +354,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
...
...
@@ -360,6 +370,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
...
...
preprocessor/DynareFlex.ll
View file @
0f2bb4c5
...
...
@@ -499,6 +499,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, "
$
");
...
...
preprocessor/ParsingDriver.cc
View file @
0f2bb4c5
...
...
@@ -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,18 +153,20 @@ 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
)
{
declare_symbol
(
name
,
eExogenous
,
tex_name
);
declare_symbol
(
name
,
eExogenous
,
tex_name
,
NULL
);
delete
name
;
if
(
tex_name
!=
NULL
)
delete
tex_name
;
...
...
@@ -170,7 +175,7 @@ ParsingDriver::declare_exogenous(string *name, string *tex_name)
void
ParsingDriver
::
declare_exogenous_det
(
string
*
name
,
string
*
tex_name
)
{
declare_symbol
(
name
,
eExogenousDet
,
tex_name
);
declare_symbol
(
name
,
eExogenousDet
,
tex_name
,
NULL
);
delete
name
;
if
(
tex_name
!=
NULL
)
delete
tex_name
;
...
...
@@ -179,7 +184,7 @@ ParsingDriver::declare_exogenous_det(string *name, string *tex_name)
void
ParsingDriver
::
declare_parameter
(
string
*
name
,
string
*
tex_name
)
{
declare_symbol
(
name
,
eParameter
,
tex_name
);
declare_symbol
(
name
,
eParameter
,
tex_name
,
NULL
);
delete
name
;
if
(
tex_name
!=
NULL
)
delete
tex_name
;
...
...
@@ -191,7 +196,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 +220,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 +338,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
...
...
@@ -2295,7 +2305,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"
)
...
...
@@ -2304,7 +2314,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
);
}
}
...
...
@@ -2314,7 +2324,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
);
}
}
...
...
@@ -2438,7 +2448,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
);
...
...
preprocessor/ParsingDriver.hh
View file @
0f2bb4c5
...
...
@@ -91,7 +91,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
);
...
...
@@ -258,7 +258,7 @@ 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
);
//! Declares an exogenous deterministic variable
...
...
@@ -641,7 +641,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
...
...
preprocessor/SymbolTable.cc
View file @
0f2bb4c5
...
...
@@ -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
)
{
...
...
@@ -188,10 +195,12 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
{
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
)
...
...
preprocessor/SymbolTable.hh
View file @
0f2bb4c5
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment