0.0.4 • Published 6 years ago

jsbrainfuck v0.0.4

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

A Simple JavaScript Brainfuck Toolset

You can use brainfuckjs either as command line tool or as library for your node projects.

library

Using brainfuckjs as a library, you can either use the interpret or the compiler function exported by the module. To use brainfuckjs as library, install it using npm i -S jsbrainfuck.

interpret example

    const { interpret } = require('jsbrainfuck');
    const { memory, pointer, output, print } = interpret(
        // program
        `+++++ +++++ 
        [ > +++++ ++ > +++++ +++++ > ++++ > +++ > + <<<<< - ]
        > ++ . > + . +++++ ++ .. +++ . > ++++ . > ++ . <<< 
        +++++ +++++ +++++ . > . +++ . ----- - .----- --- . >>>> +++ 
        [ - > +++++ +++++ + < ] > . > ++ [ - > +++++ < ] > .`,
        // optional input array
        ['x'],
    );

    // Print the result to the stdout
    print();

compile example

    const { compile } = require('jsbrainfuck');
    const { code } = compile(
        // program
        `+++++ +++++ 
        [ > +++++ ++ > +++++ +++++ > ++++ > +++ > + <<<<< - ]
        > ++ . > + . +++++ ++ .. +++ . > ++++ . > ++ . <<< 
        +++++ +++++ +++++ . > . +++ . ----- - .----- --- . >>>> +++ 
        [ - > +++++ +++++ + < ] > . > ++ [ - > +++++ < ] > .`,
    );

    // Print the result to the stdout
    process.stdout.write(code);

cli

To use brainfuckjs as cli, it is recommended to install it globally npm i -g jsbrainfuck. That way, you'll be able to use the bfjs command. To install brainfuckjs globally, use npm i -g jsbrainfuck.

compiling

With bfjs you can compile an existing brainfuck file. Therefore, the syntax of the cli works this way: bjfs compile <path-to-bf-file> <output-file>

The output will be a NodeJS CLI itself and is runnable by node <output-file> <optional-input> or ./<outputfile> <optional-input> - dependent on your operating system.

interpreting

With bfjs you can interpret an existing brainfuck file. Therefore, the syntax of the cli works this way: bfjs interpet <path-to-bf-file> <optional-input-characters>

This will directly execute the brainfuck program and print the result to the screen.

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago