Created: 2012-03-22 13:55
Updated: 2013-01-08 08:23

Brainf ck.js


  shell~> npm install
  shell~> grunt
  shell~> cp ./dist/Brainfuck.min.js /path/to/production


Basic node.js

var fs = require('fs'),
    hello = fs.readFileSync('test/'),
    Brainfuck = require('Brainfuck.js');

var bf = new Brainfuck(hello);
//=> The quick brown fox jumps over the lazy dog


A CLI extensions ships with this node library. Located in the scripts directory, console.js can be used to test, debug, and compile bf applications.

   shell~> node ./scripts/console.js --file ./test/
   The quick brown fox jumps over the lazy dog

A stand-alone executable can be built, and installed system-wide.

   shell~> grunt build
   shell~> sudo install dist/bin/bf /usr/local/bin/bf
   shell~> which bf
   shell~> bf --file ./test/
   The quick brown fox jumps over the lazy dog

CLI Usage & Options

   bf [-v[v[v]] [--test] [--input <string>] filename

   -f, --file <file>     Set filename to interpret
   -i, --input <string>  Input string for application
   -t, --test            Validate syntax without executing application
   -v, --version         Print version information
   -vv                   Print summary of application
   -vvv                  Print debug output on loop iterations

API Methods

.clean( str )

Strip out commented text from string

  • str string

  • returns string

  • example

     * Blocklevel comment
     * If statement
     * [(condition true until 0)[-]]
    +[[>++<-]-[-]] // Line comment

Interprets given bf application

  • returns string|boolean Output of application, or false on failure
.init( application [, options] )
  • application string The bf application to compile

  • options object (optional) Run-time configuration options to adjust behavior of bf interpreter, and core language attributes.

  • returns object

.merge( original, alternative )

Updated existing, or append new, attributes to existing object

  • original object Base default item
  • alternative object New item to assimilate

Return a single character from input buffer

  • return integer Value of input char, by base 10 order

Examine application for syntax errors.

  • return boolean True on valid syntax, false otherwise
.write_output_buffer( charCode )

Add char to output buffer

  • charCode integer Base 10 order

  • return string Character at given order

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more