sealife / brainfuck
Brainfuck Interpreter in PHP
Installs: 82
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sealife/brainfuck
Requires
- ext-readline: *
Requires (Dev)
- phpunit/phpunit: ^7.4
This package is auto-updated.
Last update: 2025-12-29 02:58:58 UTC
README
This script will interpret brainfuck within PHP.
Example
$parser = new Parser(); $parser->run("+++++++++ [-]"); // or to run a file $parser->runFile($file); // to modify the starting memory (to start with a custom one) do $memory = new Memory(); $parser = new Parser($memory); $result = $parser->run("[>[>+>+<<-]>>[<<+>>-]<<<-]");
Specification
| Character | C equivalent | Meaning |
|---|---|---|
| > | ++ptr; | increment the data pointer (to point to the next cell to the right). |
| < | --ptr; | decrement the data pointer (to point to the next cell to the left). |
| + | ++*ptr; | increment (increase by one) the byte at the data pointer. |
| - | --*ptr; | decrement (decrease by one) the byte at the data pointer. |
| . | putchar(*ptr); | output the byte at the data pointer. |
| , | *ptr = getchar(); | accept one byte of input, storing its value in the byte at the data pointer. |
| [ | while (*ptr) { | if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command. |
| ] | } | if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command. |
Source: Wikipedia