Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

4rtzel/cppbf

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 
Morty Proxy This is a proxified and sanitized view of the page, visit original site.