diff --git a/ComputingTasks.cc b/ComputingTasks.cc
index d3777117ba18d34d3f76afa48dd556662cb45192..e9292f90174e86d63734304cbba8bcf0b2749d41 100644
--- a/ComputingTasks.cc
+++ b/ComputingTasks.cc
@@ -94,14 +94,45 @@ SimulStatement::SimulStatement(const OptionsList &options_list_arg) :
 void
 SimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
 {
-  mod_file_struct.simul_present = true;
+  mod_file_struct.perfect_foresight_solver_present = true;
 }
 
 void
 SimulStatement::writeOutput(ostream &output, const string &basename) const
 {
   options_list.writeOutput(output);
-  output << "simul();\n";
+  output << "perfect_foresight_setup;" << endl
+         << "perfect_foresight_solver;" << endl;
+}
+
+PerfectForesightSetupStatement::PerfectForesightSetupStatement(const OptionsList &options_list_arg) :
+  options_list(options_list_arg)
+{
+}
+
+void
+PerfectForesightSetupStatement::writeOutput(ostream &output, const string &basename) const
+{
+  options_list.writeOutput(output);
+  output << "perfect_foresight_setup;" << endl;
+}
+
+PerfectForesightSolverStatement::PerfectForesightSolverStatement(const OptionsList &options_list_arg) :
+  options_list(options_list_arg)
+{
+}
+
+void
+PerfectForesightSolverStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
+{
+  mod_file_struct.perfect_foresight_solver_present = true;
+}
+
+void
+PerfectForesightSolverStatement::writeOutput(ostream &output, const string &basename) const
+{
+  options_list.writeOutput(output);
+  output << "perfect_foresight_solver;" << endl;
 }
 
 StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg,
diff --git a/ComputingTasks.hh b/ComputingTasks.hh
index c04f2f7051d2e27a0f261f4a7613edcaf9e67dfe..b1a009ffac7e2ed92df869624d27a4762adadd44 100644
--- a/ComputingTasks.hh
+++ b/ComputingTasks.hh
@@ -58,6 +58,25 @@ public:
   virtual void writeOutput(ostream &output, const string &basename) const;
 };
 
