diff --git a/DynareMain.cc b/DynareMain.cc
index 8176d6f99a5435e336332157d33f6b1b94ca186f..d37b2314d061060b27ab4601d5b5d6dc7aa6edb7 100644
--- a/DynareMain.cc
+++ b/DynareMain.cc
@@ -48,9 +48,8 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool
            , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple
            );
 
-void main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file,
-           bool no_line_macro,
-           map<string, string> &defines, vector<string> &path, stringstream &macro_output);
+void main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool save_macro, string &save_macro_file,
+           bool no_line_macro, map<string, string> &defines, vector<string> &path, stringstream &macro_output);
 
 void
 usage()
@@ -339,9 +338,34 @@ main(int argc, char **argv)
 
   // Construct basename (i.e. remove file extension if there is one)
   string basename = argv[1];
-  size_t pos = basename.find_last_of('.');
-  if (pos != string::npos)
-    basename.erase(pos);
+  string modfile, modfiletxt;
+  size_t fsc = basename.find_first_of(';');
+  if (fsc != string::npos)
+    {
+      // If a semicolon is found in argv[1], treat it as the text of the modfile
+      modfile = "mod_file_passed_as_string.mod";
+      basename = "mod_file_passed_as_string";
+      modfiletxt = argv[1];
+    }
+  else
+    {
+      // If a semicolon is NOT found in argv[1], treat it as the name of the modfile
+      modfile = argv[1];
+      size_t pos = basename.find_last_of('.');
+      if (pos != string::npos)
+        basename.erase(pos);
+
+      ifstream modfile(argv[1], ios::binary);
+      if (modfile.fail())
+        {
+          cerr << "ERROR: Could not open file: " << argv[1] << endl;
+          exit(EXIT_FAILURE);
+        }
+
+      stringstream buffer;
+      buffer << modfile.rdbuf();
+      modfiletxt = buffer.str();
+    }
 
   WarningConsolidation warnings(no_warn);
 
@@ -360,7 +384,7 @@ main(int argc, char **argv)
 
   // Do macro processing
   stringstream macro_output;
-  main1(argv[1], basename, debug, save_macro, save_macro_file, no_line_macro, defines, path, macro_output);
+  main1(modfile, basename, modfiletxt, debug, save_macro, save_macro_file, no_line_macro, defines, path, macro_output);
 
   if (only_macro)
     return EXIT_SUCCESS;
diff --git a/DynareMain1.cc b/DynareMain1.cc
index 3cbd33f376d735449120a3c48db10db2a3a7e42c..fe87ba83b4cf0c60aae726883dbc991b7af6e759 100644
--- a/DynareMain1.cc
+++ b/DynareMain1.cc
@@ -23,13 +23,13 @@
 #include "macro/MacroDriver.hh"
 
 void
-main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file, bool no_line_macro,
-      map<string, string> &defines, vector<string> &path, stringstream &macro_output)
+main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool save_macro, string &save_macro_file,
+      bool no_line_macro, map<string, string> &defines, vector<string> &path, stringstream &macro_output)
 {
   // Do macro processing
   MacroDriver m;
 
-  m.parse(modfile, macro_output, debug, no_line_macro, defines, path);
+  m.parse(modfile, modfiletxt, macro_output, debug, no_line_macro, defines, path);
   if (save_macro)
     {
       if (save_macro_file.empty())
diff --git a/macro/MacroDriver.cc b/macro/MacroDriver.cc
index 71d53b9cbaf0da6373d662f5ea3d926651906893..4d2399ec0ba91f9a300ecd708c45839305dc54d4 100644
--- a/macro/MacroDriver.cc
+++ b/macro/MacroDriver.cc
@@ -37,18 +37,11 @@ MacroDriver::~MacroDriver()
 }
 
 void
-MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro,
+MacroDriver::parse(const string &f, const string &modfiletxt, ostream &out, bool debug, bool no_line_macro,
                    map<string, string> defines, vector<string> path)
 {
   file = f;
 
-  ifstream in(f.c_str(), ios::binary);
-  if (in.fail())
-    {
-      cerr << "ERROR: Could not open file: " << f << endl;
-      exit(EXIT_FAILURE);
-    }
-
   /*
     Copy the file into a stringstream, and add an extra end-of-line. This is a
     workaround for trac ticket #73: with this workaround, MOD files ending with
@@ -66,7 +59,7 @@ MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro
       {
         file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl;
       }
-  file_with_endl << in.rdbuf() << endl;
+  file_with_endl << modfiletxt << endl;
 
   lexer = new MacroFlex(&file_with_endl, &out, no_line_macro, path);
   lexer->set_debug(debug);
diff --git a/macro/MacroDriver.hh b/macro/MacroDriver.hh
index 773a99dcfda7355cc7d6df6aec15a82a0c30d6b7..c76947de228faadaac514920e6796e93a4069b33 100644
--- a/macro/MacroDriver.hh
+++ b/macro/MacroDriver.hh
@@ -182,7 +182,7 @@ public:
 
   //! Starts parsing a file, returns output in out
   /*! \param no_line_macro should we omit the @#line statements ? */
-  void parse(const string &f, ostream &out, bool debug, bool no_line_macro,
+  void parse(const string &f, const string &modfiletxt, ostream &out, bool debug, bool no_line_macro,
              map<string, string> defines, vector<string> path);
 
   //! Name of main file being parsed