Skip to main content

Brainfuck parser

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brainfuck-venomlab-0.1.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

brainfuck_venomlab-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file brainfuck-venomlab-0.1.1.tar.gz.

File metadata

  • Download URL: brainfuck-venomlab-0.1.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for brainfuck-venomlab-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6901988c8e708d9bcd1640feff7a1d3454f10714e17254321896455c0c4f2b66
MD5 1e13598b5e25a3ecd02b458b5f6c7dab
BLAKE2b-256 96d6a3707eddb0a5eaf50efc999c619bbf3410095c42decd7a5312e4a7f2dac3

See more details on using hashes here.

File details

Details for the file brainfuck_venomlab-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: brainfuck_venomlab-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for brainfuck_venomlab-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a2e0dca663738176588815126538f1eec878b040fbf39c78d5a8e99e77f4506
MD5 a5573d0d4850ab9918dcd4527d74c6f9
BLAKE2b-256 03cceef0a8fce3ac9f91b652a5498bc64c6294cd02c819b861378d2980f1ee6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page