Jump to content




bf to Lua Compiler

utility

7 replies to this topic

#1 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

Posted 09 July 2016 - 11:01 PM

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.


#2 sci4me

  • Members
  • 225 posts
  • LocationEarth

Posted 09 July 2016 - 11:54 PM

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.

#3 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

Posted 10 July 2016 - 12:18 AM

 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

#4 sci4me

  • Members
  • 225 posts
  • LocationEarth

Posted 10 July 2016 - 12:23 AM

 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)

#5 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

Posted 10 July 2016 - 12:38 AM

 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! =)

#6 sci4me

  • Members
  • 225 posts
  • LocationEarth

Posted 10 July 2016 - 01:40 AM

 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.

#7 InternetUnexplorer

  • Members
  • 24 posts
  • Locationno

Posted 13 July 2016 - 08:49 AM

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

#8 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

Posted 14 July 2016 - 01:14 AM

Hehe, post the filesize when you're done!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users