Skip to main content

bf-gen (Brainf**k generator)

Test PyPI

Icon

With this library, you can get Brainf**k source code by just calling functions.
Why don't we write Brainf**k with your brain clear!

Features

  • Easy to use
  • Readable
  • Various functions
  • Also can be used for Brainf**k-like languages such as Blub, Ook!
  • Inspired by LLVM IRBuilder

Why use this library

Some people think that writing Brainf**k is interesting since it is unreadable and there are no reasons to use this library.
Actually, I agree with this idea.

But there are others who want to learn Brainf**k but don't know how to do.
I hope this library supports them to drive into crazy as speedily as possible without prejudice.

Examples

Hello World

from bf_gen import BFBuilder

builder = BFBuilder() # Initialize Brainf**k builder

builder.init_with_letter('H') # Fill current cell by 'H'
builder.output()              # Print a value of current cell
builder.init_with_letter('e') # Fill current cell by 'e'
builder.output()              # Print a value of current cell
builder.init_with_letter('l') # Fill current ...
builder.output()              # Print a value ...
builder.init_with_letter('l') # Fill ...
builder.output()              # Print ...
....

bf_source = builder.generate() # Get Brainf**k code

Of course, it is far from smart.
This is one of good examples for showing "Hello World":

from bf_gen import BFBuilder

builder = BFBuilder() # Initialize Brainf**k builder

for letter in 'Hello World':
    builder.init_with_letter(letter) # Fill current cell by letter given
    builder.output()                 # Print a value of current cell

bf_source = builder.generate() # Get Brainf**k code

Triangle

from bf_gen import BFBuilder

builder = BFBuilder() # Initialize Brainf**k builder
triangle_size = 5

#
# <Memory layout>
#
# [ ][ ][ ][ ]
#
# 0: Descending counter
# 1: Ascending counter
# 2: Symbol counter
# 3: Temporary value
#

DESCENDING = 0
ASCENDING = 1
SYMBOL = 2
TEMP = 3

builder.move(DESCENDING)             # Move to cell 0
builder.init_with_num(triangle_size) # Initialize cell 0 with the size of triangle

with builder.loop():
    builder.add(-1) # Decrement cell 0

    builder.move(TEMP)       # Move to cell 3
    builder.init_with_zero() # Initialize cell 3

    builder.move(ASCENDING)    # Move to cell 1
    builder.add(1)             # Increment cell 1
    builder.copy(SYMBOL, TEMP) # Copy a value of ascenfing counter to symbol counter

    builder.move(SYMBOL) # Move to cell 2

    with builder.loop():
        builder.add(-1) # Decrement cell 2

        builder.move(TEMP)            # Move to cell 3
        builder.init_with_letter('#') # Initialize cell 3 with "#"
        builder.output()              # Print "#"

    builder.move(TEMP)             # Move to cell 3
    builder.init_with_letter('\n') # Initialize cell 3 with new line character
    builder.output()               # Print new line character

bf_source = builder.generate() # Get Brainf**k code

After executing Brainf**k code, you will see following:

#
##
###
####
#####

Wow! Beatiful!

Installation

I recommend you to install from PyPI.

$ pip install bf-gen

License

This library is released under MIT License.

Metadata

Release files for bf-gen 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 bf-gen 0.1.1
File Size Uploaded
bf-gen-0.1.1.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bf-gen 0.1.1
File Interpreter ABI Platform
bf_gen-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / bf-gen-0.1.1.tar.gz

Download URL bf-gen-0.1.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bb1cae72bdd822ad72d740a4e60a52a33e264ec78072b87c819860b77e2200b3
BLAKE2b-256 checksum
How to use checksums
2ca3ddb45f5dc80b32bac4b6757770fe47cfb181372945dd9eccfc17e1cb2be4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

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

Download URL bf_gen-0.1.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74c4a374531feb582ae6a320c0df013fd4f6969eee8ecd5e5c79bacec017697d
BLAKE2b-256 checksum
How to use checksums
d3f0f28e57f15e288f360f37dade8d871629c445aaa82fb693b7331c013fb067
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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