Git Product home page Git Product logo

bf-compiler's Introduction

Brainfuck Compiler/Interpreter

Scala CI

When completed this is supposed to be able to interpret brainfuck code as well as compiling it to native code.

Brainfuck Specification

Instruction Definition
> Increment the data pointer by one (to point to the next cell to the right).
< Decrement the data pointer by one (to point to the next cell to the left).
+ Increment the byte at the data pointer by one.
- Decrement the byte at the data pointer by one.
. Output the byte at the data pointer.
, Accept one byte of input, storing its value in the byte at the data pointer.
[ If the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command.
] If the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command.

Anything following a // is considered a comment and ignored.

Usage

This can process brainfuck programs in the two following ways

Interpretation

A given brainfuck program can be interpreted via the interpret CLI subcommand:

./bf-compiler interpret [OPTIONS] <path-to-program>

The interpret subcommand provides additional options such as a --debug flag. Check the usage instructions via the --help flag for more information.

Compilation

Next to interpretation, this tool is able to compile a given brainfuck program into native code. More specifically, it generates the corresponding assembly for each instruction and then uses an assembler (e.g. as on macOS) and linker (e.g ld) to create an executable binary. To compile a program, run the following command

./bf-compiler compile [OPTIONS] <path-to-program> <output-directory>

This will generate an executable with the same name as the input file in the <output-directory> Similar to the interpret subcommand, this command also provides additional options such as a --run flag. Check the usage instructions via the --help flag for more information.

NOTE: Native compilation is currently only supported for Apple silicon.

bf-compiler's People

Contributors

treemage 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.