Jelajahi Sumber

before all compilers

Will 2 bulan lalu
induk
melakukan
620d74cc8b
2 mengubah file dengan 45 tambahan dan 9 penghapusan
  1. 15 9
      SS.k
  2. 30 0
      test.k

+ 15 - 9
SS.k

@@ -2,12 +2,12 @@
 / e exclusive
 slice: {[l;s;e] s_(e-1)#l};
 listize: {1_(,/(";",)'{"(",x,")"}'x)};
-iscl: {i: `i$x; ((i>64) & (i<91))}; // is capital letter
-isdig: {i: `i$x; ((i>47) & (i<58))}; // is digit
-/ :`i$"A"; // 65
-/ :`i$"Z"; // 90
-/ :`i$"0"; // 48
-/ :`i$"9"; // 57
+split: {[l;di] idx: (-1,&(di~'l)),(#l); {slice[x;y[0]+1;y[1]+1]}[l]'(idx@(2':!#idx))};
+s2n: {[s] `i$s;}; // string to number
+parseidx: {core: slice[x;1;#x]; split[core;";"]};
+
+ :parseidx["[1;2]"];
+/:split["1;2;3";";"];
 
 tstkey: "States/Events"; / key indicating start of transition section
 cstkey: "Events"; / key indicating start of events condition section
@@ -20,10 +20,16 @@ lines: 0: "SS.csv";
 parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;slice[l].'r};
 csv: parsel'lines;
 
-:letters: &''(iscl'''csv);
-:digits: &''(isdig'''csv);
+kw:: "self";
+rep:: "t";
+
+deps:: (#csv;#csv[0])#0;
 
-csv@''letters
+fnr:{[l;k;rp] e:(#l)-(#k); r:!e; idx: &({y~x}[;k]'({slice[y;x;x+(#z)+1]}[;l;k]'r)); l{[last;x;y;z;r]left:x#last; right:(x+(#z))_last; (left,r,right;right)}[;;l;k;rp]/(|idx)};
+rd: {[r] deps[0;0]::1; r[0]}; // register dep
+dd: {[r] $[r[1;0]~"[";rd[r];r[0]]}; // detect dep
+/ :{[l;kw;rep] r: fnr[l;kw;rep]; $[(@r)=`C;r;dd[r]]}[;kw;rep]''csv;
+/ :deps;
 
 / initialize data
 / f:<`"compiled_ss.k";

+ 30 - 0
test.k

@@ -0,0 +1,30 @@
+/ :`i$"A"; // 65
+/ :`i$"Z"; // 90
+/ :`i$"0"; // 48
+/ :`i$"9"; // 57
+/ :`i$":"; // 58
+/ :`i$"$"; // 36
+
+testAtZ: { i:`i$x; $[(i>64) & (i<91);1;0] };
+test0t9: { i:`i$x; $[(i>47) & (i<58);1;0] };
+testcol: { i:`i$x; $[i=58;1;0] };
+testend: { i:`i$x; $[i=36;1;0] };
+
+s0: ((testAtZ; 1);(test0t9; 2));
+s1: ((test0t9; 2);(testcol; 3));
+s2: ((testend; 7); (testcol;5));
+s3: (,(testAtZ; 5));
+s4: ((testAtZ; 5); (test0t9; 6));
+s5: (,(testend; 7));
+s6: (,(testend; 7));
+s7: (({`0:"SUCCESS"};7));
+// 7 is done
+states:: (s0;s1;s2;s3;s4;s5;s6;s7);
+i: 1;
+
+run: {[str] str,:"$"; `0:str; s: 0; :o:s {[s;c] r:{t: x[0][y]; o:$[t;x[1];0]; o}[;c]'states[s]; `0:`k@(s;c;ns); ns:states@(&r); ns}\str;};
+
+// todo: don't be using $
+// prepare for matching pattern and returning the start index and length
+test: "A:A";
+run[test]