python中的brainfuck解释器。
brainfuck的Python项目详细描述
brainfucky是一个用python编写的brainfuck解释器。
关于Brainfuck
brainfuck是一种深奥的编程语言。语言只有8个符号, 每个执行特定功能,请参见下文。
^{tt1}$ | Increment the value of current cell by 1. |
^{tt2}$ | Decrement the value of current cell by 1. |
^{tt3}$ | Move the current cell pointer to right, increment the pointer by 1. |
^{tt4}$ | Move the current cell pointer to left, decrement the pointer by 1. |
^{tt5}$ | Print the ascii character corresponding to the value of current cell. |
^{tt6}$ | Take an ascii input from user, and store its ascii value in current cell |
^{tt7}$ | if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ^{tt8}$ command. |
^{tt8}$ | if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching ^{tt7}$ command. |
关于实现
- 在内存元素中,使用pythonlist模拟磁带。
- 列表中第i个元素的值对应于单元格i的值。
- 单元格指针用于指向当前单元格。
- +和-递增单元格指针指向的单元格值。
- >和<有效地递增和递减单元格指针,移动 带子是左是右。
- 块中的指令在最后一个执行结束时执行 指令,检查当前单元格的值,如果为0,则继续,否则 再次执行块。
安装
$ pip install brainfucky
运行
要运行Brainfuck程序,请执行以下操作
$ brainfucky --file examples/hello_world.bf executing file examples/hello_world.bf Hello World! $ brainfucky --file examples/triangle.bf executing file examples/triangle.bf * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *