Skip to content
/ Brainf Public

Library for executing code written in the "Brainf*ck" programming language.

License

Notifications You must be signed in to change notification settings

aikidos/Brainf

Repository files navigation

Actions Status

Brainf

Library for executing code written in the Brainf*ck programming language.

Examples

On platforms supporting netstandard 2.1+

const string sourceCode = @"
>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
++++++++[>++++++++++[>++++++++++[>++++++++++[>+
+++++++++[-]<-]<-]<-]<-]<-]<-]<-]";

var parser = new BrainfParser();
var compiler = new BrainfCompiler();
var memory = new BrainfMemory();

var program = parser.Parse(sourceCode);
var func = compiler.Compile(program);

func(memory, BrainfIO.Console);

Output:

ZYXWVUTSRQPONMLKJIHGFEDCBA

const string sourceCode = @"
++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[
    -<<<[
        ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
    ]>.>+[>>]>+
]";

...

func(memory, BrainfIO.Console);

Console:

                               *
                              * *
                             *   *
                            * * * *
                           *       *
                          * *     * *
                         *   *   *   *
                        * * * * * * * *
                       *               *
                      * *             * *
                     *   *           *   *
                    * * * *         * * * *
                   *       *       *       *
                  * *     * *     * *     * *
                 *   *   *   *   *   *   *   *
                * * * * * * * * * * * * * * * *
               *                               *
              * *                             * *
             *   *                           *   *
            * * * *                         * * * *
           *       *                       *       *
          * *     * *                     * *     * *
         *   *   *   *                   *   *   *   *
        * * * * * * * *                 * * * * * * * *
       *               *               *               *
      * *             * *             * *             * *
     *   *           *   *           *   *           *   *
    * * * *         * * * *         * * * *         * * * *
   *       *       *       *       *       *       *       *
  * *     * *     * *     * *     * *     * *     * *     * *
 *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

const string sourceCode = @"
>>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[
->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<
]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[>
+<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-
[<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<[
>->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]";

...

Console.WriteLine(@"Input a `Brainfuck` program and its input, separated by an exclamation point:");

func(memory, BrainfIO.Console);

Console:

- Input a `Brainfuck` program and its input, separated by an exclamation point:
- >++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
  [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
  ++++++++[>++++++++++[>++++++++++[>++++++++++[>+
  +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.
- !
- ZYXWVUTSRQPONMLKJIHGFEDCBA

LICENSE

MIT

About

Library for executing code written in the "Brainf*ck" programming language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages