diff --git a/tests/Makefile.am b/tests/Makefile.am
index 194cdda69943cccca9825e8652d484c3fd1a060b..651f1ba03b1eeb0077508bf48bb600e00d6ff88a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,8 +52,13 @@ MODFILES = \
 	ramst.mod \
 	ramst_a.mod \
 	ramst_static_tag.mod \
+	on-the-fly/ex1.mod \
+	on-the-fly/ex2.mod \
+	on-the-fly/ex3.mod \
+	on-the-fly/ex4.mod \
+	on-the-fly/ex5.mod \
+	on-the-fly/ex6.mod \
 	example1.mod \
-	example1_on_the_fly.mod \
 	example2.mod \
 	example1_use_dll.mod \
 	example1_with_tags.mod \
@@ -482,13 +487,13 @@ deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs: determ
 deterministic_simulations/multiple_lead_lags/sim_lead_lag.m.trs: deterministic_simulations/multiple_lead_lags/sim_base.m.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.m.trs
 deterministic_simulations/multiple_lead_lags/sim_lead_lag.o.trs: deterministic_simulations/multiple_lead_lags/sim_base.o.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs
 
-deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: ramst.m.trs 
+deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: ramst.m.trs
 deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.o.trs: ramst.o.trs
 
 loglinear/example4_loglinear.m.trs: loglinear/example4_exp.m.trs
 loglinear/example4_loglinear.o.trs: loglinear/example4_exp.o.trs
-loglinear/example4_loglinear_lagged_exogenous_a.m.trs: loglinear/example4_loglinear_lagged_exogenous.m.trs 
-loglinear/example4_loglinear_lagged_exogenous_a.o.trs: loglinear/example4_loglinear_lagged_exogenous.o.trs 
+loglinear/example4_loglinear_lagged_exogenous_a.m.trs: loglinear/example4_loglinear_lagged_exogenous.m.trs
+loglinear/example4_loglinear_lagged_exogenous_a.o.trs: loglinear/example4_loglinear_lagged_exogenous.o.trs
 
 loglinear/example4_loglinear_histval.m.trs: loglinear/example4_exp_histval.m.trs
 loglinear/example4_loglinear_histval.o.trs: loglinear/example4_exp_histval.o.trs
@@ -581,6 +586,10 @@ external_function: m/external_function o/external_function
 m/external_function: $(patsubst %.mod, %.m.trs, $(filter external_function/%.mod, $(MODFILES)))
 o/external_function: $(patsubst %.mod, %.o.trs, $(filter external_function/%.mod, $(MODFILES)))
 
+on-the-fly: m/on-the-fly o/on-the-fly
+m/on-the-fly: $(patsubst %.mod, %.m.trs, $(filter on-the-fly/%.mod, $(MODFILES)))
+o/on-the-fly: $(patsubst %.mod, %.o.trs, $(filter on-the-fly/%.mod, $(MODFILES)))
+
 trend_var: m/trend_var o/trend_var
 m/trend_var: $(patsubst %.mod, %.m.trs, $(filter trend_var/%.mod, $(MODFILES)))
 o/trend_var: $(patsubst %.mod, %.o.trs, $(filter trend_var/%.mod, $(MODFILES)))
@@ -882,7 +891,7 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES)
 %.m.trs %.m.log : %.m
 	@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$*... `tput sgr0`"
 	@DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \
