lisp compiler written in brainf**k?

Whatever is on your mind, whether Lisp related or not.

lisp compiler written in brainf**k?

Postby binutils » Sun Jun 29, 2008 6:51 am

i am very interested in language simplicity.
Brainfuck is my favorite language ATM.

Could i build lisp compiler with brainfuck compiler?
Posts: 4
Joined: Sun Jun 29, 2008 6:32 am

Re: lisp compiler written in brainf**k?

Postby Exolon » Sun Jun 29, 2008 8:22 am

If it's Turing complete, then why not? It must be possible in both directions, but I suspect building a Brainfuck compiler in Lisp would be just a little bit easier :)
Posts: 49
Joined: Sat Jun 28, 2008 12:53 pm
Location: Ireland

Re: lisp compiler written in brainf**k?

Postby TheGZeus » Mon Jun 30, 2008 11:03 am

Turing complete? It's a Universal Turing Machine!
I think it would probably take pretty simple macro to write the reverse...
Posts: 79
Joined: Mon Jun 30, 2008 10:46 am

Re: lisp compiler written in brainf**k?

Postby informatimago » Thu Jul 10, 2008 4:59 pm

Responding to popular demand, I publish the brainfuck virtual machine and brainfuck compiler I hacked a rainy Sunday three years ago.
I started to write some code for a lisp VM over brainfuck, but it's far from complete. Have fun!

Re: lisp compiler written in brainf**k?

Postby findinglisp » Thu Jul 10, 2008 5:44 pm

You guys are twisted psychopaths. :shock: :D
Cheers, Dave
Slowly but surely the world is finding Lisp.
Posts: 440
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX

Re: lisp compiler written in brainf**k?

Postby binutils » Sat Jul 12, 2008 4:25 am

* bf.lisp : NO
* -- the "99 Bottles" program in brainfuck: YES thx for the source.
Posts: 4
Joined: Sun Jun 29, 2008 6:32 am

Re: lisp compiler written in brainf**k?

Postby binutils » Sat Jul 12, 2008 6:53 pm

For the brave, here is lisp compiler written in c ... ins.tar.gz
Posts: 4
Joined: Sun Jun 29, 2008 6:32 am

Re: lisp compiler written in brainf**k?

Postby sylwester » Mon Jul 11, 2011 3:46 pm

Creating a LISP compiler? I have never though of it. The resulting BF-code has to be able to be a LISP interpreter as well to be a fully functional LISP.
I'm currently working on an Interpreter that runs on any BrainFuck interpreter (or that may be compiled with a brainfuck-to-x compiler), though will make you do more stuff when cell sizes are larger than bytes. (addressing)

Around 2007 I didn't know much about LISP , but I found BF a challenge to do stuff in. It has 8 primitives and is one of the simplest languages there are.
LISP is on the other end of the scale as a high level language and it was originally defined by 7 primitives and list-lambda for function-calls. I have used
some years to learn a little about LISP among other things.

In 2009 I started created ebf-compiler. I defined som new primitives :$!@ that pretty much implemented variable handling. My compiler then read this and printed out the <'s and >'s
so that my program didn't have to worry about that. It was written in itself and hand-compiled. After that I have added features. Today EBF is in it's 7th generation and writing something in it can be verbose, readable and highly debug-able. This was my first step in writing LISP.

