Giter Site home page Giter Site logo

brainfuck's Introduction

Brainfuck with Macros

FOSSA Status

See Wikipedia on the original Brainfuck.

This implementation of Brainfuck introduces macro definition.

Installation

git clone https://github.com/SAMFYB/brainfuck.git
cd brainfuck && make install

Run Brainfuck

brainfuck your_program.bf

# To run DEBUG mode
brainfuck your_buggy_program.bf -d

# To display help message
brainfuck

# To translate macro-invoking script to plain brainfuck (original 8 commands)
brainfuck program.bf -b

Built-in Commands

  • + Increment the cell at current data pointer.
  • - Decrement the cell at current data pointer, do nothing if the cell has value 0.
  • > Move data pointer to the right.
  • < Move data pointer to the left, do nothing if data pointer has value 0, i.e. at the leftmost cell.
  • [ If the current cell has value 0, jump to the command after the matching ], otherwise continue execution.
  • ] Jump backward to the matching [.
  • . Output the current cell value decoded as Ascii.
  • , Accept one input integer as Ascii code, put into the cell at current data pointer.
  • # Start an end-of-line comment.
  • $ Import definition of a macro, in the form of $macro_name, no space between $ and the macro name.
  • | Force program termination immediately, if -d enabled, dump program status. (useful for debugging)

Macros

  • A macro can be any snippet of Brainfuck code.
  • A macro is defined in a seperate .bf file where the file name is the macro name.
  • A macro can itself invoke definitions of other macros.
  • A macro should not invoke itself. (no self-recursion)
  • Two macros cannot invoke each other. (no mutual-recursion)
  • The name of a macro can be anything matching the regex [a-zA-Z_]+

Here's an example of using macro zero.bf in one.bf. one.bf outputs number 1.

# zero.bf
# This program puts Ascii 48 (zero) on the right cell.
# Assuming both current cell and right cell has value 0.
++++ ++++ # Add 8 to current cell
[
  > +++ +++ # Add 6 to right cell
  < - # Decrement current cell by 1
]
# one.bf
$zero # use zero.bf
zero # put zero into the right cell
> + # move right and add 1
. # output

Roadmap

  • Make a REPL
  • Allow in-file macro definition
  • Fix program base path finding with relative path

License

FOSSA Status

brainfuck's People

Contributors

fossabot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.