https://github.com/clivern/bf
A Brainfuck interpreter written in Go to Learn Interpreters and Compilers.
https://github.com/clivern/bf
Last synced: 10 months ago
JSON representation
A Brainfuck interpreter written in Go to Learn Interpreters and Compilers.
- Host: GitHub
- URL: https://github.com/clivern/bf
- Owner: Clivern
- License: mit
- Created: 2021-03-23T14:42:59.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T10:26:24.000Z (over 1 year ago)
- Last Synced: 2025-03-08T04:29:27.314Z (10 months ago)
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## Brainfuck Interpreter
A [Brainfuck](https://nickdesaulniers.github.io/blog/2015/05/25/interpreter-compiler-jit/) interpreter written in `Go`
[](https://github.com/clivern/bf/actions/workflows/build.yml)
[](https://godoc.org/github.com/clivern/bf)
[](https://goreportcard.com/report/github.com/clivern/bf)
### Installation
To install `bf` package, you need to install Go (version `1.13+` is required) and setup your Go project first.
```bash
$ mkdir example
$ cd example
$ go mod init example.com
```
- Then you can use the below `Go` command to install the latest version of `bf` package.
```bash
$ go get -u github.com/clivern/bf
```
Or the following for a specific version `vx.x.x`
```bash
go get -u github.com/clivern/bf@vx.x.x
```
- Import the package in your code.
```golang
import "github.com/clivern/bf"
```
### Quick start
Add the following code in `example.go` file
```bash
$ cat example.go
```
```golang
package main
import (
"bytes"
"fmt"
"os"
"strings"
"github.com/clivern/bf"
)
func main() {
buf := new(bytes.Buffer)
interpreter := bf.NewInterpreter(
strings.NewReader("-[------->+<]>-.-[->+++++<]>++.+++++++..+++.[--->+<]>-----.---[->+++<]>.-[--->+<]>---.+++.------.--------."),
os.Stdin,
buf,
)
err := interpreter.IsValid()
if err != nil {
panic(fmt.Sprintf("Invalid code: %s", err.Error()))
}
err = interpreter.Execute()
if err != nil {
panic(fmt.Sprintf("Invalid code: %s", err.Error()))
}
fmt.Println(buf.String()) // Hello World
}
```
Run `example.go`
```bash
$ go run example.go
```
It will return `Hello World`