Commit Graph

306 Commits (3d2125287ac7a740bfac068d11357d6e1d04fa14)

Author SHA1 Message Date
Houtan Bastani 6c7d7f5d44 don’t create file if trend_component_model/var_model statement not present 2018-09-25 12:18:52 +02:00
Sébastien Villemot 913bc2f8c2 Macro-processor, comprehension: fix error message, add comments 2018-09-24 18:17:28 +02:00
Sébastien Villemot 3e5c8dd80d Macro-processor: implement comprehensions
Due to a limitation of the current implementation, this breaks syntaxes like
[ (i,j) ] (but not [ (2,j) ]; the problem only occurs when an array is
constructed by specifying as first element a tuple whose first element is a
variable name). Solving this problem requires an overhaul of the
macro-processor, with construction of ASTs at parsing time, and evaluation
later on (instead of doing on-the-fly evaluation).

Ref #5
2018-09-24 18:00:59 +02:00
Sébastien Villemot 7a5cc7e54b Minor fixes to comments 2018-09-18 19:12:25 +02:00
Houtan Bastani c9f5cef99b write AST in JSON 2018-09-18 17:48:04 +02:00
Houtan Bastani 8ec06dddc4 fix typo and remove unnecessary braces 2018-09-18 17:31:51 +02:00
Houtan Bastani 9f9c8fdfbf fix typo 2018-09-18 14:50:54 +02:00
Houtan Bastani 85dbb649b7 move trend_component_table and var_model_table to DynamicModel as they are only used there 2018-09-14 17:04:06 +02:00
Houtan Bastani eb74d48393 trend_component_model: replace `trends` option with `targets` 2018-09-13 12:21:23 +02:00
Houtan Bastani dfb0629c25 fix typo 2018-09-12 18:21:34 +02:00
Houtan Bastani dc9ecbb49a fix bug in columns of EC matrix 2018-09-12 17:56:30 +02:00
Houtan Bastani 0376f7f173 fix bugs in creation of AR/EC matrices 2018-09-12 11:57:14 +02:00
Houtan Bastani aa120abd02 simplify code 2018-09-12 11:57:14 +02:00
Houtan Bastani 8acee8fd54 fix AR and EC matrices for double diff 2018-09-11 16:56:05 +02:00
Houtan Bastani f71c861d5e output EC matrix in file for trend component models 2018-09-10 17:44:04 +02:00
Houtan Bastani 46709ada3f output AR matrix in file for trend component models 2018-09-10 14:51:33 +02:00
Houtan Bastani f5e5dea1be support hard-coded parameters and parameter expressions in AR matrix 2018-09-07 10:14:18 +02:00
Houtan Bastani acc197f539 output AR matrix in file 2018-09-06 18:00:05 +02:00
Sébastien Villemot e19a14869e Convert ExprNodeOutputType into a class enum
Incidentally, replace the IS_* macros by inline functions.
2018-09-05 18:28:32 +02:00
Sébastien Villemot c6d4cb88c3 ExprNode and its subclasses are no longer friends of DataTree
This ensures a better isolation between the container and the containees.
2018-09-05 18:28:32 +02:00
Sébastien Villemot 004d909621 Use smart pointers for storage of ExprNode in DataTree class
- BTW, store them in a std::vector rather than std::list

- incidentally, fix issue in VariableNode::removeTrendLeadLag where expression
  sharing was possibly violated when creating a new VariableNode
2018-09-05 18:28:32 +02:00
Sébastien Villemot 5d2e1cf7b9 Use smart pointers for storage of Statement in ModFile class 2018-09-05 18:28:27 +02:00
Houtan Bastani 9f0c30740e introduce epilogue block 2018-09-05 12:31:49 +02:00
Sébastien Villemot e3550a8fc0 Various fixes in comments 2018-09-04 17:28:47 +02:00
Sébastien Villemot 3fd6858fb8 Macroprocessor: fix priority of operators
- == and != have now lower priority than <= < >= >, for consistency with the
  Dynare modelling language (and incidentally C and C++, but not Julia).

- ^ has now higher priority and no associativity, for consistency with the
  Dynare modelling language (and usual arithmetic notation).

- & has now higher priority than |, and both have lower priority than + and -,
  but higher than inequality comparators. This is not the same as C and C++ (in
  which & and | are just above && and ||), but this allows for expressions such
  as "a|b == c" to have their most natural semantics (i.e. this will compare
  the union of a and b with c; the C/C++ priority level would have resulted in
  a type error).

