Skip to main content

Brainfuck

Pure python brainfuck parser, interpreter Including optimizations, translation into python AST and python code

Installation

pip install brainfuck-venomlab

Usage

From code

from brainfuck import Brainfuck
from brainfuck.contrib import execute, to_python_ast, to_python_code

source_code = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++."

bf = Brainfuck.compile(source_code)
# Execute code directly
execute(bf)

# Optimize
bf = bf.optimize()

# Get python code
python_code = to_python_code(bf)  # type: str

# Get python AST
program = to_python_ast(bf)  # type: ast.AST
# Compile AST info code object with `exec` mode - it's module
executable = compile(program, "program.py", "exec")
# Either exec or eval
exec(executable)

From command line

Execute brainfuck from *.bf file:

brainfuck -f examples/hw.bf
# Hello World!

Execute brainfuck from commandline:

brainfuck -c "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++."
# Hello

Translate brainfuck to python with -py flag:

brainfuck -py -c "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++."
# buffer = bytearray(30000)
# index = 0
# buffer[index] += 1
# buffer[index] += 1
# buffer[index] += 1
# ...
# print(chr(buffer[index]), end='')

Enable optimizations with -o flag:

brainfuck -py -o -c "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++."
# buffer = bytearray(30000)
# index = 0
# buffer[index] += 10
# ...
# buffer[index] += 3
# print(chr(buffer[index]), end='')

Write python output to file:

brainfuck -py -out "hw.py" -o -c "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++."
# file `hw.py` is created

Metadata

Release files for brainfuck-venomlab 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brainfuck-venomlab 0.1.1
File Size Uploaded Provenance Actions
brainfuck-venomlab-0.1.1.tar.gz 8.4 kB Without provenance Details for brainfuck-venomlab-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for brainfuck-venomlab 0.1.1
File Interpreter ABI Platform Actions
brainfuck_venomlab-0.1.1-py3-none-any.whl Python 3 none any Details for brainfuck_venomlab-0.1.1-py3-none-any.whl

Total release size: 18.0 kB

Release files / brainfuck-venomlab-0.1.1.tar.gz

Download URL brainfuck-venomlab-0.1.1.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6901988c8e708d9bcd1640feff7a1d3454f10714e17254321896455c0c4f2b66
BLAKE2b-256 checksum
How to use checksums
96d6a3707eddb0a5eaf50efc999c619bbf3410095c42decd7a5312e4a7f2dac3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.1

Release files / brainfuck_venomlab-0.1.1-py3-none-any.whl

Download URL brainfuck_venomlab-0.1.1-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a2e0dca663738176588815126538f1eec878b040fbf39c78d5a8e99e77f4506
BLAKE2b-256 checksum
How to use checksums
03cceef0a8fce3ac9f91b652a5498bc64c6294cd02c819b861378d2980f1ee6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.1

Security for brainfuck-venomlab 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page