Homework 4

This commit is contained in:
Carlos Galindo 2020-01-15 22:34:57 +01:00
parent 0afc86ceeb
commit 72cc3206c4
Signed by: kauron
GPG key ID: 83E68706DEE119A3
125 changed files with 4200 additions and 1636 deletions

View file

@ -0,0 +1,15 @@
/* Test illegal downcasts */
class A { }
class B extends A { }
class Main {
void main() {
A a;
B b;
a = new A();
b = (B) a; /* Should fail at runtime */
write(0);
writeln();
}
}

View file

@ -0,0 +1,23 @@
class Main {
void main() {
int a;
a = fib(20);
write(a);
writeln();
}
int fib(int n) {
int fib;
int fib2;
if (n <= 1) {
fib = n;
} else {
fib = fib(n-1);
fib2 = fib(n-2);
fib = fib + fib2;
}
return fib;
}
}

View file

@ -0,0 +1,14 @@
/* Test expressions using array elements as operands */
class Main {
int[] x;
void main() {
int i;
x = new int[3];
x[0] = 3;
x[1] = 4;
x[2] = 5;
i = x[0] + x[1] + x[2];
write(i);
writeln();
}
}

View file

@ -0,0 +1,20 @@
/* Test access to parameters and fields */
class A {
int i;
void foo(int p) {
write(p);
write(i);
writeln();
}
}
class Main {
void main() {
A a;
a = new A();
a.i = 10;
a.foo(1);
a.foo(2);
a.foo(3);
}
}

View file

@ -0,0 +1,28 @@
/* Test read() with different kinds of LHS values */
class Main {
int x;
void main() {
int y;
int[] arr;
write(1);
writeln();
y = read();
write(y + 1);
writeln();
x = read();
write(x + 1);
writeln();
arr = new int[64];
arr[x] = read();
write(arr[x] + 1);
writeln();
}
}

View file

@ -0,0 +1,4 @@
9
51
12

View file

@ -0,0 +1,14 @@
/* Test legal downcasts */
class A { }
class B extends A { }
class Main {
void main() {
A a;
B b;
a = new B();
b = (B) a; /* OK at runtime */
write(0);
}
}

View file

@ -0,0 +1,29 @@
/* Test access to fields from elements of arrays */
class A {
int field;
void foo() {
write(1);
write(field);
writeln();
}
}
class Main {
A[] x;
void main() {
int i;
x = new A[2];
i = 1;
write(i);
writeln();
x[i] = new A();
x[i].field = i + 1;
i = x[1].field;
write(i);
writeln();
x[1].foo();
}
}

View file

@ -0,0 +1,50 @@
/* Test virtual method calls */
class A {
void override() {
write(0);
writeln();
}
void base() {
write(1);
writeln();
}
}
class B extends A {
void override() {
write(2);
writeln();
}
void sub() {
write(3);
writeln();
}
}
class Main {
void main() {
A a;
B b;
a = null;
b = null;
a = new A();
a.base();
a.override();
b = new B();
b.base();
b.override();
b.sub();
a = b;
a.base();
a.override();
b.base();
b.override();
b.sub();
}
}

View file

@ -0,0 +1,81 @@
/* Overall test of arrays, loops, etc. that does a simple quicksort */
class Record {
int a;
void print() {
write(a);
writeln();
}
}
class Main {
Record [] a;
int i;
void swap(Record r1, Record r2) {
int temp;
temp = r1.a;
r1.a = r2.a;
r2.a = temp;
}
void sort(int left, int right) {
int i,j;
int m;
m = (a[left].a + a[right].a) / 2;
i = left;
j = right;
while (i <= j) {
while (a[i].a < m) { i = i+1; }
while (a[j].a > m) { j = j-1; }
if (i <= j) {
swap(a[i], a[j]);
i = i + 1;
j = j - 1;
}
}
if (left < j) { sort(left, j); }
if (i < right) { sort(i, right); }
}
void main() {
int SIZE;
int j;
SIZE = 5;
a = new Record[SIZE];
j = 0;
while (j < SIZE) {
a[j] = new Record();
j = j + 1;
}
a[0].a = 5;
a[1].a = 3;
a[2].a = 1;
a[3].a = 4;
a[4].a = 2;
/* Numbers before sorting */
j = 0;
while (j < SIZE) {
a[j].print();
j = j + 1;
}
writeln();
sort(0, 4);
/* Numbers after sorting */
j = 0;
while (j < SIZE) {
a[j].print();
j = j + 1;
}
writeln();
}
}

