From: Doni Pracner Date: Fri, 19 Jul 2019 12:27:14 +0000 (+0200) Subject: move samples to 'alpha-mj' subfolder X-Git-Tag: v1.1.0~3 X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=77e39fac55f1a366814d35e75659cb6d88cca4e1;p=mjc2wsl.git move samples to 'alpha-mj' subfolder --- diff --git a/build.xml b/build.xml index a9dac9f..762aef3 100644 --- a/build.xml +++ b/build.xml @@ -47,8 +47,8 @@ - - + + diff --git a/samples/ArrayTest.mj b/samples/ArrayTest.mj deleted file mode 100644 index c55ffd1..0000000 --- a/samples/ArrayTest.mj +++ /dev/null @@ -1,20 +0,0 @@ -program ArrayTest - int[] arr; - int i; - int max; -{ - void main(){ - max = 10; - arr = new int[max]; - i = 0; - while (i1){ - a = new int[i]; - loc = 0; - loc2 = 1; - while (loc0) - func(i-1); - } - - void main() { - func(5); - } -} \ No newline at end of file diff --git a/samples/RekFac.mj b/samples/RekFac.mj deleted file mode 100644 index 674cc14..0000000 --- a/samples/RekFac.mj +++ /dev/null @@ -1,17 +0,0 @@ -program RekFac{ - - int factorial(int f) - { - if (f<0) - return 0; - if (f<=1) - return 1; - return factorial(f-1) * f ; - } - - void main() - { - print(factorial(3),3); - print(factorial(10),10); - } -} \ No newline at end of file diff --git a/samples/RekFib.mj b/samples/RekFib.mj deleted file mode 100644 index d3a59a5..0000000 --- a/samples/RekFib.mj +++ /dev/null @@ -1,18 +0,0 @@ -program RekFib{ - - int fib(int f) - { - if (f==0) - return 0; - if (f==1) - return 1; - return fib(f-2)+fib(f-1) ; - } - - void main() - { - print(fib(0),3); - print(fib(2),3); - print(fib(7),3); - } -} \ No newline at end of file diff --git a/samples/alpha-mj/ArrayTest.mj b/samples/alpha-mj/ArrayTest.mj new file mode 100644 index 0000000..c55ffd1 --- /dev/null +++ b/samples/alpha-mj/ArrayTest.mj @@ -0,0 +1,20 @@ +program ArrayTest + int[] arr; + int i; + int max; +{ + void main(){ + max = 10; + arr = new int[max]; + i = 0; + while (i1){ + a = new int[i]; + loc = 0; + loc2 = 1; + while (loc0) + func(i-1); + } + + void main() { + func(5); + } +} \ No newline at end of file diff --git a/samples/alpha-mj/RekFac.mj b/samples/alpha-mj/RekFac.mj new file mode 100644 index 0000000..674cc14 --- /dev/null +++ b/samples/alpha-mj/RekFac.mj @@ -0,0 +1,17 @@ +program RekFac{ + + int factorial(int f) + { + if (f<0) + return 0; + if (f<=1) + return 1; + return factorial(f-1) * f ; + } + + void main() + { + print(factorial(3),3); + print(factorial(10),10); + } +} \ No newline at end of file diff --git a/samples/alpha-mj/RekFib.mj b/samples/alpha-mj/RekFib.mj new file mode 100644 index 0000000..d3a59a5 --- /dev/null +++ b/samples/alpha-mj/RekFib.mj @@ -0,0 +1,18 @@ +program RekFib{ + + int fib(int f) + { + if (f==0) + return 0; + if (f==1) + return 1; + return fib(f-2)+fib(f-1) ; + } + + void main() + { + print(fib(0),3); + print(fib(2),3); + print(fib(7),3); + } +} \ No newline at end of file diff --git a/samples/alpha-mj/chrtest.mj b/samples/alpha-mj/chrtest.mj new file mode 100644 index 0000000..ddc0b8b --- /dev/null +++ b/samples/alpha-mj/chrtest.mj @@ -0,0 +1,11 @@ +program P +{ + void main() + { + print(chr(65),5); + print('A',5); + print(chr(10),2); + print(ord('a'),5); + print('a',5); + } +} diff --git a/samples/alpha-mj/div0.mj b/samples/alpha-mj/div0.mj new file mode 100644 index 0000000..bd92135 --- /dev/null +++ b/samples/alpha-mj/div0.mj @@ -0,0 +1,11 @@ +program test +{ + void main() + int i, j; + { + i = 100; + j = 0; + print(i/j); + } + +} \ No newline at end of file diff --git a/samples/alpha-mj/div2.mj b/samples/alpha-mj/div2.mj new file mode 100644 index 0000000..455b4af --- /dev/null +++ b/samples/alpha-mj/div2.mj @@ -0,0 +1,11 @@ +program test +{ + void main() + int i, j; + { + i = 100; + j = 2; + print(i/j); + } + +} \ No newline at end of file diff --git a/samples/alpha-mj/eratos.mj b/samples/alpha-mj/eratos.mj new file mode 100644 index 0000000..92d28f8 --- /dev/null +++ b/samples/alpha-mj/eratos.mj @@ -0,0 +1,47 @@ +program Eratos + + char[] sieve; + int max; // maximum prime to be found + int npp; // numbers per page + +{ + void put(int x) + { + if (npp == 10) { + print(chr(13)); + print(chr(10)); + npp = 0; + } + print(x, 5); + npp++; + } + + void found(int x) + int i; + { + put(x); + i = x; + while (i <= max) { + sieve[i] = 'o'; i = i + x; + } + } + + void main() + int i; + { + read(max); + npp = 0; + sieve = new char[max+1]; + i = 0; + while (i <= max) { + sieve[i] = 'x'; i++; + } + i = 2; + while (i <= max) { + found(i); + while(i <= max && sieve[i] == 'o') + i++; + } + } + +}//test \ No newline at end of file diff --git a/samples/alpha-mj/fields.mj b/samples/alpha-mj/fields.mj new file mode 100644 index 0000000..f29fb26 --- /dev/null +++ b/samples/alpha-mj/fields.mj @@ -0,0 +1,44 @@ +program F + class HolderClass { + int simple; + int[] arry; + } + + HolderClass holder; + +{ + void main() + int i, size; + { + holder = new HolderClass; + holder.simple = 5; + + print(holder.simple,10); + + print(chr(10)); + + size = 5; + holder.arry = new int[size]; + holder.arry[0] = size+1; + i = 1; + while (i < size){ + holder.arry[i] = holder.arry[i-1]-1; + i++; + } + + i = 0; + while (i < size){ + print(holder.arry[i],3); + i++; + } + print(chr(10)); + + i = 0; + while (i < size){ + holder.arry[i]--; + print(holder.arry[i],3); + i++; + } + + } +} \ No newline at end of file diff --git a/samples/alpha-mj/linkedlist.mj b/samples/alpha-mj/linkedlist.mj new file mode 100644 index 0000000..6d04746 --- /dev/null +++ b/samples/alpha-mj/linkedlist.mj @@ -0,0 +1,85 @@ +program linkedlist + class Element { + int info; + Element next; + } + Element first; +{ + void add(int i) + Element newone; + { + newone = new Element; + newone.info = i; + newone.next = first; + first = newone; + } + + void printlist() + Element cur; + { + cur = first; + while (cur != null) { + print(cur.info); + cur = cur.next; + } + } + + int exists(int i) Element cur; { + cur = first; + while (cur != null && cur.info != i) + cur = cur.next; + if (cur != null) + return 1; + else + return 0; + } + + int count(int i) Element cur; int c;{ + cur = first; + c = 0; + while (cur != null) { + if (cur.info == i) + c++; + cur = cur.next; + } + return c; + } + + void main() + int num; int in; int c; { + print('l'); + print('?'); + read(num); + // demo + if (num<0) { + add(1); + add(2); + add(3); + add(2); + printlist(); + print(exists(7)); + print(count(2)); + } else { + c = 0; + while (c