Skip to main content

Supports you to generate Brainf**k code.

Project description

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.

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

bf-gen-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

bf_gen-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file bf-gen-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for bf-gen-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bb1cae72bdd822ad72d740a4e60a52a33e264ec78072b87c819860b77e2200b3
MD5 7bad105a53909ca505f233131dd07d90
BLAKE2b-256 2ca3ddb45f5dc80b32bac4b6757770fe47cfb181372945dd9eccfc17e1cb2be4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bf_gen-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 74c4a374531feb582ae6a320c0df013fd4f6969eee8ecd5e5c79bacec017697d
MD5 44d3ee1403e80b72cf6dc6360fd17789
BLAKE2b-256 d3f0f28e57f15e288f360f37dade8d871629c445aaa82fb693b7331c013fb067

See more details on using hashes here.

Supported by

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