A Brainfuck interpreter in JavaScript

5,119/4,998 bytes - uses JavaScript
License: GNU GPL, any version

I wrote a JavaScript interpreter for the minimal programming language Brainfuck so I could enter it in the 2002 5k competition. It's since been added to this code archive, minimalized even further by another programmer, and in 2011 I got around to making some modernizations and improvements. Here are both versions:

Following is the closest thing it has to documentation, a copy of the Author's Description from the 5k entry page.

This entry uses JavaScript to run programs written in Brainfuck, a tiny programming language with only eight instructions, originally designed by Urban Mueller. Type or paste your program into the "code" box, enter input in the appropriate field if desired, click "execute", and the program's output will appear in the "output" box.

JavaScript being what it is, expect non-trivial programs to run in a non-trivial amount of time. If the program is written correctly, it should finish: have patience. (Note that some browsers do not show any output until the program finishes.)

For compatibility with many existing Brainfuck programs, this interpreter limits the values of variables to the range -128 to 127 by default. To remove this restriction, enable "Large variables".

If a program attempts to read input when no more remains in the "input" field, the value zero will be used. If you want instead to be prompted to supply more input or abort the program, enable "Prompt for input".

If a program attempts to increment or decrement the pointer or a value beyond their limits, they will wrap around.

This interpreter is essentially an original work, but it could not have been written without reference to the excellent web pages linked in the "Learn more" section. In particular, the sample quine program is that written by Brian Raiter.

If you want to modify this, you may find it helpful to consult the symbols file, which indicates semi-logical associations for all those single letters used as variables and controls.

And for testing purposes, or just as a bonus, here's a little tool that will take a string of text and produce brainfuck code that outputs that string.