Skip to content
/ cppbf Public
forked from 4rtzel/cppbf

C++ Compile time Brainfuck interpreter

License

Notifications You must be signed in to change notification settings

gcker/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

About

C++ Compile time Brainfuck interpreter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 88.2%
  • CMake 11.8%