Ref #5.
2018-09-04 17:09:11 +02:00
Sébastien Villemot 4624a3104d Macroprocessor: implement power operator for integers
For consistency with the power operator for sets (see #5).
2018-09-04 16:28:38 +02:00
Stéphane Adjemian(Charybdis) a35c1785a8 Cosmetic change. 2018-09-04 12:08:05 +02:00
Houtan Bastani 49d8931fc0 fix typo in 8584323563 2018-09-04 10:45:39 +02:00
Houtan Bastani 8584323563 provide information on order of ec.vars 2018-09-04 10:39:05 +02:00
Houtan Bastani d89d6cc685 bug fix: close opened steady state file 2018-09-04 09:41:12 +02:00
Houtan Bastani 27c9a9a5e0 store LHS of trend equation in trend_vars 2018-09-03 17:25:42 +02:00
Houtan Bastani 7a438a3ce7 ensure that trend_variable found is actually a trend variable as declared in the trend_component_model statement 2018-09-03 15:05:30 +02:00
Houtan Bastani fde836d7fe trend_component_model: find trend_vars associated with equation 2018-08-31 14:24:44 +02:00
Houtan Bastani 52da3ecfa7 fix bug: missing initialization for lexer context variable 2018-08-29 18:02:12 +02:00
Houtan Bastani 95da532275 remove incorrect option as `unput` is used in flex file 2018-08-29 12:55:17 +02:00
Houtan Bastani 948e8cb6e4 fix bug in creation of ec vars for pac equation 2018-08-28 16:00:25 +02:00
Houtan Bastani 9e6bdc2334 Revert "fix bug in collection of ec vars of pac equation"
This reverts commit 74dd6a69e9.
2018-08-28 13:32:48 +02:00
Houtan Bastani 74dd6a69e9 fix bug in collection of ec vars of pac equation 2018-08-27 16:41:39 +02:00
Houtan Bastani 1ae729929b fix bug when var_expectation_model uses trend_component_model as auxiliary model 2018-08-27 14:51:54 +02:00
Houtan Bastani d5d6e8beb0 simplify updating of RHS variables for trend component and var models 2018-08-23 13:57:27 +02:00
Houtan Bastani 16f10d954f don’t rely on scope: clean up iterator names 2018-08-23 13:03:52 +02:00
Houtan Bastani 97af0ff711 fix bug in updating variables in var model table 2018-08-23 10:28:19 +02:00
Houtan Bastani 0c66e724cb fix typo 2018-08-22 17:09:16 +02:00
Houtan Bastani 54df07d0e0 remove unnecessary comment 2018-08-22 17:01:03 +02:00
Houtan Bastani 7d9072a227 var_expectation: rename var_model_name to aux_model_name 2018-08-22 16:57:36 +02:00
Stéphane Adjemia (Scylla) a406c18598 Allow trend_component_model in var_expectations. 2018-08-22 16:50:01 +02:00
Houtan Bastani 1874fa5cce remove unused variable 2018-08-22 16:01:10 +02:00
Houtan Bastani 80c45ee116 fix bug with max_lag of var model 2018-08-22 15:59:12 +02:00
Houtan Bastani 0af91c26f8 aesthetic fix 2018-08-22 15:12:17 +02:00
Houtan Bastani 91b7888e61 print nonstationary field for trend_component and var models 2018-08-22 14:29:07 +02:00
Houtan Bastani 1918a56a70 fix bug in 539fddc9f6 2018-08-22 12:56:16 +02:00
Houtan Bastani 539fddc9f6 introduce var model table 2018-08-22 12:15:02 +02:00
Houtan Bastani 6015b0e57b fixes to trend component model 2018-08-22 12:15:02 +02:00
Houtan Bastani 0d5dd11106 fix typo 2018-08-20 10:50:28 +02:00
Houtan Bastani afe0e475b1 trend_component_model statement 2018-08-17 16:52:48 +02:00
Houtan Bastani 618147a126 fix typo 2018-08-16 11:09:54 +02:00
Stéphane Adjemian(Charybdis) 74b693a1ec Cosmetic change. 2018-08-14 16:46:43 +02:00
Stéphane Adjemian(Charybdis) adbeb49b29 Do not print non optimizing behaviour field in PAC if empty. 2018-08-14 16:45:01 +02:00
Houtan Bastani ac850f5187 pac: stop processing of PAC equation if optimizing share parameter is hard-coded 2018-08-13 17:22:28 +02:00
Houtan Bastani d3bd6ace90 pac: print optimizing share parameter 2018-08-13 17:00:47 +02:00
Houtan Bastani edc242d471 preprocessor: find optimizing shares of agents in PAC equation 2018-08-13 14:34:57 +02:00
Houtan Bastani c5c61f99ba fix bug with max_lag reported for PAC equation 2018-08-13 12:12:20 +02:00
Houtan Bastani 0dffee4650 fix typo 2018-08-13 11:08:58 +02:00
Houtan Bastani d657f77149 fix typo :) 2018-08-09 13:27:05 +02:00
Houtan Bastani 719630a53c macroprocessor: allow looping over tuples. #5 2018-08-08 17:23:33 +02:00
Houtan Bastani ca066ea398 macroprocessor: introduce shortcut for Cartesion product (^). #5 2018-08-08 15:58:49 +02:00
Houtan Bastani d9c0568075 macroprocessor: introduce Cartesion product. #5 2018-08-08 15:11:06 +02:00
Houtan Bastani e24cabe3a5 var_expectation: print type specific id for discount index 2018-08-08 14:59:50 +02:00
Houtan Bastani 27d088da7e macroprocessor: fix bug in set difference introduced in 5f1465f9 2018-08-08 14:35:09 +02:00
Houtan Bastani 428b5023d3 macroprocessor: intersection operator. #5 2018-08-08 14:15:39 +02:00
Houtan Bastani 039b27bbaf macroprocessor: union operator. #5 2018-08-08 14:12:04 +02:00
Houtan Bastani 1285473aa1 macroprocessor: introduce tuple type. #5 2018-08-07 17:36:13 +02:00
Houtan Bastani 88a0162202 macroprocessor: remove terminals not used in grammar 2018-08-07 17:19:45 +02:00
Stéphane Adjemian(Charybdis) b20da7c43f Fixed timing issue in VAR_EXPECTATION expansion. 2018-08-06 21:36:52 +02:00
Stéphane Adjemian(Charybdis) 32da131a77 Added associated index in M_.endo_names for expected variable. 2018-08-04 19:50:12 +02:00
Stéphane Adjemian(Charybdis) ed32caeb46 Added missing field in VAR_EXPECTATION_MODEL description (variable). 2018-08-04 12:03:53 +02:00
Stéphane Adjemian(Charybdis) 022395aaf6 Fixed param_indices vector for VAR_EXPECTATION_MODEL. 2018-08-04 11:46:31 +02:00
Sébastien Villemot f3c2a1bf87 New var_expectation_model statement and re-design of var_expectation operator
Given a previously declared var_model, the var_expectation_model statement is
used to declare a way of forming expectations with this VAR (possibly using a
finite or infinite discounted sum). The var_expectation operator now takes a
single argument, the name of the var_expectation_model.