+class PerfectForesightSetupStatement : public Statement
+{
+private:
+  const OptionsList options_list;
+public:
+  PerfectForesightSetupStatement(const OptionsList &options_list_arg);
+  virtual void writeOutput(ostream &output, const string &basename) const;
+};
+
+class PerfectForesightSolverStatement : public Statement
+{
+private:
+  const OptionsList options_list;
+public:
+  PerfectForesightSolverStatement(const OptionsList &options_list_arg);
+  virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
+  virtual void writeOutput(ostream &output, const string &basename) const;
+};
+
 class ModelInfoStatement : public Statement
 {
 private:
diff --git a/DynareBison.yy b/DynareBison.yy
index bedda79b712c9d19470891d2f1d4ef14eeb1c3cc..3449cc6fdb878c7816dd1aefcd20e6f5234add5d 100644
--- a/DynareBison.yy
+++ b/DynareBison.yy
@@ -112,6 +112,7 @@ class ParsingDriver;
 %token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS
 %token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED OUTFILE OUTVARS
 %token PARALLEL_LOCAL_FILES PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERFECT_FORESIGHT PERIODS PERIOD PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE
+%token PERFECT_FORESIGHT_SETUP PERFECT_FORESIGHT_SOLVER
 %token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN PRUNING
 %token <string_val> QUOTED_STRING
 %token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE
@@ -272,6 +273,8 @@ statement : parameters
           | irf_calibration
           | smoother2histval
           | histval_file
+          | perfect_foresight_setup
+          | perfect_foresight_solver
           ;
 
 dsample : DSAMPLE INT_NUMBER ';'
@@ -970,6 +973,37 @@ model_info_options_list : model_info_options_list COMMA model_info_options
                    ;
 model_info_options :
 
+perfect_foresight_setup : PERFECT_FORESIGHT_SETUP ';'
+                          { driver.perfect_foresight_setup(); }
+                        | PERFECT_FORESIGHT_SETUP '(' perfect_foresight_setup_options_list ')' ';'
+                          { driver.perfect_foresight_setup(); }
+                        ;
+
+perfect_foresight_setup_options_list : perfect_foresight_setup_options_list COMMA perfect_foresight_setup_options
+                                     | perfect_foresight_setup_options
+                                     ;
+
+perfect_foresight_setup_options : o_periods
+                                | o_datafile
+                                ;
+
+perfect_foresight_solver : PERFECT_FORESIGHT_SOLVER ';'
+                          { driver.perfect_foresight_solver(); }
+                         | PERFECT_FORESIGHT_SOLVER '(' perfect_foresight_solver_options_list ')' ';'
+                          { driver.perfect_foresight_solver(); }
+                         ;
+
+perfect_foresight_solver_options_list : perfect_foresight_solver_options_list COMMA perfect_foresight_solver_options
+                                     | perfect_foresight_solver_options
+                                     ;
+
+perfect_foresight_solver_options : o_stack_solve_algo
+                                 | o_markowitz
+                                 | o_minimal_solving_periods
+                                 | o_simul_maxit
+	                         | o_endogenous_terminal_period
+                                 ;
+
 simul : SIMUL ';'
         { driver.simul(); }
       | SIMUL '(' simul_options_list ')' ';'
@@ -980,13 +1014,8 @@ simul_options_list : simul_options_list COMMA simul_options
                    | simul_options
                    ;
 
-simul_options : o_periods
-              | o_datafile
-              | o_stack_solve_algo
-              | o_markowitz
-              | o_minimal_solving_periods
-              | o_simul_maxit
-	      | o_endogenous_terminal_period
+simul_options : perfect_foresight_setup_options
+              | perfect_foresight_solver_options
               ;
 
 external_function : EXTERNAL_FUNCTION '(' external_function_options_list ')' ';'
diff --git a/DynareFlex.ll b/DynareFlex.ll
index eafa637eca407b83ac8a771629d43bda8aacf85d..4834afeee446522e2083f846800ff212813fabe4 100644
--- a/DynareFlex.ll
+++ b/DynareFlex.ll
@@ -168,6 +168,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
 <INITIAL>model_diagnostics {BEGIN DYNARE_STATEMENT; return token::MODEL_DIAGNOSTICS;}
 <INITIAL>extended_path {BEGIN DYNARE_STATEMENT; return token::EXTENDED_PATH;}
 <INITIAL>smoother2histval {BEGIN DYNARE_STATEMENT; return token::SMOOTHER2HISTVAL;}
+<INITIAL>perfect_foresight_setup {BEGIN DYNARE_STATEMENT; return token::PERFECT_FORESIGHT_SETUP;}
+<INITIAL>perfect_foresight_solver {BEGIN DYNARE_STATEMENT; return token::PERFECT_FORESIGHT_SOLVER;}
 
 <DYNARE_STATEMENT>; {
   if (!sigma_e)
diff --git a/ModFile.cc b/ModFile.cc
index f5c20837c02aeec7c698ffdcf52f366b4173dac9..7f31e86ff05e89a1a78db8aa18c53434d5be6477 100644
--- a/ModFile.cc
+++ b/ModFile.cc
@@ -129,7 +129,7 @@ ModFile::checkPass()
   // Allow empty model only when doing a standalone BVAR estimation
   if (dynamic_model.equation_number() == 0
       && (mod_file_struct.check_present
-          || mod_file_struct.simul_present
+          || mod_file_struct.perfect_foresight_solver_present
           || stochastic_statement_present))
     {
       cerr << "ERROR: At least one model equation must be declared!" << endl;
@@ -153,9 +153,9 @@ ModFile::checkPass()
       exit(EXIT_FAILURE);
     }
 
-  if (mod_file_struct.simul_present && stochastic_statement_present)
+  if (mod_file_struct.perfect_foresight_solver_present && stochastic_statement_present)
     {
-      cerr << "ERROR: A .mod file cannot contain both a simul command and one of {stoch_simul, estimation, osr, ramsey_policy, discretionary_policy}" << endl;
+      cerr << "ERROR: A .mod file cannot contain both one of {perfect_foresight_solver,simul} and one of {stoch_simul, estimation, osr, ramsey_policy, discretionary_policy}. This is not possible: one cannot mix perfect foresight context with stochastic context in the same file." << endl;
       exit(EXIT_FAILURE);
     }
 
@@ -407,9 +407,9 @@ ModFile::transformPass(bool nostrict)
       exit(EXIT_FAILURE);
     }
 
-  if (symbol_table.exo_det_nbr() > 0 && mod_file_struct.simul_present)
+  if (symbol_table.exo_det_nbr() > 0 && mod_file_struct.perfect_foresight_solver_present)
     {
-      cerr << "ERROR: A .mod file cannot contain both a simul command and varexo_det declaration (all exogenous variables are deterministic in this case)" << endl;
+      cerr << "ERROR: A .mod file cannot contain both one of {perfect_foresight_solver,simul}  and varexo_det declaration (all exogenous variables are deterministic in this case)" << endl;
       exit(EXIT_FAILURE);
     }
 
@@ -473,13 +473,13 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output)
                                      false, paramsDerivatives, block, byte_code);
         }
       // Set things to compute for dynamic model
