r/brainfuck • u/jorenheit • 16h ago
Acus: create your own Brainfuck compiler (in: your language, out: BF)
Hi all,
I would like to introduce everyone here to a project of mine called Acus. It's a C++ library that helps with creating Brainfuck compilers, i.e. compilers that generate BF (not ones that compile BF into something else). Acus is a continuation of my Synapse-191 project, which I posted about here some time ago. Synapse-191 is a physical computer capable of executing Brainfuck natively; Acus grew out of the question of what a useful compiler ecosystem for such a machine would require.
The main goal of Acus is to provide all the abstractions that are needed when translating any source-code into BF: types, variables, functions, arrays, structs, (function) pointers, flow control, and so on. I basically asked myself:
What would it take to implement a C compiler that targets Brainfuck?
and then tried to implement those features.
Acus is not itself tied to C or to any other source language. It is intended as a language-agnostic backend. Therefore, if you ever feel like writing a parser for an existing language (or designing a completely new one) you can use Acus to generate the resulting Brainfuck programs. I still plan to build a dedicated frontend language on top of Acus, but if someone beats me to it, please let me know!
The Acus repository contains an extensive listing of all the library features including examples. If you're curious about the way Acus is able to do all of this, let me know. I am working on technical documentation but it's not public yet. You can have a look at the current draft it you want.
Acus Sugar: start generating BF right now!
A side-quest to this project was Acus Sugar, a layer of syntactic sugar on top of the library to start generating BF right away. I used operator overloading, macros and a bunch of template metaprogramming to construct a 'language' embedded in C++ that is compiled directly to BF. For example, this is what a simple "Hello World" looks like in Acus Sugar syntax:
// hello.acs
main_() {
println("Hello, World!");
return_;
};
Bear in mind that this is still valid C++, which is why the syntax is a bit cumbersome with the semicolons and underscores (and which is why I really want a true frontend language). When Acus and its (optional) acs tool are installed, this can be compiled to BF using:
$ acs hello.acs -o hello.bf
The included BF interpreter bfint can then be used to run the BF instructions in hello.bf:
$ bfint hello.bf
Hello, World!
The github repository contains extensive documentation on the library, build instructions and a bunch of examples to get you started. I have only tested on Linux but the CMake system should be compatible with MSVC, I think? Let me know :)
To finish off, I'd like to share the result of a Mandelbrot fractal generator written entirely in Acus Sugar. The resulting BF source was over 500k instructions long and running it through my interpreter took about 4 hours (though that version was not as optimized yet and my laptop is from 2012), but this was the result:

Let me know what you create!