项目作者: 4rtzel

项目描述 :
C++ Compile time Brainfuck interpreter
高级语言: C++
项目地址: git://github.com/4rtzel/cppbf.git
创建时间: 2020-01-18T11:14:32Z
项目社区:https://github.com/4rtzel/cppbf

开源协议:MIT License

下载


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.

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

Reverse input.

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

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

  1. constexpr auto bf_in_bf = bf<1000, 5>(
  2. ">>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>["
  3. "->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<"
  4. "]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[>"
  5. "+<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-"
  6. "[<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<["
  7. ">->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]",
  8. "+[>,]+[<.-]!abc");

Try online

https://godbolt.org/z/VsiPME