diff --git a/tests/2/big.txt.zwei b/tests/2/big.txt.zwei new file mode 100755 index 0000000..e79ed4a --- /dev/null +++ b/tests/2/big.txt.zwei @@ -0,0 +1,44 @@ +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/2/errorRec1.txt.zwei b/tests/2/errorRec1.txt.zwei new file mode 100755 index 0000000..5f68d0c --- /dev/null +++ b/tests/2/errorRec1.txt.zwei @@ -0,0 +1,13 @@ +//The compiler should see two errors: +//the ";" after the true in the while condition and the missing of the ";" after the true after the loop + +class Temp { + + Int bla() { + while (true;) { + true; + } + true + } +} +true \ No newline at end of file diff --git a/tests/2/errorRec2.txt.zwei b/tests/2/errorRec2.txt.zwei new file mode 100755 index 0000000..0a05c55 --- /dev/null +++ b/tests/2/errorRec2.txt.zwei @@ -0,0 +1,13 @@ +//test error recovering after two missing paranthesis in an if statement +class ErrorRec2 { + + Null ident() { + + if x < 0 //here we miss two parantesis ( and ) + then_expression + else + else_expression //here we miss a ";" + } + +} +hello \ No newline at end of file diff --git a/tests/2/errorRec3.txt.zwei b/tests/2/errorRec3.txt.zwei new file mode 100755 index 0000000..0a84c19 --- /dev/null +++ b/tests/2/errorRec3.txt.zwei @@ -0,0 +1,21 @@ +//this tests if we can recover from a missing "}" (not even the java compiler can do that ;-) + +class Error1 { + + Type ident; + Type ident; + + Type ident() { + + } +//Error 1: missing "}" + +class Error2 { + + Type ident; + + Type ident() { + return //Error 2: missing expression + } +} +true \ No newline at end of file diff --git a/tests/2/forum1.txt.zwei b/tests/2/forum1.txt.zwei new file mode 100755 index 0000000..80854bb --- /dev/null +++ b/tests/2/forum1.txt.zwei @@ -0,0 +1,18 @@ +class factoriel { + + String var1; + String toString(){ + var1 = 25; + if(x == -2) var1 -- 2 else var1 - 3; + var1 = 30; + var --2; + + while(-2 == -5){ + if(-4 == -6) var --2 else var + (-4 + -5); + var2 = (5- var2 ) + nimportequoi; + } + + } +} + +2 == 4 \ No newline at end of file diff --git a/tests/2/forum2.txt.zwei b/tests/2/forum2.txt.zwei new file mode 100755 index 0000000..ad3f989 --- /dev/null +++ b/tests/2/forum2.txt.zwei @@ -0,0 +1,31 @@ +class factoriel { + + String var1; + String toString(){ + var1 = 25; + if(x == -2) var1 -- 2 else var1 - 3; + var1 = 30; + var --2; + + while(-2 == -5){ + if(-4 == -6) var --2 else var + (-4 + -5); + var2 = (5- var2 ) + nimportequoi; + } + + } + + String toString() { + monfact.soString(4, 5, 5); + } + +} + +class test{ + factoriel monfact; + + String toString() { + monfact.soString(4, 5, {return 2}); + } +} + +2 == 4 \ No newline at end of file diff --git a/tests/2/forum3.txt.zwei b/tests/2/forum3.txt.zwei new file mode 100755 index 0000000..a178e2d --- /dev/null +++ b/tests/2/forum3.txt.zwei @@ -0,0 +1,32 @@ +class A extends B { + //Check FieldDecl (-> also Formal) + Int a; + Int s; + Null z; + Object o; + boolean b; + + //Check MethodDef + Object method(Int i, Null n, Object oj) { + //Check Block (->also Statement and Expression) + while ( if ( i && !o) { return b} else { return !b}) { + b = true; + boolean c = false; + 3+2; + printInt (a); + printChar("toto et titi c'est tjs joli"); + } + + // Expression + if ( b) readInt else readChar; + if (-b) true else false; + if(a-b || c) null else ( a == b); + if (-new x (3,"HelloWorld") * ! { while ( a==b) { 4 //Comment + % 3 ; }return "viveJava"} / b && c) null; + + + return b + } +} + +7.a(b,c,d,e) \ No newline at end of file diff --git a/tests/2/hardCore.txt.zwei b/tests/2/hardCore.txt.zwei new file mode 100755 index 0000000..d9704d4 --- /dev/null +++ b/tests/2/hardCore.txt.zwei @@ -0,0 +1,76 @@ +class hardcoreZwei extends hardcore_Eins { + + Int variableA ; + Null whatGoodIsItFor ; + letsFaceTheMusic andDance ; + + Int strangersInTheNight(FRIEND Rachel, FRIEND Ross) { + while ( + if ( Rachel != Ross) + Chandler + else + (Joey + Pheobe) * + -David + + { Null Monica = Gunther ; + return Ursula + } + <= true || false + ) { + printChar( + if ( + new centralPerk(-readInt).couch( + { fabric leather = true; + return "Smelly Cat" + } + ) + ) + true.Janice.moves(BingsHouse.neighboring()) != + Janice.isMarried() || + !Chandler.isInLoveWith( + !new Marriage("Monica").isInLoveWith(Richard) + ) + else ( + { return Mona <= Emi// + -ly/London_1999 } + ) + ) ; + } + + Int babyfootScore = if (chandler.score() + joey.score() <= +monica.score()) {return ross.score} ; + } +} + +class CSI_Lab extends CSI { + + Leader Grissom ; + Investigator Nick ; + Investigator Sara ; + Investigator Warrick ; + Supervisor Catherine ; + + Null solveCrime(List evidence) { + + evidence.getFingerprints.sendTo( + { if (CSI.getLevel(Nick) <= CSI.getLevel(Sara)) + expr + else + { return Ecklie } != -readChar ; + } ); + } + +} + +{ + if ( CSI.duration() != FRIENDS.duration()) + -{ CSI.duration() - FRIENDS.startTime ; + return false + } <= + readInt.print( {} + "minutes" ) + else + {} != !a ; + + printChar({return prison} != "maison" && a * 31415926 * r); + + return int +} \ No newline at end of file diff --git a/tests/2/sys0.txt.zwei b/tests/2/sys0.txt.zwei new file mode 100755 index 0000000..9b814e0 --- /dev/null +++ b/tests/2/sys0.txt.zwei @@ -0,0 +1,5 @@ +//tests only expression +//this file is correct + +readInt.bimbo.hello + \ No newline at end of file diff --git a/tests/2/sys1.txt.zwei b/tests/2/sys1.txt.zwei new file mode 100755 index 0000000..f6bb24c --- /dev/null +++ b/tests/2/sys1.txt.zwei @@ -0,0 +1,13 @@ +//tests several classes within the same class file +//and classes without members +//This file is correct + +class A { + +} + +class B extends A { + +} + +null \ No newline at end of file diff --git a/tests/2/sys10.txt.zwei b/tests/2/sys10.txt.zwei new file mode 100755 index 0000000..7096169 --- /dev/null +++ b/tests/2/sys10.txt.zwei @@ -0,0 +1,30 @@ +//Fun with Expressions, Statements and Factors +//this file should be correct +class FunTest { + +formal formal() { + + ident.ident.ident.ident; + printInt({}); + printChar(!"a"); + + while ({}) {} + while (("da da da")) {this.dududu == true;} + while (34.da) {{};} + + if ( expr ) expr else expr; + + exrp == expr; + expr == term --factor * ! factor; + + {} == ({}); + {} && {} <= {}; + + {}.bla(); + {{};} * new bla ({return {return bla}}); + +} + +} + +test \ No newline at end of file diff --git a/tests/2/sys11.txt.zwei b/tests/2/sys11.txt.zwei new file mode 100755 index 0000000..4410e55 --- /dev/null +++ b/tests/2/sys11.txt.zwei @@ -0,0 +1,12 @@ +//correct + +class Temp { + + Int bla() { + while (true) { + true; + } + true; + } +} +true \ No newline at end of file diff --git a/tests/2/sys12.txt.zwei b/tests/2/sys12.txt.zwei new file mode 100755 index 0000000..5e0e446 --- /dev/null +++ b/tests/2/sys12.txt.zwei @@ -0,0 +1,16 @@ +//test selector +//not correct +class Temp { + + Int bla() { + "hello".first().second()().third; + + } + + Null func() { + error + + } + +} +true \ No newline at end of file diff --git a/tests/2/sys2.txt.zwei b/tests/2/sys2.txt.zwei new file mode 100755 index 0000000..feb6a8c --- /dev/null +++ b/tests/2/sys2.txt.zwei @@ -0,0 +1,7 @@ +//this file tests a file without an Expression after the class definitions +//this should raise an Error "Expression expected" + +class Bimbo { + + +} \ No newline at end of file diff --git a/tests/2/sys3.txt.zwei b/tests/2/sys3.txt.zwei new file mode 100755 index 0000000..b3cc5fb --- /dev/null +++ b/tests/2/sys3.txt.zwei @@ -0,0 +1,7 @@ +//to many expressions after class definition +//this should raise an EOF Exptected error +class bimbo { + +} + +null imho \ No newline at end of file diff --git a/tests/2/sys4.txt.zwei b/tests/2/sys4.txt.zwei new file mode 100755 index 0000000..104e9de --- /dev/null +++ b/tests/2/sys4.txt.zwei @@ -0,0 +1,12 @@ +//this tests the declaration of fields +//this file is correct + +class Bimbo { + + Null bimbo; + Int bimbo; + bimbo bimbo; + +} + +bimbo \ No newline at end of file diff --git a/tests/2/sys5.txt.zwei b/tests/2/sys5.txt.zwei new file mode 100755 index 0000000..47c73db --- /dev/null +++ b/tests/2/sys5.txt.zwei @@ -0,0 +1,10 @@ +//this file tests an wrong field declaration (no semicolon) +//this file is not correct + +class Bimbo { + + Int bimbo + +} + +bimbo \ No newline at end of file diff --git a/tests/2/sys6.txt.zwei b/tests/2/sys6.txt.zwei new file mode 100755 index 0000000..ed4cac5 --- /dev/null +++ b/tests/2/sys6.txt.zwei @@ -0,0 +1,8 @@ +//this tests a wrong field declaration (no name) +//this file is wrong + +class Bimbo { + + Int; + +} \ No newline at end of file diff --git a/tests/2/sys7.txt.zwei b/tests/2/sys7.txt.zwei new file mode 100755 index 0000000..1887eb6 --- /dev/null +++ b/tests/2/sys7.txt.zwei @@ -0,0 +1,8 @@ +//this tests wrong field definitions (invalid identifier) +//this file is wrong + +class Bimbo { + + Int Int; + +} \ No newline at end of file diff --git a/tests/2/sys8.txt.zwei b/tests/2/sys8.txt.zwei new file mode 100755 index 0000000..f73617a --- /dev/null +++ b/tests/2/sys8.txt.zwei @@ -0,0 +1,12 @@ +//this file tests method definitions +//this file is correct +class MethodTest { + + Int formal () {} + + Null formal (Int id) {return id} + + formal formal (Int id, Int id) {ident;} + +} +formal \ No newline at end of file diff --git a/tests/2/sys9.txt.zwei b/tests/2/sys9.txt.zwei new file mode 100755 index 0000000..dc8d6d2 --- /dev/null +++ b/tests/2/sys9.txt.zwei @@ -0,0 +1,12 @@ +//this file tests invalid method definitions. +// missing second ")" and missing identifier in the second method declaration +//this file is wrong +class Bimbo { + + formal formal (formal formal {} + + formal formal2(ident) {} + +} + +bimbo \ No newline at end of file