Giter Club home page Giter Club logo

braingasm's Introduction

Braingasm

Braingasm is a super-set of brainfuck, and extends the 8 original instructions with a few new ones, along with the concept of prefixes and registers.

The original idea for the language was to combine brainfuck and assembly code (asm), hence the name.

braingasm is still under development and breaking changes may occur.

Sample code

Here's an implementation of the famous FizzBuzz program written in braingasm:

100[>#3p["Fizz".+]#5p["Buzz".+]z[#:]10.]

It works like this:

100[               One hundred times:
    >                Go to the next cell.
    #3p[             If current cell number is divisble by 3:
        "Fizz".        Print "Fizz".
        +              Increment current cell
    ]
    #5p["Buzz".+]    Same thing for 5 and "Buzz".
    z[               If the current cell is 0 (hasn't been incremented):
      #:               Print current cell number
    ]
    10.              Print a newline
]

The language

As plain brainfuck, braingasm is a simple language that operates on an arbitrarily long tape. The tape is continuous array of cells which hold an integer value. In braingasm the cells may by default hold arbitrarily large values, both positive and negative. All cells are initially zero. The tape is the only form of storage available to the programmer -- there is no concept of variables.

Instructions usually consist of one character and alter the cell under the data pointer. The cell under the data pointer is known as the current cell.

Instructions

< and > moves the data pointer one step to the left or right respectively. + increments the value of the current cell by one, while - decrements it. Input is done with , (read one byte from stdin to the current cell) and ; (read a number), and output with . (print current cell as a byte) and : (print as number). Code enclosed in square brackets ([ and ]) will be repeated as long as the value of the current cell is not zero.

For the full list of instructions and more details about their behaviour, see the docs or the specs.

Prefixes

A prefix may alter the effect of an instruction in different ways. The simplest kind of prefix is a numeric literal, which makes the succeeding instruction repeat a certain number of times:

  • 5+ increases the value of the current cell by 5.
  • 7[X] Runs the loop, containing some code X, exactly 7 times.

Most prefixes are dependent on the value of the current cell:

  • The z prefix evaluates as 1 if the current cell holds the value 0, otherwise it returns 0.
  • The # register holds the current position in the data tape. #> will move to cell 12 if the current cell is 6, while #< always will return to the original start position on the tape.

Some prefixes can take prefixes themselves:

  • The parity prefix, p, alone returns 1 or 0 depending on whether the value of the current cell is even.
  • If given an integer literal, p will rather check the parity in that "base": ย 3p: will print 1 if the cell is divisible by 3, or 0 otherwise.
  • If given another prefix which returns an integer, p will evaluate the result of that prefix instead: #p: will print 1 if the current data pointer is an even number.
  • Given two integers, p checks if the first integer is divisible by the second.

More information about the different prefixes can be found in the docs or specs.

Installation

You need Ruby in order to run braingasm. Install braingasm from the command line with:

$ gem install braingasm

Usage

$ braingasm my_program.bg

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/daniero/braingasm.

License

The gem is available as open source under the terms of the MIT License.

braingasm's People

Contributors

daniero avatar

Stargazers

 avatar

Watchers

 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.