gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
expanded sample size, first version master work v1.1.1
authorDoni Pracner <quinnuendo@gmail.com>
Wed, 18 Jan 2023 00:32:57 +0000 (01:32 +0100)
committerDoni Pracner <quinnuendo@gmail.com>
Wed, 18 Jan 2023 00:32:57 +0000 (01:32 +0100)
73 files changed:
samples/alpha-mj-exp/ArrayTest.mj [new file with mode: 0644]
samples/alpha-mj-exp/ArraysTest.mj [new file with mode: 0644]
samples/alpha-mj-exp/InOut1.mj [new file with mode: 0644]
samples/alpha-mj-exp/InOut2.mj [new file with mode: 0644]
samples/alpha-mj-exp/InOut3.mj [new file with mode: 0644]
samples/alpha-mj-exp/Palindromes.mj [new file with mode: 0644]
samples/alpha-mj-exp/PalindromesList.mj [new file with mode: 0644]
samples/alpha-mj-exp/Parentheses.mj [new file with mode: 0644]
samples/alpha-mj-exp/QuickSort.mj [new file with mode: 0644]
samples/alpha-mj-exp/Rek1.mj [new file with mode: 0644]
samples/alpha-mj-exp/RekFac.mj [new file with mode: 0644]
samples/alpha-mj-exp/RekFib.mj [new file with mode: 0644]
samples/alpha-mj-exp/SortColors.mj [new file with mode: 0644]
samples/alpha-mj-exp/chrtest.mj [new file with mode: 0644]
samples/alpha-mj-exp/div0.mj [new file with mode: 0644]
samples/alpha-mj-exp/div2.mj [new file with mode: 0644]
samples/alpha-mj-exp/eratos.mj [new file with mode: 0644]
samples/alpha-mj-exp/fields.mj [new file with mode: 0644]
samples/alpha-mj-exp/gcd-proc-input.mj [new file with mode: 0644]
samples/alpha-mj-exp/gcd-proc-predef.mj [new file with mode: 0644]
samples/alpha-mj-exp/gcd-rek-input.mj [new file with mode: 0644]
samples/alpha-mj-exp/gcd-rek-predef-m3.mj [new file with mode: 0644]
samples/alpha-mj-exp/linkedlist.mj [new file with mode: 0644]
samples/alpha-mj-exp/max-arr.mj [new file with mode: 0644]
samples/alpha-mj-exp/pos-neg.mj [new file with mode: 0644]
samples/alpha-mj-exp/sort-insert.mj [new file with mode: 0644]
samples/alpha-mj-exp/sort-selection.mj [new file with mode: 0644]
samples/alpha-mj-exp/while-print.mj [new file with mode: 0644]
tests/alpha-mj-exp/ArrayTest.txt [new file with mode: 0644]
tests/alpha-mj-exp/ArraysTest.txt [new file with mode: 0644]
tests/alpha-mj-exp/InOut1.txt [new file with mode: 0644]
tests/alpha-mj-exp/InOut2.txt [new file with mode: 0644]
tests/alpha-mj-exp/InOut3.1.txt [new file with mode: 0644]
tests/alpha-mj-exp/InOut3.2.txt [new file with mode: 0644]
tests/alpha-mj-exp/Palindromes1.txt [new file with mode: 0644]
tests/alpha-mj-exp/Palindromes2.txt [new file with mode: 0644]
tests/alpha-mj-exp/Palindromes3.txt [new file with mode: 0644]
tests/alpha-mj-exp/PalindromesList1.txt [new file with mode: 0644]
tests/alpha-mj-exp/PalindromesList2.txt [new file with mode: 0644]
tests/alpha-mj-exp/PalindromesList3.txt [new file with mode: 0644]
tests/alpha-mj-exp/Parentheses1.txt [new file with mode: 0644]
tests/alpha-mj-exp/Parentheses2.txt [new file with mode: 0644]
tests/alpha-mj-exp/QuickSort.txt [new file with mode: 0644]
tests/alpha-mj-exp/Rek1.txt [new file with mode: 0644]
tests/alpha-mj-exp/RekFac.txt [new file with mode: 0644]
tests/alpha-mj-exp/RekFib.txt [new file with mode: 0644]
tests/alpha-mj-exp/SortColors.txt [new file with mode: 0644]
tests/alpha-mj-exp/chrtest.txt [new file with mode: 0644]
tests/alpha-mj-exp/div0.txt [new file with mode: 0644]
tests/alpha-mj-exp/div2.txt [new file with mode: 0644]
tests/alpha-mj-exp/eratos.1.txt [new file with mode: 0644]
tests/alpha-mj-exp/eratos.2.txt [new file with mode: 0644]
tests/alpha-mj-exp/eratos.3.txt [new file with mode: 0644]
tests/alpha-mj-exp/fields.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-proc-input1.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-proc-input2.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-proc-input3.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-proc-predef.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-rek-input1.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-rek-input2.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-rek-input3.txt [new file with mode: 0644]
tests/alpha-mj-exp/gcd-rek-predef-m3.txt [new file with mode: 0644]
tests/alpha-mj-exp/linkedlist.1.txt [new file with mode: 0644]
tests/alpha-mj-exp/linkedlist.2.txt [new file with mode: 0644]
tests/alpha-mj-exp/linkedlist.3.txt [new file with mode: 0644]
tests/alpha-mj-exp/max-arr.txt [new file with mode: 0644]
tests/alpha-mj-exp/pos-neg.1.txt [new file with mode: 0644]
tests/alpha-mj-exp/pos-neg.2.txt [new file with mode: 0644]
tests/alpha-mj-exp/pos-neg.3.txt [new file with mode: 0644]
tests/alpha-mj-exp/sort-insert1.txt [new file with mode: 0644]
tests/alpha-mj-exp/sort-insert2.txt [new file with mode: 0644]
tests/alpha-mj-exp/sort-selection.txt [new file with mode: 0644]
tests/alpha-mj-exp/while-print.txt [new file with mode: 0644]

