Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cmdada/brainfuckinterpreterpy

This is a simple Brainfuck interpreter written in Python. Brainfuck is a minimalist programming language known for its extreme minimalism and difficulty to read and write. It consists of only eight commands, each represented by a single character. This interpreter can load Brainfuck programs from files and interpret them.
https://github.com/cmdada/brainfuckinterpreterpy

Last synced: 25 days ago
JSON representation

This is a simple Brainfuck interpreter written in Python. Brainfuck is a minimalist programming language known for its extreme minimalism and difficulty to read and write. It consists of only eight commands, each represented by a single character. This interpreter can load Brainfuck programs from files and interpret them.

Awesome Lists containing this project

README

        

docs written by an llm with everything tested

# Brainfuck Interpreter

This is a simple Brainfuck interpreter written in Python. It is capable of loading Brainfuck programs from files and interpreting them.

## Usage

To use the interpreter, run the following command in your terminal:

python3 bf.py program.bf

Replace `program.bf` with the path to the Brainfuck program you want to run.

The interpreter will load the program from the file and execute it. Any output generated by the program will be printed to the console.

The interpreter supports input from the user using the `,` command. When the program encounters a `,` command, it will wait for the user to input a single character, which will be read and stored in the current cell of the program's data array.

## Features

The Brainfuck interpreter supports the following commands:

| Command | Description |
|---------|-------------|
| > | Move the data pointer to the right |
| < | Move the data pointer to the left |
| + | Increment the value at the current cell |
| - | Decrement the value at the current cell |
| . | Output the value at the current cell as a character |
| , | Read a single character of input from the user and store it in the current cell |
| [ | If the current cell is zero, jump to the corresponding ] command. Otherwise, push the current code pointer onto a loop stack |
| ] | If the current cell is non-zero, jump to the corresponding [ command. Otherwise, pop the last code pointer from the loop stack |

The interpreter also ignores any characters in the input file that are not one of the above commands.

## Examples

Here are some example Brainfuck programs you can run with the interpreter:

### Hello World

This program prints the string "Hello World!" to the console:

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

Save this program to a file named `hello.bf` and run the following command:

python3 bf.py hello.bf

The program should output the following message to the console:

Hello World!

### Echo

This program reads a character of input from the user and then echoes it back to the console:

,.

Save this program to a file named `echo.bf` and run the following command:

python3 bf.py echo.bf

The program should prompt you to enter a character. After you enter a character and press Enter, the program will output the character you entered to the console.

## Contributing

If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request. I welcome contributions from anyone!