From 90c1999c69982d7e3a539de0f60e2a46e865a1e4 Mon Sep 17 00:00:00 2001 From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152> Date: Thu, 26 Feb 2009 10:46:54 +0000 Subject: [PATCH] trunk: allow the possibility of modifying Matlab matrices which have been earlier used in initval/endval git-svn-id: https://www.dynare.org/svn/dynare/trunk@2437 ac1d8469-bf42-47a9-8791-bf33cf982152 --- DynareFlex.ll | 13 +++++++++---- ParsingDriver.cc | 6 ++++-- include/ParsingDriver.hh | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index 8924d796..8aea0759 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -387,12 +387,17 @@ int sigma_e = 0; return token::QUOTED_STRING; } - /* an instruction starting with a recognized symbol (which is not a modfile local variable) - is passed as NAME, - otherwise it is a native statement until the end of the line + /* An instruction starting with a recognized symbol (which is not a modfile local + or an unknown function) is passed as NAME, otherwise it is a native statement + until the end of the line. + We exclude modfile local vars because the user may want to modify their value + using a Matlab assignment statement. + We also exclude unknown functions because the user may have used a Matlab matrix + element in initval (in which case Dynare recognizes the matrix name as an unknown + function symbol), and may want to modify the matrix later with Matlab statements. */ <INITIAL>[A-Za-z_][A-Za-z0-9_]* { - if (driver.symbol_exists_and_is_not_modfile_local_variable(yytext)) + if (driver.symbol_exists_and_is_not_modfile_local_or_unknown_function(yytext)) { BEGIN DYNARE_STATEMENT; yylval->string_val = new string(yytext); diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 06b87379..aa38e10b 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -25,12 +25,14 @@ #include "Statement.hh" bool -ParsingDriver::symbol_exists_and_is_not_modfile_local_variable(const char *s) +ParsingDriver::symbol_exists_and_is_not_modfile_local_or_unknown_function(const char *s) { if (!mod_file->symbol_table.exists(s)) return false; - return(mod_file->symbol_table.getType(s) != eModFileLocalVariable); + SymbolType type = mod_file->symbol_table.getType(s); + + return(type != eModFileLocalVariable && type != eUnknownFunction); } void diff --git a/include/ParsingDriver.hh b/include/ParsingDriver.hh index a752a867..7120acb8 100644 --- a/include/ParsingDriver.hh +++ b/include/ParsingDriver.hh @@ -162,7 +162,7 @@ public: void warning(const string &m); //! Check if a given symbol exists in the parsing context, and is not a mod file local variable - bool symbol_exists_and_is_not_modfile_local_variable(const char *s); + bool symbol_exists_and_is_not_modfile_local_or_unknown_function(const char *s); //! Sets mode of ModelTree class to use C output void use_dll(); //! Sets mode of ModelTree class to block decompose the model and triggers the creation of the incidence matrix in a C context -- GitLab