Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE PARAMETER input_file.
- SET output TO LIST().
- SET ERR TO 0.
- SET input TO LIST().
- PRINT " kFCK v 0.0.1.2.3 ".
- PRINT "++++++++++++++++++".
- PRINT " brainfuck to ks ".
- PRINT " interpreter* ".
- PRINT "++++++++++++++++++".
- PRINT ".".
- WAIT 0.2.
- PRINT ".".
- WAIT 0.2.
- PRINT ".".
- WAIT 0.2.
- PRINT ".".
- WAIT 0.2.
- PRINT " *in the most ".
- PRINT " liberal sense.".
- RUN input_file.
- IF(input:LENGTH = 0) {
- PRINT "No program found.".
- SET ERR TO 1.
- }ELSE{
- SET output TO LIST().
- PRINT "Compiling: " + input_file.
- SET loop TO 0.
- FOR instruction IN input {
- IF(instruction = "[") {
- SET loop TO loop + 1.
- output:ADD("UNTIL(stack[p] = 0) {").
- }.
- IF(instruction = "]") {
- SET loop TO loop - 1.
- output:ADD("}.").
- }.
- IF(instruction = ">") {
- output:ADD("SET p TO p + 1.").
- }.
- IF(instruction = "<") {
- output:ADD("SET p TO p - 1.").
- }.
- IF(instruction = "+") {
- output:ADD("SET stack[p] TO stack[p] + 1.").
- output:ADD("IF(stack[p] > 255){ SET stack[p] TO 0. }.").
- }.
- IF(instruction = "-") {
- output:ADD("SET stack[p] TO stack[p] - 1.").
- output:ADD("IF(stack[p] < 0){ SET stack[p] TO 255. }.").
- }.
- IF(instruction = ".") {
- output:ADD("result:ADD(stack[p]).").
- }.
- IF(instruction = ",") {
- PRINT "ERROR: PROMPTY NIET SUPPORTY.".
- SET ERR TO 1.
- }.
- }.
- IF (NOT(loop = 0)) {
- PRINT "ERROR: SYNTAX.".
- SET ERR TO 1.
- }.
- LOG "" TO kFCKout.ks.
- DELETE kFCKout.ks.
- FOR statement IN output {
- LOG statement TO kFCKout.ks.
- }.
- PRINT "Executing program.".
- IF(ERR) {
- PRINT "Anyway. HA!".
- }.
- SET i TO 0.
- SET result TO LIST().
- SET stack TO LIST().
- UNTIL(i = 1024) { // ought to be enough for anybody...
- stack:ADD(0).
- SET i TO i + 1.
- }.
- SET p TO 0.
- RUN kFCKout.ks.
- SET ascii TO LIST().
- PRINT "computing ASCII codes for your viewing pleasures:".
- // OH DEAR LORD
- ascii:ADD(" ").
- ascii:ADD("!").
- ascii:ADD("''").
- ascii:ADD("#").
- ascii:ADD("$").
- ascii:ADD("%").
- ascii:ADD("&").
- ascii:ADD("'").
- ascii:ADD("(").
- ascii:ADD(")").
- ascii:ADD("*").
- ascii:ADD("+").
- ascii:ADD(",").
- ascii:ADD("-").
- ascii:ADD(".").
- ascii:ADD("/").
- ascii:ADD("0").
- ascii:ADD("1").
- ascii:ADD("2").
- ascii:ADD("3").
- ascii:ADD("4").
- ascii:ADD("5").
- ascii:ADD("6").
- ascii:ADD("7").
- ascii:ADD("8").
- ascii:ADD("9").
- ascii:ADD(":").
- ascii:ADD(";").
- ascii:ADD("<").
- ascii:ADD("=").
- ascii:ADD(">").
- ascii:ADD("?").
- ascii:ADD("@").
- ascii:ADD("A").
- ascii:ADD("B").
- ascii:ADD("C").
- ascii:ADD("D").
- ascii:ADD("E").
- ascii:ADD("F").
- ascii:ADD("G").
- ascii:ADD("H").
- ascii:ADD("I").
- ascii:ADD("J").
- ascii:ADD("K").
- ascii:ADD("L").
- ascii:ADD("M").
- ascii:ADD("N").
- ascii:ADD("O").
- ascii:ADD("P").
- ascii:ADD("Q").
- ascii:ADD("R").
- ascii:ADD("S").
- ascii:ADD("T").
- ascii:ADD("U").
- ascii:ADD("V").
- ascii:ADD("W").
- ascii:ADD("X").
- ascii:ADD("Y").
- ascii:ADD("Z").
- ascii:ADD("[").
- ascii:ADD("\").
- ascii:ADD("]").
- ascii:ADD("^").
- ascii:ADD("_").
- ascii:ADD("`").
- ascii:ADD("a").
- ascii:ADD("b").
- ascii:ADD("c").
- ascii:ADD("d").
- ascii:ADD("e").
- ascii:ADD("f").
- ascii:ADD("g").
- ascii:ADD("h").
- ascii:ADD("i").
- ascii:ADD("j").
- ascii:ADD("k").
- ascii:ADD("l").
- ascii:ADD("m").
- ascii:ADD("n").
- ascii:ADD("o").
- ascii:ADD("p").
- ascii:ADD("q").
- ascii:ADD("r").
- ascii:ADD("s").
- ascii:ADD("t").
- ascii:ADD("u").
- ascii:ADD("v").
- ascii:ADD("w").
- ascii:ADD("x").
- ascii:ADD("y").
- ascii:ADD("z").
- ascii:ADD("{").
- ascii:ADD("|").
- ascii:ADD("}").
- ascii:ADD("~").
- SET res TO "".
- FOR x IN result {
- IF(x > 31 AND x - 32 < ascii:LENGTH) {
- SET res TO res + ascii[x - 32].
- }.
- }.
- PRINT "OUTPUT: " + res.
- PRINT "DONE.".
- }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement