소스 검색

compilers

will 5 달 전
부모
커밋
c0820082d6
4개의 변경된 파일87개의 추가작업 그리고 5개의 파일을 삭제
  1. 67 5
      compiler.k
  2. 3 0
      fname
  3. 16 0
      tempST.k
  4. 1 0
      test

+ 67 - 5
compiler.k

@@ -1,12 +1,74 @@
-/ csv parser - e exclusive
-getrange: {[str;s;e] s_(e-1)#str};
+/helpers
+/ e exclusive
+slice: {[l;s;e] s_(e-1)#l};
+listize: {1_(,/(";",)'{"(",x,")"}'x)};
+
+tstkey: "States/Events"; / key indicating start of transition section
+cstkey: "Events"; / key indicating start of events condition section
+astkey: "Actions"; / key indicating start of actions section
+sectionkeys: (tstkey;cstkey;astkey);
 
 lines: 0: "tempST.csv";
 
 /csv parser
-parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;getrange[l].'r}
-parsel'lines
+parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;slice[l].'r};
+tempST: parsel'lines;
+tname: tempST[0;0];
+
+/ st compile
+/ separate sections
+si: (*'&'{(y~)'x}[*'tempST]'sectionkeys),(#tempST-1); / sections line numbers
+slices: si@(2':!#si);
+(t;c;a):1_'slice[tempST;] .'slices;
+
+/ postprocess sections
+s:*'t;
+t:2_'t;
+a:*'a;
+c:*'c;
+
+/ TODO: make dynamic
+args: `isOff `T ! `i `i;
+
+fname: tname,".k";
+kcode: "/ ",fname,".csv compiled\n\n";
+tstr: "";
+
+/a TODO: make dynamic
+avars: ("A",'$((!#a)+1))
+a:,[;"\"};\n"]'((,[;":{\""]'avars),'a);
+a: ,/a;
+avars: 1_,/(";",'avars);
+
+/c
+vars: {x,":args["}'$'!args;
+cargs:,[;"];"]'(vars,'($!#vars));
+cargs: ,/cargs;
+c:"{[args]",cargs,"(",listize[c],")}";
+
+/s
+s:,[;"\""]'("\"",'s);
+s:listize[s];
+
+/at
+at: ,/("`",'$:args@!args);
+
+/ t
+t:listize[listize't];
+
+kcode ,: a;
+kcode ,: ("a:(",avars,");\n");
+kcode ,: ("c:",c,";\n");
+kcode ,: ("s:(",s,");\n");
+kcode ,: ("t:(",t,");\n");
+kcode ,: ("at:",at,";\n");
+
+
+/ initialize data
+f:<`"tempST.k";
+f 0: kcode;
 
+/ -======== notes ========-
 / / how the parser works
 / t: lines[0];
 / comi: &t=","; / commas idx
@@ -15,4 +77,4 @@ parsel'lines
 / r: 2':!#comi; / ranges of comma separated parts
 / r: comi@r; / apply ranges to comma idx
 / r: (1 2#(0;r[0;0])),r; / add 0-first comma range
-/ getrange[t].'r
+/ slice[t].'r

+ 3 - 0
fname

@@ -0,0 +1,3 @@
+/ tempST.k.csv compiled
+
+

+ 16 - 0
tempST.k

@@ -0,0 +1,16 @@
+/ tempST.k.csv compiled
+
+A1:{"setFan[`l]"};
+A2:{"setFan[`m]"};
+A3:{"setFan[`h]"};
+A4:{"heaterPower[1]"};
+A5:{"ACPower[1]"};
+A6:{"allPower[0]"};
+A7:{"next"};
+A8:{"exit"};
+a:(A1;A2;A3;A4;A5;A6;A7;A8);
+c:{[args]isOff:args[0];T:args[1];((isOff);(T < 18);(T < 22);(T < 26);(T < 30))};
+s:(("Off");("FanLow");("FanMedium");("FanHigh");("Heating"));
+t:(((0N 1);(4 5);(1 2);(2 3);(3 4);(5 6));((6 1);(4 5);(0N 2);(2 3);(3 4);(5 6));((6 1);(4 5);(1 2);(0N 3);(3 4);(5 6));((6 1);(4 5);(1 2);(2 3);(0N 4);(5 6));((6 1);(0N 5);(1 2);(2 3);(3 4);(5 6)));
+at:`i`i;
+

+ 1 - 0
test

@@ -0,0 +1 @@
+tempST.k