Brainfuck.js

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

README.md

Brainf ck.js

Installation

  shell~> npm install https://github.com/emcconville/Brainfuck.js/tarball/master
  shell~> grunt
  shell~> cp ./dist/Brainfuck.min.js /path/to/production

Usage

Basic node.js

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

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

CLI

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/example.bf
   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
   /usr/local/bin/bf
   shell~> bf --file ./test/example.bf
   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
.compile()

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
.read_input_buffer()

Return a single character from input buffer

  • return integer Value of input char, by base 10 order
.validate()

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