We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

C2BF (2025)

From Esolang
(Redirected from C2bf (2025))
Jump to navigation Jump to search
c2bf
Paradigm(s) imperative
Designed by Ian Graham Martinez
Appeared in 2025
Computational class Turing Complete
Reference implementation c2bf
File extension(s) N/A

C2BF (not to be confused with Gregor Richard's C2BF) is a compiler from C into Brainfuck. The source code is available on Github, and a write-up explaining the implementation and its limitations is available here.

C2BF supports, among other features:

  • if-statements, while-loops, for-loops
  • arrays
  • functions
  • pointers
  • function pointers

Implementation

C2BF compiles C code to a stack-based intermediate language, so that each instruction can then be translated into a Brainfuck snippet. For example,

putchar('0' + 5);

... is compiled into the sequence:

Push(48)
Push(5)
Add
PutChar

Then, each of these is translated into Brainfuck (the convention is that each instruction begins execution pointing at the top of the stack, which grows rightward, and that all cells to the right of the tape head are zero):

Push(48) --> ++++++++++++++++++++++++++++++++++++++++++++++++
Push(5)  --> +++++
Add      --> [-<+>]<
PutChar  --> .[-]<

For control flow, the IR is split into basic blocks, and the entire program is placed in a [] loop. See [1] for more details about the implementation and its limitations.