终于研究出了 brainfuck 函数与递归! - 哆啦比猫的技术瞎扯 - Arch Linux · ドラえもん · 实时绘制
终于研究出了 brainfuck 函数与递归!
哆啦比猫
posted @ 2012年8月25日 11:54
in brainfuck
with tags
brainfuck bf function recursion 递归 函数 brainsuck
, 2892 阅读
在学校闲得无聊,于是研究 brainfuck,没想到居然真的把函数与递归研究出来了!
原理很简单,就是:
// for easier understanding, the theory is written in C code
push(0); // function id = 0
push(1); // continue
while (pop()) {
id = pop();
if (!id) { // id == 0
push(0); // return value placeholder
push(1); // parameter
push(2); // when function ends, return to id==2
push(1); // goto function 1
push(1); // continue
}
else if (!--id) { // id == 1
do_something_with_param();
save_result_to_return_value();
push(1); // continue
}
else if (!--id) { // id == 2
pop(); // clean up pushed parameter
do_something_with_return_value();
pop(); // clean up return value
push(0); // do not continue
}
}
然后,可以研究高级语言到 bf 的转换了!所以:

凡未特殊声明(转载/翻译),所有文章均为原创。
by Giumo Xavier Clanjor (哆啦比猫/兰威举), 2010-2019.
本作品采用知识共享署名·非商业性使用·相同方式共享 3.0 中国大陆许可协议进行许可。
文中凡未特殊声明且未声明为引用的代码均以 MIT 协议授权。
blog comments powered by Disqus