Skip to content

Someon1e/brainfuck.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

brainfuck.rs is a fast Brainfuck executor in Rust. It includes an interpreter, a Brainfuck-to-Rust transpiler, and a Brainfuck-to-C transpiler.

Install

cargo install --git https://github.com/Someon1e/brainfuck.rs brainfuck

Usage

image

How?

It works by first processing the brainfuck program into tokens. Then, the tokens are optimised into instructions (IR).

Examples:

Input Tokens IR
++- Increment, Increment, Decrement Increment(1)
[-] LoopStart, Decrement, LoopEnd SetZero
>a>b< Forward, Comment, Forward, Comment, Backward Forward(1)
[->+>+<<] LoopStart, Decrement, Forward, Increment, Forward, Increment, Backward, Backward, LoopEnd MultiplyForward(1, 1), MultiplyForward(2, 1), SetZero
[->+++>+++++++<<] LoopStart, Decrement, Forward, Increment, Increment, Increment, Forward, Increment, Increment, Increment, Increment, Increment, Increment, Increment, Backward, Backward, LoopEnd MultiplyForward(1, 3), MultiplyForward(2, 7), SetZero
[.,] LoopStart, Input, Output, LoopEnd LoopStart(4), Input, Output, LoopEnd(1)
[>] LoopStart, Forward, LoopEnd ForwardLoop(1)
[<<] LoopStart, Backward, Backward, LoopEnd BackwardLoop(2)

Finally, the IR is interpreted or transpiled.

Files

  • samples contains example brainfuck programs.
  • src/main contains the lexer, IR, interpreter, and transpiler.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages