Page 1 of 1

lisp compiler written in brainf**k?

Posted: Sun Jun 29, 2008 6:51 am
by binutils
Hi,
i am very interested in language simplicity.
Brainfuck is my favorite language ATM.
http://www.nada.kth.se/~matslina/awib/

Could i build lisp compiler with brainfuck compiler?

Re: lisp compiler written in brainf**k?

Posted: Sun Jun 29, 2008 8:22 am
by Exolon
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 :)

Re: lisp compiler written in brainf**k?

Posted: Mon Jun 30, 2008 11:03 am
by TheGZeus
Turing complete? It's a Universal Turing Machine!
I think it would probably take pretty simple macro to write the reverse...

Re: lisp compiler written in brainf**k?

Posted: Thu Jul 10, 2008 4:59 pm
by informatimago
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!
http://www.informatimago.com/develop/li ... brainfuck/

Re: lisp compiler written in brainf**k?

Posted: Thu Jul 10, 2008 5:44 pm
by findinglisp
You guys are twisted psychopaths. :shock: :D

Re: lisp compiler written in brainf**k?

Posted: Sat Jul 12, 2008 4:25 am
by binutils
* bf.lisp : NO
* 99botles.bf -- the "99 Bottles" program in brainfuck: YES thx for the source.

Re: lisp compiler written in brainf**k?

Posted: Sat Jul 12, 2008 6:53 pm
by binutils
For the brave, here is lisp compiler written in c
http://www.accesscom.com/~darius/hacks/ ... ins.tar.gz

Re: lisp compiler written in brainf**k?

Posted: Mon Jul 11, 2011 3:46 pm
by sylwester
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:
http://sylwester.no/ebf/

Link to Zozotez Lisp (not-yet) Interpreter
http://sylwester.no/zozotez/

Br
Syl

Re: lisp compiler written in brainf**k?

Posted: Tue Jul 12, 2011 10:54 am
by gugamilare
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).

Re: lisp compiler written in brainf**k?

Posted: Mon Aug 01, 2011 5:31 pm
by sylwester
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 zozotez.bf
;; 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)
    (REPL))
 ;; 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)
Zozotez-moi~>(au-revoir)
au-revoir

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)))
#'(\ (in) (? (d in) (last (d in)) in))
Zozotez-moi~>(last '(a b c))
(c)
Feel free to download and try it at http://sylwester.no/zozotez/
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: http://sylwester.no/ebf/

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