Skip to content

domluna/brainfuck-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brainfuck-go

Brainfuck compiler in Go - well not quite. A compiler outputs binaries. It's in between an interpreter and a compiler.

Intro

This is not the smallest possible implementation of a Brainfuck interpreter by any means. Nor it is the fastest. Those aren't the goals.

The goal from this was to learn a bit about how interpreters and compilers work. Using Brainfuck looked to be the simplest way to achieve this.

Steps of this process are kept in separate packages and serve as a decent blueprint for future, more complicated work.

Resources:

Lexical Scanning in Go

Ivy, APL Interpreter

How it works

  1. lexer on *.b file
  2. parses tokens from lexer
  3. create list(AST in this context) of instructions from (2)
  4. optimize instructions
  5. evalute instructions
  6. output result

Steps 1-3 run concurrently.

Usage

Get it.

$ go get github.com/domluna/brainfuck-go

Use it.

$ brainfuck-go helloworld.b
// Hello World!

Optimizing the instructions

Running examples/mandelbrot.b timings.

    without optimization -> 194.10 seconds
    with    optimization -> 52.62  seconds

That's ~400% speed up. So it's fair to say the optimizations do a fair amount.

About

Brainfuck interpreter/compiler in Go. It even has some optimizations!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published