From 973c795db8f6bdbf65c9f91f3421d39578ce9e42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Wed, 24 Nov 2010 18:26:43 +0100
Subject: [PATCH] Change the syntax for values of deterministic shocks:

Arbirtrary expressions after the "values" keywords must now be enclosed
within parentheses; consider the following example:
<code>
periods 1:2;
values -1 -2;
</code>

In the previous syntax, this was interpreted by the preprocessor as a shock of
value -1-2 = -3 for periods 1 and 2, which is clearly not the intent of the
user; with the new syntax, this will be rejected (too many values compared to
the number of ranges).

Also note that now commas are no longer required between arbitrary expressions,
since the parentheses are sufficient for separating them.
---
 DynareBison.yy   | 21 +++++++++++++--------
 ParsingDriver.cc | 10 ++++++++--
 ParsingDriver.hh |  3 ++-
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/DynareBison.yy b/DynareBison.yy
index defb9cc9..bb88b363 100644
--- a/DynareBison.yy
+++ b/DynareBison.yy
@@ -740,14 +740,19 @@ period_list : period_list COMMA INT_NUMBER
 
 sigma_e : SIGMA_E EQUAL '[' triangular_matrix ']' ';' { driver.do_sigma_e(); };
 
-value_list
- 	:  value_list COMMA expression
-    {driver.add_value($3);}
-  |  value_list number
-    {driver.add_value($2);}
-	| expression
-    {driver.add_value($1);}
-	;
+value_list : value_list COMMA '(' expression ')'
+             { driver.add_value($4); }
+           | value_list '(' expression ')'
+             { driver.add_value($3); }
+           | '(' expression ')'
+             { driver.add_value($2); }
+           | value_list COMMA signed_float
+             { driver.add_value($3); }
+           | value_list signed_float
+             { driver.add_value($2); }
+           | signed_float
+             { driver.add_value($1); }
+           ;
 
 triangular_matrix : triangular_matrix ';' triangular_row
                     { driver.end_of_row(); }
diff --git a/ParsingDriver.cc b/ParsingDriver.cc
index a719334a..e3eb96a5 100644
--- a/ParsingDriver.cc
+++ b/ParsingDriver.cc
@@ -700,9 +700,15 @@ ParsingDriver::add_value(expr_t value)
 }
 
 void
-ParsingDriver::add_value(string *p1)
+ParsingDriver::add_value(string *v)
 {
-  det_shocks_values.push_back(add_constant(p1));
+  expr_t id;
+  if (v->at(0) == '-')
+    id = data_tree->AddUMinus(data_tree->AddNumConstant(v->substr(1, string::npos)));
+  else
+    id = data_tree->AddNumConstant(*v);
+  delete v;
+  det_shocks_values.push_back(id);
 }
 
 void
diff --git a/ParsingDriver.hh b/ParsingDriver.hh
index 32147ee2..a84cf240 100644
--- a/ParsingDriver.hh
+++ b/ParsingDriver.hh
@@ -283,7 +283,8 @@ public:
   //! Adds a deterministic shock value
   void add_value(expr_t value);
   //! Adds a deterministic shock value
-  void add_value(string *p1);
+  /*! \param v a string containing a (possibly negative) numeric constant */
+  void add_value(string *v);
   //! Writes a Sigma_e block
   void do_sigma_e();
   //! Ends row of Sigma_e block
-- 
GitLab