I have spawned a new project this year called Zozotez (LISP in french, since I'm doing this while on vacation in Framce). Having written EBF I have already found solutions to many data structures (EBF today has 2 stacks, hash-table, string-array, array and a buffer) I reused many if the solutions used in EBF (two stacks, a array lookup for symbols (index=hash) and a array that expands to the end of memory to be lisp data. I have put some registeres (cells) in the middle and my macroes in EBF can use the calling cell address as a way to pass parameters. So far I have created a read-print-loop that stores what it reads in cons-cells and print, that print a address in lisp-data-array. It might not be very impressive since it might look like any implementation of echo, but I belive I'm half way to implement my interpreter.

This work has so far been very time consuming, but interesting. I can't say I'm wasting my time since I'm learning as I go and it sure beats my wife's sudoku challenges any time. The result will be something which starts out responsive but as the memory indexes goes up the interpreter will have to do more processing for each access and that will be felt on the performance. In parallel I'm making a reference design in CL.

Link to the ebf-compiler:

Link to Zozotez Lisp (not-yet) Interpreter

I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
Posts: 130
Joined: Mon Jul 11, 2011 2:53 pm

Re: lisp compiler written in brainf**k?

Postby gugamilare » Tue Jul 12, 2011 10:54 am

Instead of BrainFuck, take a look at Unlambda (Unlambda on Esolang). It is based on lambda calculus and has only 3 basic operators aside from input/output. No loops, no arrays and no integers, just functions.

(For the LOLs: LOLCODE :P).
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: lisp compiler written in brainf**k?

Postby sylwester » Mon Aug 01, 2011 5:31 pm

Unlambda is probably a wondferful language, but since bootstrapping of LISP usually means implementing some subset of LISP in an imperative world creating mine in Unlambda would not be a practical exercise.
LOLCODE is a far easier choice if it had more side effect support. Their BF interpreter lacks means of input because of limitations so even though turing complete, it would be difficult to create LISP.

Anyway.. Having worked since 2007 on paper and from 2010 on implementation I have come too far to change implementation language. I have actually released a first version. Amongst the features are
first class everything (like kernel) and macro and function-support. It is seeded with (eval(read)). As a first version it does not yet have number support, garbage collection or compilation (I need something to do in 2012).
Here is a typical session:
Code: Select all
westerp@lemur /l/n/w/a/zozotez> jitbf
;; create REPL by running a anonymous lambda == \ expression.
  (set quote lambda cons car cdr if eq atom flambda print read eval au-revoir REPL list setq)
    (print '(Bonjour to Zozotez REPL classic LISP1. (au-revoir) to exit.) NIL)
 ;; the arguments to this anonymous function
 : " \ c a d ? = s ~ p r e ; builtins
 (\ () 'au-revoir) ; exit-function
 (\ () ; REPL
      (print 'Zozotez-moi~>())
      (if (eq (print(eval(read))) 'au-revoir) () (REPL)))
 (\ q q) ; list
 (~ ($s $o) (list set (list quote $s) $o))) ; setq (last argument)

Bonjour to Zozotez REPL classic LISP1. (au-revoir) to exit.
Zozotez-moi~>(setq + (lambda (x y) (if x (cons (car x) (+ (cdr x) y)) y)))
#'(\ (x y) (if x (cons (car x) (+ (cdr x) y)) y))
Zozotez-moi~>(setq - (lambda (z w) (if w (- (cdr z) (cdr w)) z)))
#'(\ (z w) (if w (- (cdr z) (cdr w)) z))
Zozotez-moi~>(setq fibonacci (lambda (n a1 a2) (if n (fibonacci (- n '(1)) a2 (+ a2 a1)) a1)))
#'(\ (n a1 a2) (if n (fibonacci (- n (" (1))) a2 (+ a2 a1)) a1))
Zozotez-moi~>(fibonacci '(1 1 1 1 1 1 1 1 1) () '(1))
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)

I'm currently solving the L-99 in Zozotez using the internal symbol names. eg L-01:
Code: Select all
((:'@(\()(p'Zozotez-moi~>())(p(e(r)))(@)))) ; a REPL
Zozotez-moi~>(: 'last
                         (\ (in)
                           (? (d in)
                               (last (d in))
#'(\ (in) (? (d in) (last (d in)) in))
Zozotez-moi~>(last '(a b c))

Feel free to download and try it at
It is downloadable as a single file with docs and licence in one or as ebf source tarball/zip file. Windows users might need to get jitbf and ebf from my ebf-project as my included toolchain is the ebf bf-source compiled for i386-linux.
Link to the Compiler suit here:

A note about symbols. I'm using a mod 251 hash so it's prone to collisions. The first string to match a hash gets stored and everything after that to match that hash is eq. eg. (= 'p 'ok) => T
Posts: 130
Joined: Mon Jul 11, 2011 2:53 pm

Return to The Lounge

Who is online

Users browsing this forum: No registered users and 3 guests