diff --git a/samples/alpha-mj-exp/ArrayTest.mj b/samples/alpha-mj-exp/ArrayTest.mj
new file mode 100644 (file)
index 0000000..c55ffd1
--- /dev/null
@@ -0,0 +1,20 @@
+program ArrayTest
+       int[] arr;
+       int i;
+       int max;
+{
+       void main(){
+               max = 10;
+               arr = new int[max];
+               i = 0;
+               while (i<max){
+                       arr[i] = max-i;
+                       i++;
+               }
+               i = 0;
+               while (i<len(arr)){
+                       print(arr[i],3);
+                       i++;
+               }
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/ArraysTest.mj b/samples/alpha-mj-exp/ArraysTest.mj
new file mode 100644 (file)
index 0000000..e9ae981
--- /dev/null
@@ -0,0 +1,29 @@
+program ArraysTest
+{
+       void rek_arr(int i)
+       int[] a; int loc, loc2; {
+               if (i>1){ 
+                               a = new int[i];
+                               loc = 0;
+                               loc2 = 1;
+                               while (loc<i){
+                                       a[loc] = loc2;
+                                       loc++;
+                                       loc2 = loc2 * i;
+                               }
+                               rek_arr(i-1);
+                               loc = 0;
+                               while (loc<i){
+                                       print(a[loc],3);
+                                       loc++;
+                               }
+                               print(0,5);
+               }
+       }
+
+       void main() int max;
+       {
+               max = 5;
+               rek_arr(max);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/InOut1.mj b/samples/alpha-mj-exp/InOut1.mj
new file mode 100644 (file)
index 0000000..1b9a499
--- /dev/null
@@ -0,0 +1,9 @@
+program InOut1{
+       void main()
+       int i;
+       {
+                       print('?');
+                       read(i);
+                       print(i);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/InOut2.mj b/samples/alpha-mj-exp/InOut2.mj
new file mode 100644 (file)
index 0000000..7c81f38
--- /dev/null
@@ -0,0 +1,10 @@
+program InOut2{
+       void main()
+       char c;
+       {
+                       print('c');
+                       print('?');
+                       read(c);
+                       print(c);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/InOut3.mj b/samples/alpha-mj-exp/InOut3.mj
new file mode 100644 (file)
index 0000000..73d7ddd
--- /dev/null
@@ -0,0 +1,23 @@
+program InOut3{
+       void main()
+       char c;
+       int i;
+       {
+                       i = 5;
+                       print('c');
+                       print('?');
+                       read(c);
+                       print(c);
+                       print(chr(10));
+                       if (c=='y') {
+                               print('i');
+                               read(i);
+                       } else {
+                               print('c');
+                               read(c);
+                       }
+                       print(chr(10));
+                       print(i,5);
+                       print(c,5);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/Palindromes.mj b/samples/alpha-mj-exp/Palindromes.mj
new file mode 100644 (file)
index 0000000..e3b0593
--- /dev/null
@@ -0,0 +1,171 @@
+program Palindromes {
+    // return a palindrome if it can be generated from given letters
+
+    char[] load() 
+               char[] res;
+        char in;
+               int c, num; {
+               print('l');
+               print('?');
+               read(num);
+               res = new char[num];
+                c = 0;
+                while (c<num) {
+                        print(c);
+                        print('?');
+                        read(in);
+                        if (ord(in) == 10) {
+                            read(in);
+                        }
+                        res[c] = in;
+                        c++;
+                }
+               return res;
+       }
+
+    char[] reverse(char[] arr) 
+    int i;
+    char[] res;
+    {
+        res = new char[len(arr)];
+        i = 0;
+        while (i < len(arr)) {
+            res[i] = arr[len(arr) - i - 1];
+            i++;
+        }
+        return res;
+    }
+
+    void printArr(char[] arr) 
+    int i;
+    {
+        print('[');
+        if (arr != null) {
+            i = 0;
+            while (i < len(arr)) {
+                print(arr[i], 3);
+                i++;
+            }
+        }    
+        print(']', 3);
+        print('\n');    
+    }   
+
+    char[] concatA(char[] arr1, char[] arr2) 
+    char[] res;
+    int i;
+    {
+        res = new char[len(arr1) + len(arr2)];
+        i = 0;
+        while (i < len(arr1)) {
+            res[i] = arr1[i];
+            i++;
+        }
+        while (i < len(res)) {
+            res[i] = arr2[i - len(arr1)];
+            i++;
+        }
+        
+        return res;
+    }
+
+    char[] copy(char[] arr, int counter) 
+    int i;
+    char[] res;
+    {
+        res = new char[counter];
+        i = 0;
+        while (i < len(res)) {
+            res[i] = arr[i];
+            i++;
+        }
+
+        return res;
+    }
+
+    char[] concatC(char[] arr, char character) 
+    char[] res;
+    int i;
+    {
+        res = new char[len(arr) + 1];
+        i = 0;
+        while (i < len(arr)) {
+            res[i] = arr[i];
+            i++;
+        }
+        res[i] = character;
+
+        return res;
+    }
+
+    char[] findPalindrome(char[] s) 
+    int[] letters;
+    int i, j, counter, ret;
+    char ch, oddChar;
+    char[] palindrome, palindromeRes;
+    {
+        letters = new int[26];
+        
+        i = 0;
+        while (i < len(letters)) {
+            letters[i] = 0;
+            i++;
+        }
+        
+        i = 0;
+        while (i < len(s)) {
+            if (ord(s[i]) >= 97 && ord(s[i]) <= 122) {
+                letters[ord(s[i]) - 97]++;
+            }
+            i++;
+        }
+        
+        oddChar = ' ';
+        palindrome = new char[len(s)];
+        counter = 0;
+        
+        i = 0;
+        ret = 1;
+        while (i < len(letters) && ret != 0) {
+            if (letters[i] > 0 && letters[i] % 2 == 0) {
+                j = 1;
+                while (j <= letters[i] / 2) {
+                    palindrome[counter] = chr(i + 97);
+                    counter++;
+                    j++;
+                }
+            } else if (letters[i] > 0 && oddChar == ' ') {
+                oddChar = chr(i + 97);
+                j = 1;
+                while (j <= letters[i] / 2) {
+                    palindrome[counter] = chr(i + 97);
+                    counter++;
+                    j++;
+                }
+            } else if (letters[i] % 2 != 0 && oddChar != ' ') {
+                ret = 0;
+            }
+
+            i++;
+        }
+
+        palindromeRes = copy(palindrome, counter);
+        
+        if (ret == 0) {
+            return null;
+        } else if (oddChar != ' ') {
+            return concatA(concatC(palindromeRes, oddChar), reverse(palindromeRes));
+        } else {
+            return concatA(palindromeRes, reverse(palindromeRes));
+        }
+    }
+    
+    void main() 
+    char[] input;
+    int response;
+    {
+        input = load();
+        printArr(input);
+        printArr(findPalindrome(input));
+    }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/PalindromesList.mj b/samples/alpha-mj-exp/PalindromesList.mj
new file mode 100644 (file)
index 0000000..5501943
--- /dev/null
@@ -0,0 +1,116 @@
+program PalindromesList
+    class Element {
+        char info;
+        Element prev, next;
+    }
+
+    Element first, last;
+{
+    void initList() {
+        first = null;
+        last = null;
+    }
+    
+    void addToEnd(char c) 
+       Element newone;
+       {       
+               newone = new Element;
+               newone.info = c;
+               newone.next = null;
+        newone.prev = null;
+
+        if (last == null) {
+            first = newone;
+            last = newone;
+        } else {
+            newone.prev = last;
+            last.next = newone;
+            last = newone;
+        }
+       }
+
+    void printSubword(Element start, Element end) 
+    Element curr;
+    {
+        curr = start;
+        while (curr != end) {
+            print(curr.info, 3);
+            curr = curr.next;
+        }
+        print(curr.info, 3);
+        print('\n');
+    }
+
+    int isPalindrome(Element start, Element end)
+    {
+        while (start != end && start.next != end) {
+            if (start.info != end.info) {
+                return 0;
+            } else {
+                start = start.next;
+                end = end.prev;
+            }
+        }
+
+        if (start.info == end.info) {
+            return 1;
+        }
+        return 0;
+    }
+
+    void printAllPalindromes()
+    Element start, end;
+    {
+        start = first;
+        while (start != null) {
+            end = last;
+            while (end != start) {
+                if (isPalindrome(start, end) == 1) {
+                    printSubword(start, end);
+                }
+                end = end.prev;
+            }
+            start = start.next;
+        }
+    }
+
+       void printlist() 
+       Element cur;
+       {
+               cur = first;
+               while (cur != null) {
+                       print(cur.info);
+                       cur = cur.next;
+               }
+               print('\n');
+       }
+
+    void load()
+    int num, c;
+    char in;
+    {
+        print('l');
+               print('?');
+               read(num);
+               c = 0;
+        while (c<num) {
+            print(c);
+            print('?');
+            read(in);
+            if (ord(in) == 10) {
+                read(in);
+            }
+            addToEnd(in);
+            c++;
+        }
+        print('l');
+        print(':');
+        printlist();
+    }
+
+    void main() 
+    {
+        load();
+        printAllPalindromes();
+    }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/Parentheses.mj b/samples/alpha-mj-exp/Parentheses.mj
new file mode 100644 (file)
index 0000000..d691ac7
--- /dev/null
@@ -0,0 +1,44 @@
+program Parentheses 
+{
+    // generate all possibilities of n pairs of parentheses
+    // so that they are valid (open - closed)
+    
+    void parentheses(char[] solution, int pos, int left, int right, int num) 
+    int i;
+    {
+        if (right == num) {
+            i = 0;
+            while (i < len(solution)) {
+                print(solution[i]);
+                print(' ');
+                i++;
+            }
+            print('\n');
+        } 
+        if (left < num) {
+            solution[pos] = '(';
+            parentheses(solution, pos+1, left+1, right, num);
+        }
+        if (left > right) {
+            solution[pos] = ')';
+            parentheses(solution, pos+1, left, right+1, num);
+        }
+    }
+
+    void pars(char[] sln, int num) {
+        if (num > 0) {
+            parentheses(sln, 0, 0, 0, num);
+        }
+    }
+
+    void main() 
+    int i, dimension;
+    char[] solution;
+    {
+        print('d');
+        print('?');
+        read(dimension);
+        solution = new char[2*dimension];
+        pars(solution, dimension);
+    }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/QuickSort.mj b/samples/alpha-mj-exp/QuickSort.mj
new file mode 100644 (file)
index 0000000..a50c25b
--- /dev/null
@@ -0,0 +1,76 @@
+program QuickSort {
+    int[] load() 
+               int[] res;
+               int c,num,in; {
+               print('l');
+               print('?');
+               read(num);
+               res = new int[num];
+                c = 0;
+                while (c<num) {
+                        print(c);
+                        print('?');
+                        read(in);
+                        res[c] = in;
+                        c++;
+                }
+               return res;
+       }
+
+       void printar(int[] arr) 
+               int c;
+       {
+               c = 0;
+               while (c < len(arr)) {
+                       print(arr[c]);
+                       print(' ');
+                       c++;
+               }
+               print(chr(10)); 
+       }
+       
+       int partition(int[] arr, int low, int high)
+    int pivot, i, j, temp;
+    {
+        pivot = arr[high];
+        i = low - 1;
+        j = low;
+
+        while (j < high) {
+            if (arr[j] < pivot) {
+                i++;
+
+                temp = arr[i];
+                arr[i] = arr[j];
+                arr[j] = temp;
+            }
+            j++;
+        }
+
+        temp = arr[i+1];
+        arr[i+1] = arr[high];
+        arr[high] = temp;
+        
+        return i + 1;
+    }
+    
+    void sort(int[] arr, int low, int high)
+       int p;
+       {
+               if (low < high) {
+            p = partition(arr, low, high);
+
+            sort(arr, low, p-1);
+            sort(arr, p+1, high);
+        }
+       }
+
+       void main() 
+               int[] arr;
+       {
+               arr = load();
+               printar(arr);   
+               sort(arr, 0, len(arr) - 1);
+               printar(arr);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/Rek1.mj b/samples/alpha-mj-exp/Rek1.mj
new file mode 100644 (file)
index 0000000..41ab83b
--- /dev/null
@@ -0,0 +1,11 @@
+program Rek1{
+       void func(int i){
+               print(i);
+               if (i>0) 
+                       func(i-1);
+       }
+       
+       void main() {
+               func(5);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/RekFac.mj b/samples/alpha-mj-exp/RekFac.mj
new file mode 100644 (file)
index 0000000..674cc14
--- /dev/null
@@ -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-exp/RekFib.mj b/samples/alpha-mj-exp/RekFib.mj
new file mode 100644 (file)
index 0000000..d3a59a5
--- /dev/null
@@ -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-exp/SortColors.mj b/samples/alpha-mj-exp/SortColors.mj
new file mode 100644 (file)
index 0000000..231e22d
--- /dev/null
@@ -0,0 +1,64 @@
+program SortColors {
+    // array with n objects colored red, white or blue
+    // sort so that the same colored objects are adjacent
+    // red, white, blue = 0, 1, 2 (values in array)
+
+    void sortColors(int[] nums) 
+    int p0, p1, p2, temp;
+    {
+        p0 = 0;
+        p1 = 0;
+        p2 = len(nums) - 1;
+
+        while (p1 <= p2) {
+            if (nums[p1] == 0) {
+                temp = nums[p0];
+                nums[p0] = nums[p1];
+                nums[p1] = temp;
+                p0 = p0 + 1;
+                p1 = p1 + 1;
+            } else if (nums[p1] == 1) {
+                p1 = p1 + 1;
+            } else {
+                temp = nums[p1];
+                nums[p1] = nums[p2];
+                nums[p2] = temp;
+                p2 = p2 - 1;
+            }
+        }
+    }
+
+    void printArr(int[] nums) 
+    int i;
+    {
+        i = 0;
+        print('\n');
+        print('[');
+        while (i < len(nums)) {
+            print(nums[i], 2);
+            i++;
+        }
+        print(']', 2);
+    }
+
+    void main()
+    int n, i;
+    int[] nums;
+    {
+        print('n');
+        print('?');
+        read(n);
+        nums = new int[n];
+        i = 0;
+        while (i < n) {
+            print('n');
+            print(i);
+            print('?');
+            print(' ');
+            read(nums[i]);
+            i++;
+        }
+        sortColors(nums);
+        printArr(nums);
+    }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/chrtest.mj b/samples/alpha-mj-exp/chrtest.mj
new file mode 100644 (file)
index 0000000..ddc0b8b
--- /dev/null
@@ -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-exp/div0.mj b/samples/alpha-mj-exp/div0.mj
new file mode 100644 (file)
index 0000000..bd92135
--- /dev/null
@@ -0,0 +1,11 @@
+program test\r
+{\r
+       void main()\r
+               int i, j;\r
+       {\r
+               i = 100; \r
+               j = 0;\r
+               print(i/j);\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/div2.mj b/samples/alpha-mj-exp/div2.mj
new file mode 100644 (file)
index 0000000..455b4af
--- /dev/null
@@ -0,0 +1,11 @@
+program test\r
+{\r
+       void main()\r
+               int i, j;\r
+       {\r
+               i = 100; \r
+               j = 2;\r
+               print(i/j);\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/eratos.mj b/samples/alpha-mj-exp/eratos.mj
new file mode 100644 (file)
index 0000000..92d28f8
--- /dev/null
@@ -0,0 +1,47 @@
+program Eratos\r
+\r
+       char[] sieve;\r
+       int max;                // maximum prime to be found\r
+       int npp;                // numbers per page\r
+\r
+{\r
+       void put(int x)\r
+       {\r
+               if (npp == 10) {\r
+                       print(chr(13)); \r
+                       print(chr(10)); \r
+                       npp = 0;\r
+               }\r
+               print(x, 5);\r
+               npp++;\r
+       }\r
+       \r
+       void found(int x)\r
+               int i;\r
+       {\r
+               put(x);\r
+               i = x;\r
+               while (i <= max) {\r
+                       sieve[i] = 'o'; i = i + x;\r
+               }\r
+       }\r
+\r
+       void main()\r
+               int i;\r
+       {\r
+               read(max);\r
+               npp = 0;\r
+               sieve = new char[max+1];\r
+               i = 0;\r
+               while (i <= max) {\r
+                       sieve[i] = 'x'; i++;\r
+               }\r
+               i = 2;\r
+               while (i <= max) {\r
+                       found(i);\r
+                       while(i <= max && sieve[i] == 'o') \r
+                               i++;\r
+               }\r
+       }\r
+\r
+}//test
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/fields.mj b/samples/alpha-mj-exp/fields.mj
new file mode 100644 (file)
index 0000000..f29fb26
--- /dev/null
@@ -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-exp/gcd-proc-input.mj b/samples/alpha-mj-exp/gcd-proc-input.mj
new file mode 100644 (file)
index 0000000..ce38aaa
--- /dev/null
@@ -0,0 +1,26 @@
+program procgcdinput{
+
+       int gcd(int a, int b)
+       {
+               while (a != b) {
+                       if (a>b) 
+                               a = a-b;
+                       if (a<b)
+                               b = b-a;
+               }
+               return a;
+       }
+       
+       void main()
+               int a;
+               int b;
+       {
+               print('a');
+               print('?');
+               read(a);
+               print('b');
+               print('?');
+               read(b);
+               print(gcd(a,b),3);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/gcd-proc-predef.mj b/samples/alpha-mj-exp/gcd-proc-predef.mj
new file mode 100644 (file)
index 0000000..e476649
--- /dev/null
@@ -0,0 +1,20 @@
+program procgcdinput{
+
+       int gcd(int a, int b)
+       {
+               while (a != b) {
+                       if (a>b) 
+                               a = a-b;
+                       if (a<b)
+                               b = b-a;
+               }
+               return a;
+       }
+       
+       void main()
+               int a;
+               int b;
+       {
+               print(gcd(12,8),3);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/gcd-rek-input.mj b/samples/alpha-mj-exp/gcd-rek-input.mj
new file mode 100644 (file)
index 0000000..20d067a
--- /dev/null
@@ -0,0 +1,24 @@
+program rekgcdinput{
+
+       int gcd(int a, int b)
+       {
+               if (a>b) 
+                       return gcd(a-b,b);
+               if (a<b)
+                       return gcd(a,b-a);
+               return a;
+       }
+       
+       void main()
+               int a;
+               int b;
+       {
+               print('a');
+               print('?');
+               read(a);
+               print('b');
+               print('?');
+               read(b);
+               print(gcd(a,b),3);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/gcd-rek-predef-m3.mj b/samples/alpha-mj-exp/gcd-rek-predef-m3.mj
new file mode 100644 (file)
index 0000000..0b0a011
--- /dev/null
@@ -0,0 +1,18 @@
+program RekGCD{
+
+       int gcd(int a, int b)
+       {
+               if (a>b) 
+                       return gcd(a-b,b);
+               if (a<b)
+                       return gcd(a,b-a);
+               return a;
+       }
+       
+       void main()
+       {
+               print(gcd(8,12),3);
+               print(gcd(9,31),3);
+               print(gcd(164,88),3);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/linkedlist.mj b/samples/alpha-mj-exp/linkedlist.mj
new file mode 100644 (file)
index 0000000..6d04746
--- /dev/null
@@ -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<num) {
+                               print(c);
+                               print('?');
+                               read(in);
+                               add(in);
+                               c++;
+                       }
+                       printlist();
+
+                       print('e');
+                       print('?');
+
+                       read(in);
+                       print(exists(in));
+
+                       print('c');
+                       print('?');
+                       read(in);
+                       print(count(in));
+               }
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/max-arr.mj b/samples/alpha-mj-exp/max-arr.mj
new file mode 100644 (file)
index 0000000..66a3168
--- /dev/null
@@ -0,0 +1,60 @@
+// load an array of ints and print the maximum
+program max_arr {
+       int[] load() 
+               int[] res;
+               int c,num,in; {
+               print('l');
+               print('e');
+               print('n');
+               print('g');
+               print('t');
+               print('h');
+               print('?');
+               read(num);
+               res = new int[num];
+                c = 0;
+                while (c<num) {
+                        print(c);
+                        print('?');
+                        read(in);
+                        res[c] = in;
+                        c++;
+                }
+               return res;
+       }
+
+       void printar(int[] arr) 
+               int c;
+       {
+               c = 0;
+               while (c < len(arr)) {
+                       print(arr[c]);
+                       print(' ');
+                       c++;
+               }
+               print(chr(10)); 
+       }
+
+       int max(int[] arr)
+               int c, max;
+       {
+               if (len(arr) == 0)
+                  return 0;
+               max = arr[0];
+               c = 1;
+               while (c < len(arr)) {
+                     if (max < arr[c])
+                        max = arr[c];
+                     c++;
+               }
+               return max;
+       }
+       
+       void main() 
+               int[] arr;
+       {
+               arr = load();
+               printar(arr);   
+               print(max(arr));
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/pos-neg.mj b/samples/alpha-mj-exp/pos-neg.mj
new file mode 100644 (file)
index 0000000..79fd454
--- /dev/null
@@ -0,0 +1,42 @@
+program P
+       final int size = 10;
+       class Table {
+               int[] pos;
+               int[] neg;
+       }
+       Table val;
+{
+       void main()
+               int x, i;
+       { //---------- Initialize val
+               val = new Table;
+               val.pos = new int[size]; 
+               val.neg = new int[size];
+               i = 0;
+               while (i < size) {
+                       val.pos[i] = 0; 
+                       val.neg[i] = 0;
+                       i++;
+               }
+       //---------- Read values
+               read(x);
+               while (x != 0) {
+                       if (0 <= x && x < size) {
+                               val.pos[x]++;
+                       } else if (-size < x && x < 0) {
+                               val.neg[-x]++;
+                       }
+                       read(x);
+               }
+       
+       // output everything
+               i = 0;
+               while (i < size) {
+                       print(i,3);
+                       print(val.pos[i],5);
+                       print(val.neg[i],5);
+                       print(chr(10));
+                       i++;
+               }
+       }
+}
diff --git a/samples/alpha-mj-exp/sort-insert.mj b/samples/alpha-mj-exp/sort-insert.mj
new file mode 100644 (file)
index 0000000..d523f4a
--- /dev/null
@@ -0,0 +1,58 @@
+program sort {
+       
+       int[] load() 
+               int[] res;
+               int c,num,in; {
+               print('l');
+               print('?');
+               read(num);
+               res = new int[num];
+                c = 0;
+                while (c<num) {
+                        print(c);
+                        print('?');
+                        read(in);
+                        res[c] = in;
+                        c++;
+                }
+               return res;
+       }
+
+       void printar(int[] arr) 
+               int c;
+       {
+               c = 0;
+               while (c < len(arr)) {
+                       print(arr[c]);
+                       print(' ');
+                       c++;
+               }
+               print(chr(10)); 
+       }
+       
+       void sort(int[] arr)
+               int i,j,t;
+       {
+               i = 1;
+               while (i < len(arr)) {
+                       j = i;
+                       t = arr[j];
+                       while (j > 0 && t < arr[j-1]) {
+                               arr[j]=arr[j-1];
+                               j = j - 1;
+                       }
+                       arr[j] = t;
+                       i++;
+               }
+
+       }
+
+       void main() 
+               int[] arr;
+       {
+               arr = load();
+               printar(arr);   
+               sort(arr);
+               printar(arr);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/sort-selection.mj b/samples/alpha-mj-exp/sort-selection.mj
new file mode 100644 (file)
index 0000000..12abf89
--- /dev/null
@@ -0,0 +1,63 @@
+program SelectionSort {
+    int[] load() 
+               int[] res;
+               int c,num,in; {
+               print('l');
+               print('?');
+               read(num);
+               res = new int[num];
+                c = 0;
+                while (c<num) {
+                        print(c);
+                        print('?');
+                        read(in);
+                        res[c] = in;
+                        c++;
+                }
+               return res;
+       }
+
+       void printar(int[] arr) 
+               int c;
+       {
+               c = 0;
+               while (c < len(arr)) {
+                       print(arr[c]);
+                       print(' ');
+                       c++;
+               }
+               print(chr(10)); 
+       }
+       
+       void sort(int[] arr)
+               int i, j, min, temp;
+       {
+               i = 0;
+               while (i < len(arr) - 1) {
+                       min = i;
+            j = i + 1;
+                       while (j < len(arr)) {
+                               if (arr[j] < arr[min]) {
+                    min = j;
+                }
+                               j++;
+                       }
+
+            temp = arr[min];
+            arr[min] = arr[i];
+            arr[i] = temp;
+
+                       i++;
+               }
+
+       }
+
+       void main() 
+               int[] arr;
+       {
+               arr = load();
+               printar(arr);   
+               sort(arr);
+               printar(arr);
+       }
+}
\ No newline at end of file
diff --git a/samples/alpha-mj-exp/while-print.mj b/samples/alpha-mj-exp/while-print.mj
new file mode 100644 (file)
index 0000000..cdc0851
--- /dev/null
@@ -0,0 +1,12 @@
+program P\r
+{\r
+       void main()\r
+               int i;\r
+       { \r
+               i = 0;\r
+               while (i < 5) {\r
+                       print(i);\r
+                       i = i + 1;\r
+               }\r
+       }\r
+}\r
diff --git a/tests/alpha-mj-exp/ArrayTest.txt b/tests/alpha-mj-exp/ArrayTest.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/ArraysTest.txt b/tests/alpha-mj-exp/ArraysTest.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/InOut1.txt b/tests/alpha-mj-exp/InOut1.txt
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/tests/alpha-mj-exp/InOut2.txt b/tests/alpha-mj-exp/InOut2.txt
new file mode 100644 (file)
index 0000000..7898192
--- /dev/null
@@ -0,0 +1 @@
+a
diff --git a/tests/alpha-mj-exp/InOut3.1.txt b/tests/alpha-mj-exp/InOut3.1.txt
new file mode 100644 (file)
index 0000000..73bb0ff
--- /dev/null
@@ -0,0 +1,2 @@
+y
+5
diff --git a/tests/alpha-mj-exp/InOut3.2.txt b/tests/alpha-mj-exp/InOut3.2.txt
new file mode 100644 (file)
index 0000000..76a64b1
--- /dev/null
@@ -0,0 +1,2 @@
+n
+A
diff --git a/tests/alpha-mj-exp/Palindromes1.txt b/tests/alpha-mj-exp/Palindromes1.txt
new file mode 100644 (file)
index 0000000..c4b8f1b
--- /dev/null
@@ -0,0 +1,16 @@
+15
+a
+n
+a
+v
+o
+l
+i
+m
+i
+l
+o
+v
+a
+n
+a
diff --git a/tests/alpha-mj-exp/Palindromes2.txt b/tests/alpha-mj-exp/Palindromes2.txt
new file mode 100644 (file)
index 0000000..980b70b
--- /dev/null
@@ -0,0 +1,15 @@
+14
+n
+e
+v
+e
+r
+o
+d
+d
+o
+r
+e
+v
+e
+n
diff --git a/tests/alpha-mj-exp/Palindromes3.txt b/tests/alpha-mj-exp/Palindromes3.txt
new file mode 100644 (file)
index 0000000..767501d
--- /dev/null
@@ -0,0 +1,7 @@
+6
+a
+b
+a
+b
+a
+b
diff --git a/tests/alpha-mj-exp/PalindromesList1.txt b/tests/alpha-mj-exp/PalindromesList1.txt
new file mode 100644 (file)
index 0000000..c4b8f1b
--- /dev/null
@@ -0,0 +1,16 @@
+15
+a
+n
+a
+v
+o
+l
+i
+m
+i
+l
+o
+v
+a
+n
+a
diff --git a/tests/alpha-mj-exp/PalindromesList2.txt b/tests/alpha-mj-exp/PalindromesList2.txt
new file mode 100644 (file)
index 0000000..4b6d7fc
--- /dev/null
@@ -0,0 +1,7 @@
+6
+a
+b
+a
+k
+u
+s
diff --git a/tests/alpha-mj-exp/PalindromesList3.txt b/tests/alpha-mj-exp/PalindromesList3.txt
new file mode 100644 (file)
index 0000000..4c7f0bd
--- /dev/null
@@ -0,0 +1,25 @@
+24
+n
+e
+k
+o
+l
+i
+k
+o
+b
+r
+o
+d
+s
+k
+i
+h
+k
+a
+p
+a
+k
+a
diff --git a/tests/alpha-mj-exp/Parentheses1.txt b/tests/alpha-mj-exp/Parentheses1.txt
new file mode 100644 (file)
index 0000000..00750ed
--- /dev/null
@@ -0,0 +1 @@
+3
diff --git a/tests/alpha-mj-exp/Parentheses2.txt b/tests/alpha-mj-exp/Parentheses2.txt
new file mode 100644 (file)
index 0000000..b8626c4
--- /dev/null
@@ -0,0 +1 @@
+4
diff --git a/tests/alpha-mj-exp/QuickSort.txt b/tests/alpha-mj-exp/QuickSort.txt
new file mode 100644 (file)
index 0000000..d14e0f2
--- /dev/null
@@ -0,0 +1,8 @@
+7
+10
+80
+30
+90
+40
+50
+70
diff --git a/tests/alpha-mj-exp/Rek1.txt b/tests/alpha-mj-exp/Rek1.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/RekFac.txt b/tests/alpha-mj-exp/RekFac.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/RekFib.txt b/tests/alpha-mj-exp/RekFib.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/SortColors.txt b/tests/alpha-mj-exp/SortColors.txt
new file mode 100644 (file)
index 0000000..fad12d4
--- /dev/null
@@ -0,0 +1,7 @@
+6
+0
+1
+2
+2
+1
+0
diff --git a/tests/alpha-mj-exp/chrtest.txt b/tests/alpha-mj-exp/chrtest.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/div0.txt b/tests/alpha-mj-exp/div0.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/div2.txt b/tests/alpha-mj-exp/div2.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/eratos.1.txt b/tests/alpha-mj-exp/eratos.1.txt
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/tests/alpha-mj-exp/eratos.2.txt b/tests/alpha-mj-exp/eratos.2.txt
new file mode 100644 (file)
index 0000000..209e3ef
--- /dev/null
@@ -0,0 +1 @@
+20
diff --git a/tests/alpha-mj-exp/eratos.3.txt b/tests/alpha-mj-exp/eratos.3.txt
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/alpha-mj-exp/fields.txt b/tests/alpha-mj-exp/fields.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/gcd-proc-input1.txt b/tests/alpha-mj-exp/gcd-proc-input1.txt
new file mode 100644 (file)
index 0000000..0cf20a0
--- /dev/null
@@ -0,0 +1,2 @@
+12
+8
diff --git a/tests/alpha-mj-exp/gcd-proc-input2.txt b/tests/alpha-mj-exp/gcd-proc-input2.txt
new file mode 100644 (file)
index 0000000..8766764
--- /dev/null
@@ -0,0 +1,3 @@
+64
+18
+
diff --git a/tests/alpha-mj-exp/gcd-proc-input3.txt b/tests/alpha-mj-exp/gcd-proc-input3.txt
new file mode 100644 (file)
index 0000000..9acca31
--- /dev/null
@@ -0,0 +1,2 @@
+15
+125
diff --git a/tests/alpha-mj-exp/gcd-proc-predef.txt b/tests/alpha-mj-exp/gcd-proc-predef.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/gcd-rek-input1.txt b/tests/alpha-mj-exp/gcd-rek-input1.txt
new file mode 100644 (file)
index 0000000..0cf20a0
--- /dev/null
@@ -0,0 +1,2 @@
+12
+8
diff --git a/tests/alpha-mj-exp/gcd-rek-input2.txt b/tests/alpha-mj-exp/gcd-rek-input2.txt
new file mode 100644 (file)
index 0000000..8766764
--- /dev/null
@@ -0,0 +1,3 @@
+64
+18
+
diff --git a/tests/alpha-mj-exp/gcd-rek-input3.txt b/tests/alpha-mj-exp/gcd-rek-input3.txt
new file mode 100644 (file)
index 0000000..9acca31
--- /dev/null
@@ -0,0 +1,2 @@
+15
+125
diff --git a/tests/alpha-mj-exp/gcd-rek-predef-m3.txt b/tests/alpha-mj-exp/gcd-rek-predef-m3.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/alpha-mj-exp/linkedlist.1.txt b/tests/alpha-mj-exp/linkedlist.1.txt
new file mode 100644 (file)
index 0000000..d7d17fc
--- /dev/null
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/tests/alpha-mj-exp/linkedlist.2.txt b/tests/alpha-mj-exp/linkedlist.2.txt
new file mode 100644 (file)
index 0000000..3e91576
--- /dev/null
@@ -0,0 +1,7 @@
+4
+1
+2
+1
+4
+4
+1
diff --git a/tests/alpha-mj-exp/linkedlist.3.txt b/tests/alpha-mj-exp/linkedlist.3.txt
new file mode 100644 (file)
index 0000000..3c7a1eb
--- /dev/null
@@ -0,0 +1,7 @@
+4
+1
+2
+3
+4
+5
+6
diff --git a/tests/alpha-mj-exp/max-arr.txt b/tests/alpha-mj-exp/max-arr.txt
new file mode 100644 (file)
index 0000000..b421190
--- /dev/null
@@ -0,0 +1,5 @@
+4
+3
+7
+5
+2
diff --git a/tests/alpha-mj-exp/pos-neg.1.txt b/tests/alpha-mj-exp/pos-neg.1.txt
new file mode 100644 (file)
index 0000000..8b421d0
--- /dev/null
@@ -0,0 +1,6 @@
+1
+2
+3
+3
+-5
+0
diff --git a/tests/alpha-mj-exp/pos-neg.2.txt b/tests/alpha-mj-exp/pos-neg.2.txt
new file mode 100644 (file)
index 0000000..40498b6
--- /dev/null
@@ -0,0 +1,8 @@
+1
+1
+1
+1
+1
+1
+1
+0
diff --git a/tests/alpha-mj-exp/pos-neg.3.txt b/tests/alpha-mj-exp/pos-neg.3.txt
new file mode 100644 (file)
index 0000000..a477792
--- /dev/null
@@ -0,0 +1,3 @@
+11
+77
+0
diff --git a/tests/alpha-mj-exp/sort-insert1.txt b/tests/alpha-mj-exp/sort-insert1.txt
new file mode 100644 (file)
index 0000000..b421190
--- /dev/null
@@ -0,0 +1,5 @@
+4
+3
+7
+5
+2
diff --git a/tests/alpha-mj-exp/sort-insert2.txt b/tests/alpha-mj-exp/sort-insert2.txt
new file mode 100644 (file)
index 0000000..4934959
--- /dev/null
@@ -0,0 +1,5 @@
+4
+1
+2
+3
+4
diff --git a/tests/alpha-mj-exp/sort-selection.txt b/tests/alpha-mj-exp/sort-selection.txt
new file mode 100644 (file)
index 0000000..254e1d4
--- /dev/null
@@ -0,0 +1,11 @@
+10
+64
+25
+12
+22
+11
+6
+-1
+20
+65
+120
diff --git a/tests/alpha-mj-exp/while-print.txt b/tests/alpha-mj-exp/while-print.txt
new file mode 100644 (file)
index 0000000..e69de29
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner