1/30/2017 > Javascript

JS Brainfuck Interpreter

Brainfuck, if you didn't know, is an aptly named esoteric programming language.

They say it messes with your mind because there's only a couple characters you can use to make your program: [],.<>+-

In a nutshell, the "memory" consists of an infinite array of integers (each ranging from 0-255). There is a "pointer" which resides somewhere along this memory strip. ">" moves the pointer one to the right while "<" moves the pointer one to the left. You can increment and decrement the integer currently at the pointer with "+" and "-". "[" and "]" is a looping mechinism, "." prints the ascii value of the integer currently at the pointer, and "," prompts for input.

In other words, loads of fun! Check it out:

Brainfuck Interpreter
>   move pointer right
<   move pointer left
[   jump past matching bracket if value at pointer is zero
]   jump to matching bracket if value at pointer is nonzero
+   increase value at pointer by 1
-   decrease value at pointer by 1
.   print value at pointer as character
,   take input and store at pointer location
-[.-] Steps:

Speed:

Output