Skip to main content

Write brainfuck with ONLY square brackets.

Project description

Bruck

Write brainfuck with ONLY square brackets.

[]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][][[]][]][][

PyPI - Python Version PyPI GitHub

Installation

$ pip install bruck

Usage

$ bruck [-veh] PROGRAM

You can interpret a bruck program by

$ bruck <filename>.bruck

Or run a program in command line by -e option. For example:

$ bruck -e '][][]['

-v option shows version, and -h option shows help.

Bruck Syntax

The syntax of bruck is basically the same as brainfuck, but was inspired by codons in DNA or RNA molecules. We use 3-character strings consisting of [ and ] to represent 8 different commands in brainfuck.

Bruck Equivalent Brainfuck Description
[]] + Increment the memory cell at the pointer
[[] - Decrement the memory cell at the pointer
]][ > Move the pointer to the right
][[ < Move the pointer to the left
[][ . Output the character signified by the cell at the pointer
][] , Input a character and store it in the cell at the pointer
[[[ [ Jump past the matching ]]] if the cell at the pointer is 0
]]] ] Jump back to the matching [[[ if the cell at the pointer is nonzero

All characters other than [ and ] are ignored, including spaces and newlines. Having just started to use bruck, you may find it helpful to divide the program into commands:

][] []] [][

And when you get familiar with the language, you can write something cool like this:

[]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][]][][[][[]][]][]][][[]][][[[][[][[][[][][[]][]][]][][

Since the length of a bruck command is 3, the length of a bruck program (with only [ and ] counted) must be divisible by 3, otherwise the interpreter will raise an error.

Error Messages

If an error occurs when executing a bruck program, the bruck interpreter will raise a BruckError with error messages showing where and why the error has occured.

If you find the error messages generated by the interpreter a little difficult to understand, don't worry. It is a feature. Bruck is a so-called esoteric programming language, and therefore the bruck interpreter is also designed to be esoteric. You will be used to that soon.

API

A Python API is provided to interpret bruck programs. After installation, import the interpreter module by

from bruck.interpreter import *

The interpreter module includes a class BruckInterpreter to interpret and execute bruck programs. Here is an example:

from bruck.interpreter import *

bruckInterpreter = BruckInterpreter('<bruck_program_string>') # Initialize

bruckInterpreter.exec() # Execute the program

For more help on the API, try help(BruckInterpreter) after importing the module.

Contribution

If you find any bugs or have suggestions for new features, please raise an issue for further discussion. All contributions are welcomed.

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

bruck-0.1.0.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

bruck-0.1.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

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