101 posts
Location
Sweden
Posted 10 July 2016 - 12:01 AM
This is probably what I should have submitted to CCJam, but Oh well.
bf to Lua Compileris 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
+ : adds 1 to position of pointer.
- : subtracts 1 from position of pointer.
> : moves the pointer 1 step to the right.
< : moves the pointer 1 step to the left.
. : Output/prints the value of position of pointer.
, : Input/set a value for the position of pointer.
[ …… ] : loops code within brackets until value of position of pointer is 0.An example program:
Spoiler
,>,[-.<-.>]
That will take two inputs, subtract both until the first one is zero, thereby showing the difference between them, either positive or negative.No screenies, this just takes arguments in the shell.
Usage/Download:
Spoiler
pastebin get 3Eqa7RhS Compiler
or minified
pastebin get JLa4Rm1M MiniComp
Download either one, and make a file with the brainfuck code in it, then do: Compiler <bf_file_name> <Compiled_file_name>
Easy as can get! Then run <Compiled_file_name>, and it should run, since it (hopefully) is valid Lua.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 on 09 July 2016 - 10:03 PM
226 posts
Location
Earth
Posted 10 July 2016 - 12:54 AM
Nice work! I have also done this, so, I guess I may as well share it:
https://github.com/sci4me/lbfMy compiler does not output to a file, it just runs the compiled bf code with loadstring.
It also does a few basic optimizations.
101 posts
Location
Sweden
Posted 10 July 2016 - 01:18 AM
Nice work! I have also done this, so, I guess I may as well share it:
https://github.com/sci4me/lbfMy 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
226 posts
Location
Earth
Posted 10 July 2016 - 01:23 AM
Nice work! I have also done this, so, I guess I may as well share it:
https://github.com/sci4me/lbfMy 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.githubusercontent.com/sci4me/JBFJit/master/progs/mand.bf) or the towers of hanoi program (
https://raw.githubusercontent.com/sci4me/JBFJit/master/progs/hanoi.bf)
101 posts
Location
Sweden
Posted 10 July 2016 - 01:38 AM
Nice work! I have also done this, so, I guess I may as well share it:
https://github.com/sci4me/lbfMy 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! =)
226 posts
Location
Earth
Posted 10 July 2016 - 02:40 AM
Nice work! I have also done this, so, I guess I may as well share it:
https://github.com/sci4me/lbfMy 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.
24 posts
Location
no
Posted 13 July 2016 - 09:49 AM
Haha, funny that. I'm currently making a Lua to bf compiler. Fun stuff, isn't it? :)/>
101 posts
Location
Sweden
Posted 14 July 2016 - 02:14 AM
Hehe, post the filesize when you're done!