For the moment, this only works when the var_model is using equations
explicitly declared in the model block.
2018-08-02 08:39:09 +02:00
Sébastien Villemot 8a03532c78 ParsingDriver: factorize code to check symbol types 2018-08-01 10:47:56 +02:00
Sébastien Villemot 122e154764 PlannerObjectiveStatement now owns its model_tree
By the way, error out if the planner_objective statement is used two times.
2018-07-31 13:00:41 +02:00
Sébastien Villemot 0a063eecc1 More smart pointers 2018-07-31 13:00:39 +02:00
Sébastien Villemot 66a712253a Macroprocessor: cosmetic change 2018-07-31 12:02:26 +02:00
Sébastien Villemot df01e52859 Use new syntax for various Bison options 2018-07-31 12:02:26 +02:00
Sébastien Villemot 4302307f7d Force Emacs to use C++ mode when opening Bison and Flex files 2018-07-31 12:02:24 +02:00
Sébastien Villemot 7280c92642 Use variant semantic values in the Bison parser
We can therefore manipulate objects by value rather than by pointers, which
saves a lot of memory manipulations (and avoid potential segfaults and memory
leaks).

Note that there is no default action ("$$ = $1") when using the variant type,
so we add them explicitly.
2018-07-31 11:48:08 +02:00
Sébastien Villemot 725b91e5d6 Several fixes to computing tasks statements
- store objects whose persistence is not guaranteed (e.g. strings) as values
  instead of references (to avoid possible segfaults)
- on the contrary, always store the SymbolTable as a reference, since its
  persistence is guaranteed, and we don't want to copy it
