←  Programs

ComputerCraft | Programmable Computers for Minecraft

»

bf to Lua Compiler

supernicejohn's Photo supernicejohn 09 Jul 2016

This is probably what I should have submitted to CCJam, but Oh well.
bf to Lua Compiler
is a compiler I wrote because I wanted to do some experiments with the esoteric language brainfuck. i got the idea when someone linked the site esolangs.org, this person deserves credit, but I have forgotten who it was =/ (Tell me please! I want to thank you!)
This isn't the best or most efficient compiler since it sometimes leaves very redundant code, but the compiler filesize is only 999 bytes! (according to CC, 1.02KB according to pastebin...), and there's a minified version with only 882 bytes.
Feel free to one up me by writing more efficient or compact code, (since the original was 240 bytes) as a challenge.

The basic syntax:
Spoiler
An example program:
Spoiler

No screenies, this just takes arguments in the shell.

Usage/Download:
Spoiler

Let me know if you find any bugs with my implementation, for comparison an online Interpreter can be found at https://copy.sh/brainfuck/

NOTE: My implementation does not print the alphabetical equivalent to a number, it just prints a number.

Please tell me if there is anything you would like to see change, suggestions or bugs. ;)
Edited by supernicejohn, 09 July 2016 - 11:03 PM.
Quote

sci4me's Photo sci4me 09 Jul 2016

Nice work! I have also done this, so, I guess I may as well share it: https://github.com/sci4me/lbf
My compiler does not output to a file, it just runs the compiled bf code with loadstring.
It also does a few basic optimizations.
Quote

supernicejohn's Photo supernicejohn 10 Jul 2016

 sci4me, on 09 July 2016 - 11:54 PM, said:

Nice work! I have also done this, so, I guess I may as well share it: https://github.com/sci4me/lbf
My compiler does not output to a file, it just runs the compiled bf code with loadstring.
It also does a few basic optimizations.
Nice one! Yours is more fun when using big numbers like a multiply function, for example ++++++++++++++++>+++++++++++++++<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<+>>-]<-]<[.-] last bit listing all from result down to 1 =P
Quote

sci4me's Photo sci4me 10 Jul 2016

 supernicejohn, on 10 July 2016 - 12:18 AM, said:

 sci4me, on 09 July 2016 - 11:54 PM, said:

Nice work! I have also done this, so, I guess I may as well share it: https://github.com/sci4me/lbf
My compiler does not output to a file, it just runs the compiled bf code with loadstring.
It also does a few basic optimizations.
Nice one! Yours is more fun when using big numbers like a multiply function, for example ++++++++++++++++>+++++++++++++++<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<+>>-]<-]<[.-] last bit listing all from result down to 1 =P

Thanks!

Try running the mandelbrot set generator program (https://raw.githubus...r/progs/mand.bf) or the towers of hanoi program (https://raw.githubus.../progs/hanoi.bf)
Quote

supernicejohn's Photo supernicejohn 10 Jul 2016

 sci4me, on 10 July 2016 - 12:23 AM, said:

 supernicejohn, on 10 July 2016 - 12:18 AM, said:

 sci4me, on 09 July 2016 - 11:54 PM, said:

Nice work! I have also done this, so, I guess I may as well share it: https://github.com/sci4me/lbf
My compiler does not output to a file, it just runs the compiled bf code with loadstring.
It also does a few basic optimizations.
Nice one! Yours is more fun when using big numbers like a multiply function, for example ++++++++++++++++>+++++++++++++++<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<+>>-]<-]<[.-] last bit listing all from result down to 1 =P

Thanks!

Try running the mandelbrot set generator program (https://raw.githubus...r/progs/mand.bf) or the towers of hanoi program (https://raw.githubus.../progs/hanoi.bf)
Tried to compile the mandelbrot one, and on opening the compiled file, sublime text 2 crashed... It looks cool with your version one though! =)
Quote

sci4me's Photo sci4me 10 Jul 2016

 supernicejohn, on 10 July 2016 - 12:38 AM, said:

 sci4me, on 10 July 2016 - 12:23 AM, said:

 supernicejohn, on 10 July 2016 - 12:18 AM, said:

 sci4me, on 09 July 2016 - 11:54 PM, said:

Nice work! I have also done this, so, I guess I may as well share it: https://github.com/sci4me/lbf
My compiler does not output to a file, it just runs the compiled bf code with loadstring.
It also does a few basic optimizations.
Nice one! Yours is more fun when using big numbers like a multiply function, for example ++++++++++++++++>+++++++++++++++<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[<<+>>-]<-]<[.-] last bit listing all from result down to 1 =P

Thanks!

Try running the mandelbrot set generator program (https://raw.githubus...r/progs/mand.bf) or the towers of hanoi program (https://raw.githubus.../progs/hanoi.bf)
Tried to compile the mandelbrot one, and on opening the compiled file, sublime text 2 crashed... It looks cool with your version one though! =)

They're good tests for your bf programs. Can use them to test for correctness and speed.
Quote

InternetUnexplorer's Photo InternetUnexplorer 13 Jul 2016

Haha, funny that. I'm currently making a Lua to bf compiler. Fun stuff, isn't it? :)
Quote

supernicejohn's Photo supernicejohn 14 Jul 2016

Hehe, post the filesize when you're done!
Quote