View file

@ -0,0 +1,12 @@
/* Test accessing arrays with invalid index*/
class Main {
void main() {
int[] x;
x = new int[5];
x[0] = 3;
x[1] = 4;
x[2] = 5;
x[5] = 5; //this should fail
}
}

View file

@ -0,0 +1,9 @@
/* Test accessing arrays with invalid index*/
class Main {
void main() {
int[] x;
x = new int[5];
x[8] = 5; //this should fail
}
}

View file

@ -0,0 +1,9 @@
/* Test accessing arrays with invalid index*/
class Main {
void main() {
int[] x;
x = new int[5];
x[-1] = 5; //this should fail
}
}

View file

@ -0,0 +1,10 @@
/* Test access an array on a null pointer */
class Main {
void main() {
int[] x;
x = null;
x[1] = 5; //this should throw null pointer exception
}
}

View file

@ -0,0 +1,9 @@
/* Test access an array on a null pointer */
class Main {
void main() {
int[] x;
x[1] = 5; //this should throw null pointer exception
}
}

View file

@ -0,0 +1,10 @@
/* Test creating an array with negative length */
class Main {
void main() {
int[] x;
x = new int[-3];
x[0] = 3;
x[1] = 4;
x[2] = 5;
}
}

View file

@ -0,0 +1,16 @@
/* Test accessing arrays */
class Main {
void main() {
int[] x;
int i;
x = new int[3];
x[0] = 3;
x[1] = 4;
x[2] = 5;
i = x[0] + x[1] + x[2];
x[2]=55;
write(i);
writeln();
}
}

View file

@ -0,0 +1,15 @@
/* Test creating arrays of objects and accessing a null element*/
class A{}
class Main {
void main() {
A[] x;
A a;
x = new A[3];
x[1] = new A();
x[2] = a;
x[2] = new A();
}
}

View file

@ -0,0 +1,8 @@
/* Test array size=0 */
class Main {
void main() {
int[] x;
x = new int[0];
}
}

View file

@ -0,0 +1,12 @@
/* Test Arrays as Fields */
class Main {
int[] x;
void main() {
int i;
x = new int[3];
x[0] = 3;
x[1] = 4;
x[2] = 5;
}
}

View file

@ -0,0 +1,19 @@
/* Test inherited Array */
class Main {
void main() {
C1 c1;
C2 c2;
c1 = new C1();
c2 = new C2();
c1.x = new int[3];
c2.x = new int[4];
}
}
class C1{
int[] x;
}
class C2 extends C1 {}

View file

@ -0,0 +1,11 @@
/* Test creating arrays of objects */
class A{}
class Main {
void main() {
A[] x;
x = new A[2];
x[0] = new A();
}
}

View file

@ -0,0 +1,14 @@
// any array is a subtype of Object
// assignment and 'is equal' with an object of type 'Object' is fine
class Main {
void main() {
boolean y;
Object x;
int[] testArray;
testArray = new int[10];
x = testArray;
testArray = null;
x = null;
}
}

View file

@ -0,0 +1,21 @@
// assignment of subtypes
class Main {
void main() {
A a1, a2;
B b1, b2;
C c;
a1 = new A();
b2 = new B();
c = new C();
a2 = a1;
b1 = c;
}
}
class A {}
class B extends A {}
class C extends B {}

View file

@ -0,0 +1,8 @@
// Test boolean && and || operators
class Main {
void main() {
boolean a, b, c;
a = b && c || a;
}
}