- use pass-by-value in constructors whenever possible
- remove useless const keyword when passing by value
2018-07-31 10:51:28 +02:00
Sébastien Villemot 107ad1432b Fix various Bison warnings 2018-07-30 19:38:46 +02:00
Sébastien Villemot 45cd8e6853 Fix regression in nested diffs introduced in 90d8b579
See McModelTeam/McModelProject/issues/97.
2018-07-30 12:53:23 +02:00
Sébastien Villemot b9ee0bb204 aux_equations may diverge from those in the main model
aux_equations only contain the definition of auxiliary variables, and
may diverge from those in the main model (equations), if other model
transformations applied subsequently. This is not a problem, since
aux_equations is only used for regenerating the values of auxiliaries
given the others.

For example, such a divergence appears when there is an expectation
operator in a ramsey model, see
tests/optimal_policy/nk_ramsey_expectation.mod */
2018-07-27 14:20:36 +02:00
Sébastien Villemot 762f25abe9 Remove useless separate list for diff auxiliary variables
This table serves no useful purpose. It is better to append auxiliary equations
at the time they are created, to avoid messing with the recursive ordering.
2018-07-26 17:41:58 +02:00
Sébastien Villemot 90d8b579cc Fix incorrect recursive ordering of aux vars with diff not used at current period
Ensure that all diff operators appear once with their argument at current
period (i.e. maxLag=0).
If it is not the case, generate the corresponding expressions.

This is necessary to avoid lags of more than one in the auxiliary
equation, which would then be modified by subsequent transformations
(removing lags > 1), which in turn would break the recursive ordering
of auxiliary equations.

See McModelTeam/McModelProject/issues/95 for an example.
2018-07-26 17:41:58 +02:00
Sébastien Villemot 9cf3e034de Macroprocessor: allow empty arrays
This is now easy to implement, thanks to the refactoring allowing any type of
objects in arrays.

Closes DynareTeam/dynare#707
2018-07-25 18:46:55 +02:00
Sébastien Villemot 88fab669c6 Macroprocessor: length() operator called on a string returns the number of characters
Closes DynareTeam/Dynare#1547
2018-07-25 18:42:23 +02:00
Sébastien Villemot 5f1465f9d1 Macroprocessor: replace naked pointers by smart pointers
- use std::unique_ptr for MacroDriver::lexer
- use std::shared_ptr for MacroValue objects constructed by the parser
  This is made possible using Bison 3.0 variant value type.
  Using non-pointer type is not possible since MacroValue is polymorphic.
  Using std::unique_ptr is not possible since the value type must be
  copyable (see
  https://lists.gnu.org/archive/html/bug-bison/2015-03/msg00004.html).
  Define a new type MacroValuePtr == shared_ptr<const MacroValue> for code
  clarity.
  Use the following convention for shared_ptr arguments to functions:
  + if pass-by-value, means that the callee acquires ownership
  + if pass-by-const-reference, the callee does not acquire ownership
- naked pointers are still used for tracking the filename in Bison's location
  type, since we don't have control over that

Also, by the way:
- arrays can now contain elements of any type
- simplify MacroDriver::loop_stack using std::tuple
- toArray() method now fails on function objects
- no need to use const qualifiers, since all MacroValue objects are immutable
- use an exception for detecting division by zero
2018-07-25 18:40:23 +02:00
Sébastien Villemot 372005ed27 Bison: use the %language directive instead of %skeleton for specifying C++ 2018-07-24 14:02:10 +02:00
Sébastien Villemot 937659747a Macroprocessor: error out when length() operator called on a string or an int
Closes DynareTeam/Dynare#1547
2018-07-24 12:49:08 +02:00
Stéphane Adjemian(Charybdis) 49e1c43aed Partially reverted 19048bdca.
There is no reason to associate an exogenous variable or parameter to a
specific equation. For these types the user can use the pipe
notation (|x, |p) in any equations or the usual parameters and varexo statements.
2018-07-19 23:29:27 +02:00
Sébastien Villemot 4a04a38374 C++11: convert ExtendedPreprocessorTypes to class enums 2018-07-18 17:28:26 +02:00
Sébastien Villemot 97868cbd2a Remove unneeded enum keyword 2018-07-18 17:28:26 +02:00
Sébastien Villemot 04b6690d5a C++11: convert ExternalFunctionType to a class enum 2018-07-18 17:28:23 +02:00