-      if (mod_file_struct.simul_present || mod_file_struct.check_present
+      if (mod_file_struct.perfect_foresight_solver_present || mod_file_struct.check_present
           || mod_file_struct.stoch_simul_present
           || mod_file_struct.estimation_present || mod_file_struct.osr_present
           || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present
           || mod_file_struct.calib_smoother_present)
         {
-          if (mod_file_struct.simul_present)
+          if (mod_file_struct.perfect_foresight_solver_present)
             dynamic_model.computingPass(true, false, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code);
           else
             {
diff --git a/ParsingDriver.cc b/ParsingDriver.cc
index fe48e41a888577e18d2b7b94afbdb9191fb330e3..cda8804258f762ead726bb9a36a52e1587d7d90c 100644
--- a/ParsingDriver.cc
+++ b/ParsingDriver.cc
@@ -2692,3 +2692,18 @@ ParsingDriver::histval_file(string *filename)
   mod_file->addStatement(new HistvalFileStatement(*filename));
   delete filename;
 }
+
+
+void
+ParsingDriver::perfect_foresight_setup()
+{
+  mod_file->addStatement(new PerfectForesightSetupStatement(options_list));
+  options_list.clear();
+}
+
+void
+ParsingDriver::perfect_foresight_solver()
+{
+  mod_file->addStatement(new PerfectForesightSolverStatement(options_list));
+  options_list.clear();
+}
diff --git a/ParsingDriver.hh b/ParsingDriver.hh
index 464938791709315d63207d0c628d08572eb039c6..6218776e8f05900dffeaadec94a210807a1889bf 100644
--- a/ParsingDriver.hh
+++ b/ParsingDriver.hh
@@ -668,6 +668,8 @@ public:
 
   void smoother2histval();
   void histval_file(string *filename);
+  void perfect_foresight_setup();
+  void perfect_foresight_solver();  
 };
 
 #endif // ! PARSING_DRIVER_HH
diff --git a/Statement.cc b/Statement.cc
index 688883cc3879f084d7a7cc78827d66877b0c01b3..50d8ccefb0f998f94f2a748534ea4bfaf7c5a5bd 100644
--- a/Statement.cc
+++ b/Statement.cc
@@ -23,7 +23,7 @@
 ModFileStructure::ModFileStructure() :
   check_present(false),
   steady_present(false),
-  simul_present(false),
+  perfect_foresight_solver_present(false),
   stoch_simul_present(false),
   estimation_present(false),
   osr_present(false),
diff --git a/Statement.hh b/Statement.hh
index 0f5838653d75d6c4bde50cf7e2dabf24c22f577f..5bdade3910b8a77ee145856a92084ae05f13d9e6 100644
--- a/Statement.hh
+++ b/Statement.hh
@@ -36,8 +36,8 @@ public:
   bool check_present;
   //! Whether steady is present
   bool steady_present;
-  //! Whether a simul statement is present
-  bool simul_present;
+  //! Whether a perfect_foresight_solver/simul statement is present
+  bool perfect_foresight_solver_present;
   //! Whether a stoch_simul statement is present
   bool stoch_simul_present;
   //! Whether an estimation statement is present