#编程语言 #可扩展语言 #语言 #解释器 #遗传 #学习

sbrain

这是一个用于评估语义脑(Semantic Brain),一种针对遗传编程应用优化的最小化多范式编程语言的库。

7 个版本 (4 个破坏性版本)

使用旧的 Rust 2015

0.99.0 2019 年 10 月 28 日
0.5.0 2019 年 4 月 19 日
0.4.2 2017 年 4 月 12 日
0.3.2 2016 年 7 月 19 日
0.2.1 2016 年 7 月 19 日

#208科学

43 每月下载量

GPL-2.0 许可证

22KB
252

libsbrain

crates.io docs on docs.rs

一个基于 Urban Müller 的著名但无法打印的语言的执行库。

如果您正在寻找一个独立的编译器/解释器,它被称为 sbic

什么是 SBrain?

SBrain,或称语义脑(Semantic Brain),是一种基于 Urban Müller 的著名语言,只有 8 个符号(3 位指令)。SBrain 的扩展将符号数量增加到 16 个(4 位指令)并添加了一个堆栈和寄存器。

示例

规范

数据结构

SBrain 需要

  • 一个可读写 数据带,其地址可达至少 65,536(0x0 - 0xFFFF)个 8 位单元。它们必须最初设置为零。
  • 一个可读写 数据堆栈,至少可容纳 256 个值。它们必须最初设置为零。
  • 一个只读带,其中包含可执行代码。该代码以至少六位宽的无符号整数表示。
  • 一个只读不可逆带,包含程序的输入(如 getch() 函数效果良好。)
  • 一个只写不可逆带,包含程序的输出(如 putch() 函数效果良好。)
  • 一个可读写寄存器(data_p),足够存储数据带上的位置
  • 一个可读写寄存器(inst_p),足够存储指令带上的位置
  • 一个可读写寄存器(auxi_r),大小与数据带上的单元相同

命令和源代码

SBrain 源代码由文本字符组成。可执行代码由六位宽的无符号整数组成。一个转换器通过一对一映射将源代码转换为可执行代码,有一个例外:所有位于 # 字符之间的数据,包括这些字符,都被转换器忽略。

前八条指令是标准的 brainf--- 指令。 任何 brainf--- 程序都是有效的 SBrain 程序,并且应该与标准、语义等效的 brainf--- 解释器的行为相同,只要注释正确转义。

十进制 代码 语义
    0|      <| Decrement `data_p`
    1|      >| Increment `data_p`
    2|      -| Subtract one from the cell pointed at by `data_p`
    3|      +| Add one to the cell pointed at by `data_p`
    4|      [| If the cell pointed at by `data_p` is zero, move `inst_p` to point to the matching `]`, plus one, or NOP if there is none.
    5|      ]| If the cell pointed at by `data_p` is nonzero, move `inst_p` to point to the matching `]`, plus one, or NOP if there is none.
    6|      .| Place the value in the cell pointed at by `data_p` on the output tape
    7|      ,| Place the next value from the input tape in the cell pointed at by `data_p`
    8|      {| Push the value from the cell pointed at by `data_p` onto the stack
    9|      }| Pop the next value from the stack into the cell pointed at by `data_p`
   10|      (| Set `auxi_r` to the value of the cell pointed at by `data_p`
   11|      )| Set the cell pointed at by `data_p` to the value in `auxi_r`
   12|      ^| Set the value in `auxi_r` to 0
   13|      !| Perform a bitwise NOT on the value in `auxi_r`.
   14|      &| Perform a bitwise AND on the value in `auxi_r` and the cell pointed at `data_p`, placing the value in `auxi_r`.
   15|      @| End the program. The exit code is the value in `auxi_r`. 

进一步规则

读取操作决不能干扰数据磁带上任何单元格。

读取文件结束标记(EOF)始终产生0。

源代码指令部分中的非命令字符必须忽略。

如果指令指针运行到磁带末尾,它必须回绕到开始。

无运行时依赖