Last active
August 29, 2015 14:25
-
-
Save ds84182/1717f8c3d15610ffe572 to your computer and use it in GitHub Desktop.
Programs made in Boop2's shell parser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define brainfuck_meminit { | |
//Initialize Brainfuck's memory array | |
$i=1; | |
while (lte $i 256) { | |
put memory $i 0; | |
inc $i > i | |
}; | |
delete i | |
}; | |
define brainfuck_init { | |
setlist memory; | |
setlist rstack; | |
setlist output; | |
setlist code $(split "" $args); | |
$pc=1;$ptr=1; | |
brainfuck_meminit | |
}; | |
define brainfuck_jmp { | |
//Process brainfuck jumps | |
if (equals $v "[") { | |
push rstack $pc | |
} elseif (equals $v "]") { | |
if (equals $memory[$ptr] 0) { | |
pop rstack | |
} else { | |
peek rstack > pc | |
} | |
} | |
}; | |
define brainfuck_process { | |
if (equals $v ">") { | |
inc $ptr > ptr | |
} elseif (equals $v "<") { | |
dec $ptr > ptr | |
} elseif (equals $v +) { | |
put memory $ptr $(inc $memory[$ptr]) | |
} elseif (equals $v -) { | |
put memory $ptr $(dec $memory[$ptr]) | |
} elseif (equals $v ".") { | |
push output $(char $memory[$ptr]) | |
} else { | |
brainfuck_jmp | |
} | |
}; | |
define brainfuck_deinit { | |
delete memory rstack output code pc | |
}; | |
define brainfuck { | |
brainfuck_init $args; | |
while (lte $pc #code) { | |
index code $pc > v; | |
brainfuck_process; | |
inc $pc > pc | |
}; | |
getlist output | concat; | |
brainfuck_deinit | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define range { | |
if (lt $# 1) { | |
say "Usage: range [start] end [step]" | |
} else { | |
local range_thread; | |
TODO: Finish | |
thread { | |
} > range_thread; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define rpn_op1 { | |
push stack $($(arg 1) $(pop stack) $(pop stack)) | |
}; | |
define rpn_op2 { | |
swap stack; push stack $($(arg 1) $(pop stack) $(pop stack)) | |
}; | |
define rpn_opers { | |
if (isnumber $v) { | |
push stack $v | |
} elseif (equals $v +) { | |
rpn_op1 add | |
} elseif (equals $v -) { | |
rpn_op2 sub | |
} elseif (equals $v *) { | |
rpn_op1 mul | |
} elseif (equals $v /) { | |
rpn_op2 div | |
} | |
}; | |
define rpn { | |
setlist stack; | |
arg all | setlist input; | |
while (gt $(getlength input) 0) { | |
pop input 1 > v; | |
rpn_opers | |
}; | |
getlist stack; | |
delete stack input v | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define map { | |
if (lt $# 3) { | |
say "Usage: map src dest func" | |
} else { | |
foreach map_v map_i in $(getlist $1) { | |
put $2 $map_i $(exec $3 $map_v $map_i) | |
} | |
} | |
}; | |
define filter { | |
local filter_out; | |
setlist filter_out; | |
foreach filter_x filter_y in $(getlist $1) { | |
if (exec $2 $filter_x $filter_y) { | |
push filter_out $filter_x | |
} | |
}; | |
getlist filter_out | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment