diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2015 L. Thomas van Binsbergen
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/funcons-simple.cabal b/funcons-simple.cabal
new file mode 100644
--- /dev/null
+++ b/funcons-simple.cabal
@@ -0,0 +1,47 @@
+-- Initial funcons-simple.cabal generated by cabal init.  For further 
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name:                funcons-simple
+version:             0.1.0.3
+synopsis:            A modular interpreter for executing SIMPLE funcons 
+description:         
+    The PLanCompS (<http://plancomps.org>) project has developed a component-based approach to formal semantics.
+    A reusable component of language definition corresponds to a fundamental 
+    programming construct: a `funcon', which has a fixed operational interpretation.
+
+    This package provides an interpreter for the funcons of SIMPLE <https://plancomps.github.io/CBS-beta/Languages-beta/SIMPLE/> extending the interpreter for the reusable funcons of /funcons-tools/ <https://hackage.haskell.org/package/funcons-tools>
+    
+homepage:            https://plancomps.github.io/CBS-beta/Languages-beta/SIMPLE/
+license:             MIT
+license-file:        LICENSE
+author:              L. Thomas van Binsbergen and Neil Sculthorpe
+maintainer:          L. Thomas van Binsbergen <ltvanbinsbergen@acm.org>
+copyright:           Copyright (C) 2015 L. Thomas van Binsbergen and Neil Sculthorpe
+category:            Compilers/Interpreters
+-- copyright:           
+build-type:          Simple
+extra-source-files:   tests/Advanced/*.smp,
+                      tests/Advanced/*.fct, 
+                      tests/Advanced/*.output, 
+                      tests/Basic/*.smp, 
+                      tests/Basic/*.fct, 
+                      tests/Basic/*.output,
+                      tests/Kdiverse/*.smp,
+                      tests/Kdiverse/*.fct,
+                      tests/Kdiverse/*.output,
+                      tests/Kdiverse/*.config,
+                      tests/Kexceptions/*.smp 
+                      tests/Kexceptions/*.fct
+                      tests/Kexceptions/*.output
+                      tests/SIMPLE.config
+                      tests/SIMPLE-interactive.config
+                      tests/README.txt
+cabal-version:       >=1.10
+
+executable runfct-SIMPLE 
+  main-is:             Main.hs
+  other-modules:       Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations, Funcons.SIMPLE.Library 
+  -- other-extensions:    
+  build-depends:       base >=4.8 && <=5, funcons-tools >= 0.2.0.5, funcons-values >= 0.1.0.3
+  hs-source-dirs:      src
+  default-language:    Haskell2010
diff --git a/src/Funcons/SIMPLE/Library.hs b/src/Funcons/SIMPLE/Library.hs
new file mode 100644
--- /dev/null
+++ b/src/Funcons/SIMPLE/Library.hs
@@ -0,0 +1,19 @@
+module Funcons.SIMPLE.Library (
+    funcons, entities, types,
+   module Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations,
+    ) where 
+import Funcons.EDSL
+import Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations hiding (funcons,types,entities)
+import qualified Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations
+funcons = libUnions
+    [
+     Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations.funcons
+    ]
+entities = concat 
+    [
+     Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations.entities
+    ]
+types = typeEnvUnions 
+    [
+     Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations.types
+    ]
diff --git a/src/Funcons/SIMPLE/SIMPLE4Declarations/SIMPLE4Declarations.hs b/src/Funcons/SIMPLE/SIMPLE4Declarations/SIMPLE4Declarations.hs
new file mode 100644
--- /dev/null
+++ b/src/Funcons/SIMPLE/SIMPLE4Declarations/SIMPLE4Declarations.hs
@@ -0,0 +1,27 @@
+-- GeNeRaTeD fOr: ../SIMPLE-cbs/SIMPLE//SIMPLE-4-Declarations/SIMPLE-4-Declarations.cbs
+{-# LANGUAGE OverloadedStrings #-}
+
+module Funcons.SIMPLE.SIMPLE4Declarations.SIMPLE4Declarations where
+
+import Funcons.EDSL
+
+import Funcons.Operations hiding (Values,libFromList)
+entities = []
+
+types = typeEnvFromList
+    []
+
+funcons = libFromList
+    [("allocate-nested-vectors",StrictFuncon stepAllocate_nested_vectors)]
+
+allocate_nested_vectors_ fargs = FApp "allocate-nested-vectors" (fargs)
+stepAllocate_nested_vectors fargs =
+    evalRules [rewrite1,rewrite2] []
+    where rewrite1 = do
+            let env = emptyEnv
+            env <- vsMatch fargs [VPAnnotated (VPMetaVar "N") (TName "nats")] env
+            rewriteTermTo (TApp "allocate-initialised-variable" [TApp "vectors" [TName "variables"],TApp "vector" [TApp "left-to-right-repeat" [TApp "allocate-variable" [TName "values"],TFuncon (FValue (Nat 1)),TVar "N"]]]) env
+          rewrite2 = do
+            let env = emptyEnv
+            env <- vsMatch fargs [VPAnnotated (VPMetaVar "N") (TName "nats"),VPAnnotated (VPSeqVar "N+" PlusOp) (TSortSeq (TName "nats") PlusOp)] env
+            rewriteTermTo (TApp "allocate-initialised-variable" [TApp "vectors" [TName "variables"],TApp "vector" [TApp "left-to-right-repeat" [TApp "allocate-nested-vectors" [TVar "N+"],TFuncon (FValue (Nat 1)),TVar "N"]]]) env
diff --git a/src/Main.hs b/src/Main.hs
new file mode 100644
--- /dev/null
+++ b/src/Main.hs
@@ -0,0 +1,3 @@
+import Funcons.Tools (mkMainWithLibraryEntitiesTypes)
+import Funcons.SIMPLE.Library
+main = mkMainWithLibraryEntitiesTypes funcons entities types
diff --git a/tests/Advanced/Advanced1.fct b/tests/Advanced/Advanced1.fct
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced1.fct
@@ -0,0 +1,45 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("fact",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (print (apply
+           (assigned (bound ("fact")),
+            tuple (decimal-natural ("5")))))))),
+   assign
+     (bound ("fact"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (if-else
+           (is-equal
+             (assigned (bound ("n")),
+              decimal-natural ("1")),
+            return (decimal-natural ("1")),
+            return (integer-multiply
+              (assigned (bound ("n")),
+               apply
+                 (assigned (bound ("fact")),
+                  tuple (integer-subtract
+                    (assigned (bound ("n")),
+                     decimal-natural ("1"))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Advanced/Advanced1.output b/tests/Advanced/Advanced1.output
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced1.output
@@ -0,0 +1,19 @@
+=== Program ===
+function main () {
+	print(fact(5));
+}
+
+function fact(n) {
+	if (n == 1) {
+		return 1;
+	} else {
+		return (n * fact(n-1));
+	}
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+120
+
diff --git a/tests/Advanced/Advanced1.smp b/tests/Advanced/Advanced1.smp
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced1.smp
@@ -0,0 +1,11 @@
+function main () {
+	print(fact(5));
+}
+
+function fact(n) {
+	if (n == 1) {
+		return 1;
+	} else {
+		return (n * fact(n-1));
+	}
+}
diff --git a/tests/Advanced/Advanced2.fct b/tests/Advanced/Advanced2.fct
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced2.fct
@@ -0,0 +1,54 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("fib",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (print (apply
+           (assigned (bound ("fib")),
+            tuple (decimal-natural ("6")))))))),
+   assign
+     (bound ("fib"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (if-else
+           (is-equal
+             (assigned (bound ("n")),
+              decimal-natural ("0")),
+            return (decimal-natural ("0")),
+            if-else
+              (is-equal
+                (assigned (bound ("n")),
+                 decimal-natural ("1")),
+               return (decimal-natural ("1")),
+               return (integer-add
+                 (apply
+                   (assigned (bound ("fib")),
+                    tuple (integer-subtract
+                      (assigned (bound ("n")),
+                       decimal-natural ("1")))),
+                  apply
+                    (assigned (bound ("fib")),
+                     tuple (integer-subtract
+                       (assigned (bound ("n")),
+                        decimal-natural ("2")))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Advanced/Advanced2.output b/tests/Advanced/Advanced2.output
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced2.output
@@ -0,0 +1,23 @@
+=== Program ===
+function main () {
+	print(fib(6));
+}
+
+function fib(n) {
+	if (n == 0) {
+		return 0;
+	} else {
+		if (n == 1) {
+			return 1;
+		} else {
+			return (fib(n-1) + fib(n-2));
+		}
+	}
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+8
+
diff --git a/tests/Advanced/Advanced2.smp b/tests/Advanced/Advanced2.smp
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced2.smp
@@ -0,0 +1,15 @@
+function main () {
+	print(fib(6));
+}
+
+function fib(n) {
+	if (n == 0) {
+		return 0;
+	} else {
+		if (n == 1) {
+			return 1;
+		} else {
+			return (fib(n-1) + fib(n-2));
+		}
+	}
+}
diff --git a/tests/Advanced/Advanced3.fct b/tests/Advanced/Advanced3.fct
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced3.fct
@@ -0,0 +1,208 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("insertion_sort",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("a",
+              allocate-nested-vectors (decimal-natural ("5"))),
+            sequential
+              (effect (give
+                (decimal-natural ("5"),
+                 sequential
+                   (assign
+                     (checked index
+                       (integer-add
+                         (1,
+                          decimal-natural ("0")),
+                        vector-elements (assigned (bound ("a")))),
+                      given),
+                    given))),
+               effect (give
+                 (decimal-natural ("4"),
+                  sequential
+                    (assign
+                      (checked index
+                        (integer-add
+                          (1,
+                           decimal-natural ("1")),
+                         vector-elements (assigned (bound ("a")))),
+                       given),
+                     given))),
+               effect (give
+                 (decimal-natural ("1"),
+                  sequential
+                    (assign
+                      (checked index
+                        (integer-add
+                          (1,
+                           decimal-natural ("2")),
+                         vector-elements (assigned (bound ("a")))),
+                       given),
+                     given))),
+               effect (give
+                 (decimal-natural ("8"),
+                  sequential
+                    (assign
+                      (checked index
+                        (integer-add
+                          (1,
+                           decimal-natural ("3")),
+                         vector-elements (assigned (bound ("a")))),
+                       given),
+                     given))),
+               effect (give
+                 (decimal-natural ("7"),
+                  sequential
+                    (assign
+                      (checked index
+                        (integer-add
+                          (1,
+                           decimal-natural ("4")),
+                         vector-elements (assigned (bound ("a")))),
+                       given),
+                     given))),
+               effect (apply
+                 (assigned (bound ("insertion_sort")),
+                  tuple (assigned (bound ("a"))))),
+               scope
+                 (bind
+                   ("i",
+                    allocate-initialised-variable
+                      (values,
+                       decimal-natural ("0"))),
+                  while
+                    (is-less
+                      (assigned (bound ("i")),
+                       length (vector-elements (assigned (bound ("a"))))),
+                     sequential
+                       (print (assigned (checked index
+                         (integer-add
+                           (1,
+                            assigned (bound ("i"))),
+                          vector-elements (assigned (bound ("a")))))),
+                        effect (give
+                          (bound ("i"),
+                           sequential
+                             (assign
+                               (given,
+                                integer-add
+                                  (assigned (given),
+                                   1)),
+                              assigned (given))))))))))))),
+   assign
+     (bound ("insertion_sort"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("a",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("i",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            while
+              (is-less
+                (assigned (bound ("i")),
+                 length (vector-elements (assigned (bound ("a"))))),
+               sequential
+                 (scope
+                   (bind
+                     ("val_i",
+                      allocate-initialised-variable
+                        (values,
+                         assigned (checked index
+                           (integer-add
+                             (1,
+                              assigned (bound ("i"))),
+                            vector-elements (assigned (bound ("a"))))))),
+                    scope
+                      (bind
+                        ("j",
+                         allocate-initialised-variable
+                           (values,
+                            assigned (bound ("i")))),
+                       sequential
+                         (while
+                           (if-else
+                             (is-greater
+                               (assigned (bound ("j")),
+                                decimal-natural ("0")),
+                              is-less
+                                (assigned (bound ("val_i")),
+                                 assigned (checked index
+                                   (integer-add
+                                     (1,
+                                      integer-subtract
+                                        (assigned (bound ("j")),
+                                         decimal-natural ("1"))),
+                                    vector-elements (assigned (bound ("a")))))),
+                              false),
+                            sequential
+                              (effect (give
+                                (assigned (checked index
+                                  (integer-add
+                                    (1,
+                                     integer-subtract
+                                       (assigned (bound ("j")),
+                                        decimal-natural ("1"))),
+                                   vector-elements (assigned (bound ("a"))))),
+                                 sequential
+                                   (assign
+                                     (checked index
+                                       (integer-add
+                                         (1,
+                                          assigned (bound ("j"))),
+                                        vector-elements (assigned (bound ("a")))),
+                                      given),
+                                    given))),
+                               effect (give
+                                 (integer-subtract
+                                   (assigned (bound ("j")),
+                                    decimal-natural ("1")),
+                                  sequential
+                                    (assign
+                                      (bound ("j"),
+                                       given),
+                                     given))))),
+                          effect (give
+                            (assigned (bound ("val_i")),
+                             sequential
+                               (assign
+                                 (checked index
+                                   (integer-add
+                                     (1,
+                                      assigned (bound ("j"))),
+                                    vector-elements (assigned (bound ("a")))),
+                                  given),
+                                given)))))),
+                  effect (give
+                    (bound ("i"),
+                     sequential
+                       (assign
+                         (given,
+                          integer-add
+                            (assigned (given),
+                             1)),
+                        assigned (given))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Advanced/Advanced3.output b/tests/Advanced/Advanced3.output
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced3.output
@@ -0,0 +1,37 @@
+=== Program ===
+function main() {
+	
+	var a[5];
+	
+	a[0] = 5;
+	a[1] = 4;
+	a[2] = 1;
+	a[3] = 8;
+	a[4] = 7;
+	
+	insertion_sort(a);
+	
+	for (var i = 0; i < sizeOf(a) ; ++i) {
+		print(a[i]);
+	}
+	
+}
+
+function insertion_sort(a) {
+  for (var i = 1; i < sizeOf(a); ++i) {
+    var val_i = a[i];
+    var j = i;
+    while (j > 0 && val_i < a[j-1]) {
+      a[j] = a[j-1];
+      j = j-1;
+    }
+    a[j] = val_i;
+  }
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1,4,5,7,8
+
diff --git a/tests/Advanced/Advanced3.smp b/tests/Advanced/Advanced3.smp
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced3.smp
@@ -0,0 +1,29 @@
+function main() {
+	
+	var a[5];
+	
+	a[0] = 5;
+	a[1] = 4;
+	a[2] = 1;
+	a[3] = 8;
+	a[4] = 7;
+	
+	insertion_sort(a);
+	
+	for (var i = 0; i < sizeOf(a) ; ++i) {
+		print(a[i]);
+	}
+	
+}
+
+function insertion_sort(a) {
+  for (var i = 1; i < sizeOf(a); ++i) {
+    var val_i = a[i];
+    var j = i;
+    while (j > 0 && val_i < a[j-1]) {
+      a[j] = a[j-1];
+      j = j-1;
+    }
+    a[j] = val_i;
+  }
+}
diff --git a/tests/Advanced/Advanced4.fct b/tests/Advanced/Advanced4.fct
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced4.fct
@@ -0,0 +1,102 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("fib_aux",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("fib",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("fib_aux"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("i",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("m",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (if-else
+           (is-equal
+             (assigned (bound ("i")),
+              decimal-natural ("1")),
+            return (assigned (bound ("n"))),
+            return (apply
+              (assigned (bound ("fib_aux")),
+               tuple (integer-subtract
+                 (assigned (bound ("i")),
+                  decimal-natural ("1")),
+               assigned (bound ("n")),
+               integer-add
+                 (assigned (bound ("m")),
+                  assigned (bound ("n"))))))))))),
+   assign
+     (bound ("fib"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (if-else
+           (is-equal
+             (assigned (bound ("n")),
+              decimal-natural ("0")),
+            return (decimal-natural ("0")),
+            return (apply
+              (assigned (bound ("fib_aux")),
+               tuple (assigned (bound ("n")),
+               decimal-natural ("0"),
+               decimal-natural ("1"))))))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("i",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            while
+              (is-less
+                (assigned (bound ("i")),
+                 decimal-natural ("8")),
+               sequential
+                 (print (apply
+                   (assigned (bound ("fib")),
+                    tuple (assigned (bound ("i"))))),
+                  effect (give
+                    (bound ("i"),
+                     sequential
+                       (assign
+                         (given,
+                          integer-add
+                            (assigned (given),
+                             1)),
+                        assigned (given))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Advanced/Advanced4.output b/tests/Advanced/Advanced4.output
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced4.output
@@ -0,0 +1,29 @@
+=== Program ===
+function fib_aux(i,m,n) {
+	if (i == 1) {
+		return n;
+	} else {
+		return fib_aux(i-1,n,m+n);
+	}
+}
+
+function fib(n) {
+	if (n == 0 ) {
+		return 0;
+	} else {
+		return fib_aux(n,0,1);
+	}
+}
+
+function main() {
+	for (var i = 1 ; i < 8 ; ++i) {
+		print(fib(i));
+	}
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1,1,2,3,5,8,13
+
diff --git a/tests/Advanced/Advanced4.smp b/tests/Advanced/Advanced4.smp
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced4.smp
@@ -0,0 +1,21 @@
+function fib_aux(i,m,n) {
+	if (i == 1) {
+		return n;
+	} else {
+		return fib_aux(i-1,n,m+n);
+	}
+}
+
+function fib(n) {
+	if (n == 0 ) {
+		return 0;
+	} else {
+		return fib_aux(n,0,1);
+	}
+}
+
+function main() {
+	for (var i = 1 ; i < 8 ; ++i) {
+		print(fib(i));
+	}
+}
diff --git a/tests/Advanced/Advanced5.fct b/tests/Advanced/Advanced5.fct
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced5.fct
@@ -0,0 +1,101 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("15"))),
+            scope
+              (bind
+                ("fib",
+                 allocate-nested-vectors (integer-add
+                   (assigned (bound ("n")),
+                    decimal-natural ("2")))),
+               sequential
+                 (effect (give
+                   (decimal-natural ("0"),
+                    sequential
+                      (assign
+                        (checked index
+                          (integer-add
+                            (1,
+                             decimal-natural ("0")),
+                           vector-elements (assigned (bound ("fib")))),
+                         given),
+                       given))),
+                  effect (give
+                    (decimal-natural ("1"),
+                     sequential
+                       (assign
+                         (checked index
+                           (integer-add
+                             (1,
+                              decimal-natural ("1")),
+                            vector-elements (assigned (bound ("fib")))),
+                          given),
+                        given))),
+                  scope
+                    (bind
+                      ("i",
+                       allocate-initialised-variable
+                         (values,
+                          decimal-natural ("0"))),
+                     while
+                       (is-less
+                         (assigned (bound ("i")),
+                          assigned (bound ("n"))),
+                        sequential
+                          (sequential
+                            (effect (give
+                              (integer-add
+                                (assigned (checked index
+                                  (integer-add
+                                    (1,
+                                     assigned (bound ("i"))),
+                                   vector-elements (assigned (bound ("fib"))))),
+                                 assigned (checked index
+                                   (integer-add
+                                     (1,
+                                      integer-add
+                                        (assigned (bound ("i")),
+                                         decimal-natural ("1"))),
+                                    vector-elements (assigned (bound ("fib")))))),
+                               sequential
+                                 (assign
+                                   (checked index
+                                     (integer-add
+                                       (1,
+                                        integer-add
+                                          (assigned (bound ("i")),
+                                           decimal-natural ("2"))),
+                                      vector-elements (assigned (bound ("fib")))),
+                                    given),
+                                  given))),
+                             print (assigned (checked index
+                               (integer-add
+                                 (1,
+                                  assigned (bound ("i"))),
+                                vector-elements (assigned (bound ("fib"))))))),
+                           effect (give
+                             (bound ("i"),
+                              sequential
+                                (assign
+                                  (given,
+                                   integer-add
+                                     (assigned (given),
+                                      1)),
+                                 assigned (given)))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Advanced/Advanced5.output b/tests/Advanced/Advanced5.output
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced5.output
@@ -0,0 +1,21 @@
+=== Program ===
+function main() {
+	
+	var n = 15;
+	
+	var fib[n+2];
+	
+	fib[0] = 0;
+	fib[1] = 1;
+	
+	for(var i=0; i<n; ++i) {
+		fib[i+2] = fib[i] + fib[i+1];
+		print(fib[i]);
+	}
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+0,1,1,2,3,5,8,13,21,34,55,89,144,233,377
+
diff --git a/tests/Advanced/Advanced5.smp b/tests/Advanced/Advanced5.smp
new file mode 100644
--- /dev/null
+++ b/tests/Advanced/Advanced5.smp
@@ -0,0 +1,14 @@
+function main() {
+	
+	var n = 15;
+	
+	var fib[n+2];
+	
+	fib[0] = 0;
+	fib[1] = 1;
+	
+	for(var i=0; i<n; ++i) {
+		fib[i+2] = fib[i] + fib[i+1];
+		print(fib[i]);
+	}
+}
diff --git a/tests/Basic/Basic01.fct b/tests/Basic/Basic01.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic01.fct
@@ -0,0 +1,16 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (null)))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic01.output b/tests/Basic/Basic01.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic01.output
@@ -0,0 +1,6 @@
+=== Program ===
+function main() { }
+=== Output ===
+Result:
+null-value
+
diff --git a/tests/Basic/Basic01.smp b/tests/Basic/Basic01.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic01.smp
@@ -0,0 +1,1 @@
+function main() { }
diff --git a/tests/Basic/Basic02.fct b/tests/Basic/Basic02.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic02.fct
@@ -0,0 +1,16 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (decimal-natural ("0")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic02.output b/tests/Basic/Basic02.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic02.output
@@ -0,0 +1,8 @@
+=== Program ===
+function main() {
+  return 0;
+}
+=== Output ===
+Result:
+0
+
diff --git a/tests/Basic/Basic02.smp b/tests/Basic/Basic02.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic02.smp
@@ -0,0 +1,3 @@
+function main() {
+  return 0;
+}
diff --git a/tests/Basic/Basic03.fct b/tests/Basic/Basic03.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic03.fct
@@ -0,0 +1,22 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            return (assigned (bound ("x")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic03.output b/tests/Basic/Basic03.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic03.output
@@ -0,0 +1,9 @@
+=== Program ===
+function main() {
+  var x = 1;
+  return x;
+}
+=== Output ===
+Result:
+1
+
diff --git a/tests/Basic/Basic03.smp b/tests/Basic/Basic03.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic03.smp
@@ -0,0 +1,4 @@
+function main() {
+  var x = 1;
+  return x;
+}
diff --git a/tests/Basic/Basic04.fct b/tests/Basic/Basic04.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic04.fct
@@ -0,0 +1,26 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-variable (values)),
+            scope
+              (bind
+                ("y",
+                 allocate-variable (values)),
+               effect (bind
+                 ("z",
+                  allocate-variable (values))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic04.output b/tests/Basic/Basic04.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic04.output
@@ -0,0 +1,10 @@
+=== Program ===
+function main() {
+  var x;
+  var y;
+  var z;
+}
+=== Output ===
+Result:
+null-value
+
diff --git a/tests/Basic/Basic04.smp b/tests/Basic/Basic04.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic04.smp
@@ -0,0 +1,5 @@
+function main() {
+  var x;
+  var y;
+  var z;
+}
diff --git a/tests/Basic/Basic05.fct b/tests/Basic/Basic05.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic05.fct
@@ -0,0 +1,32 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            scope
+              (bind
+                ("y",
+                 allocate-variable (values)),
+               scope
+                 (bind
+                   ("z",
+                    allocate-initialised-variable
+                      (values,
+                       assigned (bound ("x")))),
+                  return (assigned (bound ("z")))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic05.output b/tests/Basic/Basic05.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic05.output
@@ -0,0 +1,9 @@
+=== Program ===
+function main() {
+  var x = 1, y, z = x;
+  return z;
+}
+=== Output ===
+Result:
+1
+
diff --git a/tests/Basic/Basic05.smp b/tests/Basic/Basic05.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic05.smp
@@ -0,0 +1,4 @@
+function main() {
+  var x = 1, y, z = x;
+  return z;
+}
diff --git a/tests/Basic/Basic06.fct b/tests/Basic/Basic06.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic06.fct
@@ -0,0 +1,18 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (integer-add
+           (decimal-natural ("3"),
+            decimal-natural ("4"))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic06.output b/tests/Basic/Basic06.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic06.output
@@ -0,0 +1,8 @@
+=== Program ===
+function main() {
+  return 3 + 4;
+}
+=== Output ===
+Result:
+7
+
diff --git a/tests/Basic/Basic06.smp b/tests/Basic/Basic06.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic06.smp
@@ -0,0 +1,3 @@
+function main() {
+  return 3 + 4;
+}
diff --git a/tests/Basic/Basic07.fct b/tests/Basic/Basic07.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic07.fct
@@ -0,0 +1,32 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 integer-subtract
+                   (checked integer-modulo
+                     (integer-multiply
+                       (decimal-natural ("8"),
+                        decimal-natural ("5")),
+                      decimal-natural ("14")),
+                    checked integer-divide
+                      (integer-multiply
+                        (decimal-natural ("2"),
+                         decimal-natural ("6")),
+                       decimal-natural ("3"))))),
+            return (assigned (bound ("x")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic07.output b/tests/Basic/Basic07.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic07.output
@@ -0,0 +1,8 @@
+=== Program ===
+function main() {
+  var x = 8 * 5 % 14 - 2 * 6 / 3;
+  return x;
+}=== Output ===
+Result:
+8
+
diff --git a/tests/Basic/Basic07.smp b/tests/Basic/Basic07.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic07.smp
@@ -0,0 +1,4 @@
+function main() {
+  var x = 8 * 5 % 14 - 2 * 6 / 3;
+  return x;
+}
diff --git a/tests/Basic/Basic08.fct b/tests/Basic/Basic08.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic08.fct
@@ -0,0 +1,45 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            scope
+              (bind
+                ("y",
+                 allocate-initialised-variable
+                   (values,
+                    assigned (bound ("x")))),
+               sequential
+                 (if-else
+                   (if-else
+                     (if-else
+                       (is-greater
+                         (decimal-natural ("7"),
+                          decimal-natural ("4")),
+                        not (is-equal
+                          (assigned (bound ("x")),
+                           assigned (bound ("y")))),
+                        false),
+                      true,
+                      is-greater
+                        (assigned (bound ("x")),
+                         decimal-natural ("1"))),
+                    return (decimal-natural ("1")),
+                    null),
+                  return (decimal-natural ("0"))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic08.output b/tests/Basic/Basic08.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic08.output
@@ -0,0 +1,13 @@
+=== Program ===
+function main() {
+  var x = 1;
+  var y = x;
+  if (7 > 4 && !(x==y) || x > 1) {
+    return 1;
+  }
+  return 0;
+}
+=== Output ===
+Result:
+0
+
diff --git a/tests/Basic/Basic08.smp b/tests/Basic/Basic08.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic08.smp
@@ -0,0 +1,8 @@
+function main() {
+  var x = 1;
+  var y = x;
+  if (7 > 4 && !(x==y) || x > 1) {
+    return 1;
+  }
+  return 0;
+}
diff --git a/tests/Basic/Basic09.fct b/tests/Basic/Basic09.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic09.fct
@@ -0,0 +1,54 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("a",
+              allocate-initialised-variable
+                (values,
+                 is-less
+                   (decimal-natural ("2"),
+                    decimal-natural ("3")))),
+            scope
+              (bind
+                ("b",
+                 allocate-initialised-variable
+                   (values,
+                    is-greater
+                      (decimal-natural ("4"),
+                       decimal-natural ("5")))),
+               scope
+                 (bind
+                   ("c",
+                    allocate-initialised-variable
+                      (values,
+                       is-less-or-equal
+                         (decimal-natural ("6"),
+                          decimal-natural ("7")))),
+                  scope
+                    (bind
+                      ("d",
+                       allocate-initialised-variable
+                         (values,
+                          is-greater-or-equal
+                            (decimal-natural ("8"),
+                             decimal-natural ("9")))),
+                     sequential
+                       (print (is-equal
+                         (assigned (bound ("a")),
+                          assigned (bound ("c")))),
+                        print (not (is-equal
+                          (assigned (bound ("b")),
+                           assigned (bound ("d")))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic09.output b/tests/Basic/Basic09.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic09.output
@@ -0,0 +1,16 @@
+=== Program ===
+function main() {
+  var a = 2 < 3;  
+  var b = 4 > 5; 
+  var c = 6 <= 7; 
+  var d = 8 >= 9; 
+  print(a == c); // true
+  print(b != d); // false
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+true,false
+
diff --git a/tests/Basic/Basic09.smp b/tests/Basic/Basic09.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic09.smp
@@ -0,0 +1,8 @@
+function main() {
+  var a = 2 < 3;  
+  var b = 4 > 5; 
+  var c = 6 <= 7; 
+  var d = 8 >= 9; 
+  print(a == c); // true
+  print(b != d); // false
+}
diff --git a/tests/Basic/Basic10.fct b/tests/Basic/Basic10.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic10.fct
@@ -0,0 +1,24 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (print (decimal-natural ("1")),
+            scope
+              (bind
+                ("x",
+                 allocate-initialised-variable
+                   (values,
+                    decimal-natural ("2"))),
+               print (assigned (bound ("x"))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic10.output b/tests/Basic/Basic10.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic10.output
@@ -0,0 +1,12 @@
+=== Program ===
+function main() {
+  print(1);
+  var x = 2;
+  print(x);
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1,2
+
diff --git a/tests/Basic/Basic10.smp b/tests/Basic/Basic10.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic10.smp
@@ -0,0 +1,5 @@
+function main() {
+  print(1);
+  var x = 2;
+  print(x);
+}
diff --git a/tests/Basic/Basic11.fct b/tests/Basic/Basic11.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic11.fct
@@ -0,0 +1,47 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-variable (values)),
+            scope
+              (bind
+                ("y",
+                 allocate-variable (values)),
+               sequential
+                 (effect (give
+                   (give
+                     (decimal-natural ("2"),
+                      sequential
+                        (assign
+                          (bound ("y"),
+                           given),
+                         given)),
+                    sequential
+                      (assign
+                        (bound ("x"),
+                         given),
+                       given))),
+                  print (give
+                    (bound ("x"),
+                     sequential
+                       (assign
+                         (given,
+                          integer-add
+                            (assigned (given),
+                             1)),
+                        assigned (given)))),
+                  print (assigned (bound ("y")))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic11.output b/tests/Basic/Basic11.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic11.output
@@ -0,0 +1,13 @@
+=== Program ===
+function main() {
+  var x,y;
+  x = y = 2;
+  print(++x);
+  print(y);
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+3,2
+
diff --git a/tests/Basic/Basic11.smp b/tests/Basic/Basic11.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic11.smp
@@ -0,0 +1,6 @@
+function main() {
+  var x,y;
+  x = y = 2;
+  print(++x);
+  print(y);
+}
diff --git a/tests/Basic/Basic12.fct b/tests/Basic/Basic12.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic12.fct
@@ -0,0 +1,21 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (if-else
+           (not (is-equal
+             (decimal-natural ("3"),
+              decimal-natural ("4"))),
+            print ("good"),
+            print ("bad")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic12.output b/tests/Basic/Basic12.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic12.output
@@ -0,0 +1,15 @@
+=== Program ===
+function main() {
+	if (3 != 4) {
+		print("good");
+	} else {
+	    print("bad");
+	}
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"good"
+
diff --git a/tests/Basic/Basic12.smp b/tests/Basic/Basic12.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic12.smp
@@ -0,0 +1,7 @@
+function main() {
+	if (3 != 4) {
+		print("good");
+	} else {
+	    print("bad");
+	}
+}
diff --git a/tests/Basic/Basic13.fct b/tests/Basic/Basic13.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic13.fct
@@ -0,0 +1,21 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (if-else
+           (not (is-equal
+             (decimal-natural ("3"),
+              decimal-natural ("4"))),
+            print ("good"),
+            null))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic13.output b/tests/Basic/Basic13.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic13.output
@@ -0,0 +1,13 @@
+=== Program ===
+function main() {
+	if (3 != 4) {
+		print("good");
+	}
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"good"
+
diff --git a/tests/Basic/Basic13.smp b/tests/Basic/Basic13.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic13.smp
@@ -0,0 +1,5 @@
+function main() {
+	if (3 != 4) {
+		print("good");
+	}
+}
diff --git a/tests/Basic/Basic14.fct b/tests/Basic/Basic14.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic14.fct
@@ -0,0 +1,38 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("0"))),
+            sequential
+              (while
+                (is-less
+                  (assigned (bound ("x")),
+                   decimal-natural ("5")),
+                 sequential
+                   (print (assigned (bound ("x"))),
+                    effect (give
+                      (bound ("x"),
+                       sequential
+                         (assign
+                           (given,
+                            integer-add
+                              (assigned (given),
+                               1)),
+                          assigned (given)))))),
+               print ("done"))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic14.output b/tests/Basic/Basic14.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic14.output
@@ -0,0 +1,15 @@
+=== Program ===
+function main() {
+	var x = 0;
+	while (x < 5) {
+		print(x);
+		++x;
+	}
+	print("done");
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+0,1,2,3,4,"done"
+
diff --git a/tests/Basic/Basic14.smp b/tests/Basic/Basic14.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic14.smp
@@ -0,0 +1,8 @@
+function main() {
+	var x = 0;
+	while (x < 5) {
+		print(x);
+		++x;
+	}
+	print("done");
+}
diff --git a/tests/Basic/Basic15.fct b/tests/Basic/Basic15.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic15.fct
@@ -0,0 +1,38 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (scope
+             (bind
+               ("x",
+                allocate-initialised-variable
+                  (values,
+                   decimal-natural ("0"))),
+              while
+                (is-less
+                  (assigned (bound ("x")),
+                   decimal-natural ("5")),
+                 sequential
+                   (print (assigned (bound ("x"))),
+                    effect (give
+                      (bound ("x"),
+                       sequential
+                         (assign
+                           (given,
+                            integer-add
+                              (assigned (given),
+                               1)),
+                          assigned (given))))))),
+            print ("done")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic15.output b/tests/Basic/Basic15.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic15.output
@@ -0,0 +1,14 @@
+=== Program ===
+function main() {
+	for (var x = 0; x < 5 ; ++x) {
+		print(x);
+	}
+	print("done");
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+0,1,2,3,4,"done"
+
diff --git a/tests/Basic/Basic15.smp b/tests/Basic/Basic15.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic15.smp
@@ -0,0 +1,6 @@
+function main() {
+	for (var x = 0; x < 5 ; ++x) {
+		print(x);
+	}
+	print("done");
+}
diff --git a/tests/Basic/Basic16.fct b/tests/Basic/Basic16.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic16.fct
@@ -0,0 +1,24 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 true)),
+            print (assigned (bound ("x")),
+            decimal-natural ("1"),
+            "good")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic16.output b/tests/Basic/Basic16.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic16.output
@@ -0,0 +1,11 @@
+=== Program ===
+function main() {
+	var x = true;
+	print(x,1,"good");
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+true,1,"good"
+
diff --git a/tests/Basic/Basic16.smp b/tests/Basic/Basic16.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic16.smp
@@ -0,0 +1,4 @@
+function main() {
+	var x = true;
+	print(x,1,"good");
+}
diff --git a/tests/Basic/Basic17.fct b/tests/Basic/Basic17.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic17.fct
@@ -0,0 +1,24 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (handle-thrown
+           (print (decimal-natural ("1")),
+            scope
+              (bind
+                ("x",
+                 allocate-initialised-variable
+                   (values,
+                    given)),
+               print (decimal-natural ("2")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic17.output b/tests/Basic/Basic17.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic17.output
@@ -0,0 +1,15 @@
+=== Program ===
+function main() {
+	try {
+	  print(1);
+	} catch(x) {
+	  print(2);
+	}
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1
+
diff --git a/tests/Basic/Basic17.smp b/tests/Basic/Basic17.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic17.smp
@@ -0,0 +1,7 @@
+function main() {
+	try {
+	  print(1);
+	} catch(x) {
+	  print(2);
+	}
+}
diff --git a/tests/Basic/Basic18.fct b/tests/Basic/Basic18.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic18.fct
@@ -0,0 +1,29 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (handle-thrown
+           (sequential
+             (print (decimal-natural ("1")),
+              throw ("exc"),
+              print (decimal-natural ("2"))),
+            scope
+              (bind
+                ("x",
+                 allocate-initialised-variable
+                   (values,
+                    given)),
+               sequential
+                 (print (decimal-natural ("3")),
+                  print (assigned (bound ("x")))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic18.output b/tests/Basic/Basic18.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic18.output
@@ -0,0 +1,18 @@
+=== Program ===
+function main() {
+	try {
+	  print(1);
+	  throw("exc");
+	  print(2);	
+	} catch(x)
+	{
+	  print(3);
+	  print(x);
+	}
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1,3,"exc"
+
diff --git a/tests/Basic/Basic18.smp b/tests/Basic/Basic18.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic18.smp
@@ -0,0 +1,11 @@
+function main() {
+	try {
+	  print(1);
+	  throw("exc");
+	  print(2);	
+	} catch(x)
+	{
+	  print(3);
+	  print(x);
+	}
+}
diff --git a/tests/Basic/Basic19.fct b/tests/Basic/Basic19.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic19.fct
@@ -0,0 +1,36 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("a",
+              allocate-nested-vectors (decimal-natural ("3"))),
+            sequential
+              (effect (give
+                ("B",
+                 sequential
+                   (assign
+                     (checked index
+                       (integer-add
+                         (1,
+                          decimal-natural ("1")),
+                        vector-elements (assigned (bound ("a")))),
+                      given),
+                    given))),
+               print (assigned (checked index
+                 (integer-add
+                   (1,
+                    decimal-natural ("1")),
+                  vector-elements (assigned (bound ("a")))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic19.output b/tests/Basic/Basic19.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic19.output
@@ -0,0 +1,12 @@
+=== Program ===
+function main() {
+	var a[3];
+	a[1] = "B";
+	print(a[1]);
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"B"
+
diff --git a/tests/Basic/Basic19.smp b/tests/Basic/Basic19.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic19.smp
@@ -0,0 +1,5 @@
+function main() {
+	var a[3];
+	a[1] = "B";
+	print(a[1]);
+}
diff --git a/tests/Basic/Basic20.fct b/tests/Basic/Basic20.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic20.fct
@@ -0,0 +1,45 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("a",
+              allocate-nested-vectors (decimal-natural ("2"),
+              decimal-natural ("3"))),
+            sequential
+              (effect (give
+                (true,
+                 sequential
+                   (assign
+                     (checked index
+                       (integer-add
+                         (1,
+                          decimal-natural ("2")),
+                        vector-elements (assigned (checked index
+                          (integer-add
+                            (1,
+                             decimal-natural ("1")),
+                           vector-elements (assigned (bound ("a"))))))),
+                      given),
+                    given))),
+               print (assigned (checked index
+                 (integer-add
+                   (1,
+                    decimal-natural ("2")),
+                  vector-elements (assigned (checked index
+                    (integer-add
+                      (1,
+                       decimal-natural ("1")),
+                     vector-elements (assigned (bound ("a"))))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic20.output b/tests/Basic/Basic20.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic20.output
@@ -0,0 +1,12 @@
+=== Program ===
+function main() {
+	var a[2][3];
+	a[1][2] = true;
+	print(a[1][2]);
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+true
+
diff --git a/tests/Basic/Basic20.smp b/tests/Basic/Basic20.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic20.smp
@@ -0,0 +1,5 @@
+function main() {
+	var a[2][3];
+	a[1][2] = true;
+	print(a[1][2]);
+}
diff --git a/tests/Basic/Basic21.fct b/tests/Basic/Basic21.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic21.fct
@@ -0,0 +1,45 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("a",
+              allocate-nested-vectors (decimal-natural ("2"),
+              decimal-natural ("3"))),
+            sequential
+              (effect (give
+                (true,
+                 sequential
+                   (assign
+                     (checked index
+                       (integer-add
+                         (1,
+                          decimal-natural ("2")),
+                        vector-elements (assigned (checked index
+                          (integer-add
+                            (1,
+                             decimal-natural ("1")),
+                           vector-elements (assigned (bound ("a"))))))),
+                      given),
+                    given))),
+               print (assigned (checked index
+                 (integer-add
+                   (1,
+                    decimal-natural ("2")),
+                  vector-elements (assigned (checked index
+                    (integer-add
+                      (1,
+                       decimal-natural ("1")),
+                     vector-elements (assigned (bound ("a"))))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic21.output b/tests/Basic/Basic21.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic21.output
@@ -0,0 +1,12 @@
+=== Program ===
+function main() {
+	var a[2,3];
+	a[1,2] = true;
+	print(a[1,2]);
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+true
+
diff --git a/tests/Basic/Basic21.smp b/tests/Basic/Basic21.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic21.smp
@@ -0,0 +1,5 @@
+function main() {
+	var a[2,3];
+	a[1,2] = true;
+	print(a[1,2]);
+}
diff --git a/tests/Basic/Basic22.fct b/tests/Basic/Basic22.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic22.fct
@@ -0,0 +1,63 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("a",
+              allocate-nested-vectors (decimal-natural ("1"),
+              decimal-natural ("2"),
+              decimal-natural ("3"),
+              decimal-natural ("4"))),
+            sequential
+              (effect (give
+                (true,
+                 sequential
+                   (assign
+                     (checked index
+                       (integer-add
+                         (1,
+                          decimal-natural ("3")),
+                        vector-elements (assigned (checked index
+                          (integer-add
+                            (1,
+                             decimal-natural ("1")),
+                           vector-elements (assigned (checked index
+                             (integer-add
+                               (1,
+                                decimal-natural ("1")),
+                              vector-elements (assigned (checked index
+                                (integer-add
+                                  (1,
+                                   decimal-natural ("0")),
+                                 vector-elements (assigned (bound ("a"))))))))))))),
+                      given),
+                    given))),
+               print (assigned (checked index
+                 (integer-add
+                   (1,
+                    decimal-natural ("3")),
+                  vector-elements (assigned (checked index
+                    (integer-add
+                      (1,
+                       decimal-natural ("1")),
+                     vector-elements (assigned (checked index
+                       (integer-add
+                         (1,
+                          decimal-natural ("1")),
+                        vector-elements (assigned (checked index
+                          (integer-add
+                            (1,
+                             decimal-natural ("0")),
+                           vector-elements (assigned (bound ("a"))))))))))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic22.output b/tests/Basic/Basic22.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic22.output
@@ -0,0 +1,12 @@
+=== Program ===
+function main() {
+	var a[1][2,3][4];
+	a[0][1,1][3] = true;
+	print(a[0][1,1][3]);
+}=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+true
+
diff --git a/tests/Basic/Basic22.smp b/tests/Basic/Basic22.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic22.smp
@@ -0,0 +1,5 @@
+function main() {
+	var a[1][2,3][4];
+	a[0][1,1][3] = true;
+	print(a[0][1,1][3]);
+}
diff --git a/tests/Basic/Basic23.fct b/tests/Basic/Basic23.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic23.fct
@@ -0,0 +1,44 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("a",
+     allocate-nested-vectors (integer-add
+       (decimal-natural ("2"),
+        decimal-natural ("3")))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("y",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("4"))),
+            sequential
+              (effect (give
+                ("A",
+                 sequential
+                   (assign
+                     (checked index
+                       (integer-add
+                         (1,
+                          assigned (bound ("y"))),
+                        vector-elements (assigned (bound ("a")))),
+                      given),
+                    given))),
+               print (assigned (checked index
+                 (integer-add
+                   (1,
+                    assigned (bound ("y"))),
+                  vector-elements (assigned (bound ("a")))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic23.output b/tests/Basic/Basic23.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic23.output
@@ -0,0 +1,15 @@
+=== Program ===
+var a[2+3];
+
+function main() {
+  var y = 4;
+  a[y] = "A";
+  print(a[y]);
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"A"
+
diff --git a/tests/Basic/Basic23.smp b/tests/Basic/Basic23.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic23.smp
@@ -0,0 +1,7 @@
+var a[2+3];
+
+function main() {
+  var y = 4;
+  a[y] = "A";
+  print(a[y]);
+}
diff --git a/tests/Basic/Basic24.fct b/tests/Basic/Basic24.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic24.fct
@@ -0,0 +1,50 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("x",
+     allocate-initialised-variable
+       (values,
+        decimal-natural ("3"))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("a",
+              allocate-nested-vectors (integer-add
+                (decimal-natural ("2"),
+                 assigned (bound ("x"))))),
+            scope
+              (bind
+                ("y",
+                 allocate-initialised-variable
+                   (values,
+                    decimal-natural ("4"))),
+               sequential
+                 (effect (give
+                   ("A",
+                    sequential
+                      (assign
+                        (checked index
+                          (integer-add
+                            (1,
+                             assigned (bound ("y"))),
+                           vector-elements (assigned (bound ("a")))),
+                         given),
+                       given))),
+                  print (assigned (checked index
+                    (integer-add
+                      (1,
+                       assigned (bound ("y"))),
+                     vector-elements (assigned (bound ("a"))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic24.output b/tests/Basic/Basic24.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic24.output
@@ -0,0 +1,16 @@
+=== Program ===
+var x = 3;
+
+function main() {
+  var a[2+x];
+  var y = 4;
+  a[y] = "A";
+  print(a[y]);
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"A"
+
diff --git a/tests/Basic/Basic24.smp b/tests/Basic/Basic24.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic24.smp
@@ -0,0 +1,8 @@
+var x = 3;
+
+function main() {
+  var a[2+x];
+  var y = 4;
+  a[y] = "A";
+  print(a[y]);
+}
diff --git a/tests/Basic/Basic25.fct b/tests/Basic/Basic25.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic25.fct
@@ -0,0 +1,30 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("f",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (print (apply
+           (assigned (bound ("f")),
+            tuple ())))))),
+   assign
+     (bound ("f"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (decimal-natural ("3")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic25.output b/tests/Basic/Basic25.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic25.output
@@ -0,0 +1,15 @@
+=== Program ===
+function main() {
+	print(f());
+}
+
+function f() {
+	return 3;
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+3
+
diff --git a/tests/Basic/Basic25.smp b/tests/Basic/Basic25.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic25.smp
@@ -0,0 +1,7 @@
+function main() {
+	print(f());
+}
+
+function f() {
+	return 3;
+}
diff --git a/tests/Basic/Basic26.fct b/tests/Basic/Basic26.fct
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic26.fct
@@ -0,0 +1,36 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("f",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (print (apply
+           (assigned (bound ("f")),
+            tuple (decimal-natural ("3")))))))),
+   assign
+     (bound ("f"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (return (integer-add
+           (assigned (bound ("x")),
+            assigned (bound ("x")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Basic/Basic26.output b/tests/Basic/Basic26.output
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic26.output
@@ -0,0 +1,15 @@
+=== Program ===
+function main() {
+	print(f(3));
+}
+
+function f(x) {
+	return (x + x);
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+6
+
diff --git a/tests/Basic/Basic26.smp b/tests/Basic/Basic26.smp
new file mode 100644
--- /dev/null
+++ b/tests/Basic/Basic26.smp
@@ -0,0 +1,7 @@
+function main() {
+	print(f(3));
+}
+
+function f(x) {
+	return (x + x);
+}
diff --git a/tests/Kdiverse/Kdiverse1.fct b/tests/Kdiverse/Kdiverse1.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse1.fct
@@ -0,0 +1,43 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            print (checked integer-divide
+              (give
+                (bound ("x"),
+                 sequential
+                   (assign
+                     (given,
+                      integer-add
+                        (assigned (given),
+                         1)),
+                    assigned (given))),
+               checked integer-divide
+                 (give
+                   (bound ("x"),
+                    sequential
+                      (assign
+                        (given,
+                         integer-add
+                           (assigned (given),
+                            1)),
+                       assigned (given))),
+                  assigned (bound ("x")))),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kdiverse/Kdiverse1.output b/tests/Kdiverse/Kdiverse1.output
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse1.output
@@ -0,0 +1,24 @@
+=== Program ===
+// copied from K: tests/diverse/div-nondet.simple
+// Program manifesting several behaviors, including an undefined one.
+// However, to make it generate all those behaviors, you need to add
+// the "superheat" tag to the division and the "supercool" tag to the
+// variable lookup and increment rules.
+
+function main() {
+  var x = 1 ;
+  print(++ x / (++ x / x),"\n");
+}
+
+// 0
+// 1
+// 2
+// 3
+// undefined (gets stuck with division-by-zero at top of computation)
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+2,"\n"
+
diff --git a/tests/Kdiverse/Kdiverse1.smp b/tests/Kdiverse/Kdiverse1.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse1.smp
@@ -0,0 +1,16 @@
+// copied from K: tests/diverse/div-nondet.simple
+// Program manifesting several behaviors, including an undefined one.
+// However, to make it generate all those behaviors, you need to add
+// the "superheat" tag to the division and the "supercool" tag to the
+// variable lookup and increment rules.
+
+function main() {
+  var x = 1 ;
+  print(++ x / (++ x / x),"\n");
+}
+
+// 0
+// 1
+// 2
+// 3
+// undefined (gets stuck with division-by-zero at top of computation)
diff --git a/tests/Kdiverse/Kdiverse2.config b/tests/Kdiverse/Kdiverse2.config
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse2.config
@@ -0,0 +1,3 @@
+inputs {
+    standard-in: 5;
+}
diff --git a/tests/Kdiverse/Kdiverse2.fct b/tests/Kdiverse/Kdiverse2.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse2.fct
@@ -0,0 +1,77 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("factorial",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("factorial"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("y",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (sequential
+           (print ("Factorial of ",
+           assigned (bound ("y")),
+           " is: "),
+            scope
+              (bind
+                ("t",
+                 allocate-initialised-variable
+                   (values,
+                    decimal-natural ("1"))),
+               sequential
+                 (scope
+                   (bind
+                     ("i",
+                      allocate-initialised-variable
+                        (values,
+                         decimal-natural ("1"))),
+                    while
+                      (is-less-or-equal
+                        (assigned (bound ("i")),
+                         assigned (bound ("y"))),
+                       sequential
+                         (effect (give
+                           (integer-multiply
+                             (assigned (bound ("t")),
+                              assigned (bound ("i"))),
+                            sequential
+                              (assign
+                                (bound ("t"),
+                                 given),
+                               given))),
+                          effect (give
+                            (bound ("i"),
+                             sequential
+                               (assign
+                                 (given,
+                                  integer-add
+                                    (assigned (given),
+                                     1)),
+                                assigned (given))))))),
+                  return (assigned (bound ("t")))))))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (print ("Input a natural number: "),
+            print (apply
+              (assigned (bound ("factorial")),
+               tuple (read)),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kdiverse/Kdiverse2.output b/tests/Kdiverse/Kdiverse2.output
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse2.output
@@ -0,0 +1,24 @@
+=== Program ===
+// copied from K: tests/diverse/factorial.simple
+// The following program calculates the factorial of a user-provided number.
+
+function factorial(y) {
+  print("Factorial of ", y, " is: ");
+  var t=1;
+  for(var i=1; i<=y; ++i) {
+    t = t*i;
+  }
+  return t;
+}
+
+function main() {
+  print("Input a natural number: ");
+  print(factorial(read()),"\n");
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"Input a natural number: ","Factorial of ",5," is: ",120,"\n"
+
diff --git a/tests/Kdiverse/Kdiverse2.smp b/tests/Kdiverse/Kdiverse2.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse2.smp
@@ -0,0 +1,16 @@
+// copied from K: tests/diverse/factorial.simple
+// The following program calculates the factorial of a user-provided number.
+
+function factorial(y) {
+  print("Factorial of ", y, " is: ");
+  var t=1;
+  for(var i=1; i<=y; ++i) {
+    t = t*i;
+  }
+  return t;
+}
+
+function main() {
+  print("Input a natural number: ");
+  print(factorial(read()),"\n");
+}
diff --git a/tests/Kdiverse/Kdiverse3.config b/tests/Kdiverse/Kdiverse3.config
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse3.config
@@ -0,0 +1,3 @@
+inputs {
+    standard-in: 5;
+}
diff --git a/tests/Kdiverse/Kdiverse3.fct b/tests/Kdiverse/Kdiverse3.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse3.fct
@@ -0,0 +1,118 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("collatz",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("collatz"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("s",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("0"))),
+            sequential
+              (print ("Testing Collatz' conjecture for n = ",
+              assigned (bound ("n")),
+              " ... "),
+               while
+                 (is-greater
+                   (assigned (bound ("n")),
+                    decimal-natural ("1")),
+                  sequential
+                    (effect (give
+                      (integer-add
+                        (assigned (bound ("s")),
+                         decimal-natural ("1")),
+                       sequential
+                         (assign
+                           (bound ("s"),
+                            given),
+                          given))),
+                     if-else
+                       (is-equal
+                         (assigned (bound ("n")),
+                          integer-multiply
+                            (checked integer-divide
+                              (assigned (bound ("n")),
+                               decimal-natural ("2")),
+                             decimal-natural ("2"))),
+                        effect (give
+                          (checked integer-divide
+                            (assigned (bound ("n")),
+                             decimal-natural ("2")),
+                           sequential
+                             (assign
+                               (bound ("n"),
+                                given),
+                              given))),
+                        effect (give
+                          (integer-add
+                            (integer-multiply
+                              (decimal-natural ("3"),
+                               assigned (bound ("n"))),
+                             decimal-natural ("1")),
+                           sequential
+                             (assign
+                               (bound ("n"),
+                                given),
+                              given)))))),
+               print ("Done! It took ",
+               assigned (bound ("s")),
+               " steps.\n"))))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (print ("Testing Collatz' conjecture up to what number? "),
+            scope
+              (bind
+                ("m",
+                 allocate-initialised-variable
+                   (values,
+                    read)),
+               sequential
+                 (scope
+                   (bind
+                     ("i",
+                      allocate-initialised-variable
+                        (values,
+                         decimal-natural ("1"))),
+                    while
+                      (is-less-or-equal
+                        (assigned (bound ("i")),
+                         assigned (bound ("m"))),
+                       sequential
+                         (effect (apply
+                           (assigned (bound ("collatz")),
+                            tuple (assigned (bound ("i"))))),
+                          effect (give
+                            (bound ("i"),
+                             sequential
+                               (assign
+                                 (given,
+                                  integer-add
+                                    (assigned (given),
+                                     1)),
+                                assigned (given))))))),
+                  print ("Done.  It appears to hold.\n")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kdiverse/Kdiverse3.output b/tests/Kdiverse/Kdiverse3.output
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse3.output
@@ -0,0 +1,28 @@
+=== Program ===
+// copied from K: tests/diverse/collatz.simple
+// Program testing Collatz' conjecture up to a user-provided number.
+
+function collatz(n) {
+  var s=0;
+  print("Testing Collatz' conjecture for n = ",n," ... ");
+  while (n > 1) {
+    s = s+1;
+    if (n == (n/2)*2) { n = n/2; }
+    else { n = 3*n+1; }
+  }
+  print("Done! It took ",s," steps.\n");
+}
+
+function main() {
+  print("Testing Collatz' conjecture up to what number? ");
+  var m = read();
+  for (var i=1; i<=m; ++i) { collatz(i); }
+  print("Done.  It appears to hold.\n");
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"Testing Collatz' conjecture up to what number? ","Testing Collatz' conjecture for n = ",1," ... ","Done! It took ",0," steps.\n","Testing Collatz' conjecture for n = ",2," ... ","Done! It took ",1," steps.\n","Testing Collatz' conjecture for n = ",3," ... ","Done! It took ",7," steps.\n","Testing Collatz' conjecture for n = ",4," ... ","Done! It took ",2," steps.\n","Testing Collatz' conjecture for n = ",5," ... ","Done! It took ",5," steps.\n","Done.  It appears to hold.\n"
+
diff --git a/tests/Kdiverse/Kdiverse3.smp b/tests/Kdiverse/Kdiverse3.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse3.smp
@@ -0,0 +1,20 @@
+// copied from K: tests/diverse/collatz.simple
+// Program testing Collatz' conjecture up to a user-provided number.
+
+function collatz(n) {
+  var s=0;
+  print("Testing Collatz' conjecture for n = ",n," ... ");
+  while (n > 1) {
+    s = s+1;
+    if (n == (n/2)*2) { n = n/2; }
+    else { n = 3*n+1; }
+  }
+  print("Done! It took ",s," steps.\n");
+}
+
+function main() {
+  print("Testing Collatz' conjecture up to what number? ");
+  var m = read();
+  for (var i=1; i<=m; ++i) { collatz(i); }
+  print("Done.  It appears to hold.\n");
+}
diff --git a/tests/Kdiverse/Kdiverse4.fct b/tests/Kdiverse/Kdiverse4.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse4.fct
@@ -0,0 +1,449 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("x",
+     allocate-variable (values)),
+  bind
+    ("a",
+     allocate-nested-vectors (decimal-natural ("10"))),
+  bind
+    ("incx",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("zero",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("id",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("double",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("hoincx",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("hozero",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("hoid",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("hodouble",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("app0",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("app1",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("app2",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("map",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("printall",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   null,
+   assign
+     (bound ("incx"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (effect (give
+           (bound ("x"),
+            sequential
+              (assign
+                (given,
+                 integer-add
+                   (assigned (given),
+                    1)),
+               assigned (given)))))))),
+   assign
+     (bound ("zero"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (decimal-natural ("0")))))),
+   assign
+     (bound ("id"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (return (assigned (bound ("x"))))))),
+   assign
+     (bound ("double"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (return (integer-multiply
+           (decimal-natural ("2"),
+            assigned (bound ("x")))))))),
+   assign
+     (bound ("hoincx"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (assigned (bound ("incx"))))))),
+   assign
+     (bound ("hozero"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (assigned (bound ("zero"))))))),
+   assign
+     (bound ("hoid"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (assigned (bound ("id"))))))),
+   assign
+     (bound ("hodouble"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (return (assigned (bound ("double"))))))),
+   assign
+     (bound ("app0"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("f",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (effect (apply
+           (assigned (bound ("f")),
+            tuple ())))))),
+   assign
+     (bound ("app1"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("f",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (return (apply
+           (assigned (bound ("f")),
+            tuple ())))))),
+   assign
+     (bound ("app2"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("f",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (return (apply
+           (assigned (bound ("f")),
+            tuple (assigned (bound ("x"))))))))),
+   assign
+     (bound ("map"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("f",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("i",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("0"))),
+            while
+              (is-less-or-equal
+                (assigned (bound ("i")),
+                 integer-subtract
+                   (length (vector-elements (assigned (bound ("x")))),
+                    decimal-natural ("1"))),
+               sequential
+                 (effect (give
+                   (apply
+                     (assigned (bound ("app2")),
+                      tuple (assigned (bound ("f")),
+                      assigned (checked index
+                        (integer-add
+                          (1,
+                           assigned (bound ("i"))),
+                         vector-elements (assigned (bound ("x"))))))),
+                    sequential
+                      (assign
+                        (checked index
+                          (integer-add
+                            (1,
+                             assigned (bound ("i"))),
+                           vector-elements (assigned (bound ("x")))),
+                         given),
+                       given))),
+                  effect (give
+                    (bound ("i"),
+                     sequential
+                       (assign
+                         (given,
+                          integer-add
+                            (assigned (given),
+                             1)),
+                        assigned (given))))))))))),
+   assign
+     (bound ("printall"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (print ("x = ",
+           assigned (bound ("x")),
+           ";  a[] = "),
+            scope
+              (bind
+                ("i",
+                 allocate-initialised-variable
+                   (values,
+                    decimal-natural ("0"))),
+               while
+                 (is-less-or-equal
+                   (assigned (bound ("i")),
+                    integer-subtract
+                      (length (vector-elements (assigned (bound ("a")))),
+                       decimal-natural ("1"))),
+                  sequential
+                    (print (assigned (checked index
+                      (integer-add
+                        (1,
+                         assigned (bound ("i"))),
+                       vector-elements (assigned (bound ("a"))))),
+                    " "),
+                     effect (give
+                       (bound ("i"),
+                        sequential
+                          (assign
+                            (given,
+                             integer-add
+                               (assigned (given),
+                                1)),
+                           assigned (given))))))),
+            print ("\n")))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (effect (give
+             (decimal-natural ("0"),
+              sequential
+                (assign
+                  (bound ("x"),
+                   given),
+                 given))),
+            scope
+              (bind
+                ("i",
+                 allocate-variable (values)),
+               sequential
+                 (scope
+                   (bind
+                     ("i",
+                      allocate-initialised-variable
+                        (values,
+                         decimal-natural ("0"))),
+                    while
+                      (is-less-or-equal
+                        (assigned (bound ("i")),
+                         integer-subtract
+                           (length (vector-elements (assigned (bound ("a")))),
+                            decimal-natural ("1"))),
+                       sequential
+                         (effect (give
+                           (assigned (bound ("i")),
+                            sequential
+                              (assign
+                                (checked index
+                                  (integer-add
+                                    (1,
+                                     assigned (bound ("i"))),
+                                   vector-elements (assigned (bound ("a")))),
+                                 given),
+                               given))),
+                          effect (give
+                            (bound ("i"),
+                             sequential
+                               (assign
+                                 (given,
+                                  integer-add
+                                    (assigned (given),
+                                     1)),
+                                assigned (given))))))),
+                  effect (apply
+                    (assigned (bound ("printall")),
+                     tuple ())),
+                  effect (apply
+                    (apply
+                      (assigned (bound ("hoincx")),
+                       tuple ()),
+                     tuple ())),
+                  print (assigned (bound ("x")),
+                  " ",
+                  apply
+                    (apply
+                      (assigned (bound ("hozero")),
+                       tuple ()),
+                     tuple ()),
+                  " ",
+                  apply
+                    (apply
+                      (assigned (bound ("hoid")),
+                       tuple ()),
+                     tuple (decimal-natural ("7"))),
+                  " ",
+                  apply
+                    (apply
+                      (assigned (bound ("hodouble")),
+                       tuple ()),
+                     tuple (decimal-natural ("7"))),
+                  "\n"),
+                  effect (apply
+                    (apply
+                      (assigned (bound ("id")),
+                       tuple (apply
+                         (assigned (bound ("hoincx")),
+                          tuple ()))),
+                     tuple ())),
+                  print (assigned (bound ("x")),
+                  " ",
+                  apply
+                    (apply
+                      (assigned (bound ("id")),
+                       tuple (apply
+                         (assigned (bound ("hozero")),
+                          tuple ()))),
+                     tuple ()),
+                  " ",
+                  apply
+                    (apply
+                      (assigned (bound ("id")),
+                       tuple (apply
+                         (assigned (bound ("hoid")),
+                          tuple ()))),
+                     tuple (decimal-natural ("7"))),
+                  " ",
+                  apply
+                    (apply
+                      (assigned (bound ("id")),
+                       tuple (apply
+                         (assigned (bound ("hodouble")),
+                          tuple ()))),
+                     tuple (decimal-natural ("7"))),
+                  "\n"),
+                  effect (apply
+                    (assigned (bound ("app0")),
+                     tuple (apply
+                       (assigned (bound ("id")),
+                        tuple (apply
+                          (assigned (bound ("hoincx")),
+                           tuple ())))))),
+                  print (assigned (bound ("x")),
+                  " ",
+                  apply
+                    (assigned (bound ("app1")),
+                     tuple (apply
+                       (assigned (bound ("id")),
+                        tuple (apply
+                          (assigned (bound ("hozero")),
+                           tuple ()))))),
+                  " ",
+                  apply
+                    (assigned (bound ("app2")),
+                     tuple (apply
+                       (assigned (bound ("id")),
+                        tuple (apply
+                          (assigned (bound ("hoid")),
+                           tuple ()))),
+                     decimal-natural ("7"))),
+                  " ",
+                  apply
+                    (assigned (bound ("app2")),
+                     tuple (apply
+                       (assigned (bound ("id")),
+                        tuple (apply
+                          (assigned (bound ("hodouble")),
+                           tuple ()))),
+                     decimal-natural ("7"))),
+                  "\n"),
+                  effect (apply
+                    (assigned (bound ("map")),
+                     tuple (assigned (bound ("double")),
+                     assigned (bound ("a"))))),
+                  effect (apply
+                    (assigned (bound ("printall")),
+                     tuple ()))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kdiverse/Kdiverse4.output b/tests/Kdiverse/Kdiverse4.output
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse4.output
@@ -0,0 +1,86 @@
+=== Program ===
+// copied from K: tests/diverse/higher-order.simple
+var x, a[10];
+
+function incx() {
+  ++x;
+}
+
+function zero() {
+  return 0;
+}
+
+function id(x) {
+  return x;
+}
+
+function double(x) {
+  return 2*x;
+}
+
+function hoincx() {
+  return incx;
+}
+
+function hozero() {
+  return zero;
+}
+
+function hoid() {
+  return id;
+}
+
+function hodouble() {
+  return double;
+}
+
+function app0(f) {
+  f();
+}
+
+function app1(f) {
+  return f();
+}
+
+function app2(f,x) {
+  return f(x);
+}
+
+function map(f,x) {
+  for (var i = 0; i <= sizeOf(x) - 1; ++i) {
+    x[i] = app2(f,x[i]);
+  }
+}
+
+function printall() {
+  print("x = ",x, ";  a[] = ");
+  for (var i = 0; i <= sizeOf(a) - 1; ++i) {
+    print(a[i], " ");
+  }
+  print("\n");
+}
+
+function main() {
+  x = 0; var i;
+  for (var i=0; i <= sizeOf(a) - 1; ++i) {
+    a[i]=i;
+  }
+  printall();
+  hoincx()();
+  print(x," ", hozero()()," ", hoid()(7)," ", hodouble()(7),"\n");
+  id(hoincx())();
+  print(x," ", id(hozero())()," ", 
+        id(hoid())(7)," ", id(hodouble())(7),"\n");
+  app0(id(hoincx()));
+  print(x," ", app1(id(hozero()))," ", 
+        app2(id(hoid()),7)," ", app2(id(hodouble()),7),"\n");
+  map(double,a);
+  printall();
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"x = ",0,";  a[] = ",0," ",1," ",2," ",3," ",4," ",5," ",6," ",7," ",8," ",9," ","\n",1," ",0," ",7," ",14,"\n",2," ",0," ",7," ",14,"\n",3," ",0," ",7," ",14,"\n","x = ",3,";  a[] = ",0," ",2," ",4," ",6," ",8," ",10," ",12," ",14," ",16," ",18," ","\n"
+
diff --git a/tests/Kdiverse/Kdiverse4.smp b/tests/Kdiverse/Kdiverse4.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse4.smp
@@ -0,0 +1,78 @@
+// copied from K: tests/diverse/higher-order.simple
+var x, a[10];
+
+function incx() {
+  ++x;
+}
+
+function zero() {
+  return 0;
+}
+
+function id(x) {
+  return x;
+}
+
+function double(x) {
+  return 2*x;
+}
+
+function hoincx() {
+  return incx;
+}
+
+function hozero() {
+  return zero;
+}
+
+function hoid() {
+  return id;
+}
+
+function hodouble() {
+  return double;
+}
+
+function app0(f) {
+  f();
+}
+
+function app1(f) {
+  return f();
+}
+
+function app2(f,x) {
+  return f(x);
+}
+
+function map(f,x) {
+  for (var i = 0; i <= sizeOf(x) - 1; ++i) {
+    x[i] = app2(f,x[i]);
+  }
+}
+
+function printall() {
+  print("x = ",x, ";  a[] = ");
+  for (var i = 0; i <= sizeOf(a) - 1; ++i) {
+    print(a[i], " ");
+  }
+  print("\n");
+}
+
+function main() {
+  x = 0; var i;
+  for (var i=0; i <= sizeOf(a) - 1; ++i) {
+    a[i]=i;
+  }
+  printall();
+  hoincx()();
+  print(x," ", hozero()()," ", hoid()(7)," ", hodouble()(7),"\n");
+  id(hoincx())();
+  print(x," ", id(hozero())()," ", 
+        id(hoid())(7)," ", id(hodouble())(7),"\n");
+  app0(id(hoincx()));
+  print(x," ", app1(id(hozero()))," ", 
+        app2(id(hoid()),7)," ", app2(id(hodouble()),7),"\n");
+  map(double,a);
+  printall();
+}
diff --git a/tests/Kdiverse/Kdiverse5.config b/tests/Kdiverse/Kdiverse5.config
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse5.config
@@ -0,0 +1,3 @@
+inputs {
+    standard-in: (2,4,1,5,7,8,27,1,2,3);
+}
diff --git a/tests/Kdiverse/Kdiverse5.fct b/tests/Kdiverse/Kdiverse5.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse5.fct
@@ -0,0 +1,549 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("readArray",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("printArray",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("transArray",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("mulArray",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("readArray"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("a",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("m",
+              allocate-initialised-variable
+                (values,
+                 integer-subtract
+                   (length (vector-elements (assigned (bound ("a")))),
+                    decimal-natural ("1")))),
+            scope
+              (bind
+                ("n",
+                 allocate-initialised-variable
+                   (values,
+                    integer-subtract
+                      (length (vector-elements (assigned (checked index
+                        (integer-add
+                          (1,
+                           decimal-natural ("0")),
+                         vector-elements (assigned (bound ("a"))))))),
+                       decimal-natural ("1")))),
+               scope
+                 (bind
+                   ("i",
+                    allocate-initialised-variable
+                      (values,
+                       decimal-natural ("0"))),
+                  while
+                    (is-less-or-equal
+                      (assigned (bound ("i")),
+                       assigned (bound ("m"))),
+                     sequential
+                       (sequential
+                         (print ("Line ",
+                         integer-add
+                           (assigned (bound ("i")),
+                            decimal-natural ("1")),
+                         " (",
+                         integer-add
+                           (assigned (bound ("n")),
+                            decimal-natural ("1")),
+                         " elements): "),
+                          scope
+                            (bind
+                              ("j",
+                               allocate-initialised-variable
+                                 (values,
+                                  decimal-natural ("0"))),
+                             while
+                               (is-less-or-equal
+                                 (assigned (bound ("j")),
+                                  assigned (bound ("n"))),
+                                sequential
+                                  (effect (give
+                                    (read,
+                                     sequential
+                                       (assign
+                                         (checked index
+                                           (integer-add
+                                             (1,
+                                              assigned (bound ("j"))),
+                                            vector-elements (assigned (checked index
+                                              (integer-add
+                                                (1,
+                                                 assigned (bound ("i"))),
+                                               vector-elements (assigned (bound ("a"))))))),
+                                          given),
+                                        given))),
+                                   effect (give
+                                     (bound ("j"),
+                                      sequential
+                                        (assign
+                                          (given,
+                                           integer-add
+                                             (assigned (given),
+                                              1)),
+                                         assigned (given)))))))),
+                        effect (give
+                          (bound ("i"),
+                           sequential
+                             (assign
+                               (given,
+                                integer-add
+                                  (assigned (given),
+                                   1)),
+                              assigned (given))))))))))))),
+   assign
+     (bound ("printArray"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("a",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("m",
+              allocate-initialised-variable
+                (values,
+                 integer-subtract
+                   (length (vector-elements (assigned (bound ("a")))),
+                    decimal-natural ("1")))),
+            scope
+              (bind
+                ("n",
+                 allocate-initialised-variable
+                   (values,
+                    integer-subtract
+                      (length (vector-elements (assigned (checked index
+                        (integer-add
+                          (1,
+                           decimal-natural ("0")),
+                         vector-elements (assigned (bound ("a"))))))),
+                       decimal-natural ("1")))),
+               scope
+                 (bind
+                   ("i",
+                    allocate-initialised-variable
+                      (values,
+                       decimal-natural ("0"))),
+                  while
+                    (is-less-or-equal
+                      (assigned (bound ("i")),
+                       assigned (bound ("m"))),
+                     sequential
+                       (sequential
+                         (print ("Line ",
+                         integer-add
+                           (assigned (bound ("i")),
+                            decimal-natural ("1")),
+                         " (",
+                         integer-add
+                           (assigned (bound ("n")),
+                            decimal-natural ("1")),
+                         " elements):"),
+                          scope
+                            (bind
+                              ("j",
+                               allocate-initialised-variable
+                                 (values,
+                                  decimal-natural ("0"))),
+                             while
+                               (is-less-or-equal
+                                 (assigned (bound ("j")),
+                                  assigned (bound ("n"))),
+                                sequential
+                                  (print (" ",
+                                  assigned (checked index
+                                    (integer-add
+                                      (1,
+                                       assigned (bound ("j"))),
+                                     vector-elements (assigned (checked index
+                                       (integer-add
+                                         (1,
+                                          assigned (bound ("i"))),
+                                        vector-elements (assigned (bound ("a"))))))))),
+                                   effect (give
+                                     (bound ("j"),
+                                      sequential
+                                        (assign
+                                          (given,
+                                           integer-add
+                                             (assigned (given),
+                                              1)),
+                                         assigned (given))))))),
+                          print ("\n")),
+                        effect (give
+                          (bound ("i"),
+                           sequential
+                             (assign
+                               (given,
+                                integer-add
+                                  (assigned (given),
+                                   1)),
+                              assigned (given))))))))))))),
+   assign
+     (bound ("transArray"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("a",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("m",
+              allocate-initialised-variable
+                (values,
+                 integer-subtract
+                   (length (vector-elements (assigned (bound ("a")))),
+                    decimal-natural ("1")))),
+            scope
+              (bind
+                ("n",
+                 allocate-initialised-variable
+                   (values,
+                    integer-subtract
+                      (length (vector-elements (assigned (checked index
+                        (integer-add
+                          (1,
+                           decimal-natural ("0")),
+                         vector-elements (assigned (bound ("a"))))))),
+                       decimal-natural ("1")))),
+               scope
+                 (bind
+                   ("b",
+                    allocate-nested-vectors (integer-add
+                      (assigned (bound ("n")),
+                       decimal-natural ("1")),
+                    integer-add
+                      (assigned (bound ("m")),
+                       decimal-natural ("1")))),
+                  sequential
+                    (scope
+                      (bind
+                        ("i",
+                         allocate-initialised-variable
+                           (values,
+                            decimal-natural ("0"))),
+                       while
+                         (is-less-or-equal
+                           (assigned (bound ("i")),
+                            assigned (bound ("m"))),
+                          sequential
+                            (scope
+                              (bind
+                                ("j",
+                                 allocate-initialised-variable
+                                   (values,
+                                    decimal-natural ("0"))),
+                               while
+                                 (is-less-or-equal
+                                   (assigned (bound ("j")),
+                                    assigned (bound ("n"))),
+                                  sequential
+                                    (effect (give
+                                      (assigned (checked index
+                                        (integer-add
+                                          (1,
+                                           assigned (bound ("j"))),
+                                         vector-elements (assigned (checked index
+                                           (integer-add
+                                             (1,
+                                              assigned (bound ("i"))),
+                                            vector-elements (assigned (bound ("a")))))))),
+                                       sequential
+                                         (assign
+                                           (checked index
+                                             (integer-add
+                                               (1,
+                                                assigned (bound ("i"))),
+                                              vector-elements (assigned (checked index
+                                                (integer-add
+                                                  (1,
+                                                   assigned (bound ("j"))),
+                                                 vector-elements (assigned (bound ("b"))))))),
+                                            given),
+                                          given))),
+                                     effect (give
+                                       (bound ("j"),
+                                        sequential
+                                          (assign
+                                            (given,
+                                             integer-add
+                                               (assigned (given),
+                                                1)),
+                                           assigned (given))))))),
+                             effect (give
+                               (bound ("i"),
+                                sequential
+                                  (assign
+                                    (given,
+                                     integer-add
+                                       (assigned (given),
+                                        1)),
+                                   assigned (given))))))),
+                     return (assigned (bound ("b"))))))))))),
+   assign
+     (bound ("mulArray"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("a",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("b",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("m",
+              allocate-initialised-variable
+                (values,
+                 integer-subtract
+                   (length (vector-elements (assigned (bound ("a")))),
+                    decimal-natural ("1")))),
+            scope
+              (bind
+                ("n",
+                 allocate-initialised-variable
+                   (values,
+                    integer-subtract
+                      (length (vector-elements (assigned (bound ("b")))),
+                       decimal-natural ("1")))),
+               scope
+                 (bind
+                   ("p",
+                    allocate-initialised-variable
+                      (values,
+                       integer-subtract
+                         (length (vector-elements (assigned (checked index
+                           (integer-add
+                             (1,
+                              decimal-natural ("0")),
+                            vector-elements (assigned (bound ("b"))))))),
+                          decimal-natural ("1")))),
+                  scope
+                    (bind
+                      ("c",
+                       allocate-nested-vectors (integer-add
+                         (assigned (bound ("m")),
+                          decimal-natural ("1")),
+                       integer-add
+                         (assigned (bound ("p")),
+                          decimal-natural ("1")))),
+                     sequential
+                       (scope
+                         (bind
+                           ("i",
+                            allocate-initialised-variable
+                              (values,
+                               decimal-natural ("0"))),
+                          while
+                            (is-less-or-equal
+                              (assigned (bound ("i")),
+                               assigned (bound ("m"))),
+                             sequential
+                               (scope
+                                 (bind
+                                   ("j",
+                                    allocate-initialised-variable
+                                      (values,
+                                       decimal-natural ("0"))),
+                                  while
+                                    (is-less-or-equal
+                                      (assigned (bound ("j")),
+                                       assigned (bound ("p"))),
+                                     sequential
+                                       (sequential
+                                         (effect (give
+                                           (decimal-natural ("0"),
+                                            sequential
+                                              (assign
+                                                (checked index
+                                                  (integer-add
+                                                    (1,
+                                                     assigned (bound ("j"))),
+                                                   vector-elements (assigned (checked index
+                                                     (integer-add
+                                                       (1,
+                                                        assigned (bound ("i"))),
+                                                      vector-elements (assigned (bound ("c"))))))),
+                                                 given),
+                                               given))),
+                                          scope
+                                            (bind
+                                              ("k",
+                                               allocate-initialised-variable
+                                                 (values,
+                                                  decimal-natural ("0"))),
+                                             while
+                                               (is-less-or-equal
+                                                 (assigned (bound ("k")),
+                                                  assigned (bound ("n"))),
+                                                sequential
+                                                  (effect (give
+                                                    (integer-add
+                                                      (assigned (checked index
+                                                        (integer-add
+                                                          (1,
+                                                           assigned (bound ("j"))),
+                                                         vector-elements (assigned (checked index
+                                                           (integer-add
+                                                             (1,
+                                                              assigned (bound ("i"))),
+                                                            vector-elements (assigned (bound ("c")))))))),
+                                                       integer-multiply
+                                                         (assigned (checked index
+                                                           (integer-add
+                                                             (1,
+                                                              assigned (bound ("k"))),
+                                                            vector-elements (assigned (checked index
+                                                              (integer-add
+                                                                (1,
+                                                                 assigned (bound ("i"))),
+                                                               vector-elements (assigned (bound ("a")))))))),
+                                                          assigned (checked index
+                                                            (integer-add
+                                                              (1,
+                                                               assigned (bound ("j"))),
+                                                             vector-elements (assigned (checked index
+                                                               (integer-add
+                                                                 (1,
+                                                                  assigned (bound ("k"))),
+                                                                vector-elements (assigned (bound ("b")))))))))),
+                                                     sequential
+                                                       (assign
+                                                         (checked index
+                                                           (integer-add
+                                                             (1,
+                                                              assigned (bound ("j"))),
+                                                            vector-elements (assigned (checked index
+                                                              (integer-add
+                                                                (1,
+                                                                 assigned (bound ("i"))),
+                                                               vector-elements (assigned (bound ("c"))))))),
+                                                          given),
+                                                        given))),
+                                                   effect (give
+                                                     (bound ("k"),
+                                                      sequential
+                                                        (assign
+                                                          (given,
+                                                           integer-add
+                                                             (assigned (given),
+                                                              1)),
+                                                         assigned (given)))))))),
+                                        effect (give
+                                          (bound ("j"),
+                                           sequential
+                                             (assign
+                                               (given,
+                                                integer-add
+                                                  (assigned (given),
+                                                   1)),
+                                              assigned (given))))))),
+                                effect (give
+                                  (bound ("i"),
+                                   sequential
+                                     (assign
+                                       (given,
+                                        integer-add
+                                          (assigned (given),
+                                           1)),
+                                      assigned (given))))))),
+                        return (assigned (bound ("c")))))))))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (print ("Input the number of lines and columns (two natural numbers): "),
+            scope
+              (bind
+                ("x",
+                 allocate-initialised-variable
+                   (values,
+                    read)),
+               scope
+                 (bind
+                   ("y",
+                    allocate-initialised-variable
+                      (values,
+                       read)),
+                  scope
+                    (bind
+                      ("a",
+                       allocate-nested-vectors (assigned (bound ("x")),
+                       assigned (bound ("y")))),
+                     sequential
+                       (effect (apply
+                         (assigned (bound ("readArray")),
+                          tuple (assigned (bound ("a"))))),
+                        print ("Your matrix is:\n"),
+                        effect (apply
+                          (assigned (bound ("printArray")),
+                           tuple (assigned (bound ("a"))))),
+                        print ("The transpose of your matrix is:\n"),
+                        effect (apply
+                          (assigned (bound ("printArray")),
+                           tuple (apply
+                             (assigned (bound ("transArray")),
+                              tuple (assigned (bound ("a"))))))),
+                        print ("You matrix multiplied with its transpose is:\n"),
+                        effect (apply
+                          (assigned (bound ("printArray")),
+                           tuple (apply
+                             (assigned (bound ("mulArray")),
+                              tuple (assigned (bound ("a")),
+                              apply
+                                (assigned (bound ("transArray")),
+                                 tuple (assigned (bound ("a"))))))))),
+                        print ("The transpose of your matrix multiplied with your matrix is:\n"),
+                        effect (apply
+                          (assigned (bound ("printArray")),
+                           tuple (apply
+                             (assigned (bound ("mulArray")),
+                              tuple (apply
+                                (assigned (bound ("transArray")),
+                                 tuple (assigned (bound ("a")))),
+                              assigned (bound ("a")))))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kdiverse/Kdiverse5.output b/tests/Kdiverse/Kdiverse5.output
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse5.output
@@ -0,0 +1,66 @@
+=== Program ===
+// copied from K: tests/diverse/matrix.simple
+// This program tests multi-dimensional arrays.
+
+function readArray(a) {
+  var m = sizeOf(a) - 1, n = sizeOf(a[0]) - 1;
+  for(var i=0; i<=m; ++i) {
+    print("Line ",i+1," (",n+1," elements): ");
+    for(var j=0; j<=n; ++j) { a[i][j] = read(); }
+  }
+}
+
+function printArray(a) {
+  var m = sizeOf(a) - 1, n = sizeOf(a[0]) - 1;
+  for(var i=0; i<=m; ++i) {
+    print("Line ",i+1," (",n+1," elements):");
+    for(var j=0; j<=n; ++j) { print(" ",a[i,j]); }
+  print("\n");
+  }
+}
+
+function transArray(a) {
+  var  m = sizeOf(a) - 1, n = sizeOf(a[0]) - 1, b[n+1,m+1];
+  for (var i=0; i<=m; ++i) {
+    for (var j=0; j<=n; ++j) {
+      b[j,i] = a[i,j];
+    }
+  }
+  return b;
+}
+
+function mulArray(a,b) {
+  var m = sizeOf(a) - 1, n = sizeOf(b) - 1, p = sizeOf(b[0]) - 1, c[m+1,p+1];
+  for (var i=0; i<=m; ++i) {
+    for (var j=0; j<=p; ++j) {
+      c[i,j] = 0;
+      for (var k=0; k<=n; ++k) {
+        c[i,j] = c[i,j] + a[i,k] * b[k,j];
+      }
+    }
+  }
+  return c;
+}
+
+function main() {
+  print("Input the number of lines and columns (two natural numbers): ");
+  var x = read(), y = read(), a[x,y];
+  readArray(a);
+  print("Your matrix is:\n");
+  printArray(a);
+  print("The transpose of your matrix is:\n");
+  printArray(transArray(a));
+  print("You matrix multiplied with its transpose is:\n");
+  printArray(mulArray(a,transArray(a)));
+  print("The transpose of your matrix multiplied with your matrix is:\n");
+  printArray(mulArray(transArray(a),a));
+}
+
+// Should output what it says.
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"Input the number of lines and columns (two natural numbers): ","Line ",1," (",4," elements): ","Line ",2," (",4," elements): ","Your matrix is:\n","Line ",1," (",4," elements):"," ",1," ",5," ",7," ",8,"\n","Line ",2," (",4," elements):"," ",27," ",1," ",2," ",3,"\n","The transpose of your matrix is:\n","Line ",1," (",2," elements):"," ",1," ",27,"\n","Line ",2," (",2," elements):"," ",5," ",1,"\n","Line ",3," (",2," elements):"," ",7," ",2,"\n","Line ",4," (",2," elements):"," ",8," ",3,"\n","You matrix multiplied with its transpose is:\n","Line ",1," (",2," elements):"," ",139," ",70,"\n","Line ",2," (",2," elements):"," ",70," ",743,"\n","The transpose of your matrix multiplied with your matrix is:\n","Line ",1," (",4," elements):"," ",730," ",32," ",61," ",89,"\n","Line ",2," (",4," elements):"," ",32," ",26," ",37," ",43,"\n","Line ",3," (",4," elements):"," ",61," ",37," ",53," ",62,"\n","Line ",4," (",4," elements):"," ",89," ",43," ",62," ",73,"\n"
+
diff --git a/tests/Kdiverse/Kdiverse5.smp b/tests/Kdiverse/Kdiverse5.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse5.smp
@@ -0,0 +1,58 @@
+// copied from K: tests/diverse/matrix.simple
+// This program tests multi-dimensional arrays.
+
+function readArray(a) {
+  var m = sizeOf(a) - 1, n = sizeOf(a[0]) - 1;
+  for(var i=0; i<=m; ++i) {
+    print("Line ",i+1," (",n+1," elements): ");
+    for(var j=0; j<=n; ++j) { a[i][j] = read(); }
+  }
+}
+
+function printArray(a) {
+  var m = sizeOf(a) - 1, n = sizeOf(a[0]) - 1;
+  for(var i=0; i<=m; ++i) {
+    print("Line ",i+1," (",n+1," elements):");
+    for(var j=0; j<=n; ++j) { print(" ",a[i,j]); }
+  print("\n");
+  }
+}
+
+function transArray(a) {
+  var  m = sizeOf(a) - 1, n = sizeOf(a[0]) - 1, b[n+1,m+1];
+  for (var i=0; i<=m; ++i) {
+    for (var j=0; j<=n; ++j) {
+      b[j,i] = a[i,j];
+    }
+  }
+  return b;
+}
+
+function mulArray(a,b) {
+  var m = sizeOf(a) - 1, n = sizeOf(b) - 1, p = sizeOf(b[0]) - 1, c[m+1,p+1];
+  for (var i=0; i<=m; ++i) {
+    for (var j=0; j<=p; ++j) {
+      c[i,j] = 0;
+      for (var k=0; k<=n; ++k) {
+        c[i,j] = c[i,j] + a[i,k] * b[k,j];
+      }
+    }
+  }
+  return c;
+}
+
+function main() {
+  print("Input the number of lines and columns (two natural numbers): ");
+  var x = read(), y = read(), a[x,y];
+  readArray(a);
+  print("Your matrix is:\n");
+  printArray(a);
+  print("The transpose of your matrix is:\n");
+  printArray(transArray(a));
+  print("You matrix multiplied with its transpose is:\n");
+  printArray(mulArray(a,transArray(a)));
+  print("The transpose of your matrix multiplied with your matrix is:\n");
+  printArray(mulArray(transArray(a),a));
+}
+
+// Should output what it says.
diff --git a/tests/Kdiverse/Kdiverse6.config b/tests/Kdiverse/Kdiverse6.config
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse6.config
@@ -0,0 +1,3 @@
+inputs {
+    standard-in: (5,71,23,43,23,91);
+}
diff --git a/tests/Kdiverse/Kdiverse6.fct b/tests/Kdiverse/Kdiverse6.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse6.fct
@@ -0,0 +1,1082 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("init",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("printArray",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("reverse",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("map",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("insertionSort",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("bubbleSort",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("siftDown",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("heapSort",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("init"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-nested-vectors (assigned (bound ("n")))),
+            sequential
+              (print ("Type ",
+              assigned (bound ("n")),
+              " numbers: "),
+               scope
+                 (bind
+                   ("i",
+                    allocate-initialised-variable
+                      (values,
+                       decimal-natural ("0"))),
+                  while
+                    (is-less-or-equal
+                      (assigned (bound ("i")),
+                       integer-subtract
+                         (assigned (bound ("n")),
+                          decimal-natural ("1"))),
+                     sequential
+                       (effect (give
+                         (read,
+                          sequential
+                            (assign
+                              (checked index
+                                (integer-add
+                                  (1,
+                                   assigned (bound ("i"))),
+                                 vector-elements (assigned (bound ("x")))),
+                               given),
+                             given))),
+                        effect (give
+                          (bound ("i"),
+                           sequential
+                             (assign
+                               (given,
+                                integer-add
+                                  (assigned (given),
+                                   1)),
+                              assigned (given))))))),
+               print ("Finished reading the ",
+               assigned (bound ("n")),
+               " numbers\n"),
+               return (assigned (bound ("x"))))))))),
+   assign
+     (bound ("printArray"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (sequential
+           (print ("\n"),
+            scope
+              (bind
+                ("i",
+                 allocate-initialised-variable
+                   (values,
+                    decimal-natural ("0"))),
+               while
+                 (is-less-or-equal
+                   (assigned (bound ("i")),
+                    integer-subtract
+                      (length (vector-elements (assigned (bound ("x")))),
+                       decimal-natural ("1"))),
+                  sequential
+                    (print (assigned (checked index
+                      (integer-add
+                        (1,
+                         assigned (bound ("i"))),
+                       vector-elements (assigned (bound ("x"))))),
+                    " "),
+                     effect (give
+                       (bound ("i"),
+                        sequential
+                          (assign
+                            (given,
+                             integer-add
+                               (assigned (given),
+                                1)),
+                           assigned (given))))))),
+            print ("\n")))))),
+   assign
+     (bound ("reverse"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 length (vector-elements (assigned (bound ("x")))))),
+            scope
+              (bind
+                ("i",
+                 allocate-initialised-variable
+                   (values,
+                    decimal-natural ("0"))),
+               while
+                 (is-less-or-equal
+                   (assigned (bound ("i")),
+                    integer-subtract
+                      (checked integer-divide
+                        (assigned (bound ("n")),
+                         decimal-natural ("2")),
+                       decimal-natural ("1"))),
+                  sequential
+                    (scope
+                      (bind
+                        ("t",
+                         allocate-initialised-variable
+                           (values,
+                            assigned (checked index
+                              (integer-add
+                                (1,
+                                 assigned (bound ("i"))),
+                               vector-elements (assigned (bound ("x"))))))),
+                       sequential
+                         (effect (give
+                           (assigned (checked index
+                             (integer-add
+                               (1,
+                                integer-subtract
+                                  (integer-subtract
+                                    (assigned (bound ("n")),
+                                     assigned (bound ("i"))),
+                                   decimal-natural ("1"))),
+                              vector-elements (assigned (bound ("x"))))),
+                            sequential
+                              (assign
+                                (checked index
+                                  (integer-add
+                                    (1,
+                                     assigned (bound ("i"))),
+                                   vector-elements (assigned (bound ("x")))),
+                                 given),
+                               given))),
+                          effect (give
+                            (assigned (bound ("t")),
+                             sequential
+                               (assign
+                                 (checked index
+                                   (integer-add
+                                     (1,
+                                      integer-subtract
+                                        (integer-subtract
+                                          (assigned (bound ("n")),
+                                           assigned (bound ("i"))),
+                                         decimal-natural ("1"))),
+                                    vector-elements (assigned (bound ("x")))),
+                                  given),
+                                given))))),
+                     effect (give
+                       (bound ("i"),
+                        sequential
+                          (assign
+                            (given,
+                             integer-add
+                               (assigned (given),
+                                1)),
+                           assigned (given)))))))))))),
+   assign
+     (bound ("map"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("m",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("f",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("i",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("0"))),
+            while
+              (is-less-or-equal
+                (assigned (bound ("i")),
+                 integer-subtract
+                   (length (vector-elements (assigned (bound ("f")))),
+                    decimal-natural ("1"))),
+               sequential
+                 (sequential
+                   (print (assigned (checked index
+                     (integer-add
+                       (1,
+                        assigned (bound ("i"))),
+                      vector-elements (assigned (bound ("m")))))),
+                    effect (apply
+                      (assigned (checked index
+                        (integer-add
+                          (1,
+                           assigned (bound ("i"))),
+                         vector-elements (assigned (bound ("f"))))),
+                       tuple (assigned (bound ("x")))))),
+                  effect (give
+                    (bound ("i"),
+                     sequential
+                       (assign
+                         (given,
+                          integer-add
+                            (assigned (given),
+                             1)),
+                        assigned (given))))))))))),
+   assign
+     (bound ("insertionSort"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("i",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            while
+              (is-less-or-equal
+                (assigned (bound ("i")),
+                 integer-subtract
+                   (length (vector-elements (assigned (bound ("x")))),
+                    decimal-natural ("1"))),
+               sequential
+                 (scope
+                   (bind
+                     ("v",
+                      allocate-initialised-variable
+                        (values,
+                         assigned (checked index
+                           (integer-add
+                             (1,
+                              assigned (bound ("i"))),
+                            vector-elements (assigned (bound ("x"))))))),
+                    scope
+                      (bind
+                        ("j",
+                         allocate-initialised-variable
+                           (values,
+                            integer-subtract
+                              (assigned (bound ("i")),
+                               decimal-natural ("1")))),
+                       sequential
+                         (while
+                           (if-else
+                             (is-greater
+                               (assigned (bound ("j")),
+                                decimal-natural ("0")),
+                              is-greater
+                                (assigned (checked index
+                                  (integer-add
+                                    (1,
+                                     assigned (bound ("j"))),
+                                   vector-elements (assigned (bound ("x"))))),
+                                 assigned (bound ("v"))),
+                              false),
+                            sequential
+                              (effect (give
+                                (assigned (checked index
+                                  (integer-add
+                                    (1,
+                                     assigned (bound ("j"))),
+                                   vector-elements (assigned (bound ("x"))))),
+                                 sequential
+                                   (assign
+                                     (checked index
+                                       (integer-add
+                                         (1,
+                                          integer-add
+                                            (assigned (bound ("j")),
+                                             decimal-natural ("1"))),
+                                        vector-elements (assigned (bound ("x")))),
+                                      given),
+                                    given))),
+                               effect (give
+                                 (integer-subtract
+                                   (assigned (bound ("j")),
+                                    decimal-natural ("1")),
+                                  sequential
+                                    (assign
+                                      (bound ("j"),
+                                       given),
+                                     given))))),
+                          if-else
+                            (is-greater
+                              (assigned (checked index
+                                (integer-add
+                                  (1,
+                                   decimal-natural ("0")),
+                                 vector-elements (assigned (bound ("x"))))),
+                               assigned (bound ("v"))),
+                             sequential
+                               (effect (give
+                                 (assigned (checked index
+                                   (integer-add
+                                     (1,
+                                      decimal-natural ("0")),
+                                    vector-elements (assigned (bound ("x"))))),
+                                  sequential
+                                    (assign
+                                      (checked index
+                                        (integer-add
+                                          (1,
+                                           decimal-natural ("1")),
+                                         vector-elements (assigned (bound ("x")))),
+                                       given),
+                                     given))),
+                                effect (give
+                                  (assigned (bound ("v")),
+                                   sequential
+                                     (assign
+                                       (checked index
+                                         (integer-add
+                                           (1,
+                                            decimal-natural ("0")),
+                                          vector-elements (assigned (bound ("x")))),
+                                        given),
+                                      given)))),
+                             effect (give
+                               (assigned (bound ("v")),
+                                sequential
+                                  (assign
+                                    (checked index
+                                      (integer-add
+                                        (1,
+                                         integer-add
+                                           (assigned (bound ("j")),
+                                            decimal-natural ("1"))),
+                                       vector-elements (assigned (bound ("x")))),
+                                     given),
+                                   given))))))),
+                  effect (give
+                    (bound ("i"),
+                     sequential
+                       (assign
+                         (given,
+                          integer-add
+                            (assigned (given),
+                             1)),
+                        assigned (given))))))))))),
+   assign
+     (bound ("bubbleSort"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("v",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 length (vector-elements (assigned (bound ("v")))))),
+            scope
+              (bind
+                ("i",
+                 allocate-initialised-variable
+                   (values,
+                    decimal-natural ("0"))),
+               while
+                 (is-less-or-equal
+                   (assigned (bound ("i")),
+                    integer-subtract
+                      (assigned (bound ("n")),
+                       decimal-natural ("1"))),
+                  sequential
+                    (scope
+                      (bind
+                        ("j",
+                         allocate-initialised-variable
+                           (values,
+                            decimal-natural ("0"))),
+                       while
+                         (is-less-or-equal
+                           (assigned (bound ("j")),
+                            integer-subtract
+                              (assigned (bound ("n")),
+                               decimal-natural ("2"))),
+                          sequential
+                            (if-else
+                              (is-greater
+                                (assigned (checked index
+                                  (integer-add
+                                    (1,
+                                     assigned (bound ("j"))),
+                                   vector-elements (assigned (bound ("v"))))),
+                                 assigned (checked index
+                                   (integer-add
+                                     (1,
+                                      integer-add
+                                        (assigned (bound ("j")),
+                                         decimal-natural ("1"))),
+                                    vector-elements (assigned (bound ("v")))))),
+                               scope
+                                 (bind
+                                   ("t",
+                                    allocate-initialised-variable
+                                      (values,
+                                       assigned (checked index
+                                         (integer-add
+                                           (1,
+                                            integer-add
+                                              (assigned (bound ("j")),
+                                               decimal-natural ("1"))),
+                                          vector-elements (assigned (bound ("v"))))))),
+                                  sequential
+                                    (effect (give
+                                      (assigned (checked index
+                                        (integer-add
+                                          (1,
+                                           assigned (bound ("j"))),
+                                         vector-elements (assigned (bound ("v"))))),
+                                       sequential
+                                         (assign
+                                           (checked index
+                                             (integer-add
+                                               (1,
+                                                integer-add
+                                                  (assigned (bound ("j")),
+                                                   decimal-natural ("1"))),
+                                              vector-elements (assigned (bound ("v")))),
+                                            given),
+                                          given))),
+                                     effect (give
+                                       (assigned (bound ("t")),
+                                        sequential
+                                          (assign
+                                            (checked index
+                                              (integer-add
+                                                (1,
+                                                 assigned (bound ("j"))),
+                                               vector-elements (assigned (bound ("v")))),
+                                             given),
+                                           given))))),
+                               null),
+                             effect (give
+                               (bound ("j"),
+                                sequential
+                                  (assign
+                                    (given,
+                                     integer-add
+                                       (assigned (given),
+                                        1)),
+                                   assigned (given))))))),
+                     effect (give
+                       (bound ("i"),
+                        sequential
+                          (assign
+                            (given,
+                             integer-add
+                               (assigned (given),
+                                1)),
+                           assigned (given)))))))))))),
+   assign
+     (bound ("siftDown"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("root",
+              allocate-initialised-variable
+                (values,
+                 given))),
+           pattern closure (bind
+             ("bottom",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("done",
+              allocate-initialised-variable
+                (values,
+                 false)),
+            scope
+              (bind
+                ("maxChild",
+                 allocate-variable (values)),
+               while
+                 (if-else
+                   (is-less-or-equal
+                     (integer-multiply
+                       (assigned (bound ("root")),
+                        decimal-natural ("2")),
+                      assigned (bound ("bottom"))),
+                    not (assigned (bound ("done"))),
+                    false),
+                  sequential
+                    (if-else
+                      (is-equal
+                        (integer-multiply
+                          (assigned (bound ("root")),
+                           decimal-natural ("2")),
+                         assigned (bound ("bottom"))),
+                       effect (give
+                         (integer-multiply
+                           (assigned (bound ("root")),
+                            decimal-natural ("2")),
+                          sequential
+                            (assign
+                              (bound ("maxChild"),
+                               given),
+                             given))),
+                       if-else
+                         (is-greater
+                           (assigned (checked index
+                             (integer-add
+                               (1,
+                                integer-multiply
+                                  (assigned (bound ("root")),
+                                   decimal-natural ("2"))),
+                              vector-elements (assigned (bound ("x"))))),
+                            assigned (checked index
+                              (integer-add
+                                (1,
+                                 integer-add
+                                   (integer-multiply
+                                     (assigned (bound ("root")),
+                                      decimal-natural ("2")),
+                                    decimal-natural ("1"))),
+                               vector-elements (assigned (bound ("x")))))),
+                          effect (give
+                            (integer-multiply
+                              (assigned (bound ("root")),
+                               decimal-natural ("2")),
+                             sequential
+                               (assign
+                                 (bound ("maxChild"),
+                                  given),
+                                given))),
+                          effect (give
+                            (integer-add
+                              (integer-multiply
+                                (assigned (bound ("root")),
+                                 decimal-natural ("2")),
+                               decimal-natural ("1")),
+                             sequential
+                               (assign
+                                 (bound ("maxChild"),
+                                  given),
+                                given))))),
+                     if-else
+                       (is-less
+                         (assigned (checked index
+                           (integer-add
+                             (1,
+                              assigned (bound ("root"))),
+                            vector-elements (assigned (bound ("x"))))),
+                          assigned (checked index
+                            (integer-add
+                              (1,
+                               assigned (bound ("maxChild"))),
+                             vector-elements (assigned (bound ("x")))))),
+                        scope
+                          (bind
+                            ("t",
+                             allocate-initialised-variable
+                               (values,
+                                assigned (checked index
+                                  (integer-add
+                                    (1,
+                                     assigned (bound ("root"))),
+                                   vector-elements (assigned (bound ("x"))))))),
+                           sequential
+                             (effect (give
+                               (assigned (checked index
+                                 (integer-add
+                                   (1,
+                                    assigned (bound ("maxChild"))),
+                                  vector-elements (assigned (bound ("x"))))),
+                                sequential
+                                  (assign
+                                    (checked index
+                                      (integer-add
+                                        (1,
+                                         assigned (bound ("root"))),
+                                       vector-elements (assigned (bound ("x")))),
+                                     given),
+                                   given))),
+                              effect (give
+                                (assigned (bound ("t")),
+                                 sequential
+                                   (assign
+                                     (checked index
+                                       (integer-add
+                                         (1,
+                                          assigned (bound ("maxChild"))),
+                                        vector-elements (assigned (bound ("x")))),
+                                      given),
+                                    given))),
+                              effect (give
+                                (assigned (bound ("maxChild")),
+                                 sequential
+                                   (assign
+                                     (bound ("root"),
+                                      given),
+                                    given))))),
+                        effect (give
+                          (true,
+                           sequential
+                             (assign
+                               (bound ("done"),
+                                given),
+                              given)))))))))))),
+   assign
+     (bound ("heapSort"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("n",
+              allocate-initialised-variable
+                (values,
+                 length (vector-elements (assigned (bound ("x")))))),
+            scope
+              (bind
+                ("i",
+                 allocate-initialised-variable
+                   (values,
+                    integer-subtract
+                      (checked integer-divide
+                        (assigned (bound ("n")),
+                         decimal-natural ("2")),
+                       decimal-natural ("1")))),
+               sequential
+                 (while
+                   (is-greater-or-equal
+                     (assigned (bound ("i")),
+                      decimal-natural ("0")),
+                    sequential
+                      (effect (apply
+                        (assigned (bound ("siftDown")),
+                         tuple (assigned (bound ("x")),
+                         assigned (bound ("i")),
+                         integer-subtract
+                           (assigned (bound ("n")),
+                            decimal-natural ("1"))))),
+                       effect (give
+                         (integer-subtract
+                           (assigned (bound ("i")),
+                            decimal-natural ("1")),
+                          sequential
+                            (assign
+                              (bound ("i"),
+                               given),
+                             given))))),
+                  effect (give
+                    (integer-subtract
+                      (assigned (bound ("n")),
+                       decimal-natural ("1")),
+                     sequential
+                       (assign
+                         (bound ("i"),
+                          given),
+                        given))),
+                  while
+                    (is-greater-or-equal
+                      (assigned (bound ("i")),
+                       decimal-natural ("1")),
+                     scope
+                       (bind
+                         ("t",
+                          allocate-initialised-variable
+                            (values,
+                             assigned (checked index
+                               (integer-add
+                                 (1,
+                                  decimal-natural ("0")),
+                                vector-elements (assigned (bound ("x"))))))),
+                        sequential
+                          (effect (give
+                            (assigned (checked index
+                              (integer-add
+                                (1,
+                                 assigned (bound ("i"))),
+                               vector-elements (assigned (bound ("x"))))),
+                             sequential
+                               (assign
+                                 (checked index
+                                   (integer-add
+                                     (1,
+                                      decimal-natural ("0")),
+                                    vector-elements (assigned (bound ("x")))),
+                                  given),
+                                given))),
+                           effect (give
+                             (assigned (bound ("t")),
+                              sequential
+                                (assign
+                                  (checked index
+                                    (integer-add
+                                      (1,
+                                       assigned (bound ("i"))),
+                                     vector-elements (assigned (bound ("x")))),
+                                   given),
+                                 given))),
+                           effect (apply
+                             (assigned (bound ("siftDown")),
+                              tuple (assigned (bound ("x")),
+                              decimal-natural ("0"),
+                              integer-subtract
+                                (assigned (bound ("i")),
+                                 decimal-natural ("1"))))),
+                           effect (give
+                             (integer-subtract
+                               (assigned (bound ("i")),
+                                decimal-natural ("1")),
+                              sequential
+                                (assign
+                                  (bound ("i"),
+                                   given),
+                                 given))))))))))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (print ("Size of the array to sort = "),
+            scope
+              (bind
+                ("x",
+                 allocate-initialised-variable
+                   (values,
+                    apply
+                      (assigned (bound ("init")),
+                       tuple (read)))),
+               scope
+                 (bind
+                   ("m",
+                    allocate-nested-vectors (decimal-natural ("11"))),
+                  scope
+                    (bind
+                      ("f",
+                       allocate-nested-vectors (decimal-natural ("11"))),
+                     sequential
+                       (effect (give
+                         ("The original unsorted array is:",
+                          sequential
+                            (assign
+                              (checked index
+                                (integer-add
+                                  (1,
+                                   decimal-natural ("0")),
+                                 vector-elements (assigned (bound ("m")))),
+                               given),
+                             given))),
+                        effect (give
+                          (assigned (bound ("printArray")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("0")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Reversing the array ... ",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("1")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("reverse")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("1")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Done!\nThe reversed array is:",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("2")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("printArray")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("2")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Sorting the array using insertion sort ... ",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("3")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("insertionSort")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("3")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Done!\nThe resulting array is:",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("4")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("printArray")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("4")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Reversing the array ... ",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("5")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("reverse")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("5")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Done!\nSorting the array using bubble sort ... ",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("6")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("bubbleSort")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("6")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Done!\nThe resulting array is:",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("7")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("printArray")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("7")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Reversing the array ... ",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("8")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("reverse")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("8")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Done!\nSorting the array using heap sort ... ",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("9")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("heapSort")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("9")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (give
+                          ("Done!\nThe resulting array is:",
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("10")),
+                                  vector-elements (assigned (bound ("m")))),
+                                given),
+                              given))),
+                        effect (give
+                          (assigned (bound ("printArray")),
+                           sequential
+                             (assign
+                               (checked index
+                                 (integer-add
+                                   (1,
+                                    decimal-natural ("10")),
+                                  vector-elements (assigned (bound ("f")))),
+                                given),
+                              given))),
+                        effect (apply
+                          (assigned (bound ("map")),
+                           tuple (assigned (bound ("m")),
+                           assigned (bound ("f")),
+                           assigned (bound ("x")))))))))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kdiverse/Kdiverse6.output b/tests/Kdiverse/Kdiverse6.output
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse6.output
@@ -0,0 +1,143 @@
+=== Program ===
+// copied from K: tests/diverse/sortings.simple
+
+function init(n) {
+  var x[n];
+  print("Type ",n," numbers: ");
+  for (var i = 0; i <= n - 1; ++i) {
+    x[i] = read();
+  }
+  print("Finished reading the ",n," numbers\n");
+  return x;
+}
+
+function printArray(x) {
+  print("\n");
+  for (var i = 0; i <= sizeOf(x) - 1; ++i) {
+    print(x[i]," ");
+  }
+  print("\n");
+}
+
+function reverse(x) {
+  var n = sizeOf(x);
+  for (var i = 0; i <= n/2 - 1; ++i) {
+    var t = x[i];
+    x[i] = x[n - i - 1];
+    x[n - i - 1] = t;
+  }
+}
+
+function map(m,f,x) {
+  for (var i = 0; i <= sizeOf(f) - 1; ++i) {
+    print(m[i]);
+    f[i](x);
+  }
+}
+
+function insertionSort(x) {
+  for (var i = 1; i <= sizeOf(x) - 1; ++i) {
+    var v = x[i], j = i - 1;
+    while (j > 0 && x[j] > v) {  // doing the loop only up to 1
+      x[j + 1] = x[j];
+      j = j - 1;
+    }
+    if (x[0] > v) { 
+      x[1] = x[0];
+      x[0] = v;
+    }
+    else {
+      x[j+1] = v;
+    }
+  }
+}
+
+function bubbleSort(v) {
+  var n = sizeOf(v);
+  for (var i = 0; i <= n - 1; ++i) {
+    for (var j = 0; j <= n - 2; ++j) {
+      if (v[j] > v[j+1]) {
+        var t = v[j+1];
+        v[j+1] = v[j];
+        v[j] = t;
+      }
+    }
+  }
+}
+
+function siftDown(x, root, bottom) {
+  var done = false, maxChild;
+  while (root*2 <= bottom && !done) {
+    if (root*2 == bottom) {
+      maxChild = root*2;
+    }
+    else {
+      if (x[root*2] > x[root*2 + 1]) {
+        maxChild = root*2;
+      }
+      else {
+        maxChild = root*2 + 1;
+      }
+    }
+    if (x[root] < x[maxChild]) {
+      var t = x[root];
+      x[root] = x[maxChild];
+      x[maxChild] = t;
+      root = maxChild;
+    }
+    else {
+      done = true;
+    }
+  }
+}
+
+function heapSort(x) {
+  var n = sizeOf(x), i = n/2 - 1;
+  while (i >= 0) {
+    siftDown(x, i, n - 1);
+    i = i - 1;
+  }
+  i = n - 1;
+  while (i >= 1 ) {
+    var t = x[0];
+    x[0] = x[i] ;
+    x[i] = t;
+    siftDown(x, 0, i - 1);
+    i = i - 1;
+  }
+}
+
+function main() {
+  print("Size of the array to sort = ");
+  var x = init(read()), m[11], f[11];
+  m[ 0] = "The original unsorted array is:";
+  f[ 0] = printArray;
+  m[ 1] = "Reversing the array ... ";
+  f[ 1] = reverse;
+  m[ 2] = "Done!\nThe reversed array is:";
+  f[ 2] = printArray;
+  m[ 3] = "Sorting the array using insertion sort ... ";
+  f[ 3] = insertionSort;
+  m[ 4] = "Done!\nThe resulting array is:";
+  f[ 4] = printArray;
+  m[ 5] = "Reversing the array ... ";
+  f[ 5] = reverse;
+  m[ 6] = "Done!\nSorting the array using bubble sort ... ";
+  f[ 6] = bubbleSort;
+  m[ 7] = "Done!\nThe resulting array is:";
+  f[ 7] = printArray;
+  m[ 8] = "Reversing the array ... ";
+  f[ 8] = reverse;
+  m[ 9] = "Done!\nSorting the array using heap sort ... ";
+  f[ 9] = heapSort;
+  m[10] = "Done!\nThe resulting array is:";
+  f[10] = printArray;
+  map(m,f,x);
+}
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+"Size of the array to sort = ","Type ",5," numbers: ","Finished reading the ",5," numbers\n","The original unsorted array is:","\n",71," ",23," ",43," ",23," ",91," ","\n","Reversing the array ... ","Done!\nThe reversed array is:","\n",91," ",23," ",43," ",23," ",71," ","\n","Sorting the array using insertion sort ... ","Done!\nThe resulting array is:","\n",23," ",23," ",43," ",71," ",91," ","\n","Reversing the array ... ","Done!\nSorting the array using bubble sort ... ","Done!\nThe resulting array is:","\n",23," ",23," ",43," ",71," ",91," ","\n","Reversing the array ... ","Done!\nSorting the array using heap sort ... ","Done!\nThe resulting array is:","\n",23," ",23," ",43," ",71," ",91," ","\n"
+
diff --git a/tests/Kdiverse/Kdiverse6.smp b/tests/Kdiverse/Kdiverse6.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kdiverse/Kdiverse6.smp
@@ -0,0 +1,135 @@
+// copied from K: tests/diverse/sortings.simple
+
+function init(n) {
+  var x[n];
+  print("Type ",n," numbers: ");
+  for (var i = 0; i <= n - 1; ++i) {
+    x[i] = read();
+  }
+  print("Finished reading the ",n," numbers\n");
+  return x;
+}
+
+function printArray(x) {
+  print("\n");
+  for (var i = 0; i <= sizeOf(x) - 1; ++i) {
+    print(x[i]," ");
+  }
+  print("\n");
+}
+
+function reverse(x) {
+  var n = sizeOf(x);
+  for (var i = 0; i <= n/2 - 1; ++i) {
+    var t = x[i];
+    x[i] = x[n - i - 1];
+    x[n - i - 1] = t;
+  }
+}
+
+function map(m,f,x) {
+  for (var i = 0; i <= sizeOf(f) - 1; ++i) {
+    print(m[i]);
+    f[i](x);
+  }
+}
+
+function insertionSort(x) {
+  for (var i = 1; i <= sizeOf(x) - 1; ++i) {
+    var v = x[i], j = i - 1;
+    while (j > 0 && x[j] > v) {  // doing the loop only up to 1
+      x[j + 1] = x[j];
+      j = j - 1;
+    }
+    if (x[0] > v) { 
+      x[1] = x[0];
+      x[0] = v;
+    }
+    else {
+      x[j+1] = v;
+    }
+  }
+}
+
+function bubbleSort(v) {
+  var n = sizeOf(v);
+  for (var i = 0; i <= n - 1; ++i) {
+    for (var j = 0; j <= n - 2; ++j) {
+      if (v[j] > v[j+1]) {
+        var t = v[j+1];
+        v[j+1] = v[j];
+        v[j] = t;
+      }
+    }
+  }
+}
+
+function siftDown(x, root, bottom) {
+  var done = false, maxChild;
+  while (root*2 <= bottom && !done) {
+    if (root*2 == bottom) {
+      maxChild = root*2;
+    }
+    else {
+      if (x[root*2] > x[root*2 + 1]) {
+        maxChild = root*2;
+      }
+      else {
+        maxChild = root*2 + 1;
+      }
+    }
+    if (x[root] < x[maxChild]) {
+      var t = x[root];
+      x[root] = x[maxChild];
+      x[maxChild] = t;
+      root = maxChild;
+    }
+    else {
+      done = true;
+    }
+  }
+}
+
+function heapSort(x) {
+  var n = sizeOf(x), i = n/2 - 1;
+  while (i >= 0) {
+    siftDown(x, i, n - 1);
+    i = i - 1;
+  }
+  i = n - 1;
+  while (i >= 1 ) {
+    var t = x[0];
+    x[0] = x[i] ;
+    x[i] = t;
+    siftDown(x, 0, i - 1);
+    i = i - 1;
+  }
+}
+
+function main() {
+  print("Size of the array to sort = ");
+  var x = init(read()), m[11], f[11];
+  m[ 0] = "The original unsorted array is:";
+  f[ 0] = printArray;
+  m[ 1] = "Reversing the array ... ";
+  f[ 1] = reverse;
+  m[ 2] = "Done!\nThe reversed array is:";
+  f[ 2] = printArray;
+  m[ 3] = "Sorting the array using insertion sort ... ";
+  f[ 3] = insertionSort;
+  m[ 4] = "Done!\nThe resulting array is:";
+  f[ 4] = printArray;
+  m[ 5] = "Reversing the array ... ";
+  f[ 5] = reverse;
+  m[ 6] = "Done!\nSorting the array using bubble sort ... ";
+  f[ 6] = bubbleSort;
+  m[ 7] = "Done!\nThe resulting array is:";
+  f[ 7] = printArray;
+  m[ 8] = "Reversing the array ... ";
+  f[ 8] = reverse;
+  m[ 9] = "Done!\nSorting the array using heap sort ... ";
+  f[ 9] = heapSort;
+  m[10] = "Done!\nThe resulting array is:";
+  f[10] = printArray;
+  map(m,f,x);
+}
diff --git a/tests/Kexceptions/Kexceptions01.fct b/tests/Kexceptions/Kexceptions01.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions01.fct
@@ -0,0 +1,51 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("e",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("100"))),
+            sequential
+              (handle-thrown
+                (scope
+                  (bind
+                    ("x",
+                     allocate-initialised-variable
+                       (values,
+                        decimal-natural ("5"))),
+                   sequential
+                     (if-else
+                       (is-greater-or-equal
+                         (assigned (bound ("x")),
+                          decimal-natural ("0")),
+                        throw (integer-add
+                          (assigned (bound ("x")),
+                           decimal-natural ("2"))),
+                        null),
+                      print (decimal-natural ("20")))),
+                 scope
+                   (bind
+                     ("e",
+                      allocate-initialised-variable
+                        (values,
+                         given)),
+                    print (assigned (bound ("e")),
+                    " "))),
+               print (assigned (bound ("e")),
+               " "),
+               print (decimal-natural ("10"),
+               "\n"))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions01.output b/tests/Kexceptions/Kexceptions01.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions01.output
@@ -0,0 +1,24 @@
+=== Program ===
+function main() {
+  var e = 100;
+  try {
+    var x = 5;
+    if (x >= 0) {
+      throw x+2;
+    }
+    print(20);      // should not be printed
+  } catch(e) {
+    print(e," ");   // should print 7
+  }
+  print(e," ");     // should print 100
+  print(10,"\n");
+}
+
+// 7 100 10
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+7," ",100," ",10,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions01.smp b/tests/Kexceptions/Kexceptions01.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions01.smp
@@ -0,0 +1,16 @@
+function main() {
+  var e = 100;
+  try {
+    var x = 5;
+    if (x >= 0) {
+      throw x+2;
+    }
+    print(20);      // should not be printed
+  } catch(e) {
+    print(e," ");   // should print 7
+  }
+  print(e," ");     // should print 100
+  print(10,"\n");
+}
+
+// 7 100 10
diff --git a/tests/Kexceptions/Kexceptions02.fct b/tests/Kexceptions/Kexceptions02.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions02.fct
@@ -0,0 +1,53 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("foo",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (handle-thrown
+           (effect (apply
+             (assigned (bound ("foo")),
+              tuple ())),
+            scope
+              (bind
+                ("e",
+                 allocate-initialised-variable
+                   (values,
+                    given)),
+               print (assigned (bound ("e")),
+               "\n"))))))),
+   assign
+     (bound ("foo"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (handle-thrown
+             (sequential
+               (throw (decimal-natural ("5")),
+                print (decimal-natural ("17"))),
+              scope
+                (bind
+                  ("e",
+                   allocate-initialised-variable
+                     (values,
+                      given)),
+                 throw (integer-add
+                   (assigned (bound ("e")),
+                    decimal-natural ("2"))))),
+            throw (decimal-natural ("1"))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions02.output b/tests/Kexceptions/Kexceptions02.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions02.output
@@ -0,0 +1,28 @@
+=== Program ===
+function main() {
+  try {
+    foo();
+  }
+  catch(e) {
+    print(e,"\n");  // should print 7
+  }
+}
+
+function foo() {
+  try {
+    throw 5;
+    print(17);      // should not be printed
+  } catch(e) {
+    throw e + 2;    // throws 7
+  }
+  throw 1;          // should not be reached
+}
+
+// 7
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+7,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions02.smp b/tests/Kexceptions/Kexceptions02.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions02.smp
@@ -0,0 +1,20 @@
+function main() {
+  try {
+    foo();
+  }
+  catch(e) {
+    print(e,"\n");  // should print 7
+  }
+}
+
+function foo() {
+  try {
+    throw 5;
+    print(17);      // should not be printed
+  } catch(e) {
+    throw e + 2;    // throws 7
+  }
+  throw 1;          // should not be reached
+}
+
+// 7
diff --git a/tests/Kexceptions/Kexceptions03.fct b/tests/Kexceptions/Kexceptions03.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions03.fct
@@ -0,0 +1,60 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            sequential
+              (handle-thrown
+                (sequential
+                  (effect (give
+                    (integer-add
+                      (assigned (bound ("x")),
+                       decimal-natural ("1")),
+                     sequential
+                       (assign
+                         (bound ("x"),
+                          given),
+                        given))),
+                   throw (assigned (bound ("x"))),
+                   effect (give
+                     (checked integer-divide
+                       (assigned (bound ("x")),
+                        decimal-natural ("0")),
+                      sequential
+                        (assign
+                          (bound ("x"),
+                           given),
+                         given)))),
+                 scope
+                   (bind
+                     ("y",
+                      allocate-initialised-variable
+                        (values,
+                         given)),
+                    effect (give
+                      (integer-add
+                        (assigned (bound ("y")),
+                         decimal-natural ("1")),
+                       sequential
+                         (assign
+                           (bound ("x"),
+                            given),
+                          given))))),
+               print (assigned (bound ("x")),
+               "\n"))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions03.output b/tests/Kexceptions/Kexceptions03.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions03.output
@@ -0,0 +1,16 @@
+=== Program ===
+function main() {
+  var x = 1;
+  try { x = x + 1; throw x; x = x/0;}     // division by zero unreachable
+  catch(y) {x = y+1;}
+  print(x,"\n");
+}
+
+// 3
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+3,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions03.smp b/tests/Kexceptions/Kexceptions03.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions03.smp
@@ -0,0 +1,8 @@
+function main() {
+  var x = 1;
+  try { x = x + 1; throw x; x = x/0;}     // division by zero unreachable
+  catch(y) {x = y+1;}
+  print(x,"\n");
+}
+
+// 3
diff --git a/tests/Kexceptions/Kexceptions04.fct b/tests/Kexceptions/Kexceptions04.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions04.fct
@@ -0,0 +1,58 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("x",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            sequential
+              (handle-thrown
+                (scope
+                  (bind
+                    ("x",
+                     allocate-initialised-variable
+                       (values,
+                        decimal-natural ("5"))),
+                   sequential
+                     (throw (assigned (bound ("x"))),
+                      effect (bind
+                        ("y",
+                         allocate-initialised-variable
+                           (values,
+                            checked integer-divide
+                              (assigned (bound ("x")),
+                               decimal-natural ("0"))))))),
+                 scope
+                   (bind
+                     ("y",
+                      allocate-initialised-variable
+                        (values,
+                         given)),
+                    sequential
+                      (effect (give
+                        (integer-add
+                          (assigned (bound ("y")),
+                           decimal-natural ("2")),
+                         sequential
+                           (assign
+                             (bound ("y"),
+                              given),
+                            given))),
+                       print (assigned (bound ("y")),
+                       " ")))),
+               print (assigned (bound ("x")),
+               "\n"))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions04.output b/tests/Kexceptions/Kexceptions04.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions04.output
@@ -0,0 +1,16 @@
+=== Program ===
+function main() {
+  var x = 1;
+  try { var x = 5; throw x; var y = x/0;}   // division by zero unreachable
+  catch(y) {y = y + 2; print(y," ");}       // new y here, the one declared by catch
+  print(x,"\n");
+}
+
+// 7 1
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+7," ",1,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions04.smp b/tests/Kexceptions/Kexceptions04.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions04.smp
@@ -0,0 +1,8 @@
+function main() {
+  var x = 1;
+  try { var x = 5; throw x; var y = x/0;}   // division by zero unreachable
+  catch(y) {y = y + 2; print(y," ");}       // new y here, the one declared by catch
+  print(x,"\n");
+}
+
+// 7 1
diff --git a/tests/Kexceptions/Kexceptions05.fct b/tests/Kexceptions/Kexceptions05.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions05.fct
@@ -0,0 +1,99 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("x",
+     allocate-variable (values)),
+  bind
+    ("f",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   assign
+     (bound ("f"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("y",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("t",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            sequential
+              (handle-thrown
+                (sequential
+                  (print (assigned (bound ("t")),
+                  " "),
+                   throw (decimal-natural ("5")),
+                   print (decimal-natural ("8"))),
+                 scope
+                   (bind
+                     ("p",
+                      allocate-initialised-variable
+                        (values,
+                         given)),
+                    print (integer-add
+                      (assigned (bound ("p")),
+                       decimal-natural ("10")),
+                    " "))),
+               scope
+                 (bind
+                   ("i",
+                    allocate-initialised-variable
+                      (values,
+                       decimal-natural ("1"))),
+                  while
+                    (is-less-or-equal
+                      (assigned (bound ("i")),
+                       assigned (bound ("y"))),
+                     sequential
+                       (effect (give
+                         (integer-multiply
+                           (assigned (bound ("t")),
+                            assigned (bound ("i"))),
+                          sequential
+                            (assign
+                              (bound ("t"),
+                               given),
+                             given))),
+                        effect (give
+                          (bound ("i"),
+                           sequential
+                             (assign
+                               (given,
+                                integer-add
+                                  (assigned (given),
+                                   1)),
+                              assigned (given))))))),
+               return (assigned (bound ("t"))))))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (effect (give
+             (decimal-natural ("5"),
+              sequential
+                (assign
+                  (bound ("x"),
+                   given),
+                 given))),
+            print (apply
+              (assigned (bound ("f")),
+               tuple (assigned (bound ("x")))),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions05.output b/tests/Kexceptions/Kexceptions05.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions05.output
@@ -0,0 +1,31 @@
+=== Program ===
+var x;
+
+function f(y) {
+  var t = 1;
+  try{
+    print(t," ");
+    throw 5;
+    print(8);      // not reachable
+  } catch(p) {
+    print(p+10," ");
+  }
+  for (var i = 1; i <= y; ++i) {
+    t = t*i;
+  }
+  return t;
+}
+
+function main() {
+  x = 5;
+  print(f(x),"\n");
+}
+
+// 1 15 120
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1," ",15," ",120,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions05.smp b/tests/Kexceptions/Kexceptions05.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions05.smp
@@ -0,0 +1,23 @@
+var x;
+
+function f(y) {
+  var t = 1;
+  try{
+    print(t," ");
+    throw 5;
+    print(8);      // not reachable
+  } catch(p) {
+    print(p+10," ");
+  }
+  for (var i = 1; i <= y; ++i) {
+    t = t*i;
+  }
+  return t;
+}
+
+function main() {
+  x = 5;
+  print(f(x),"\n");
+}
+
+// 1 15 120
diff --git a/tests/Kexceptions/Kexceptions06.fct b/tests/Kexceptions/Kexceptions06.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions06.fct
@@ -0,0 +1,98 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("x",
+     allocate-variable (values)),
+  bind
+    ("f",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   assign
+     (bound ("f"),
+      function closure (scope
+        (match
+          (given,
+           tuple (pattern closure (bind
+             ("y",
+              allocate-initialised-variable
+                (values,
+                 given))))),
+         handle-return (scope
+           (bind
+             ("t",
+              allocate-initialised-variable
+                (values,
+                 decimal-natural ("1"))),
+            sequential
+              (handle-thrown
+                (sequential
+                  (print (assigned (bound ("t")),
+                  " "),
+                   print (decimal-natural ("8"),
+                   " ")),
+                 scope
+                   (bind
+                     ("p",
+                      allocate-initialised-variable
+                        (values,
+                         given)),
+                    print (integer-add
+                      (assigned (bound ("p")),
+                       decimal-natural ("10"))))),
+               scope
+                 (bind
+                   ("i",
+                    allocate-initialised-variable
+                      (values,
+                       decimal-natural ("1"))),
+                  while
+                    (is-less-or-equal
+                      (assigned (bound ("i")),
+                       assigned (bound ("y"))),
+                     sequential
+                       (effect (give
+                         (integer-multiply
+                           (assigned (bound ("t")),
+                            assigned (bound ("i"))),
+                          sequential
+                            (assign
+                              (bound ("t"),
+                               given),
+                             given))),
+                        effect (give
+                          (bound ("i"),
+                           sequential
+                             (assign
+                               (given,
+                                integer-add
+                                  (assigned (given),
+                                   1)),
+                              assigned (given))))))),
+               return (assigned (bound ("t"))))))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (effect (give
+             (decimal-natural ("5"),
+              sequential
+                (assign
+                  (bound ("x"),
+                   given),
+                 given))),
+            print (apply
+              (assigned (bound ("f")),
+               tuple (assigned (bound ("x")))),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions06.output b/tests/Kexceptions/Kexceptions06.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions06.output
@@ -0,0 +1,30 @@
+=== Program ===
+var x;
+
+function f(y) {
+  var t = 1;
+  try {
+    print(t," ");
+    print(8," ");
+  } catch(p) {
+    print(p+10);  // not reachable
+  }
+  for (var i = 1; i <= y; ++i) {
+    t = t*i;
+  }
+  return t;
+}
+
+function main() {
+  x = 5;
+  print(f(x),"\n");
+}
+
+// 1 8 120
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1," ",8," ",120,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions06.smp b/tests/Kexceptions/Kexceptions06.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions06.smp
@@ -0,0 +1,22 @@
+var x;
+
+function f(y) {
+  var t = 1;
+  try {
+    print(t," ");
+    print(8," ");
+  } catch(p) {
+    print(p+10);  // not reachable
+  }
+  for (var i = 1; i <= y; ++i) {
+    t = t*i;
+  }
+  return t;
+}
+
+function main() {
+  x = 5;
+  print(f(x),"\n");
+}
+
+// 1 8 120
diff --git a/tests/Kexceptions/Kexceptions07.fct b/tests/Kexceptions/Kexceptions07.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions07.fct
@@ -0,0 +1,48 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("e",
+              allocate-variable (values)),
+            handle-thrown
+              (scope
+                (bind
+                  ("x",
+                   allocate-initialised-variable
+                     (values,
+                      decimal-natural ("2"))),
+                 sequential
+                   (print (assigned (bound ("x")),
+                   " "),
+                    throw (integer-add
+                      (give
+                        (bound ("x"),
+                         sequential
+                           (assign
+                             (given,
+                              integer-add
+                                (assigned (given),
+                                 1)),
+                            assigned (given))),
+                       assigned (bound ("x")))))),
+               scope
+                 (bind
+                   ("e",
+                    allocate-initialised-variable
+                      (values,
+                       given)),
+                  print (assigned (bound ("e")),
+                  "\n")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions07.output b/tests/Kexceptions/Kexceptions07.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions07.output
@@ -0,0 +1,21 @@
+=== Program ===
+function main() {
+  var e;
+  try {
+    var x = 2;
+    print(x," ");
+    throw ++x + x;
+  }
+  catch(e) {
+    print(e,"\n");
+  }
+}
+
+// 2 6 or 2 5
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+2," ",6,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions07.smp b/tests/Kexceptions/Kexceptions07.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions07.smp
@@ -0,0 +1,13 @@
+function main() {
+  var e;
+  try {
+    var x = 2;
+    print(x," ");
+    throw ++x + x;
+  }
+  catch(e) {
+    print(e,"\n");
+  }
+}
+
+// 2 6 or 2 5
diff --git a/tests/Kexceptions/Kexceptions08.fct b/tests/Kexceptions/Kexceptions08.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions08.fct
@@ -0,0 +1,103 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (scope
+           (bind
+             ("e",
+              allocate-variable (values)),
+            handle-thrown
+              (handle-thrown
+                (handle-thrown
+                  (handle-thrown
+                    (scope
+                      (bind
+                        ("x",
+                         allocate-initialised-variable
+                           (values,
+                            decimal-natural ("1"))),
+                       sequential
+                         (print (assigned (bound ("x")),
+                         " "),
+                          throw (give
+                            (bound ("x"),
+                             sequential
+                               (assign
+                                 (given,
+                                  integer-add
+                                    (assigned (given),
+                                     1)),
+                                assigned (given)))))),
+                     scope
+                       (bind
+                         ("e",
+                          allocate-initialised-variable
+                            (values,
+                             given)),
+                        sequential
+                          (print (assigned (bound ("e")),
+                          " "),
+                           throw (give
+                             (bound ("e"),
+                              sequential
+                                (assign
+                                  (given,
+                                   integer-add
+                                     (assigned (given),
+                                      1)),
+                                 assigned (given))))))),
+                   scope
+                     (bind
+                       ("e",
+                        allocate-initialised-variable
+                          (values,
+                           given)),
+                      sequential
+                        (print (assigned (bound ("e")),
+                        " "),
+                         throw (give
+                           (bound ("e"),
+                            sequential
+                              (assign
+                                (given,
+                                 integer-add
+                                   (assigned (given),
+                                    1)),
+                               assigned (given))))))),
+                 scope
+                   (bind
+                     ("e",
+                      allocate-initialised-variable
+                        (values,
+                         given)),
+                    sequential
+                      (print (assigned (bound ("e")),
+                      " "),
+                       throw (give
+                         (bound ("e"),
+                          sequential
+                            (assign
+                              (given,
+                               integer-add
+                                 (assigned (given),
+                                  1)),
+                             assigned (given))))))),
+               scope
+                 (bind
+                   ("e",
+                    allocate-initialised-variable
+                      (values,
+                       given)),
+                  print (assigned (bound ("e")),
+                  "\n")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions08.output b/tests/Kexceptions/Kexceptions08.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions08.output
@@ -0,0 +1,35 @@
+=== Program ===
+function main() {
+  var e;
+  try {
+    try {
+      try {
+        try {
+          var x = 1;
+          print(x," ");
+          throw ++x;
+        } catch(e) {
+          print(e," ");
+          throw ++e;
+        }
+      } catch(e) {
+        print(e," ");
+        throw ++e;
+      }
+    } catch(e) {
+      print(e," ");
+      throw ++e;
+    }
+  } catch(e) {
+    print(e,"\n");
+  }
+}
+
+// 1 2 3 4 5
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1," ",2," ",3," ",4," ",5,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions08.smp b/tests/Kexceptions/Kexceptions08.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions08.smp
@@ -0,0 +1,27 @@
+function main() {
+  var e;
+  try {
+    try {
+      try {
+        try {
+          var x = 1;
+          print(x," ");
+          throw ++x;
+        } catch(e) {
+          print(e," ");
+          throw ++e;
+        }
+      } catch(e) {
+        print(e," ");
+        throw ++e;
+      }
+    } catch(e) {
+      print(e," ");
+      throw ++e;
+    }
+  } catch(e) {
+    print(e,"\n");
+  }
+}
+
+// 1 2 3 4 5
diff --git a/tests/Kexceptions/Kexceptions09.fct b/tests/Kexceptions/Kexceptions09.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions09.fct
@@ -0,0 +1,84 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("x",
+     allocate-variable (values)),
+  bind
+    ("y",
+     allocate-variable (values)),
+  bind
+    ("z",
+     allocate-variable (values)),
+  bind
+    ("g",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("f",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values))),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   null,
+   null,
+   assign
+     (bound ("g"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (throw (decimal-natural ("15")))))),
+   assign
+     (bound ("f"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (effect (apply
+           (assigned (bound ("g")),
+            tuple ())))))),
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (effect (give
+             (decimal-natural ("5"),
+              sequential
+                (assign
+                  (bound ("x"),
+                   given),
+                 given))),
+            effect (give
+              (decimal-natural ("10"),
+               sequential
+                 (assign
+                   (bound ("y"),
+                    given),
+                  given))),
+            handle-thrown
+              (effect (apply
+                (assigned (bound ("f")),
+                 tuple ())),
+               scope
+                 (bind
+                   ("y",
+                    allocate-initialised-variable
+                      (values,
+                       given)),
+                  print (assigned (bound ("y")),
+                  " "))),
+            print (assigned (bound ("x")),
+            " "),
+            print (assigned (bound ("y")),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions09.output b/tests/Kexceptions/Kexceptions09.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions09.output
@@ -0,0 +1,32 @@
+=== Program ===
+var x, y, z;
+
+function g() {
+  throw 15;
+}
+
+function f() {
+  g();
+}
+
+function main() {
+  x = 5;
+  y = 10;
+
+  try {
+    f();
+  } catch(y) {
+    print(y," ");
+  }
+  print(x," ");
+  print(y,"\n");
+}
+
+// 15 5 10
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+15," ",5," ",10,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions09.smp b/tests/Kexceptions/Kexceptions09.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions09.smp
@@ -0,0 +1,24 @@
+var x, y, z;
+
+function g() {
+  throw 15;
+}
+
+function f() {
+  g();
+}
+
+function main() {
+  x = 5;
+  y = 10;
+
+  try {
+    f();
+  } catch(y) {
+    print(y," ");
+  }
+  print(x," ");
+  print(y,"\n");
+}
+
+// 15 5 10
diff --git a/tests/Kexceptions/Kexceptions1.output b/tests/Kexceptions/Kexceptions1.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions1.output
@@ -0,0 +1,24 @@
+=== Program ===
+function main() {
+  var e = 100;
+  try {
+    var x = 5;
+    if (x >= 0) {
+      throw x+2;
+    }
+    print(20);      // should not be printed
+  } catch(e) {
+    print(e," ");   // should print 7
+  }
+  print(e," ");     // should print 100
+  print(10,"\n");
+}
+
+// 7 100 10
+=== Output ===
+Result:
+()
+
+Output Entity: standard-out
+[7,"",100,"",10,"\n"]
+
diff --git a/tests/Kexceptions/Kexceptions10.fct b/tests/Kexceptions/Kexceptions10.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions10.fct
@@ -0,0 +1,39 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("x",
+     allocate-variable (values)),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (effect (give
+             (decimal-natural ("5"),
+              sequential
+                (assign
+                  (bound ("x"),
+                   given),
+                 given))),
+            handle-thrown
+              (sequential
+                (throw (decimal-natural ("3")),
+                 print (assigned (bound ("x")))),
+               scope
+                 (bind
+                   ("y",
+                    allocate-initialised-variable
+                      (values,
+                       given)),
+                  print (assigned (bound ("y")),
+                  "\n")))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions10.output b/tests/Kexceptions/Kexceptions10.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions10.output
@@ -0,0 +1,21 @@
+=== Program ===
+var x;
+
+function main() {
+  x = 5;
+  try {
+    throw 3;
+    print(x);       // should not print this
+  } catch(y) {
+    print(y,"\n");  // should print this
+  }
+}
+
+// 3
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+3,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions10.smp b/tests/Kexceptions/Kexceptions10.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions10.smp
@@ -0,0 +1,13 @@
+var x;
+
+function main() {
+  x = 5;
+  try {
+    throw 3;
+    print(x);       // should not print this
+  } catch(y) {
+    print(y,"\n");  // should print this
+  }
+}
+
+// 3
diff --git a/tests/Kexceptions/Kexceptions11.fct b/tests/Kexceptions/Kexceptions11.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions11.fct
@@ -0,0 +1,87 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("i",
+     allocate-variable (values)),
+  bind
+    ("j",
+     allocate-variable (values)),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   null,
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (effect (give
+             (decimal-natural ("0"),
+              sequential
+                (assign
+                  (bound ("i"),
+                   given),
+                 given))),
+            while
+              (is-less-or-equal
+                (give
+                  (bound ("i"),
+                   sequential
+                     (assign
+                       (given,
+                        integer-add
+                          (assigned (given),
+                           1)),
+                      assigned (given))),
+                 decimal-natural ("3")),
+               print (assigned (bound ("i")),
+               " ")),
+            handle-thrown
+              (sequential
+                (throw (give
+                  (decimal-natural ("1"),
+                   sequential
+                     (assign
+                       (bound ("j"),
+                        given),
+                      given))),
+                 effect (give
+                   (decimal-natural ("10"),
+                    sequential
+                      (assign
+                        (bound ("i"),
+                         given),
+                       given))),
+                 print (assigned (bound ("i")))),
+               scope
+                 (bind
+                   ("j",
+                    allocate-initialised-variable
+                      (values,
+                       given)),
+                  sequential
+                    (effect (give
+                      (decimal-natural ("20"),
+                       sequential
+                         (assign
+                           (bound ("i"),
+                            given),
+                          given))),
+                     print (assigned (bound ("i")),
+                     " ")))),
+            effect (give
+              (decimal-natural ("15"),
+               sequential
+                 (assign
+                   (bound ("i"),
+                    given),
+                  given))),
+            print (assigned (bound ("i")),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions11.output b/tests/Kexceptions/Kexceptions11.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions11.output
@@ -0,0 +1,28 @@
+=== Program ===
+var i, j;
+
+function main() {
+  i = 0;
+  while (++i <= 3) {
+    print(i," ");
+  }
+  try {
+    throw j=1;
+    i = 10;
+    print(i);   // should not print this
+  } catch(j) {
+    i = 20;
+    print(i," ");   // should print this
+  }
+  i = 15;
+  print(i,"\n");
+}
+
+// 1 2 3 20 15
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1," ",2," ",3," ",20," ",15,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions11.smp b/tests/Kexceptions/Kexceptions11.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions11.smp
@@ -0,0 +1,20 @@
+var i, j;
+
+function main() {
+  i = 0;
+  while (++i <= 3) {
+    print(i," ");
+  }
+  try {
+    throw j=1;
+    i = 10;
+    print(i);   // should not print this
+  } catch(j) {
+    i = 20;
+    print(i," ");   // should print this
+  }
+  i = 15;
+  print(i,"\n");
+}
+
+// 1 2 3 20 15
diff --git a/tests/Kexceptions/Kexceptions12.fct b/tests/Kexceptions/Kexceptions12.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions12.fct
@@ -0,0 +1,80 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("i",
+     allocate-variable (values)),
+  bind
+    ("j",
+     allocate-variable (values)),
+  bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (null,
+   null,
+   assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (effect (give
+             (decimal-natural ("0"),
+              sequential
+                (assign
+                  (bound ("i"),
+                   given),
+                 given))),
+            while
+              (is-less-or-equal
+                (give
+                  (bound ("i"),
+                   sequential
+                     (assign
+                       (given,
+                        integer-add
+                          (assigned (given),
+                           1)),
+                      assigned (given))),
+                 decimal-natural ("3")),
+               print (assigned (bound ("i")),
+               " ")),
+            handle-thrown
+              (sequential
+                (effect (give
+                  (decimal-natural ("10"),
+                   sequential
+                     (assign
+                       (bound ("i"),
+                        given),
+                      given))),
+                 print (assigned (bound ("i")),
+                 " ")),
+               scope
+                 (bind
+                   ("j",
+                    allocate-initialised-variable
+                      (values,
+                       given)),
+                  sequential
+                    (effect (give
+                      (decimal-natural ("20"),
+                       sequential
+                         (assign
+                           (bound ("i"),
+                            given),
+                          given))),
+                     print (assigned (bound ("i")))))),
+            effect (give
+              (decimal-natural ("15"),
+               sequential
+                 (assign
+                   (bound ("i"),
+                    given),
+                  given))),
+            print (assigned (bound ("i")),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions12.output b/tests/Kexceptions/Kexceptions12.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions12.output
@@ -0,0 +1,27 @@
+=== Program ===
+var i, j;
+
+function main() {
+  i = 0;
+  while (++i <= 3) {
+    print(i," ");
+  }
+  try {
+    i = 10;
+    print(i," ");
+  } catch(j) {
+    i = 20;
+    print(i);  // should not print this
+  }
+  i = 15;
+  print(i,"\n");
+}
+
+// 1 2 3 10 15
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1," ",2," ",3," ",10," ",15,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions12.smp b/tests/Kexceptions/Kexceptions12.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions12.smp
@@ -0,0 +1,19 @@
+var i, j;
+
+function main() {
+  i = 0;
+  while (++i <= 3) {
+    print(i," ");
+  }
+  try {
+    i = 10;
+    print(i," ");
+  } catch(j) {
+    i = 20;
+    print(i);  // should not print this
+  }
+  i = 15;
+  print(i,"\n");
+}
+
+// 1 2 3 10 15
diff --git a/tests/Kexceptions/Kexceptions13.fct b/tests/Kexceptions/Kexceptions13.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions13.fct
@@ -0,0 +1,28 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (handle-thrown
+             (throw (decimal-natural ("4")),
+              scope
+                (bind
+                  ("e",
+                   allocate-initialised-variable
+                     (values,
+                      given)),
+                 print (assigned (bound ("e")),
+                 " "))),
+            print (decimal-natural ("42"),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions13.output b/tests/Kexceptions/Kexceptions13.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions13.output
@@ -0,0 +1,18 @@
+=== Program ===
+function main() {
+  try {
+    throw 4;
+  } catch (e) {
+    print(e," ");
+  }
+  print(42,"\n");
+}
+
+// 4 42
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+4," ",42,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions13.smp b/tests/Kexceptions/Kexceptions13.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions13.smp
@@ -0,0 +1,10 @@
+function main() {
+  try {
+    throw 4;
+  } catch (e) {
+    print(e," ");
+  }
+  print(42,"\n");
+}
+
+// 4 42
diff --git a/tests/Kexceptions/Kexceptions14.fct b/tests/Kexceptions/Kexceptions14.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions14.fct
@@ -0,0 +1,27 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (sequential
+           (handle-thrown
+             (effect (decimal-natural ("15")),
+              scope
+                (bind
+                  ("e",
+                   allocate-initialised-variable
+                     (values,
+                      given)),
+                 print (assigned (bound ("e"))))),
+            print (decimal-natural ("42"),
+            "\n")))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions14.output b/tests/Kexceptions/Kexceptions14.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions14.output
@@ -0,0 +1,18 @@
+=== Program ===
+function main() {
+  try {
+    15;
+  } catch(e) {
+    print(e);   // should not print this
+  }
+  print(42,"\n");
+}
+
+// 42
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+42,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions14.smp b/tests/Kexceptions/Kexceptions14.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions14.smp
@@ -0,0 +1,10 @@
+function main() {
+  try {
+    15;
+  } catch(e) {
+    print(e);   // should not print this
+  }
+  print(42,"\n");
+}
+
+// 42
diff --git a/tests/Kexceptions/Kexceptions15.fct b/tests/Kexceptions/Kexceptions15.fct
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions15.fct
@@ -0,0 +1,36 @@
+initialise-binding initialise-storing initialise-giving finalise-failing finalise-throwing scope
+  (collateral (bind
+    ("main",
+     allocate-variable (functions
+       (tuples ((values)*),
+        values)))),
+   sequential (assign
+     (bound ("main"),
+      function closure (scope
+        (match
+          (given,
+           tuple ()),
+         handle-return (handle-thrown
+           (sequential
+             (effect (decimal-natural ("1")),
+              handle-thrown
+                (effect (decimal-natural ("2")),
+                 scope
+                   (bind
+                     ("a",
+                      allocate-initialised-variable
+                        (values,
+                         given)),
+                    print (decimal-natural ("2")))),
+              throw (decimal-natural ("1"))),
+            scope
+              (bind
+                ("b",
+                 allocate-initialised-variable
+                   (values,
+                    given)),
+               print (decimal-natural ("1"),
+               "\n"))))))),
+   apply
+     (assigned (bound ("main")),
+      tuple ())))
diff --git a/tests/Kexceptions/Kexceptions15.output b/tests/Kexceptions/Kexceptions15.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions15.output
@@ -0,0 +1,23 @@
+=== Program ===
+function main() {
+  try {
+    1;
+    try {
+      2;
+    } catch(a) {
+      print(2);     // should not print this
+    }
+    throw 1;
+  } catch(b) {
+    print(1,"\n");  // should print this
+  }
+}
+
+// 1
+=== Output ===
+Result:
+null-value
+
+Output Entity: standard-out
+1,"\n"
+
diff --git a/tests/Kexceptions/Kexceptions15.smp b/tests/Kexceptions/Kexceptions15.smp
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions15.smp
@@ -0,0 +1,15 @@
+function main() {
+  try {
+    1;
+    try {
+      2;
+    } catch(a) {
+      print(2);     // should not print this
+    }
+    throw 1;
+  } catch(b) {
+    print(1,"\n");  // should print this
+  }
+}
+
+// 1
diff --git a/tests/Kexceptions/Kexceptions2.output b/tests/Kexceptions/Kexceptions2.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions2.output
@@ -0,0 +1,28 @@
+=== Program ===
+function main() {
+  try {
+    foo();
+  }
+  catch(e) {
+    print(e,"\n");  // should print 7
+  }
+}
+
+function foo() {
+  try {
+    throw 5;
+    print(17);      // should not be printed
+  } catch(e) {
+    throw e + 2;    // throws 7
+  }
+  throw 1;          // should not be reached
+}
+
+// 7
+=== Output ===
+Result:
+()
+
+Output Entity: standard-out
+[7,"\n"]
+
diff --git a/tests/Kexceptions/Kexceptions3.output b/tests/Kexceptions/Kexceptions3.output
new file mode 100644
--- /dev/null
+++ b/tests/Kexceptions/Kexceptions3.output
@@ -0,0 +1,16 @@
+=== Program ===
+function main() {
+  var x = 1;
+  try { x = x + 1; throw x; x = x/0;}     // division by zero unreachable
+  catch(y) {x = y+1;}
+  print(x,"\n");
+}
+
+// 3
+=== Output ===
+Result:
+()
+
+Output Entity: standard-out
+[3,"\n"]
+
diff --git a/tests/README.txt b/tests/README.txt
new file mode 100644
--- /dev/null
+++ b/tests/README.txt
@@ -0,0 +1,48 @@
+SIMPLE TESTS
+============
+
+This directors contains several sets of SIMPLE test programs:
+  - Basic
+  - Advanced
+  - KExceptions
+  - Kdiverse
+The latter two sets are taken from the K Framework distribution.
+
+Each directory contains:
+  - several test programs (*.smp), 
+  - the funcon terms generated from those test programs (*.fct), and 
+  - in some cases, configuration files providing sample input values (*.config).
+
+
+Running Funcon Terms
+--------------------
+
+To run a test, you will first need to have built the SIMPLE interpreter 
+(see ../README.txt). Then invoke it as follows (using Kdiverse2.fct as an example):
+
+> runfct-SIMPLE Kdiverse/Kdiverse2.fct
+
+Tests involving reading input take their input from the individual .config files,
+e.g. Kdiverse/Kdiverse2.config.
+
+To run a test interactively, you should load the "SIMPLE-interactive.config"
+configuration file:
+
+> runfct-SIMPLE --config SIMPLE-interactive.config Kdiverse/Kdiverse2.fct
+
+
+Regenerating Funcon Terms
+-------------------------
+
+Note: All funcon terms have already been generated, so regenerating them is only
+necessary if you have added or modified a test program, or changed the CBS
+definition of SIMPLE.
+
+To generate the funcon terms from test files, you first need to have imported
+and built the "SIMPLE-Editor" Spoofax project in Eclipse.
+
+Then you can run the "regen-funcons" script.  E.g.
+
+> sh ./regen-funcons.sh Basic
+
+will generate a *.fct file for each *.smp file in the folder "Basic".
diff --git a/tests/SIMPLE-interactive.config b/tests/SIMPLE-interactive.config
new file mode 100644
--- /dev/null
+++ b/tests/SIMPLE-interactive.config
@@ -0,0 +1,4 @@
+general {
+    interactive-mode;
+    auto-config: false;
+}
diff --git a/tests/SIMPLE.config b/tests/SIMPLE.config
new file mode 100644
--- /dev/null
+++ b/tests/SIMPLE.config
@@ -0,0 +1,3 @@
+general {
+  refocus;
+}
