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
                               *
                              * *
                             *   *
                            * * * *
                           *       *
                          * *     * *
                         *   *   *   *
                        * * * * * * * *
                       *               *
                      * *             * *
                     *   *           *   *
                    * * * *         * * * *
                   *       *       *       *
                  * *     * *     * *     * *
                 *   *   *   *   *   *   *   *
                * * * * * * * * * * * * * * * *
               *                               *
              * *                             * *
             *   *                           *   *
            * * * *                         * * * *
           *       *                       *       *
          * *     * *                     * *     * *
         *   *   *   *                   *   *   *   *
        * * * * * * * *                 * * * * * * * *
       *               *               *               *
      * *             * *             * *             * *
     *   *           *   *           *   *           *   *
    * * * *         * * * *         * * * *         * * * *
   *       *       *       *       *       *       *       *
  * *     * *     * *     * *     * *     * *     * *     * *
 *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
将Java中的对象列表序列化为json   在同一Play Framework项目中同时使用Ebean和JPA的java   oop如何在整个Java项目中共享API密钥   java ADT Eclipse SDK故障未找到DDM   扫描程序中变量的递归Java输入值未应用于方法中的变量   java将空格转换为命令行类型的空格   JavaSpring,如何决定客户机应该使用哪个服务?   java致命异常:main(Android标准)   java编译错误是因为类型检查还是三元运算符?   java Sikuli+Webdriver:getting error x.png看起来像一个文件,但在磁盘上找不到。假设是文本   java选择位置。。。。ms sql 2005中需要电气状态   由于OSGi捆绑包依赖性问题,java无法启动RCP应用程序   json java gson fromjson返回非泛型的null   如何将google api访问令牌从java服务器传递到gapi javascript客户端?   java在已排序的LinkedList中添加元素   java ForkJoinPool为什么程序抛出OutOfMemoryError?   java SQUARE无法解析为Processing/Eclipse中的变量   java如何为Sun App Server 8.2设置JNDI