0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

みゃー姉への愛で動くbrainmyaaneeを作った

Posted at

brainmyaaneeとは?

New Generation Japanase Programing Langage brainfxxk派生
brainfxxk + みゃー姉 = brainmyaanee

そもそもみゃー姉とは?

テレビアニメそして漫画における「私に天使が舞い降りた」の主人公 彼女にはひなたという妹がいる
この言語はそのひなたのセリフの一部を元に命令を書ける言語になっている

言語の仕様

brainmyaaneeは6個の命令で構成されている

みゃー姉!: pointerの値をインクリメントする
みゃー姉に友達はいないぞ: pointerの値をデクリメントする
みゃー姉一緒に寝よう!: ポインターの位置を1つ進める
みゃー姉一緒にお風呂入ろう! ポインターの位置を1つ下げる
みゃーーーーー姉! メモリ位置を0に設定
起きたかー? ポインタを0に設定

helloの例 非常に長いので私のブログでどうぞご覧ください asciiコードでhelloを表現している

インタープリターのソースコード

pythonで書かれている でもあまり複雑な事はしていない

import sys

# Brainfuckファイルの名前をコマンドライン引数から取得
bf_file_name = sys.argv[1]

# ポインタの初期位置とメモリの初期設定
pointer = 0
memory_place = 0
memory = [0 for n in range(16)]

# Brainfuckの命令一覧
instructions = [
    "みゃー姉!",             # ポインタをインクリメント
    "みゃー姉に友達はいないぞ",  # ポインタをデクリメント
    "みゃー姉一緒に寝よう!",    # メモリ位置をインクリメント
    "みゃー姉一緒にお風呂入ろう!",  # メモリ位置をデクリメント
    "みゃーーーーー姉!",         # メモリ位置を0に設定
    "起きたかー?",             # ポインタを0に設定
    ""                        # 空行(その内命令を追加したい)
]

# Brainfuckファイルを開く
with open(bf_file_name, "r") as bfn:
    try:
        # ファイルの内容を読み込んで、命令ごとに処理
        for instruction in bfn.read().replace("+", " ").split(" "):
            if instruction == instructions[0]:  # "みゃー姉!"の場合
                pointer += 1                   # ポインタをインクリメント
                memory[memory_place] = pointer  # メモリにポインタの値を格納
            elif instruction == instructions[1]:  # "みゃー姉に友達はいないぞ"の場合
                pointer -= 1                   # ポインタをデクリメント
                memory[memory_place] = pointer  # メモリにポインタの値を格納
            elif instruction == instructions[2]:  # "みゃー姉一緒に寝よう!"の場合
                memory_place += 1              # メモリ位置をインクリメント
            elif instruction == instructions[3]:  # "みゃー姉一緒にお風呂入ろう!"の場合
                memory_place -= 1              # メモリ位置をデクリメント
            elif instruction == instructions[4]:  # "みゃーーーーー姉!"の場合
                memory_place = 0               # メモリ位置を0に設定
            elif instruction == instructions[5]:  # "起きたかー?"の場合
                pointer = 0                    # ポインタを0に設定
                memory[memory_place] = pointer  # メモリにポインタの値を格納
            assert instruction in instructions  # 未知の命令を検出した場合、AssertionErrorを発生
    except AssertionError:
        print("Invalid Instruction", instruction)  # 未知の命令を検出した場合にエラーメッセージを表示

# メモリの内容を表示
print("memory ")
for x in memory:
    print(x, end=" ")
print()

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?