有一个extended version of bf它有一个goto
指令,?
。Brainf中的GOTO指令***
我知道理论上应该可以在经典的bf指令版本中模拟goto。我如何在实践中做到这一点?有没有existing bf goto pattern or algorithm?有没有办法将goto ?
指令转换为bf版本而无需转到?
指令?
有一个extended version of bf它有一个goto
指令,?
。Brainf中的GOTO指令***
我知道理论上应该可以在经典的bf指令版本中模拟goto。我如何在实践中做到这一点?有没有existing bf goto pattern or algorithm?有没有办法将goto ?
指令转换为bf版本而无需转到?
指令?
其实它并不那么复杂。你想的伪代码是这样的:
goflg := 1
while goflg do begin
// repeat this for each section
if goflg <> 0 then begin
goflg := goflg - 1
end else begin
// run your code in here and at the end
// set goflg to get to the section you want next.
end
// to here
// repeat this for each section
if goflg <> 0 then begin
goflg := goflg - 1
end else begin
// run your code in here and at the end
// set goflg to get to the section you want next.
end
// to here
end
你必须添加一个标志做ELSE部分,另一个,如果你想要做的IF部分without a copy但它是相当可行的。
我能想到的唯一方法就是通过使用brainfuck编写的brainfuck解释器来运行该程序(如dbfi)。通过一些修改,您可以添加新的说明,如LBL和GOTO。
唯一的问题是它会很慢。另一个问题是,你将不得不将实际的brainfuck程序存储在内存磁带上(最简单的方法就是通过输入程序,就像dbfi一样)。对于一个更“干净”的做法,你将不得不制作一个brainfuck程序,将实际的程序放在内存磁带上,以便解释器可以读取和运行它。
这当然不是一个非常优雅的方法,但我认为它实际上可能工作得很好,尽管它肯定会很慢。
谢谢,BF的编译器正是我想到的。不仅要实现goto,还要实现通用递归和指向函数的指针,我需要一个goto指令。 – vz0