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.
You will need my StackVM to be able to assemble and execute the resulting assembly file. Take look at the installation instructions over there.
git clone https://github.com/KCreate/brainfuck-compiler
make
bin/bfc input.bf > myprog.asm
stackvm build myprog.asm -s -o myprog.bc
stackvm run myprog.bc
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 [ |
✓ |
- Simple peep-hole optimizations
- Better error handling
- Location information in the AST
-
,
command (StackVM needs to be patched for this to work)