View file

@ -0,0 +1,31 @@
// Test the equal/not equal operations, one of the types must be a subtype of the other
class Main {
void main() {
C1 c1;
C2 c2;
C3 c3;
Object o1, o2;
boolean s;
o1 = new Object();
o2 = new Object();
c1 = new C1();
c2 = new C2();
c3 = new C3();
s = o1 == o2;
s = c1 != c2;
s = c3 == c1;
s = o2 != o1;
s = null == c2;
s = o1 == c2;
//s = null == o;
}
}
class C1 {}
class C2 extends C1{}
class C3 extends C2{}

View file

@ -0,0 +1,15 @@
// Test the equal/not equal operations, one of the types must be a subtype of the other
class Main {
void main() {
int a,b;
boolean c;
a = 8;
b = 6;
c = a==b;
if (!c){
write(5);}
}
}

View file

@ -0,0 +1,14 @@
// Test the equal/not equal operations, one of the types must be a subtype of the other
class Main {
void main() {
boolean a,b,c;
a = true;
b = 6<10;
c = a==b;
if (c){
write(5);}
}
}

View file

@ -0,0 +1,36 @@
// Test '!' operator
class Main {
void main() {
boolean a,b,c,d;
int x,y;
a = true;
c = !false;
b = !a;
x = 100;
y = 5;
if (a) {
write(1);}
writeln();
if (!b){
write(2);
}
writeln();
while(c){
write(3);
c = false;
}
writeln();
// !x < 2 * y --> !x type error
// !(x < 2 * y) --> correct syntax
while(!(x<2*y)){
write(y);
y = y*2;
}
}
}

View file

@ -0,0 +1,21 @@
// Test types in a Cast (cannot cast to unrelated type)
class Main {
void main() {
C1 a, b;
C2 c, d;
Object o;
c = new C2();
a = new C1();
b = (C1) c;
d = (C2) a;
o = (Object) a;
o = (Object) c;
o = (Main) c;
}
}
class C1 {}
class C2 extends C1{}

View file

@ -0,0 +1,14 @@
// Test downcast from Object to array
class Main {
void main() {
A[] a;
Object o;
o = new Object();
a = (A[]) o;
}
}
class A{}

View file

@ -0,0 +1,12 @@
// Test types in a Cast
// cannot cast an int to an boolean
class Main {
void main() {
int a;
boolean b;
a = 1;
b = (boolean) a;
}
}

View file

@ -0,0 +1,11 @@
// Test types in a Cast (cannot cast to unrelated type)
class Main {
void main() {
int a;
boolean b;
//b = false;
a = (int) b;
}
}

View file

@ -0,0 +1,12 @@
// Test downcast from array to Object
class Main {
void main() {
int[] x;
Object o;
x = new int[5];
o = (Object) x;
}
}

View file

@ -0,0 +1,14 @@
// Test downcast from array to Object
class Main {
void main() {
A[] a;
Object o;
a = new A[5];
o = (Object) a;
}
}
class A{}

View file

@ -0,0 +1,15 @@
// Test cast from a type to the same type
class Main {
void main() {
C c,d;
Object o,g;
c = new C();
g = new Object();
d = (C) c;
o = (Object) g;
}
}
class C {}

View file

@ -0,0 +1,26 @@
// Test valid casts
class Main {
void main() {
C1 a, x;
C2 c,d;
C4 b,f;
Object o;
c = new C2();
a = new C1();
b = new C4();
f = new C4();
x = (C1) b;
o = (Object) f;
}
}
class C1 {}
class C2 extends C1{}
class C3 extends C2{}
class C4 extends C3{}

View file

@ -0,0 +1,23 @@
// Test casts from type to object
class Main {
void main() {
C1 a;
Object o,f,g;
int x;
boolean y;
a = new C1();
x = 2;
y = true;
o = (Object) a;
//f = (Object) x;
//g = (Object) y;
}
}
class C1 {}

