diff --git a/tests/3/Factorial.zwei b/tests/3/Factorial.zwei new file mode 100755 index 0000000..e08d923 --- /dev/null +++ b/tests/3/Factorial.zwei @@ -0,0 +1,45 @@ +class Factorial { + Int factorial1(Int x) { + return if (x == 0) 1 + else x * this.factorial1(x - 1) + } + + Int factorial2_aux(Int x, Int acc) { + Int r = 0; + if (x == 0) { + r = acc; + } else { + r = this.factorial2_aux(x - 1, acc * x); + }; + return r + } + + Int factorial2(Int x) { + return this.factorial2_aux(x, 1) + } + + Int factorial3(Int x) { + Int p = 1; + while (x > 0) { + p = p * x; + x = x - 1; + } + return p + } + +} + +class Example { + Null main() { + Factorial fac = new Factorial(); + Int x = 5; + printInt(fac.factorial1(x)); + printChar(10); + printInt(fac.factorial2(x)); + printChar(10); + printInt(fac.factorial3(x)); + printChar(10); + } +} + +new Example().main() diff --git a/tests/3/Factorial.zwei~ b/tests/3/Factorial.zwei~ new file mode 100755 index 0000000..1264f0e --- /dev/null +++ b/tests/3/Factorial.zwei~ @@ -0,0 +1,46 @@ +class Factorial { + + // Recursive definition + Int factorial1(Int x) { + return if (x == 0) 1 + else x * this.factorial1(x - 1) + } + + // Tail-recursive definition + Int factorial2_aux(Int x, Int acc) { + return if (x == 0) { + acc; + } else { + this.factorial2_aux(x - 1, acc * x); + } + } + Int factorial2(Int x) { + return this.factorial2_aux(x, 1) + } + + // Iterative definition + Int factorial3(Int x) { + Int p = 1; + while (x > 0) { + p = p * x; + x = x - 1; + } + return p + } + +} + +class Example { + Null main() { + Factorial fac = new Factorial(); + Int x = 5; + printInt(fac.factorial1(x)); + printChar(10); + printInt(fac.factorial2(x)); + printChar(10); + printInt(fac.factorial3(x)); + printChar(10); + } +} + +new Example().main() diff --git a/tests/3/bizarrReturn.zwei b/tests/3/bizarrReturn.zwei new file mode 100755 index 0000000..71b5f31 --- /dev/null +++ b/tests/3/bizarrReturn.zwei @@ -0,0 +1,11 @@ +class Factorial { + Int factorial2_aux(Int x, Int acc) { + return if (x == 0) { + acc; + } else { + this.factorial2_aux(x - 1, acc * x); + } + } +} + +new Factorial().factorial2_aux() diff --git a/tests/3/bizarrReturn.zwei~ b/tests/3/bizarrReturn.zwei~ new file mode 100755 index 0000000..1264f0e --- /dev/null +++ b/tests/3/bizarrReturn.zwei~ @@ -0,0 +1,46 @@ +class Factorial { + + // Recursive definition + Int factorial1(Int x) { + return if (x == 0) 1 + else x * this.factorial1(x - 1) + } + + // Tail-recursive definition + Int factorial2_aux(Int x, Int acc) { + return if (x == 0) { + acc; + } else { + this.factorial2_aux(x - 1, acc * x); + } + } + Int factorial2(Int x) { + return this.factorial2_aux(x, 1) + } + + // Iterative definition + Int factorial3(Int x) { + Int p = 1; + while (x > 0) { + p = p * x; + x = x - 1; + } + return p + } + +} + +class Example { + Null main() { + Factorial fac = new Factorial(); + Int x = 5; + printInt(fac.factorial1(x)); + printChar(10); + printInt(fac.factorial2(x)); + printChar(10); + printInt(fac.factorial3(x)); + printChar(10); + } +} + +new Example().main() diff --git a/tests/3/logic.zwei b/tests/3/logic.zwei new file mode 100755 index 0000000..a0ea03f --- /dev/null +++ b/tests/3/logic.zwei @@ -0,0 +1,9 @@ +class arith { + Int euler (Int temp) { + if (temp || a == c && (k == 2)) { + }; + return 1 + } +} + +runit \ No newline at end of file diff --git a/tests/3/logic.zwei~ b/tests/3/logic.zwei~ new file mode 100755 index 0000000..a0ea03f --- /dev/null +++ b/tests/3/logic.zwei~ @@ -0,0 +1,9 @@ +class arith { + Int euler (Int temp) { + if (temp || a == c && (k == 2)) { + }; + return 1 + } +} + +runit \ No newline at end of file