Giter Club home page Giter Club logo

preprocessor_brainfuck's Introduction

Preprocessor Brainfuck Interpreter

This project contains an interpreter for brainfuck programs that is written solely in C preprocessor macros.

This implementation only uses simple preprocessor conditionals (#if some-expression), preprocessor defines without arguments (#define FOO some-expression), and inclusion of header files (#include HEADER). There exist other (IMO better) implementations of brainfuck for the C preprocessor that use other features, such as token pasting (such as CPP_COMPLETE).

This implementation also makes use of generated header files to create modifiable variables whose size is dependent on the max number of steps, the max size of the tape, and the max value of each value on the tape. The only generated file that is dependent on the input brainfuck program is the file that defines the code tape and the input tape (main.h, generated by bf_to_main.sh), which is a simple 1:1 translation of the brainfuck code and input to a sequence of defines.

Since the number of steps is limited and the size of variables is finite, this implementation is not turing complete. A recursive inclusion of the main run loop header file doesn't really help, because every major compiler has limits on the recursion depth of header files.

How to use

  1. Generate the headers
$ make
  1. Encode your program into main.h, and provide the file used as input
$ ./bf_to_main.sh hello.bf /dev/null > main.h
  1. Run the brainfuck interpreter
$ make run

or

$ make run DEBUG=1

Note

The preprocessor brainfuck interpreter is very very inefficient and will use around 16 GIGABYTES of memory and 15 to 20 minutes of processing time while running hello.bf.

preprocessor_brainfuck's People

Contributors

ferdi265 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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