Skip to content

KCreate/brainfuck-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brainfuck to StackVM compiler

This repository is the home of a small compiler written in C. It compiles codes written in the Brainfuck Language to assembly code for my own virtual machine.

Installation

You will need my StackVM to be able to assemble and execute the resulting assembly file. Take look at the installation instructions over there.

  1. git clone https://github.com/KCreate/brainfuck-compiler
  2. make
  3. bin/bfc input.bf > myprog.asm
  4. stackvm build myprog.asm -s -o myprog.bc
  5. stackvm run myprog.bc

Features

Command Meaning Status
> Increment data pointer
< Decrement data pointer
+ Increment the value in the current cell
- Decrement the value in the current cell
. Output the byte at the data pointer
, Read a byte of input and store it in the byte at the data pointer 𐄂
[ Jump to the matching ] command if the byte at the data pointer is 0
] If the current byte is nonzero, jump back to the command after the matching [

Todos

  • Simple peep-hole optimizations
  • Better error handling
  • Location information in the AST
  • , command (StackVM needs to be patched for this to work)

Credits

Additional resources

About

Brainfuck to StackVM compiler written in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published