BFT is a Brainfuck transcompiler. Currently, BFT can translate Brainfuck into C which can then be compiled into a native binary.
If you are not familiar with Brainfuck, check out this link to learn more about it.
A few examples of complete Brainfuck programs can be found in the
folder. You can use these programs to test out the transcompiler. Below you can
mandelbrot.bf example output.
The gem can be installed via Rubygems,
The gem itself is lightweight and has no external dependencies. An alternative
way to install the gem is available. If you wish to build the gem and install
it you can do so using the
make tasks that are available.
$ make build $ make install
If you wish to run the test suite you can do so via
make as well,
There are two ways you can use the BFT gem.
The gem comes with a simple script that is installed for you. The script can be used to compile Brainfuck via the command line (see examples below).
The second way the gem can be used is via Ruby itself. You can require the gem and use programmatically generate C code.
Usage: bft [options] -t, --target Target Language Language name -s, --source Source Filename Source filename -o, --output Output Filename Output filename -h, --help Help
The most common way to use
bft is via the command line with simple arguments.
Since the default behavior is to dump the emitted code to stdout you can then
pipe it into a compiler or a file etc.
$ bft -s examples/hello_world.bf -t c | gcc -xc - -o hello.out $ ./hello.out Hello World!
bft transcompiler was built to be Unix friendly and supports piping to
$ cat examples/echo.bf | bft | gcc -xc - $ ./a.out hello hello
You can also use
bft in the standard compiler fashion,
$ bft -s examples/hello_world.bf -t c -o hello_world.c $ gcc hello_world.c -o hello.out $ ./hello.out Hello World!
Currently, BFT can translate Brainfuck to C. Other language support can be added with relative ease.
The Ruby API usage is relatively simple,
require 'bft' # Some Brainfuck source code as a string bf_src = '+++[-]' # Initialize a translator for some source code translator = Bft::Translator.new(bf_src) # Translate to a known language, such as C c_code = translator.translate_to :c
Copyright (c) 2015, Corey Prophitt. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.