Skip to content

Brainfuck Interpreter in Python is a fully featured Brainfuck interpreter written in Python. It supports interactive mode, executing code from files, or running raw Brainfuck code passed as command-line arguments.

License

Notifications You must be signed in to change notification settings

BaseMax/brainfuck-interpreter-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Brainfuck Interpreter in Python

License: MIT

Brainfuck Interpreter in Python is a fully featured Brainfuck interpreter written in Python. This interpreter is a port and improvement over the original C version by Fabian Mastenbroek. It supports interactive mode, executing code from files, or running raw Brainfuck code passed as command-line arguments.

Features

  • Interactive Console: Launch an interactive session to enter Brainfuck code.
  • File Mode: Execute Brainfuck code stored in .bf files.
  • Raw Code Execution: Provide raw Brainfuck code directly on the command line.
  • Piped Input: Execute Brainfuck code provided via standard input.
  • Error Handling: Clear error messages for parse errors and runtime errors (e.g. tape overruns/underruns).
  • Modular Codebase: Clean, well-documented code split into modular functions for parsing, execution, and CLI handling.

Installation

Requirements

  • Python 3.6 or later

Clone the Repository

git clone https://github.com/BaseMax/brainfuck-interpreter-python.git
cd brainfuck-interpreter-python

There is no additional installation step required; the interpreter is contained within a single Python script.

Usage

You can run the interpreter in several ways:

Interactive Mode

If you run the interpreter without any arguments, it will start in interactive mode:

python3 brainfuck-interpreter.py

Then, enter Brainfuck code at the prompt (>> ). Use Ctrl-D (or Ctrl-Z on Windows) to exit.

Running a File

If an argument ends with .bf, the interpreter treats it as a file containing Brainfuck code:

python3 brainfuck-interpreter.py program.bf

Running Raw Code

If an argument does not end with .bf, it is treated as raw Brainfuck code:

python3 brainfuck-interpreter.py "++++++++[>++++++++<-]>+.[-]<"

Piped Input

You can also pipe Brainfuck code into the interpreter:

echo "+++++[>+++++<-]>." | python3 brainfuck-interpreter.py

Command Line Options

  • -h, --help

Show the help message.

  • -v, --version

Show version information.

The interpreter automatically distinguishes between file paths (ending with .bf) and raw Brainfuck code provided as arguments.

Contributing

Contributions are welcome! If you have ideas for improvements or bug fixes, please fork the repository and open a pull request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

© 2025 Max Base (Seyyed Ali Mohammadiyeh)

About

Brainfuck Interpreter in Python is a fully featured Brainfuck interpreter written in Python. It supports interactive mode, executing code from files, or running raw Brainfuck code passed as command-line arguments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages