Skip to content

4rtzel/cppbf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Compile time Brainfuck interpreter

This library could be used to run a Brainfuck program at compile time using user-defined string literal operator templates (gcc/clang extension) or a simple function.

Examples

Simple hello world.

constexpr auto hello_world = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."_bf;
// hello_world has std::array<char, N> type.
std::cout << std::string(hello_world.begin(), hello_world.end()) << std::endl;

Reverse input.

constexpr auto reversed = "+[>,]+[<.-]"_bfi << "fbppc";

A branfuck interpreter that takes a brainfuck program as input. http://www.hevanet.com/cristofd/brainfuck/dbfi.b

constexpr auto bf_in_bf = bf<1000, 5>(
          ">>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>["
          "->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<"
          "]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[>"
          "+<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-"
          "[<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<["
          ">->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]",
          "+[>,]+[<.-]!abc");

Try online

https://godbolt.org/z/VsiPME

Releases

No releases published

Packages

No packages published