From ebd9d9dee73b9b1f4a32b084fbccdf938e42b74d Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Mon, 16 Sep 2013 16:13:56 -0400
Subject: [PATCH] nostrict command-line option ignores extraneous assignments
 in initval. closes #1

---
 doc/dynare.texi               | 8 +++++---
 preprocessor/DynareMain2.cc   | 2 +-
 preprocessor/ParsingDriver.cc | 8 ++++++++
 preprocessor/ParsingDriver.hh | 4 +++-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/doc/dynare.texi b/doc/dynare.texi
index 91758669ea..ca8de288e5 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -785,9 +785,11 @@ Defines a macro-variable from the command line (the same effect as using
 the Macro directive @code{@@#define} in a model file, @pxref{Macro-processing language}).
 
 @item nostrict
-Allows Dynare to continue processing when there are more endogenous
-variables than equations, issuing a warning for each endogenous
-variable ignored.
+Allows Dynare to issue a warning and continue processing when
+@enumerate
+@item there are more endogenous variables than equations
+@item an undeclared symbol is assigned in @code{initval}
+@end enumerate
 @end table
 
 @outputhead
diff --git a/preprocessor/DynareMain2.cc b/preprocessor/DynareMain2.cc
index a8f17602e1..eb0446200e 100644
--- a/preprocessor/DynareMain2.cc
+++ b/preprocessor/DynareMain2.cc
@@ -36,7 +36,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm
 {
   WarningConsolidation warnings(no_warn);
 
-  ParsingDriver p(warnings);
+  ParsingDriver p(warnings, nostrict);
 
   // Do parsing and construct internal representation of mod file
   ModFile *mod_file = p.parse(in, debug);
diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc
index ffc60a4bc2..c0efb2a270 100644
--- a/preprocessor/ParsingDriver.cc
+++ b/preprocessor/ParsingDriver.cc
@@ -401,6 +401,14 @@ ParsingDriver::init_param(string *name, expr_t rhs)
 void
 ParsingDriver::init_val(string *name, expr_t rhs)
 {
+  if (nostrict)
+    if (!mod_file->symbol_table.exists(*name))
+      {
+        warnings << "WARNING: discarding '" << *name << "' not recognized in initval statement" << endl;
+        delete name;
+        return;
+      }
+
   check_symbol_existence(*name);
   int symb_id = mod_file->symbol_table.getID(*name);
   SymbolType type = mod_file->symbol_table.getType(symb_id);
diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh
index 1ab71514d4..8b9b21e96c 100644
--- a/preprocessor/ParsingDriver.hh
+++ b/preprocessor/ParsingDriver.hh
@@ -209,8 +209,10 @@ private:
 
   WarningConsolidation &warnings;
 
+  bool nostrict;
+
 public:
-  ParsingDriver(WarningConsolidation &warnings_arg) : warnings(warnings_arg) { };
+  ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : warnings(warnings_arg), nostrict(nostrict_arg) { };
 
   //! Starts parsing, and constructs the MOD file representation
   /*! The returned pointer should be deleted after use */
-- 
GitLab