Custom programming language
It supported extensions in C++, for example, all basic types like int, float, string, array are not built-in, but written as an extension. Real script supported non-strict grammar. That meant that type can not only redefine operators, but define a new ones describing their behavoiur.
Here are some examples (an external class and qsort implementation):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
class qsort { function partition(array a,int left,int right,int pivotIndex) returns int; { int pivotValue = (int)a[pivotIndex]; int t1 = (int)a[right]; int t2 = (int)a[pivotIndex]; a.setValue(right,t2); a.setValue(pivotIndex,t1);
int storeIndex = left; int i = left; while (i<right) { t1 = (int)a[i]; if (t1<pivotValue) { t2 = (int)a[storeIndex]; a.setValue(i,t2); a.setValue(storeIndex,t1); storeIndex+=1; } i+=1; } t1 = (int)a[storeIndex]; t2 = (int)a[right]; a.setValue(storeIndex,t2); a.setValue(right,t1); return storeIndex; } function sort(array a,int left,int right) returns int; { int pivotIndex = left+right; pivotIndex = pivotIndex/2; int pni,v1,v2; if (right>left) { pni = partition(a,left,right,pivotIndex); v1 = pni-1; v1 = sort(a,left,v1); v2 = pni+1; v2 = sort(a,v2,right); } return 0; } function Main(); { array A; int n.read(); A.setSize(n,typeof(int)); int i = 0; while (i<n) { ((int)A[i]).read(); i+=1; } sort(A,0,n-1); i=0; while (i<n) { ((int)A[i]).write(); i+=1; } } }
|