-		$(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null 
+		$(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null
 	@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$* Done!`tput sgr0`"
 
 %.o.trs %.o.log: %.mod
diff --git a/tests/example1_on_the_fly.mod b/tests/on-the-fly/ex1.mod
similarity index 76%
rename from tests/example1_on_the_fly.mod
rename to tests/on-the-fly/ex1.mod
index fd0786eda8e857cb3e190c7d181e6f850734dc27..8ef9c1b9adbf646912c028096bb39537b76ca737 100644
--- a/tests/example1_on_the_fly.mod
+++ b/tests/on-the-fly/ex1.mod
@@ -30,24 +30,16 @@ beta  = 0.99;
 delta = 0.025;
 psi   = 0;
 theta = 2.95;
-
 phi   = 0.1;
 
-initval;
-y = 1.08068253095672;
-c = 0.80359242014163;
-h = 0.29175631001732;
-k = 11.08360443260358;
-a = 0;
-b = 0;
-e = 0;
-u = 0;
-end;
+if ~isequal(length(intersect(M_.endo_names, {'c'; 'h'; 'y'; 'k'; 'b'; 'a'})), 6)
+   error('Endogenous variables are wrong.')
+end
 
-shocks;
-var e; stderr 0.009;
-var u; stderr 0.009;
-var e, u = phi*0.009*0.009;
-end;
+if ~isequal(length(intersect(M_.param_names, {'theta'; 'psi'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 7)
+   error('Parameters are wrong.')
+end
 
-stoch_simul;
+if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'})), 2)
+   error('Exogenous variables are wrong.')
+end
\ No newline at end of file
diff --git a/tests/on-the-fly/ex2.mod b/tests/on-the-fly/ex2.mod
new file mode 100644
index 0000000000000000000000000000000000000000..cc73d29f07733ccde7cfe7510d6933bf583cbed5
--- /dev/null
+++ b/tests/on-the-fly/ex2.mod
@@ -0,0 +1,38 @@
+// --+ options: nostrict +--
+/*
+** Same as ex1.mod without the first equation -> h is an exogenous variable, psi is not a model object (because it
+** is not used in the remaining equations), and theta is an exogenous equation (see the last equation).
+*/
+
+model;
+//c*theta|p*h|e^(1+psi|p)=(1-alpha)*y;
+k|e = beta|p*(((exp(b)*c)/(exp(b(+1))*c(+1)))
+    *(exp(b(+1))*alpha|p*y(+1)+(1-delta)*k));
+y|e = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
+k = exp(b)*(y-c|e)+(1-delta|p)*k(-1);
+a|e = rho|p*a(-1)+tau*b(-1) + e|x;
+b|e = tau|p*a(-1)+rho*b(-1) + u|x + .0*theta; // The last term is here just for testing purpose.
+end;
+
+alpha = 0.36;
+rho   = 0.95;
+tau   = 0.025;
+beta  = 0.99;
+delta = 0.025;
+psi   = 0;
+// If the following line is uncommented, this will trigger an error from the preprocessor
+// because it is not allowed to give a value to an exogenous variable.
+//theta = 2.95;
+phi   = 0.1;
+
+if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'})), 5)
+   error('Endogenous variables are wrong.')
+end
+
+if ~isequal(length(intersect(M_.param_names, {'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 5)
+   error('Parameters are wrong.')
+end
+
+if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'h'; 'theta'})), 4)
+   error('Exogenous variables are wrong.')
+end
\ No newline at end of file
diff --git a/tests/on-the-fly/ex3.mod b/tests/on-the-fly/ex3.mod
new file mode 100644
index 0000000000000000000000000000000000000000..d1f02a459e65b6ed9fdf4e682b1a6fafe45f814f
--- /dev/null
+++ b/tests/on-the-fly/ex3.mod
@@ -0,0 +1,40 @@
+// --+ options: nostrict +--
+/*
+** In the following example, we only declare one endogenous variable per equation. Because the other objects are not declared
+** they are treated as exogenous variables. An equation tag is used to associate an endogenous variable to each equation.
+*/
+
+model;
+
+[endogenous='h']
+c*theta*h^(1+psi)=(1-alpha)*y;
+
+[endogenous='k']
+k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
+    *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
+
+[endogenous='y']
+y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
+
+[endogenous='c']
+k = exp(b)*(y-c)+(1-delta)*k(-1);
+
+[endogenous='a']
+a = rho*a(-1)+tau*b(-1) + e;
+
+[endogenous='b']
+b = tau*a(-1)+rho*b(-1) + u;
+
+end;
+
+if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'; 'h'})), 6)
+   error('Endogenous variables are wrong.')
+end
+
+if isfield(M_, 'param_names')
+   error('Parameters are wrong.')
+end
+
+if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'theta'; 'psi'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 9)
+   error('Exogenous variables are wrong.')
+end
\ No newline at end of file
diff --git a/tests/on-the-fly/ex4.mod b/tests/on-the-fly/ex4.mod
new file mode 100644
index 0000000000000000000000000000000000000000..601699e95666ed900b58f62e574e18874ad43b45
--- /dev/null
+++ b/tests/on-the-fly/ex4.mod
@@ -0,0 +1,39 @@
+// --+ options: nostrict +--
+/*
+** Same as ex3.mod without the first equation, hours (h) are exogenous.
+*/
+
+model;
+
+//[endogenous='h']
+//c*theta*h^(1+psi)=(1-alpha)*y;
+
+[endogenous='k']
+k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
+    *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
+
+[endogenous='y']
+y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
+
+[endogenous='c']
+k = exp(b)*(y-c)+(1-delta)*k(-1);
+
+[endogenous='a']
+a = rho*a(-1)+tau*b(-1) + e;
+
+[endogenous='b']
+b = tau*a(-1)+rho*b(-1) + u;
+
+end;
+
+if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'})), 5)
+   error('Endogenous variables are wrong.')
+end
+
+if isfield(M_, 'param_names')
+   error('Parameters are wrong.')
+end
+
+if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'h'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 8)
+   error('Exogenous variables are wrong.')
+end
\ No newline at end of file
diff --git a/tests/on-the-fly/ex5.mod b/tests/on-the-fly/ex5.mod
new file mode 100644
index 0000000000000000000000000000000000000000..4129465a7f468000ead2308de4cdb30cf6150082
--- /dev/null
+++ b/tests/on-the-fly/ex5.mod
@@ -0,0 +1,36 @@
+// --+ options: nostrict +--
+
+/*
+** It is possible to associate an endogenous variable to an equation were the variable does not appear (if it makes sense).
+*/
+
+
+parameters a0, a1, b0, b1;
+
+a0 = 1.0;
+a1 = 0.1;
+b0 = 0.5;
+b1 = 0.2;
+
+
+
+model;
+
+[endogenous='D']
+D = a0 - a1*p;
+
+[endogenous='S']
+S = b0 + b1*p;
+
+[endogenous='p']
+S = D;
+
+end;
+
+if ~isequal(length(intersect(M_.endo_names, {'D'; 'S'; 'p'})), 3)
+   error('Endogenous variables are wrong.')
+end
+
+if isfield(M_, 'exo_names')
+   error('Exogenous variables are wrong.')
+end
diff --git a/tests/on-the-fly/ex6.mod b/tests/on-the-fly/ex6.mod
new file mode 100644
index 0000000000000000000000000000000000000000..2d40e991e51237d1926eb298cad3f8a63dcda634
--- /dev/null
+++ b/tests/on-the-fly/ex6.mod
@@ -0,0 +1,33 @@
+// --+ options: nostrict +--
+
+/*
+** Same as ex5.mod, but price is treated as an exoenous variable.
+*/
+
+parameters a0, a1, b0, b1;
+
+a0 = 1.0;
+a1 = 0.1;
+b0 = 0.5;
+b1 = 0.2;
+
+model;
+
+[endogenous='D']
+D = a0 - a1*p;
+
+[endogenous='S']
+S = b0 + b1*p;
+
+//[endogenous='p']
+//S = D;
+
+end;
+
+if ~isequal(length(intersect(M_.endo_names, {'D'; 'S'})), 2)
+   error('Endogenous variables are wrong.')
+end
+
+if ~isequal(M_.exo_names, {'p'})
+   error('Exogenous variables are wrong.')
+end