Giter Site home page Giter Site logo

brainfuck's Introduction

Brainfuck 0.3

This is a little project that I wrote in QB64. It contains three CLI tools:

  • the Brainfuck Compiler "BFC.exe"
  • the Brainfuck Assembler "BFASM.exe"
  • the Brainfuck Interbreter "BF.exe"

The Brainfuck Compiler

"BFC.exe" compiles your Brainfuck source code into byte code. The calling syntax is as follows: bfc <sourceFile>
Important: Do not provide a file extension, because the compiler assumes source files having ".bf" and byte code file having ".bfc".

Before compiling the commands, the Brainfuck pre-processor will be executed:

  • #<file> = Include another Brainfuck source code.
  • "<name>" = Define a macro called name.
  • (<name>) = Call macro by its name.
  • {<code>} = Provide the code linked to a macro.

Includes cannot be nested, i.e. includes in include files will not be processed.
Also, the include command must be the only or the last command in a line!

The macros will not be called like procedures, but the code will be inserted as it is.
Macros can also be defined multiple times, therefore multiple codes can be saved,
and therefore multiple codes will be inserted.

Brainfuck itself knows the following commands:

  • ">" = goto next cell
  • "<" = goto previous cell
  • "+" = increment current cell
  • "-" = decrement current cell
  • "[" = begin a loop if current cell is not 0
  • "]" = repeat loop if current cell is not 0
  • "." = print out an ASCII character
  • "," = read in an ASCII character

You can also provide a number, to multiply the number of executions. Following numbers will be added together.
Examples:

  • "+7" = increment seven times
  • "+0" = do not increment at all
  • "-55" = decrement ten (5+5) times

The Brainfuck Assembler

"BFASM.exe" compiles your Brainfuck Assembler code into byte code. The calling syntax is as follows: bfasm <sourceFile>
Important: Do not provide a file extension, because the assembler assumes source files having ".bfa" and byte code file having ".bfc".

The Brainfuck Assembler knows the following pseudo-commands:

  • ";": comment line
  • ".mode <mode>": config one of the display modes:
    • "ascii" / "byte": input and output characters
    • "digit" / "number": input and output numbers
    • "console" / "text": input and output text
    • "graphic(s)" / "video": input and output pixels
  • ".ascii": shortcut for ".mode ascii"
  • ".byte": shortcut for ".mode byte"
  • ".console": shortcut for ".mode console"
  • ".digit": shortcut for ".mode digit"
  • ".graphic": shortcut for ".mode graphic"
  • ".graphics": shortcut for ".mode graphics"
  • ".text": shortcut for ".mode text"
  • ".video": shortcut for ".mode video"


The Brainfuck Assembler knows the following commands:

  • "add" / "inc": increment current cell
  • "call": insert macro code; the following token is used as the name
  • "cin" / "in" / "inp": read in ASCII character
  • "cout" / "out": print out ASCII character
  • "dec" / "sub": decrement current cell
  • "endm" / "endp": end of a macro definition
  • "if" / "while": begin a loop, if current cell is not 0
  • "include <file>": include another assembler file provided as following token
  • "loop" / "loopne" / "loopnz": repeat loop, if current cell is not 0
  • "macro <name>" / "proc <name>": define a macro called name
  • "nop": perform no operation
  • "pop": goto previous cell
  • "push": goto next cell
  • "ret": return from subroutine
  • "st_X": store byte code "X", where X is a hexadecimal digit (0-9,A-F)

The Brainfuck Interpreter

"BF.exe" runs your compiled Brainfuck byte code. The calling syntax is as follows: bf <sourceFile>
Important: Do not provide a file extension, because the interpreter assumes files having ".bc"

The code is running inside a BVM, i.e. a Brainfuck Virtual Machine, refering to JVM (Java Virtual Machine).

brainfuck's People

Contributors

derrobert-28 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.