Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.07 KB

README.md

File metadata and controls

48 lines (37 loc) · 1.07 KB

brainfuck

Package brainfuck implements a Brainfuck interpreter in Go.

Default brainfuck interpreter implements 8 commands defined here wiki but this library also provides a mechanism to add/remove commands.

Add command:
brainfuck.AddInstruction(<instructionType>, <Handler to be executed>)
Remove command:
brainfuck.RemoveInstruction(<instructionType>)

How to use

$ go get github.com/shani1998/brainfuck
// create new io.Reader from inputs
code := strings.NewReader("++[>++.<-]>+")

// Standards interface to io
input := new(bytes.Buffer)
output := new(bytes.Buffer)

// initialize the brainfuck interpreter
bf := brainfuck.NewInterpreter(input, output)

// Store the result in output interface 
_ = bf.Run(code)

// print the result 
fmt.Println (output.String())

How to run tests

To run all tests in the root of the project

$ make test

To run cli that uses brainfuck library

$ make run-cli