Coder Social home page Coder Social logo

gobrainfuck's Introduction

GoBrainfuck

Go Version

A Brainfuck language interpreter with a few slight additions, written in Go.

Usage

Running a compiled file

  • Windows
./brainfuck-windows.exe <file path> [memory allocation]
./brainfuck-windows-32.exe <file path> [memory allocation]
./brainfuck-windows-arm64.exe <file path> [memory allocation]
  • macOS
./brainfuck-macos-intel <file path> [memory allocation] # For Macs with Intel processors
./brainfuck-macos-arm <file path> [memory allocation] # For Macs with Apple M processors 
  • Linux
./brainfuck-linux <file path> [memory allocation]
./brainfuck-linux-32 <file path> [memory allocation]
./brainfuck-linux-arm <file path> [memory allocation]
./brainfuck-linux-arm64 <file path> [memory allocation]

Note

If you see permission denied error when running the file, make the file executable by typing chmod +x brainfuck-*

Running from source

To do this, you must have the Go 1.22+ compiler installed.

go run brainfuck <file path> [memory allocation]

Docker usage

This project is available as a Docker image and can be pulled from GitHub Container Registry.

Dockerfile example:

FROM ghcr.io/wavy-cat/gobrainfuck

COPY . .

ENTRYPOINT ["brainfuck", "main.bf"]

Commands

Command Go Equivalent Meaning
> cursor++ Move to the next cell
< cursor-- Move to the previous cell
+ memory[cursor]++ Increase the value in the current cell by 1
- memory[cursor]-- Decrease the value in the current cell by 1
. fmt.Print(string(memory[cursor])) Print the contents of the current cell
, fmt.Scanln(&byte) Store user input in a cell
[ for memory[cursor] != 0 { Start of loop
] } End of loop
* fmt.Print(memory[cursor]) Print the contents of the current cell in raw form

The * command is not present in the official language specification, nevertheless, it was introduced in this implementation for simplicity of debugging. Whenever possible, use code that fully conforms to the official specification, for example n>>+++++++++[<++++++>-]----[<+>-]<..

I/O

Input

Input using , command works with os.Stdin. Only the first byte (the first character) is written. An empty input will write the value 0 to the cell. Usually, ASCII characters are accepted, but you can specify a number directly if you start the line with //. For example, //69 will write the number 69 to the cell.

Output

Output is implemented via fmt.Print(). Usually, the character under the number written in the cell is displayed, however, you can print the number itself using the * command.

Memory allocation

By default, the interpreter allocates 30,000 memory cells, by the language design. But you can specify a different number of cells before starting the program. All you need to do is specify the desired number of memory cells in the launch command, placing the number immediately after the file path. Here is an example, where 100 memory cells are allocated:

./brainfuck-* <file path> 100

Installation on Linux

This is an optional step.

  1. Download the file of the latest version of the interpreter.
  2. Make it executable by running chmod +x brainfuck-*.
  3. Move it to /usr/bin using the command sudo mv brainfuck-* brainfuck.
  4. Verify its functionality by executing brainfuck version.

Building the project

Note

Please note that compiled builds are available in Actions.

  1. Install the latest version of the Go compiler from the official site
  2. Initiate the compilation using go build brainfuck

Example for Linux on the amd64 platform with root permissions:

wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go build brainfuck

gobrainfuck's People

Contributors

wavy-cat avatar

Stargazers

IDIGMA avatar AndcoolSystems avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.