Advertisement
Guest User

kFCK.ks

a guest
Nov 30th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. DECLARE PARAMETER input_file.
  2. SET output TO LIST().
  3. SET ERR TO 0.
  4. SET input TO LIST().
  5.  
  6. PRINT " kFCK v 0.0.1.2.3 ".
  7.  
  8. PRINT "++++++++++++++++++".
  9. PRINT " brainfuck to ks ".
  10. PRINT " interpreter* ".
  11. PRINT "++++++++++++++++++".
  12. PRINT ".".
  13. WAIT 0.2.
  14. PRINT ".".
  15. WAIT 0.2.
  16. PRINT ".".
  17. WAIT 0.2.
  18. PRINT ".".
  19. WAIT 0.2.
  20. PRINT " *in the most ".
  21. PRINT " liberal sense.".
  22.  
  23.  
  24.  
  25. RUN input_file.
  26. IF(input:LENGTH = 0) {
  27. PRINT "No program found.".
  28. SET ERR TO 1.
  29.  
  30. }ELSE{
  31. SET output TO LIST().
  32.  
  33. PRINT "Compiling: " + input_file.
  34. SET loop TO 0.
  35. FOR instruction IN input {
  36.  
  37. IF(instruction = "[") {
  38. SET loop TO loop + 1.
  39. output:ADD("UNTIL(stack[p] = 0) {").
  40. }.
  41.  
  42. IF(instruction = "]") {
  43. SET loop TO loop - 1.
  44. output:ADD("}.").
  45. }.
  46.  
  47. IF(instruction = ">") {
  48. output:ADD("SET p TO p + 1.").
  49. }.
  50.  
  51. IF(instruction = "<") {
  52. output:ADD("SET p TO p - 1.").
  53. }.
  54.  
  55. IF(instruction = "+") {
  56. output:ADD("SET stack[p] TO stack[p] + 1.").
  57. output:ADD("IF(stack[p] > 255){ SET stack[p] TO 0. }.").
  58. }.
  59.  
  60. IF(instruction = "-") {
  61. output:ADD("SET stack[p] TO stack[p] - 1.").
  62. output:ADD("IF(stack[p] < 0){ SET stack[p] TO 255. }.").
  63. }.
  64.  
  65. IF(instruction = ".") {
  66. output:ADD("result:ADD(stack[p]).").
  67. }.
  68.  
  69. IF(instruction = ",") {
  70. PRINT "ERROR: PROMPTY NIET SUPPORTY.".
  71. SET ERR TO 1.
  72. }.
  73. }.
  74.  
  75. IF (NOT(loop = 0)) {
  76. PRINT "ERROR: SYNTAX.".
  77. SET ERR TO 1.
  78. }.
  79. LOG "" TO kFCKout.ks.
  80. DELETE kFCKout.ks.
  81. FOR statement IN output {
  82. LOG statement TO kFCKout.ks.
  83. }.
  84.  
  85. PRINT "Executing program.".
  86.  
  87. IF(ERR) {
  88. PRINT "Anyway. HA!".
  89. }.
  90.  
  91. SET i TO 0.
  92. SET result TO LIST().
  93. SET stack TO LIST().
  94. UNTIL(i = 1024) { // ought to be enough for anybody...
  95. stack:ADD(0).
  96. SET i TO i + 1.
  97. }.
  98. SET p TO 0.
  99. RUN kFCKout.ks.
  100.  
  101. SET ascii TO LIST().
  102. PRINT "computing ASCII codes for your viewing pleasures:".
  103. // OH DEAR LORD
  104. ascii:ADD(" ").
  105. ascii:ADD("!").
  106. ascii:ADD("''").
  107. ascii:ADD("#").
  108. ascii:ADD("$").
  109. ascii:ADD("%").
  110. ascii:ADD("&").
  111. ascii:ADD("'").
  112. ascii:ADD("(").
  113. ascii:ADD(")").
  114. ascii:ADD("*").
  115. ascii:ADD("+").
  116. ascii:ADD(",").
  117. ascii:ADD("-").
  118. ascii:ADD(".").
  119. ascii:ADD("/").
  120. ascii:ADD("0").
  121. ascii:ADD("1").
  122. ascii:ADD("2").
  123. ascii:ADD("3").
  124. ascii:ADD("4").
  125. ascii:ADD("5").
  126. ascii:ADD("6").
  127. ascii:ADD("7").
  128. ascii:ADD("8").
  129. ascii:ADD("9").
  130. ascii:ADD(":").
  131. ascii:ADD(";").
  132. ascii:ADD("<").
  133. ascii:ADD("=").
  134. ascii:ADD(">").
  135. ascii:ADD("?").
  136. ascii:ADD("@").
  137. ascii:ADD("A").
  138. ascii:ADD("B").
  139. ascii:ADD("C").
  140. ascii:ADD("D").
  141. ascii:ADD("E").
  142. ascii:ADD("F").
  143. ascii:ADD("G").
  144. ascii:ADD("H").
  145. ascii:ADD("I").
  146. ascii:ADD("J").
  147. ascii:ADD("K").
  148. ascii:ADD("L").
  149. ascii:ADD("M").
  150. ascii:ADD("N").
  151. ascii:ADD("O").
  152. ascii:ADD("P").
  153. ascii:ADD("Q").
  154. ascii:ADD("R").
  155. ascii:ADD("S").
  156. ascii:ADD("T").
  157. ascii:ADD("U").
  158. ascii:ADD("V").
  159. ascii:ADD("W").
  160. ascii:ADD("X").
  161. ascii:ADD("Y").
  162. ascii:ADD("Z").
  163. ascii:ADD("[").
  164. ascii:ADD("\").
  165. ascii:ADD("]").
  166. ascii:ADD("^").
  167. ascii:ADD("_").
  168. ascii:ADD("`").
  169. ascii:ADD("a").
  170. ascii:ADD("b").
  171. ascii:ADD("c").
  172. ascii:ADD("d").
  173. ascii:ADD("e").
  174. ascii:ADD("f").
  175. ascii:ADD("g").
  176. ascii:ADD("h").
  177. ascii:ADD("i").
  178. ascii:ADD("j").
  179. ascii:ADD("k").
  180. ascii:ADD("l").
  181. ascii:ADD("m").
  182. ascii:ADD("n").
  183. ascii:ADD("o").
  184. ascii:ADD("p").
  185. ascii:ADD("q").
  186. ascii:ADD("r").
  187. ascii:ADD("s").
  188. ascii:ADD("t").
  189. ascii:ADD("u").
  190. ascii:ADD("v").
  191. ascii:ADD("w").
  192. ascii:ADD("x").
  193. ascii:ADD("y").
  194. ascii:ADD("z").
  195. ascii:ADD("{").
  196. ascii:ADD("|").
  197. ascii:ADD("}").
  198. ascii:ADD("~").
  199.  
  200. SET res TO "".
  201. FOR x IN result {
  202. IF(x > 31 AND x - 32 < ascii:LENGTH) {
  203. SET res TO res + ascii[x - 32].
  204. }.
  205. }.
  206. PRINT "OUTPUT: " + res.
  207. PRINT "DONE.".
  208. }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement