靈符

From Esolang
Jump to navigation Jump to search

靈符 is designed by PSTF and his ChatGPT.

Commands

The language operates on a tape of cells, each containing an integer.

The program consists of a series of Chinese characters, each representing a different operation.

Instructions:

  1. 移 (Yí) - Move the data pointer to the next cell to the right.
  2. 靈 (Líng) - Move the data pointer to the next cell to the left.
  3. 增 (Zēng) - Increment the value at the current cell by 1.
  4. 減 (Jiǎn) - Decrement the value at the current cell by 1.
  5. 若 (Ruò) - If the value at the current cell is 0, jump forward to the character after the matching 則 (Zé).
  6. 則 (Zé) - Go back to the matching 若 (Ruò) if the value at the current cell is not zero.
  7. 輸 (Shū) - Output the ASCII character represented by the value at the current cell.
  8. 讀 (Dú) - Input a character and store its ASCII value at the current cell.

(This is just a Brainfuck deriative!)

Example(Written by myself)

Hello, World!

增增增增增增增增增增增若移增增增增增增移增增增增增
增增增增移增增增增增增增增移增增增增移增增增移增靈
靈靈靈靈靈減則移增增增增增增輸移增增輸增增增增增增
增輸輸增增增輸移移輸移減輸靈靈減輸靈輸增增增輸減減
減減減減輸減減減減減減減減輸移移移增輸移減輸

Cat program

讀若輸讀則

Implementation

import sys
def lingfu(code):
    s=[]
    matches={}
    tape=[0]*1000000
    for i,j in enumerate(code):
        if j=='若':
            s.append(i)
        if j=='則':
            m=s.pop()
            matches[m]=i
            matches[i]=m
    cp=0
    p=0
    while cp<len(code):
        if code[cp]=='增':
            tape[p]=(tape[p]+1)%256
        if code[cp]=='減':
            tape[p]=(tape[p]-1)%256
        if code[cp]=='輸':
            c=sys.stdin.read(1)
            tape[p]=(ord(c) if c else 0)%256
        if code[cp]=='讀':
            print(chr(tape[p]),end='')
        if code[cp]=='靈':
            p-=1
        if code[cp]=='移':
            p+=1
        if code[cp]=='若':
            if not tape[p]:
                cp=matches[cp]
        if code[cp]=='則':
            if tape[p]:
                cp=matches[cp]
        cp+=1
lingfu(sys.stdin.read())

See also

Categories