View file

@ -13,7 +13,7 @@ class Main {
i6 = 6;
i7 = 7;
write(i0 + (i1 + ( i2 + ( i3 + ( i4 + (i5 + (i6 + i7))))))); writeln();
write(i0 + (i1 + ( i2 + ( i3 + ( i4 + (i5 + (i6 + (i7 + i0)))))))); writeln();
write(((((((i0 + i1) + i2) + i3) + i4) + i5) + i6) + i7); writeln();
write(((i0 + i1) + (i2 + i3)) + ((i4 + i5) + (i6 + i7))); writeln();
}

View file

@ -0,0 +1,10 @@
// test division by zero
class Main {
void main() {
int a;
int b;
a = 10;
b = a / 0;
}
}

View file

@ -0,0 +1,27 @@
// access a field from a class and a superclass (also includes hidden fields)
class Main {
void main() {
C1 c1;
C2 c2;
C4 c4;
c1 = new C1();
c2 = new C2();
c4 = new C4();
c1.a = 5;
c2.a = 6;
c4.a = false;
}
}
class C1{
int a;
}
class C2 extends C1 {}
class C3 extends C2 {}
class C4 extends C3 {
boolean a;
}

View file

@ -0,0 +1,19 @@
// test an Array of Objects and access their field
class Main {
void main() {
D[] x;
x = new D[50];
x[22].c.a = 2;
}
}
class C{
int a;
}
class D {
C c;
}

View file

@ -0,0 +1,5 @@
class Main {
void main() {
write(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15);
}
}

View file

@ -0,0 +1,30 @@
// Access inherited and hidden fields (general check)
class Other {
int a;
int b;
Object c;
Other o;
}
class Main extends Other {
int a, b;
void main() {
Other o;
o = (Other) this;
a = 1;
b = 2;
o.a = -1;
o.b = -2;
write(a);
write(b);
write(o.a);
write(o.b);
if (c != null) {
if (o.o != null) {
write(0);
}
}
}
}

View file

@ -0,0 +1,34 @@
/* testing assign statements*/
class Main {
int methodCall() { return 0; }
int methodCall2(int a, int b) {
if (a >= b) {
return 0;
} else {
if (b <= a) {
return 1;
}
}
return a * b;
}
void main() {
int a, b, c, e;
Ast d;
int[] g;
Object f;
a = read();
b = methodCall();
c = methodCall2(a, b);
d = new Ast();
e = d.field;
g = new int[a];
f = new Object[a];
f = g;
g = (int[]) f;
}
}
class Ast {
int field;
}

View file

@ -0,0 +1 @@
1

View file

