first commit
This commit is contained in:
commit
063194f8be
349 changed files with 36508 additions and 0 deletions
1
tester/testsuite/bad/bad001.jl
Normal file
1
tester/testsuite/bad/bad001.jl
Normal file
|
@ -0,0 +1 @@
|
|||
/*
|
1
tester/testsuite/bad/bad002.jl
Normal file
1
tester/testsuite/bad/bad002.jl
Normal file
|
@ -0,0 +1 @@
|
|||
a
|
3
tester/testsuite/bad/bad003.jl
Normal file
3
tester/testsuite/bad/bad003.jl
Normal file
|
@ -0,0 +1,3 @@
|
|||
int f(int x, int x) {
|
||||
return x;
|
||||
}
|
4
tester/testsuite/bad/bad004.jl
Normal file
4
tester/testsuite/bad/bad004.jl
Normal file
|
@ -0,0 +1,4 @@
|
|||
int main)( {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
1
tester/testsuite/bad/bad005.jl
Normal file
1
tester/testsuite/bad/bad005.jl
Normal file
|
@ -0,0 +1 @@
|
|||
foo() {}
|
4
tester/testsuite/bad/bad006.jl
Normal file
4
tester/testsuite/bad/bad006.jl
Normal file
|
@ -0,0 +1,4 @@
|
|||
int main() {
|
||||
x = 14;
|
||||
return 0 ;
|
||||
}
|
5
tester/testsuite/bad/bad007.jl
Normal file
5
tester/testsuite/bad/bad007.jl
Normal file
|
@ -0,0 +1,5 @@
|
|||
int main() {
|
||||
int x;
|
||||
int x;
|
||||
return 0 ;
|
||||
}
|
4
tester/testsuite/bad/bad008.jl
Normal file
4
tester/testsuite/bad/bad008.jl
Normal file
|
@ -0,0 +1,4 @@
|
|||
int main() {
|
||||
if (false)
|
||||
return 0;
|
||||
}
|
5
tester/testsuite/bad/bad009.jl
Normal file
5
tester/testsuite/bad/bad009.jl
Normal file
|
@ -0,0 +1,5 @@
|
|||
int main() {
|
||||
int x;
|
||||
x = true;
|
||||
return 1;
|
||||
}
|
6
tester/testsuite/bad/bad010.jl
Normal file
6
tester/testsuite/bad/bad010.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
int main() {
|
||||
if (true)
|
||||
return;
|
||||
;
|
||||
return 1;
|
||||
}
|
3
tester/testsuite/bad/bad011.jl
Normal file
3
tester/testsuite/bad/bad011.jl
Normal file
|
@ -0,0 +1,3 @@
|
|||
int main() {
|
||||
return true;
|
||||
}
|
6
tester/testsuite/bad/bad012.jl
Normal file
6
tester/testsuite/bad/bad012.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
int main() {
|
||||
int i = foo(true);
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int foo(boolean b) { b = true; }
|
5
tester/testsuite/bad/bad013.jl
Normal file
5
tester/testsuite/bad/bad013.jl
Normal file
|
@ -0,0 +1,5 @@
|
|||
int main() {
|
||||
double x ;
|
||||
x = 2 * 3.14 ;
|
||||
return 0 ;
|
||||
}
|
6
tester/testsuite/bad/bad015.jl
Normal file
6
tester/testsuite/bad/bad015.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
// passing doubles to printInt().
|
||||
|
||||
int main() {
|
||||
printInt(1.0);
|
||||
return 0 ;
|
||||
}
|
6
tester/testsuite/bad/bad016.jl
Normal file
6
tester/testsuite/bad/bad016.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
// passing integers to printDouble().
|
||||
|
||||
int main() {
|
||||
printDouble(1);
|
||||
return 0 ;
|
||||
}
|
11
tester/testsuite/bad/bad017.jl
Normal file
11
tester/testsuite/bad/bad017.jl
Normal file
|
@ -0,0 +1,11 @@
|
|||
// 0 instead of 1 argument
|
||||
|
||||
int main() {
|
||||
int x = foo();
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int foo(int y) {
|
||||
return y;
|
||||
}
|
||||
|
11
tester/testsuite/bad/bad018.jl
Normal file
11
tester/testsuite/bad/bad018.jl
Normal file
|
@ -0,0 +1,11 @@
|
|||
// 1 instead of 2 arguments
|
||||
|
||||
int main() {
|
||||
int x = foo(1);
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int foo(int y,int z) {
|
||||
return y;
|
||||
}
|
||||
|
11
tester/testsuite/bad/bad019.jl
Normal file
11
tester/testsuite/bad/bad019.jl
Normal file
|
@ -0,0 +1,11 @@
|
|||
// 2 instead of 1 arguments
|
||||
|
||||
int main() {
|
||||
int x = foo(1,2);
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int foo(int y) {
|
||||
return y;
|
||||
}
|
||||
|
8
tester/testsuite/bad/bad020.jl
Normal file
8
tester/testsuite/bad/bad020.jl
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Compare double with boolean.
|
||||
|
||||
int main() {
|
||||
if (2.0 == true) {
|
||||
printString("foo");
|
||||
}
|
||||
return 0 ;
|
||||
}
|
6
tester/testsuite/bad/bad021.jl
Normal file
6
tester/testsuite/bad/bad021.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
/* Testing that main must return. */
|
||||
|
||||
/* All functions should return a value of their value type. This is not a valid Javalette program: */
|
||||
|
||||
int main() {
|
||||
}
|
6
tester/testsuite/bad/bad022.jl
Normal file
6
tester/testsuite/bad/bad022.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Assigning double to int variable.
|
||||
|
||||
int main () {
|
||||
int x = 1.0;
|
||||
return 0 ;
|
||||
}
|
6
tester/testsuite/bad/bad023.jl
Normal file
6
tester/testsuite/bad/bad023.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Assigning int to double variable.
|
||||
|
||||
int main () {
|
||||
double x = 1;
|
||||
return 0 ;
|
||||
}
|
4
tester/testsuite/bad/bad024.jl
Normal file
4
tester/testsuite/bad/bad024.jl
Normal file
|
@ -0,0 +1,4 @@
|
|||
int main() {
|
||||
if (false)
|
||||
return 0;
|
||||
}
|
8
tester/testsuite/bad/bad025.jl
Normal file
8
tester/testsuite/bad/bad025.jl
Normal file
|
@ -0,0 +1,8 @@
|
|||
int main() {
|
||||
return f(3);
|
||||
}
|
||||
|
||||
int f(int x) {
|
||||
if (x<0)
|
||||
return x;
|
||||
}
|
7
tester/testsuite/bad/bad026.jl
Normal file
7
tester/testsuite/bad/bad026.jl
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Assigning double to int variable.
|
||||
|
||||
int main () {
|
||||
int x;
|
||||
x = 1.0;
|
||||
return 0 ;
|
||||
}
|
7
tester/testsuite/bad/bad027.jl
Normal file
7
tester/testsuite/bad/bad027.jl
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Assigning int to double variable.
|
||||
|
||||
int main () {
|
||||
double x;
|
||||
x = 1;
|
||||
return 0 ;
|
||||
}
|
16
tester/testsuite/extensions/arrays1/array001.jl
Normal file
16
tester/testsuite/extensions/arrays1/array001.jl
Normal file
|
@ -0,0 +1,16 @@
|
|||
int main() {
|
||||
|
||||
int[] a = new int[10];
|
||||
int j=0;
|
||||
while (j<a.length) {
|
||||
a[j] = j;
|
||||
j++;
|
||||
}
|
||||
|
||||
for (int x : a)
|
||||
printInt(x);
|
||||
|
||||
int x = 45;
|
||||
printInt(x);
|
||||
return 0;
|
||||
}
|
11
tester/testsuite/extensions/arrays1/array001.output
Normal file
11
tester/testsuite/extensions/arrays1/array001.output
Normal file
|
@ -0,0 +1,11 @@
|
|||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
45
|
0
tester/testsuite/extensions/arrays1/array002.j
Normal file
0
tester/testsuite/extensions/arrays1/array002.j
Normal file
46
tester/testsuite/extensions/arrays1/array002.jl
Normal file
46
tester/testsuite/extensions/arrays1/array002.jl
Normal file
|
@ -0,0 +1,46 @@
|
|||
int [] doubleArray (int [] a){
|
||||
int [] res = new int [a . length];
|
||||
int i = 0 ;
|
||||
for (int n : a){
|
||||
res [i] = 2 * n ;
|
||||
i ++ ;
|
||||
}
|
||||
return res ;
|
||||
}
|
||||
|
||||
void shiftLeft (int [] a){
|
||||
int x = a [0];
|
||||
int i = 0 ;
|
||||
while (i < a.length - 1){
|
||||
a [i] = a [i + 1];
|
||||
i ++ ;
|
||||
}
|
||||
a[a.length - 1]= x ;
|
||||
return;
|
||||
}
|
||||
|
||||
int scalProd(int[] a, int[] b) {
|
||||
int res = 0;
|
||||
int i = 0;
|
||||
while (i < a.length) {
|
||||
res = res + a[i] * b[i];
|
||||
i++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main () {
|
||||
int [] a = new int [5];
|
||||
int i = 0 ;
|
||||
while (i < a.length){
|
||||
a [i]= i ;
|
||||
i ++ ;
|
||||
}
|
||||
shiftLeft (a);
|
||||
int [] b = doubleArray (a);
|
||||
for (int x : a)printInt (x);
|
||||
for (int x : b)printInt (x);
|
||||
printInt(scalProd(a,b));
|
||||
return 0 ;
|
||||
}
|
||||
|
0
tester/testsuite/extensions/arrays1/array002.ll
Normal file
0
tester/testsuite/extensions/arrays1/array002.ll
Normal file
11
tester/testsuite/extensions/arrays1/array002.output
Normal file
11
tester/testsuite/extensions/arrays1/array002.output
Normal file
|
@ -0,0 +1,11 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
0
|
||||
2
|
||||
4
|
||||
6
|
||||
8
|
||||
0
|
||||
60
|
35
tester/testsuite/extensions/arrays2/array003.jl
Normal file
35
tester/testsuite/extensions/arrays2/array003.jl
Normal file
|
@ -0,0 +1,35 @@
|
|||
int main() {
|
||||
|
||||
double[] vector = new double[4];
|
||||
double[][] matrix = new double[3][4];
|
||||
|
||||
int i=0;
|
||||
while (i<matrix.length) {
|
||||
int j=0;
|
||||
while (j<matrix[0].length) {
|
||||
matrix[i][j] = 5.0;
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
i=0;
|
||||
while (i<vector.length-1) {
|
||||
vector[i] = 3.0;
|
||||
i++;
|
||||
}
|
||||
|
||||
matrix[0] = vector;
|
||||
|
||||
int j = 0;
|
||||
while (j<vector.length) {
|
||||
matrix[1][j] = vector[j]+1.0;
|
||||
j++;
|
||||
}
|
||||
|
||||
for (double[] x : matrix)
|
||||
for (double y : x)
|
||||
printDouble(y);
|
||||
|
||||
return 0 ;
|
||||
}
|
12
tester/testsuite/extensions/arrays2/array003.output
Normal file
12
tester/testsuite/extensions/arrays2/array003.output
Normal file
|
@ -0,0 +1,12 @@
|
|||
3.0
|
||||
3.0
|
||||
3.0
|
||||
0.0
|
||||
4.0
|
||||
4.0
|
||||
4.0
|
||||
1.0
|
||||
5.0
|
||||
5.0
|
||||
5.0
|
||||
5.0
|
19
tester/testsuite/extensions/objects1/counter.jl
Normal file
19
tester/testsuite/extensions/objects1/counter.jl
Normal file
|
@ -0,0 +1,19 @@
|
|||
int main () {
|
||||
Counter c;
|
||||
c = new Counter;
|
||||
c.incr();
|
||||
c.incr();
|
||||
c.incr();
|
||||
int x = c.value();
|
||||
printInt(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
class Counter {
|
||||
int val;
|
||||
|
||||
void incr () {val++; return;}
|
||||
|
||||
int value () {return val;}
|
||||
|
||||
}
|
1
tester/testsuite/extensions/objects1/counter.output
Normal file
1
tester/testsuite/extensions/objects1/counter.output
Normal file
|
@ -0,0 +1 @@
|
|||
3
|
50
tester/testsuite/extensions/objects1/linked.jl
Normal file
50
tester/testsuite/extensions/objects1/linked.jl
Normal file
|
@ -0,0 +1,50 @@
|
|||
class Node {
|
||||
int elem;
|
||||
Node next;
|
||||
|
||||
void setElem(int c) { elem = c; }
|
||||
|
||||
void setNext(Node n) { next = n; }
|
||||
|
||||
int getElem() { return elem; }
|
||||
|
||||
Node getNext() { return next; }
|
||||
}
|
||||
|
||||
class Stack {
|
||||
Node head;
|
||||
|
||||
void push(int c) {
|
||||
Node newHead = new Node;
|
||||
newHead.setElem(c);
|
||||
newHead.setNext(head);
|
||||
head = newHead;
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return head==(Node)null;
|
||||
}
|
||||
|
||||
int top() {
|
||||
return head.getElem();
|
||||
}
|
||||
|
||||
void pop() {
|
||||
head = head.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
Stack s = new Stack;
|
||||
int i= 0;
|
||||
while (i<10) {
|
||||
s.push(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
while (!s.isEmpty()) {
|
||||
printInt(s.top());
|
||||
s.pop();
|
||||
}
|
||||
return 0;
|
||||
}
|
10
tester/testsuite/extensions/objects1/linked.output
Normal file
10
tester/testsuite/extensions/objects1/linked.output
Normal file
|
@ -0,0 +1,10 @@
|
|||
9
|
||||
8
|
||||
7
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
2
|
||||
1
|
||||
0
|
62
tester/testsuite/extensions/objects1/points.jl
Normal file
62
tester/testsuite/extensions/objects1/points.jl
Normal file
|
@ -0,0 +1,62 @@
|
|||
class Point2 {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
void move (int dx, int dy) {
|
||||
x = x + dx;
|
||||
y = y + dy;
|
||||
}
|
||||
|
||||
int getX () { return x; }
|
||||
|
||||
int getY () { return y; }
|
||||
}
|
||||
|
||||
class Point3 extends Point2 {
|
||||
int z;
|
||||
|
||||
void moveZ (int dz) {
|
||||
z = z + dz;
|
||||
}
|
||||
|
||||
int getZ () { return z; }
|
||||
|
||||
}
|
||||
|
||||
class Point4 extends Point3 {
|
||||
int w;
|
||||
|
||||
void moveW (int dw) {
|
||||
w = w + dw;
|
||||
}
|
||||
|
||||
int getW () { return w; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main () {
|
||||
Point2 p = new Point3;
|
||||
|
||||
Point3 q = new Point3;
|
||||
|
||||
Point4 r = new Point4;
|
||||
|
||||
q.move(2,4);
|
||||
q.moveZ(7);
|
||||
p = q;
|
||||
|
||||
p.move(3,5);
|
||||
|
||||
r.move(1,3);
|
||||
r.moveZ(6);
|
||||
r.moveW(2);
|
||||
|
||||
printInt(p.getX());
|
||||
printInt(p.getY());
|
||||
printInt(q.getZ());
|
||||
printInt(r.getW());
|
||||
return 0;
|
||||
|
||||
}
|
4
tester/testsuite/extensions/objects1/points.output
Normal file
4
tester/testsuite/extensions/objects1/points.output
Normal file
|
@ -0,0 +1,4 @@
|
|||
5
|
||||
9
|
||||
7
|
||||
2
|
61
tester/testsuite/extensions/objects1/queue.jl
Normal file
61
tester/testsuite/extensions/objects1/queue.jl
Normal file
|
@ -0,0 +1,61 @@
|
|||
class Node {
|
||||
int elem;
|
||||
Node next;
|
||||
|
||||
void setElem (int e) { elem = e; }
|
||||
void setNext (Node n) { next = n; }
|
||||
|
||||
int getElem () { return elem; }
|
||||
Node getNext () { return next; }
|
||||
|
||||
}
|
||||
|
||||
class IntQueue {
|
||||
Node front;
|
||||
Node rear;
|
||||
|
||||
boolean isEmpty () { return front == (Node)null; }
|
||||
|
||||
void insert (int x) {
|
||||
Node last = new Node;
|
||||
last.setElem(x);
|
||||
if (self.isEmpty())
|
||||
front = last;
|
||||
else
|
||||
rear.setNext(last);
|
||||
rear = last;
|
||||
}
|
||||
|
||||
int first () { return front.getElem(); }
|
||||
|
||||
void rmFirst () {
|
||||
front = front.getNext();
|
||||
}
|
||||
|
||||
int size () {
|
||||
Node n = front;
|
||||
int res = 0;
|
||||
while (n != (Node)null) {
|
||||
n = n.getNext();
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
int f (int x) {
|
||||
return x*x + 3;
|
||||
}
|
||||
|
||||
int main () {
|
||||
IntQueue q = new IntQueue;
|
||||
q.insert(f(3));
|
||||
q.insert(5);
|
||||
q.insert(7);
|
||||
printInt(q.first());
|
||||
q.rmFirst();
|
||||
printInt(q.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
2
tester/testsuite/extensions/objects1/queue.output
Normal file
2
tester/testsuite/extensions/objects1/queue.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
12
|
||||
2
|
82
tester/testsuite/extensions/objects2/shapes.jl
Normal file
82
tester/testsuite/extensions/objects2/shapes.jl
Normal file
|
@ -0,0 +1,82 @@
|
|||
class Node {
|
||||
Shape elem;
|
||||
Node next;
|
||||
|
||||
void setElem(Shape c) { elem = c; }
|
||||
|
||||
void setNext(Node n) { next = n; }
|
||||
|
||||
Shape getElem() { return elem; }
|
||||
|
||||
Node getNext() { return next; }
|
||||
}
|
||||
|
||||
class Stack {
|
||||
Node head;
|
||||
|
||||
void push(Shape c) {
|
||||
Node newHead = new Node;
|
||||
newHead.setElem(c);
|
||||
newHead.setNext(head);
|
||||
head = newHead;
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return head==(Node)null;
|
||||
}
|
||||
|
||||
Shape top() {
|
||||
return head.getElem();
|
||||
}
|
||||
|
||||
void pop() {
|
||||
head = head.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
class Shape {
|
||||
void tell () {
|
||||
printString("I'm a shape");
|
||||
}
|
||||
|
||||
void tellAgain() {
|
||||
printString("I'm just a shape");
|
||||
}
|
||||
}
|
||||
|
||||
class Rectangle extends Shape {
|
||||
void tellAgain() {
|
||||
printString("I'm really a rectangle");
|
||||
}
|
||||
}
|
||||
|
||||
class Circle extends Shape {
|
||||
void tellAgain() {
|
||||
printString("I'm really a circle");
|
||||
}
|
||||
}
|
||||
|
||||
class Square extends Rectangle {
|
||||
void tellAgain() {
|
||||
printString("I'm really a square");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
Stack stk = new Stack;
|
||||
Shape s = new Shape;
|
||||
stk.push(s);
|
||||
s = new Rectangle;
|
||||
stk.push(s);
|
||||
s = new Square;
|
||||
stk.push(s);
|
||||
s = new Circle;
|
||||
stk.push(s);
|
||||
while (!stk.isEmpty()) {
|
||||
s = stk.top();
|
||||
s.tell();
|
||||
s.tellAgain();
|
||||
stk.pop();
|
||||
}
|
||||
return 0;
|
||||
}
|
8
tester/testsuite/extensions/objects2/shapes.output
Normal file
8
tester/testsuite/extensions/objects2/shapes.output
Normal file
|
@ -0,0 +1,8 @@
|
|||
I'm a shape
|
||||
I'm really a circle
|
||||
I'm a shape
|
||||
I'm really a square
|
||||
I'm a shape
|
||||
I'm really a rectangle
|
||||
I'm a shape
|
||||
I'm just a shape
|
0
tester/testsuite/extensions/pointers/list.j
Normal file
0
tester/testsuite/extensions/pointers/list.j
Normal file
48
tester/testsuite/extensions/pointers/list.jl
Normal file
48
tester/testsuite/extensions/pointers/list.jl
Normal file
|
@ -0,0 +1,48 @@
|
|||
typedef struct Node *list;
|
||||
|
||||
struct Node {
|
||||
int elem;
|
||||
list next;
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
printInt(length(fromTo(1,50)));
|
||||
printInt(length2(fromTo(1,100)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int head (list xs) {
|
||||
return xs -> elem;
|
||||
}
|
||||
|
||||
list cons (int x, list xs) {
|
||||
list n;
|
||||
n = new Node;
|
||||
n->elem = x;
|
||||
n->next = xs;
|
||||
return n;
|
||||
}
|
||||
|
||||
int length (list xs) {
|
||||
if (xs==(list)null)
|
||||
return 0;
|
||||
else
|
||||
return 1 + length (xs->next);
|
||||
}
|
||||
|
||||
list fromTo (int m, int n) {
|
||||
if (m>n)
|
||||
return (list)null;
|
||||
else
|
||||
return cons (m,fromTo (m+1,n));
|
||||
}
|
||||
|
||||
int length2 (list xs) {
|
||||
int res = 0;
|
||||
while (xs != (list)null) {
|
||||
res++;
|
||||
xs = xs->next;
|
||||
}
|
||||
return res;
|
||||
}
|
2
tester/testsuite/extensions/pointers/list.output
Normal file
2
tester/testsuite/extensions/pointers/list.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
50
|
||||
100
|
0
tester/testsuite/extensions/pointers/tree.j
Normal file
0
tester/testsuite/extensions/pointers/tree.j
Normal file
78
tester/testsuite/extensions/pointers/tree.jl
Normal file
78
tester/testsuite/extensions/pointers/tree.jl
Normal file
|
@ -0,0 +1,78 @@
|
|||
struct Node {
|
||||
tree left;
|
||||
int val;
|
||||
tree right;
|
||||
};
|
||||
|
||||
typedef struct Node *tree;
|
||||
|
||||
struct Header {
|
||||
tree elems;
|
||||
};
|
||||
|
||||
typedef struct Header *intset;
|
||||
|
||||
void insert (int x, intset s) {
|
||||
s->elems = insertTree(x,s->elems);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isElem(int x, intset s) {
|
||||
return isElemTree (x,s->elems);
|
||||
}
|
||||
|
||||
tree insertTree(int x,tree t) {
|
||||
if (t==(tree)null) {
|
||||
tree n1;
|
||||
n1 = new Node;
|
||||
n1->left = (tree)null;
|
||||
n1->val = x;
|
||||
n1->right = (tree)null;
|
||||
return n1;
|
||||
}
|
||||
else if (x < t->val)
|
||||
t->left = insertTree (x,t->left);
|
||||
else if (x > t->val)
|
||||
t->right = insertTree (x,t->right);
|
||||
return t;
|
||||
}
|
||||
|
||||
boolean isElemTree(int x,tree t) {
|
||||
if (t==(tree)null)
|
||||
return false;
|
||||
else if (x==t->val)
|
||||
return true;
|
||||
else if (x < t->val)
|
||||
return isElemTree (x, t->left);
|
||||
else
|
||||
return isElemTree(x, t->right);
|
||||
}
|
||||
|
||||
void printElem(int n, intset s) {
|
||||
if (isElem(n,s))
|
||||
printString("Elem!");
|
||||
else
|
||||
printString("Not elem!");
|
||||
return;
|
||||
}
|
||||
|
||||
int main () {
|
||||
intset s;
|
||||
s = new Header;
|
||||
s->elems = (tree)null;
|
||||
|
||||
int x = 3;
|
||||
int i = 0;
|
||||
while (i<100) {
|
||||
x = (x * 37) % 100;
|
||||
i++;
|
||||
insert(x, s);
|
||||
}
|
||||
printElem(23,s);
|
||||
printElem(24,s);
|
||||
printElem(25,s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
3
tester/testsuite/extensions/pointers/tree.output
Normal file
3
tester/testsuite/extensions/pointers/tree.output
Normal file
|
@ -0,0 +1,3 @@
|
|||
Elem!
|
||||
Not elem!
|
||||
Not elem!
|
73
tester/testsuite/good/core001.jl
Normal file
73
tester/testsuite/good/core001.jl
Normal file
|
@ -0,0 +1,73 @@
|
|||
int main() {
|
||||
printInt(fac(10));
|
||||
printInt(rfac(10));
|
||||
printInt(mfac(10));
|
||||
printInt(ifac(10));
|
||||
double r ; // just to test blocks
|
||||
{
|
||||
int n = 10;
|
||||
int r = 1;
|
||||
while (n>0) {
|
||||
r = r * n;
|
||||
n--;
|
||||
}
|
||||
printInt(r);
|
||||
}
|
||||
printDouble(dfac(10.0));
|
||||
printString ("hello */");
|
||||
printString ("/* world") ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int fac(int a) {
|
||||
int r;
|
||||
int n;
|
||||
|
||||
r = 1;
|
||||
n = a;
|
||||
while (n > 0) {
|
||||
r = r * n;
|
||||
n = n - 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int rfac(int n) {
|
||||
if (n == 0)
|
||||
return 1;
|
||||
else
|
||||
return n * rfac(n-1);
|
||||
}
|
||||
|
||||
int mfac(int n) {
|
||||
if (n == 0)
|
||||
return 1;
|
||||
else
|
||||
return n * nfac(n-1);
|
||||
}
|
||||
|
||||
int nfac(int n) {
|
||||
if (n != 0)
|
||||
return mfac(n-1) * n;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
double dfac(double n) {
|
||||
if (n == 0.0)
|
||||
return 1.0;
|
||||
else
|
||||
return n * dfac(n-1.0);
|
||||
}
|
||||
|
||||
int ifac(int n) { return ifac2f(1,n); }
|
||||
|
||||
int ifac2f(int l, int h) {
|
||||
if (l == h)
|
||||
return l;
|
||||
if (l > h)
|
||||
return 1;
|
||||
int m;
|
||||
m = (l + h) / 2;
|
||||
return ifac2f(l,m) * ifac2f(m+1,h);
|
||||
}
|
8
tester/testsuite/good/core001.output
Normal file
8
tester/testsuite/good/core001.output
Normal file
|
@ -0,0 +1,8 @@
|
|||
3628800
|
||||
3628800
|
||||
3628800
|
||||
3628800
|
||||
3628800
|
||||
3628800.0
|
||||
hello */
|
||||
/* world
|
12
tester/testsuite/good/core002.jl
Normal file
12
tester/testsuite/good/core002.jl
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* void expression as statement */
|
||||
|
||||
int main() {
|
||||
foo();
|
||||
return 0 ;
|
||||
|
||||
}
|
||||
|
||||
void foo() {
|
||||
printString("foo");
|
||||
return;
|
||||
}
|
1
tester/testsuite/good/core002.output
Normal file
1
tester/testsuite/good/core002.output
Normal file
|
@ -0,0 +1 @@
|
|||
foo
|
23
tester/testsuite/good/core003.jl
Normal file
23
tester/testsuite/good/core003.jl
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Testing the return checker
|
||||
|
||||
int f () {
|
||||
if (true)
|
||||
return 0;
|
||||
else
|
||||
{}
|
||||
}
|
||||
|
||||
int g () {
|
||||
if (false)
|
||||
{}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void p () {}
|
||||
|
||||
|
||||
int main() {
|
||||
p();
|
||||
return 0;
|
||||
}
|
0
tester/testsuite/good/core003.output
Normal file
0
tester/testsuite/good/core003.output
Normal file
7
tester/testsuite/good/core004.jl
Normal file
7
tester/testsuite/good/core004.jl
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* allow comparing booleans. */
|
||||
|
||||
int main() {
|
||||
if (true == true) { printInt(42); }
|
||||
return 0 ;
|
||||
|
||||
}
|
1
tester/testsuite/good/core004.output
Normal file
1
tester/testsuite/good/core004.output
Normal file
|
@ -0,0 +1 @@
|
|||
42
|
14
tester/testsuite/good/core005.jl
Normal file
14
tester/testsuite/good/core005.jl
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* usage of variable initialized in both branches. */
|
||||
|
||||
int main () {
|
||||
int x;
|
||||
int y = 56;
|
||||
if (y + 45 <= 2) {
|
||||
x = 1;
|
||||
} else {
|
||||
x = 2;
|
||||
}
|
||||
printInt(x);
|
||||
return 0 ;
|
||||
|
||||
}
|
1
tester/testsuite/good/core005.output
Normal file
1
tester/testsuite/good/core005.output
Normal file
|
@ -0,0 +1 @@
|
|||
2
|
11
tester/testsuite/good/core006.jl
Normal file
11
tester/testsuite/good/core006.jl
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Declaration of multiple variables of the same type in one statement:
|
||||
|
||||
int main () {
|
||||
int x, y;
|
||||
x = 45;
|
||||
y = -36;
|
||||
printInt(x);
|
||||
printInt(y);
|
||||
return 0 ;
|
||||
|
||||
}
|
2
tester/testsuite/good/core006.output
Normal file
2
tester/testsuite/good/core006.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
45
|
||||
-36
|
8
tester/testsuite/good/core007.jl
Normal file
8
tester/testsuite/good/core007.jl
Normal file
|
@ -0,0 +1,8 @@
|
|||
// declaration and initialization in same statement
|
||||
|
||||
int main() {
|
||||
int x = 7;
|
||||
printInt(x);
|
||||
return 0 ;
|
||||
|
||||
}
|
1
tester/testsuite/good/core007.output
Normal file
1
tester/testsuite/good/core007.output
Normal file
|
@ -0,0 +1 @@
|
|||
7
|
11
tester/testsuite/good/core008.jl
Normal file
11
tester/testsuite/good/core008.jl
Normal file
|
@ -0,0 +1,11 @@
|
|||
// multiple variables of the same type declared
|
||||
// and possibly initialized in the same statement
|
||||
|
||||
int main() {
|
||||
int x, y = 7;
|
||||
x = -1234234;
|
||||
printInt(x);
|
||||
printInt(y);
|
||||
return 0 ;
|
||||
|
||||
}
|
2
tester/testsuite/good/core008.output
Normal file
2
tester/testsuite/good/core008.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
-1234234
|
||||
7
|
13
tester/testsuite/good/core009.jl
Normal file
13
tester/testsuite/good/core009.jl
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Calling functions which take zero parameters
|
||||
|
||||
int main() {
|
||||
int x = foo();
|
||||
printInt(x);
|
||||
return 0 ;
|
||||
|
||||
}
|
||||
|
||||
int foo() {
|
||||
return 10;
|
||||
}
|
||||
|
1
tester/testsuite/good/core009.output
Normal file
1
tester/testsuite/good/core009.output
Normal file
|
@ -0,0 +1 @@
|
|||
10
|
19
tester/testsuite/good/core010.jl
Normal file
19
tester/testsuite/good/core010.jl
Normal file
|
@ -0,0 +1,19 @@
|
|||
// count function parameters as initialized
|
||||
|
||||
int main() {
|
||||
printInt(fac(5));
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int fac (int a) {
|
||||
int r;
|
||||
int n;
|
||||
r = 1;
|
||||
n = a;
|
||||
while (n > 0)
|
||||
{
|
||||
r = r * n;
|
||||
n = n - 1;
|
||||
}
|
||||
return r;
|
||||
}
|
1
tester/testsuite/good/core010.output
Normal file
1
tester/testsuite/good/core010.output
Normal file
|
@ -0,0 +1 @@
|
|||
120
|
6
tester/testsuite/good/core011.jl
Normal file
6
tester/testsuite/good/core011.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
/* Test pushing -1. */
|
||||
|
||||
int main() {
|
||||
printInt(-1);
|
||||
return 0 ;
|
||||
}
|
1
tester/testsuite/good/core011.output
Normal file
1
tester/testsuite/good/core011.output
Normal file
|
@ -0,0 +1 @@
|
|||
-1
|
26
tester/testsuite/good/core012.jl
Normal file
26
tester/testsuite/good/core012.jl
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* Test arithmetic and comparisons. */
|
||||
|
||||
int main() {
|
||||
int x = 56;
|
||||
int y = -23;
|
||||
printInt(x+y);
|
||||
printInt(x-y);
|
||||
printInt(x*y);
|
||||
printInt(45/2);
|
||||
printInt(78%3);
|
||||
double z = -9.3;
|
||||
double w = 5.1;
|
||||
printBool(z+w > z-w);
|
||||
printBool(z/w <= z*w);
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
void printBool(boolean b) {
|
||||
if (b) {
|
||||
printString("true");
|
||||
return;
|
||||
} else {
|
||||
printString("false");
|
||||
return;
|
||||
}
|
||||
}
|
7
tester/testsuite/good/core012.output
Normal file
7
tester/testsuite/good/core012.output
Normal file
|
@ -0,0 +1,7 @@
|
|||
33
|
||||
79
|
||||
-1288
|
||||
22
|
||||
0
|
||||
true
|
||||
false
|
33
tester/testsuite/good/core013.jl
Normal file
33
tester/testsuite/good/core013.jl
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* Test boolean operators. */
|
||||
|
||||
int main() {
|
||||
printString("&&");
|
||||
printBool(test(-1) && test(0));
|
||||
printBool(test(-2) && test(1));
|
||||
printBool(test(3) && test(-5));
|
||||
printBool(test(234234) && test(21321));
|
||||
printString("||");
|
||||
printBool(test(-1) || test(0));
|
||||
printBool(test(-2) || test(1));
|
||||
printBool(test(3) || test(-5));
|
||||
printBool(test(234234) || test(21321));
|
||||
printString("!");
|
||||
printBool(true);
|
||||
printBool(false);
|
||||
return 0 ;
|
||||
|
||||
}
|
||||
|
||||
void printBool(boolean b) {
|
||||
if (!b) {
|
||||
printString("false");
|
||||
} else {
|
||||
printString("true");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean test(int i) {
|
||||
printInt(i);
|
||||
return i > 0;
|
||||
}
|
25
tester/testsuite/good/core013.output
Normal file
25
tester/testsuite/good/core013.output
Normal file
|
@ -0,0 +1,25 @@
|
|||
&&
|
||||
-1
|
||||
false
|
||||
-2
|
||||
false
|
||||
3
|
||||
-5
|
||||
false
|
||||
234234
|
||||
21321
|
||||
true
|
||||
||
|
||||
-1
|
||||
0
|
||||
false
|
||||
-2
|
||||
1
|
||||
true
|
||||
3
|
||||
true
|
||||
234234
|
||||
true
|
||||
!
|
||||
true
|
||||
false
|
17
tester/testsuite/good/core014.jl
Normal file
17
tester/testsuite/good/core014.jl
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* Fibonacci. */
|
||||
|
||||
int main () {
|
||||
int lo,hi,mx ;
|
||||
lo = 1 ;
|
||||
hi = lo ;
|
||||
mx = 5000000 ;
|
||||
printInt(lo) ;
|
||||
while (hi < mx) {
|
||||
printInt(hi) ;
|
||||
hi = lo + hi ;
|
||||
lo = hi - lo ;
|
||||
}
|
||||
return 0 ;
|
||||
|
||||
}
|
||||
|
33
tester/testsuite/good/core014.output
Normal file
33
tester/testsuite/good/core014.output
Normal file
|
@ -0,0 +1,33 @@
|
|||
1
|
||||
1
|
||||
2
|
||||
3
|
||||
5
|
||||
8
|
||||
13
|
||||
21
|
||||
34
|
||||
55
|
||||
89
|
||||
144
|
||||
233
|
||||
377
|
||||
610
|
||||
987
|
||||
1597
|
||||
2584
|
||||
4181
|
||||
6765
|
||||
10946
|
||||
17711
|
||||
28657
|
||||
46368
|
||||
75025
|
||||
121393
|
||||
196418
|
||||
317811
|
||||
514229
|
||||
832040
|
||||
1346269
|
||||
2178309
|
||||
3524578
|
16
tester/testsuite/good/core015.jl
Normal file
16
tester/testsuite/good/core015.jl
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* parity of positive integers by recursion */
|
||||
|
||||
int main () {
|
||||
printInt(ev(17)) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int ev (int y) {
|
||||
if (y > 0)
|
||||
return ev (y-2) ;
|
||||
else
|
||||
if (y < 0)
|
||||
return 0 ;
|
||||
else
|
||||
return 1 ;
|
||||
}
|
1
tester/testsuite/good/core015.output
Normal file
1
tester/testsuite/good/core015.output
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
15
tester/testsuite/good/core016.jl
Normal file
15
tester/testsuite/good/core016.jl
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* parity of positive integers by loop */
|
||||
|
||||
int main () {
|
||||
int y = 17;
|
||||
while (y > 0)
|
||||
y = y - 2;
|
||||
if (y < 0) {
|
||||
printInt(0);
|
||||
return 0 ;
|
||||
}
|
||||
else {
|
||||
printInt(1);
|
||||
return 0 ;
|
||||
}
|
||||
}
|
1
tester/testsuite/good/core016.output
Normal file
1
tester/testsuite/good/core016.output
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
40
tester/testsuite/good/core017.jl
Normal file
40
tester/testsuite/good/core017.jl
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* Test boolean operators */
|
||||
|
||||
int main () {
|
||||
int x = 4;
|
||||
if (3 <= x && 4 != 2 && true) {
|
||||
printBool(true);
|
||||
} else {
|
||||
printString("apa");
|
||||
}
|
||||
|
||||
printBool(true == true || dontCallMe(1));
|
||||
printBool(4.0 < -50.0 && dontCallMe(2));
|
||||
|
||||
printBool(4 == x && true == !false && true);
|
||||
|
||||
printBool(implies(false,false));
|
||||
printBool(implies(false,true));
|
||||
printBool(implies(true,false));
|
||||
printBool(implies(true,true));
|
||||
return 0 ;
|
||||
|
||||
}
|
||||
|
||||
boolean dontCallMe(int x) {
|
||||
printInt(x);
|
||||
return true;
|
||||
}
|
||||
|
||||
void printBool(boolean b) {
|
||||
if (b) {
|
||||
printString("true");
|
||||
} else {
|
||||
printString("false");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean implies(boolean x, boolean y) {
|
||||
return !x || x == y;
|
||||
}
|
8
tester/testsuite/good/core017.output
Normal file
8
tester/testsuite/good/core017.output
Normal file
|
@ -0,0 +1,8 @@
|
|||
true
|
||||
true
|
||||
false
|
||||
true
|
||||
true
|
||||
true
|
||||
false
|
||||
true
|
2
tester/testsuite/good/core018.input
Normal file
2
tester/testsuite/good/core018.input
Normal file
|
@ -0,0 +1,2 @@
|
|||
-5673
|
||||
42.5
|
15
tester/testsuite/good/core018.jl
Normal file
15
tester/testsuite/good/core018.jl
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* test input */
|
||||
|
||||
int main() {
|
||||
int x = readInt();
|
||||
double y = readDouble();
|
||||
|
||||
printInt(x-5);
|
||||
|
||||
if (y > 42.0 || y < 43.0)
|
||||
printString("yay!");
|
||||
else
|
||||
printString("nay!");
|
||||
return 0 ;
|
||||
|
||||
}
|
2
tester/testsuite/good/core018.output
Normal file
2
tester/testsuite/good/core018.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
-5678
|
||||
yay!
|
26
tester/testsuite/good/core019.jl
Normal file
26
tester/testsuite/good/core019.jl
Normal file
|
@ -0,0 +1,26 @@
|
|||
int main() {
|
||||
int i = 78;
|
||||
{
|
||||
int i = 1;
|
||||
printInt(i);
|
||||
}
|
||||
printInt(i);
|
||||
while (i > 76) {
|
||||
i--;
|
||||
printInt(i);
|
||||
// this is a little tricky
|
||||
// on the right hand side, i refers to the outer i
|
||||
int i = i + 7;
|
||||
printInt(i);
|
||||
}
|
||||
printInt(i);
|
||||
if (i > 4) {
|
||||
int i = 4;
|
||||
printInt(i);
|
||||
} else {
|
||||
printString("foo");
|
||||
}
|
||||
printInt(i);
|
||||
return 0 ;
|
||||
|
||||
}
|
9
tester/testsuite/good/core019.output
Normal file
9
tester/testsuite/good/core019.output
Normal file
|
@ -0,0 +1,9 @@
|
|||
1
|
||||
78
|
||||
77
|
||||
84
|
||||
76
|
||||
83
|
||||
76
|
||||
4
|
||||
76
|
7
tester/testsuite/good/core020.jl
Normal file
7
tester/testsuite/good/core020.jl
Normal file
|
@ -0,0 +1,7 @@
|
|||
int main() {
|
||||
p();
|
||||
printInt(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void p() {}
|
1
tester/testsuite/good/core020.output
Normal file
1
tester/testsuite/good/core020.output
Normal file
|
@ -0,0 +1 @@
|
|||
1
|
6
tester/testsuite/good/core021.jl
Normal file
6
tester/testsuite/good/core021.jl
Normal file
|
@ -0,0 +1,6 @@
|
|||
int main() {
|
||||
if (true) {
|
||||
printInt(1);
|
||||
return 0;
|
||||
}
|
||||
}
|
1
tester/testsuite/good/core021.output
Normal file
1
tester/testsuite/good/core021.output
Normal file
|
@ -0,0 +1 @@
|
|||
1
|
7
tester/testsuite/good/core022.jl
Normal file
7
tester/testsuite/good/core022.jl
Normal file
|
@ -0,0 +1,7 @@
|
|||
int main() {
|
||||
int x;
|
||||
double y;
|
||||
printInt(x);
|
||||
printDouble(y);
|
||||
return 0;
|
||||
}
|
2
tester/testsuite/good/core022.output
Normal file
2
tester/testsuite/good/core022.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
0
|
||||
0.0
|
Loading…
Add table
Add a link
Reference in a new issue