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?

bfソースをlisp(sbcl)にトランスパイルする。

0
Last updated at Posted at 2026-02-27

bfソースをlisp(sbcl)にトランスパイルする。

LGBTの発展形として、bfで書かれたソースををCommon Lisp系であるsbclに変換し、実行させることに成功しました。

マップファイル

map.lisp.json
{
  ">": " (incf ptr)",
  "<": " (decf ptr)",
  "+": " (setf (aref tape ptr) (mod (1+ (aref tape ptr)) 256))",
  "-": " (setf (aref tape ptr) (mod (1- (aref tape ptr)) 256))",
  ".": " (write-char (code-char (aref tape ptr)))",
  ",": " (let ((c (read-char nil nil nil))) (setf (aref tape ptr) (if c (char-code c) 0)))",
  "[": " (loop while (/= (aref tape ptr) 0) do",
  "]": " )"
}

header file

header.lisp
;; header.lisp -- main とテープ初期化を定義
(defun main ()
  (let ((tape (make-array 30000 :initial-element 0))
        (ptr 0))
    ;; ここから Brainfuck 変換コードが挿入されます

tailor file

tailor.lisp
    ;; 変換コードの末尾に来る補助出力(必要なら)
    (finish-output)))  ; let の中と defun を閉じる

;; スクリプトとして実行されたとき main を呼ぶ
  (main)

Transpilation and execution

lgbt.py map.lisp.json header.lisp hello.bf tailor.lisp >hello.lisp #
sbcl --script hello.lisp
Hello world!
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?