差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
| mozeinn:rjyl [2025/12/06 03:35] – Thakin Syltus Chau | mozeinn:rjyl [2025/12/06 18:59] (当前版本) – [Transfer from Brainfuck] Thakin Syltus Chau | ||
|---|---|---|---|
| 行 29: | 行 29: | ||
| **革故鼎新** is an Esolang and it's a derivative of [[https:// | **革故鼎新** is an Esolang and it's a derivative of [[https:// | ||
| - | Its syntax is same as Brainfuck. | + | Its syntax is same as Brainfuck's. |
| - | ==== Command | + | ==== Syntax |
| + | |||
| + | **Command** | ||
| ^ 革故鼎新 | ^ 革故鼎新 | ||
| ^ 标新立异 | ^ 标新立异 | ||
| 行 44: | 行 46: | ||
| ==== Example ==== | ==== Example ==== | ||
| - | **Cat** | + | === Cat === |
| < | < | ||
| - | 实事求是 革故鼎新 精益求精 实事求是 标新立异 | + | 实事求是 |
| + | </ | ||
| + | === Hello World === | ||
| + | < | ||
| + | 革故鼎新 | ||
| + | </ | ||
| + | |||
| + | ==== Transfer from Brainfuck ==== | ||
| + | === Python === | ||
| + | <code python> | ||
| + | def bf2g(str): | ||
| + | code_list = [] | ||
| + | c = 0 | ||
| + | while c < len(str): | ||
| + | match str[c]: | ||
| + | case " | ||
| + | case " | ||
| + | case ",": | ||
| + | case " | ||
| + | case " | ||
| + | case " | ||
| + | case "<": | ||
| + | case ">": | ||
| + | c += 1 | ||
| + | return " " | ||
| + | |||
| + | bf_text = input(" | ||
| + | |||
| + | while(bf_text != "" | ||
| + | print(bf2g(bf_text)) | ||
| + | bf_text = input(" | ||
| + | </ | ||
| + | |||
| + | ==== Interpreter ==== | ||
| + | === Python === | ||
| + | <code python> | ||
| + | import sys | ||
| + | |||
| + | def ggdx(code): | ||
| + | s=[] | ||
| + | matches={} | ||
| + | tape = [0]*65536 | ||
| + | codeList = code.strip().replace(" | ||
| + | for i,j in enumerate(codeList): | ||
| + | if j == " | ||
| + | s.append(i) | ||
| + | if j == " | ||
| + | m = s.pop() | ||
| + | matches[m] = i | ||
| + | matches[i] = m | ||
| + | cp=0 | ||
| + | p=0 | ||
| + | while cp < len(codeList): | ||
| + | if codeList[cp] == " | ||
| + | tape[p]=(tape[p]+1)%256 | ||
| + | if codeList[cp] == "标新立异": | ||
| + | tape[p]=(tape[p]-1)%256 | ||
| + | if codeList[cp] == " | ||
| + | tape[p]=ord(sys.stdin.read(1))%256 | ||
| + | if codeList[cp] == " | ||
| + | print(chr(tape[p]), | ||
| + | if codeList[cp] == " | ||
| + | p-=1 | ||
| + | if codeList[cp] == " | ||
| + | p+=1 | ||
| + | if codeList[cp] == " | ||
| + | if not tape[p]: | ||
| + | cp=matches[cp] | ||
| + | if codeList[cp] == " | ||
| + | if tape[p]: | ||
| + | cp=matches[cp] | ||
| + | cp+=1 | ||
| + | ggdx(sys.stdin.read()) | ||
| </ | </ | ||