@ -8,11 +8,11 @@ class Main {
d = 40;
e = 1;
while ( b > c ) {
while ( b >= c ) {
write(b);
b = b-1;
}
a = c < (b+4-5/2);
a = c <= (b+4-5/2);
if (a){
write(13);}
if (100/2>d*e){

View file

@ -0,0 +1,17 @@
// call an method from a superclass
class Main {
void main() {
C2 c;
c = new C2();
c.aux();
}
}
class C1{
void aux(){
write(2);
}
}
class C2 extends C1 {}

View file

@ -0,0 +1,10 @@
class Main {
void main() {
while(false) {}
if(false) {
return;
}
if (false) {} else {}
if (false) {} else {return;}
}
}

View file

@ -0,0 +1,5 @@
class Main {
void main() {
while(false) {}
}
}

View file

@ -0,0 +1,16 @@
// Hide a field from a superclass (type doesn't need to match)
class Parent {
int a;
}
class Main extends Parent {
Object a;
Main b;
void main() {
Parent c;
b = new Main();
b.a = new Object();
c = new Parent();
c.a = 10;
}
}

View file

@ -7,14 +7,10 @@ class Main {
int a;
boolean b;
Object c;
a = null;
b = null;
c = null;
write(a);
writeln();
//write(null)
}
}

View file

@ -0,0 +1,14 @@
/* test overwritten main method */
class OtherMain {
void main () {
int a;
}
}
class Main extends OtherMain {
void main () {
int b;
}
}

View file

@ -0,0 +1,32 @@
/* this test forces the compiler to push registers to the stack */
class Main {
void main() {
int u,v,x,y,z;
boolean e,f,g,h,i,j;
B b1,b2;
e = true;
f = true;
g = true;
z = 0;
while (z < 30) {
if (f){
if (g){
u = 5;
v = 8;
x = u/v;
b1 = new B();
e = false;
}
}
else {
j = true;
}
z = z + 1;
}
}
}
class B {}

View file

@ -0,0 +1,29 @@
/* Test expression evaluation with more than 8 variables
Test Register use
*/
class Main {
void main() {
int r1, r2, r3;
int i0, i1, i2, i3, i4, i5, i6, i7;
int a,b,c,d,e;
i0 = 0;
i1 = 1;
i2 = 2;
i3 = 3;
i4 = 4;
i5 = 5;
i6 = 6;
i7 = 7;
a = 5;
b = 5;
c = 5;
d = 5;
e = 5;
write(i0 + (i1 + ( i2 + ( i3 + (a+b+c+d+e) + ( i4 + (i5 + (i6 + (i7 + i0)))))))); writeln();
write(((((((i0 + i1) + i2) + i3) + i4 + (a*b*c*d*e)) + i5) + i6) + i7); writeln();
write(((i0 + i1) + (i2 + i3)) + ((i4 + i5) + (i6 + i7))); writeln();
}
}

View file

@ -0,0 +1,9 @@
/* Test that variables are zero initialized */
class Main {
void main() {
int a;
write(a);
}
}

View file

@ -0,0 +1,79 @@
// A if/else block is valid return statment if all possible branches return some value
// Also serves to check subtyping
// The return logic leads to nonsensical programs with statements after the return, but that's ok
class Main {
// All returns must be empty, but we don't care for their existence
void main() {
int a, b, c;
if (a == b) {
return;
} else {
while (a > b) {
return;
}
if (c > b) {
return;
}
}
}
// All returns must be null, Main (all subtypes of Main), and there must be an unconditional return
Main action1() {
Main a;
Object b;
boolean x, y;
if (x) {
if (y) {
if (x || y) {
if (x == y && x != y) {
return null;
} else {
return a;
}
} else {
if (b == null) {
return a;
} else {
return a;
}
}
} else {
if (b == a || a == null) {
return null;
} else {
return a;
}
}
} else {
return null;
}
}
// All returns must be null, Main[] (all subtypes of Main[]), and there must be an unconditional return
Main[] action2() {
Main[] a, b;
if (a == b) {
return a;
} else {
if (b != null) {
return b;
} else {
return null;
}
}
}
// All returns must be int (no subtypes), and there must be an unconditional return
int action3() {
int a, b, c, d;
if (a > b) {
return c - d;
while (a != a) {
return b;
}
} else {
return c * d / a + b % c - a;
}
}
}

View file

@ -0,0 +1,9 @@
class Main {
int n() {
return 0;
}
void main() {
n();
}
}

View file

@ -0,0 +1,21 @@
// The return statement can be placed in the middle of the method, and no warning will be thrown about unexecuted
// statements
class Main {
void main() {
write(things());
writeln();
}
int things() {
int a;
a = 10;
return a;
// These statements won't be reached
// but there is a complete return statement
a = 20;
writeln();
writeln();
}
}

View file

@ -0,0 +1,22 @@
/* test method that returns an object */
class Main {
void main() {
int x;
B b;
b = aux();
x = b.a;
write(x);
}
B aux(){
B b;
b = new B();
b.a = 10;
return b;
}
}
class B {
int a;
}

View file

@ -0,0 +1,24 @@
// A if/else with a return in both branches is valid
class Main {
void main() {
write(things());
writeln();
}
int things() {
int a;
int b;
Object c, d;
a = 10;
b = 100;
c = new Object();
d = new Object();
if (c == d) {
return 10;
} else {
return 5;
}
}
}

View file

@ -0,0 +1,22 @@
// test that call-by-value is used
class Main {
void main() {
int x;
A a;
a = new A();
a.a = 50;
aux(a.a);
x = a.a;
write(x);
}
void aux (int arg){
arg = arg + 1;
}
}
class A {
int a;
}

View file

@ -0,0 +1,18 @@
// test that call-by-value is used
class Main {
void main() {
int[] y;
int x;
y = new int[5];
y[2] = 50;
aux(y[2]);
x = y[2];
write(x);
}
void aux (int arg){
arg = arg + 1;
}
}

View file

@ -0,0 +1,18 @@
// test that call-by-value is used
class Main {
void main() {
int[] y;
int x;
y = new int[5];
y[2] = 50;
aux(y);
x = y[2];
write(x);
}
void aux (int[] arg){
arg[2] = 100;
}
}

View file

@ -0,0 +1,17 @@
// call an method from a superclass
class Main {
void main() {
C2 c;
c = new C2();
c.aux();
}
}
class C1{
void aux(){
write(2);
}
}
class C2 extends C1 {}

View file

@ -0,0 +1,19 @@
// call a simple method and use its return value
class Main {
void main() {
int a,b;
C c;
c = new C();
a = 5;
b = c.aux(a);
}
}
class C{
int aux(int arg){
return arg*2;
}
}

View file

@ -0,0 +1,35 @@
// call a method with many parameters and use its return value
// also Test Register use, by allocating memory
class Main {
void main() {
int a,b,c,d,e,f,g,h,x;
a = 5;
b = 5;
c = 5;
d = 5;
e = 5;
f = 5;
g = 5;
h = 5;
x = aux(a,b,c,d,e,f,g,h);
}
int aux(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8){
int[] x;
int i;
D d;
x = new int[20];
i = arg1 + arg2 + arg3 + arg4 - arg5 - arg6 + arg7 - arg8;
d = new D();
return i;
}
}
class D{
int[] x;
}

View file

@ -1,24 +0,0 @@
/* testing arrays with primitive types as well as new objects
the if/else statements shows that the array is boolean array is initialized with false
*/
class Main {
void main() {
int [] testArray;
boolean [] boolarray;
boolarray = new boolean [3];
testArray = new int [10];
testArray[5] = 3;
boolarray[1] = true;
if (boolarray[0]){
write(1);}
else{
write(5);}
writeln();
if (boolarray[1]){
write(1);}
}
}

View file

@ -1,12 +0,0 @@
/* testing assign statements*/
class Main {
void main() {
a = read();
b = methodCall();
c = methodCall(param1, param2);
d = object.access;
e = new Ast();
d = new int[size];
f = new Object[size];
}
}

View file

@ -1,21 +0,0 @@
class Main {
void main() {
int a, b, c, d, e;
a = 10;
b = -1;
c = 0;
d = 100;
e = 2;
write(a / b); writeln();
write(d / e); writeln();
write(c / d); writeln();
write(b / a + c); writeln();
write(d / e * a / b * c); writeln();
write(d / e * a / b); writeln();
write(d / e + a / b); writeln();
write(d / e * a * b * c); writeln();
write(d / e * a - b + c); writeln();
}
}

View file

@ -1,9 +0,0 @@
/* testing basic inheritance*/
class C1 {}
class C2 extends C1 {}
class C3 extends C2 {}
class C4 extends C2 {}
class C5 extends C3 {}
class Main {
void main() {}
}

View file

@ -1,22 +0,0 @@
/* testing different expressions
compiler should recognize Type error: Return statement of method with void return type should not have arguments
*/
class Main {
void main() {
return;
return true;
return false;
return 0x10;
return 10;
return variable;
return array[index];
return methodAccess();
return object.field;
return object.call();
return op + op2;
return op / asd * asd && a == true;
return this.run();
return this;
return this.field;
}
}

View file

@ -1,31 +0,0 @@
class Main {
void main() {
int r1;
int i0, i1;
int x,y,z;
i0 = 5;
i1 = 2;
r1 = i1 * 3;
write(r1); writeln();
r1 = i0 * i1;
write(r1); writeln();
r1 = r1 * i0 * i1 * 3;
write(r1); writeln();
y = 5;
z = 10;
x = (-y * z);
write(x); writeln();
y = 0;
z = - 10;
x = (y * z);
write(x); writeln();
write(y * z); writeln();
write(0 * -10); writeln();
}
}

View file

@ -1,8 +0,0 @@
/*Check the order of the declarations in the generated parser
* Do the variables come always first or in their place? */
class ClassName {
void a() {}
int a;
void a() {}
void tests(boolean d, nulle a) {}
}

View file

@ -1,25 +0,0 @@
/* Test what happens for Integers that are to big for 32bits
2147483647 (=0x7FFFFFFF) is the biggest integer in 32bits (IntMAX)
*/
class Main {
void main() {
int x,y,z;
x = 2147483647;
write( x ); writeln();
/* add 1 to IntMax and output it */
write( x + 1); writeln();
/* read an int bigger than IntMAX */
x = read();
write(x); writeln();
/* performe some operation that should generate an int overflow */
x = 21474836400;
y = 60000;
write( x + y); writeln();
z = 20000000;
write( y * z); writeln();
write( (y * z) ); writeln();
}
}

View file

@ -1 +0,0 @@
2147483647

View file

@ -1,15 +0,0 @@
/*Testing all related to methods (declaration and execution)*/
class Main {
void main() {
callWithParams(a, b, c, 0, false);
object.call(a, b, d);
}
int method(int a, String b, int[] c) {
}
int[] method2() {}
Object method3() {}
Model[] method4() {}
}

View file

@ -1,26 +0,0 @@
/* Test read/write native functions */
class Main {
void main() {
int r1, r2, readvar, a1;
r1 = 6;
/* r2 = 22 */
r2 = read();
write(r1); writeln(); // 6
/* test expressions inside write() */
write(r1 - 3); writeln(); // 3
write(r1 - 6); writeln(); // 0
write(r1 - 7); writeln(); // -1
/* should output 111 */
readvar = read(); // 1
write( (r1 + (r2 * 5)) + readvar); // 117
write(- r1); // -6
writeln();
/* should output 15 */
a1 = read(); // -15
write(- a1); // 15
}
}

View file

@ -1,6 +0,0 @@
22
1
-15

View file

@ -1,34 +0,0 @@
/* testing different statements
'condition' is not initialized
*/
class Main {
void main() {
if (condition) {
instructions();
asd.b = c;
if (cond2) {
} else {
nonEmptyBlock = a;
}
} else {
}
// Whiles
while (condition) {
while (anotherLoop == false) {
nestedLoops();
}
}
while (false) {} // emptyloop
// Returns
return; // empty
return expr; // with expressions (expressions already tested)
return array[index];
// Writes
write(a);
write(9 + 10);
writeln();
write(call());
}
}

View file

@ -1,12 +0,0 @@
/* testing invalid casts */
class Main
{
void main()
{
int a;
Object d;
d = new Object();
a = (Object) d;
a = (boolean[]) a;
}
}

View file

@ -1,14 +0,0 @@
class Main {
void main() {
boolean b;
int a,c,n;
a = 10;
//b = true;
while ( a>0 ) {
a = a-1;
}
}

View file

@ -1,24 +0,0 @@
/* test what happens if there are no parentheses */
class Main {
void main() {
int x;
int y;
int z;
x = 5;
y = 10;
z = 100;
write( x + y + z); writeln();
/* */
write( - x + y - z); writeln();
/* should output 205 */
write( x + 2 * z); writeln();
write( x + 2 * z / x + 1); writeln();
write(+x); writeln();
}
}