Search

Lib.rs

› Emulators
#brainfuck #brainfuck-compiler #interpreter #compiler

brainhug

A simple brainf*ck translator

by Siddharth and 6 contributors

  • Install
  • API reference
  • GitHub repo (sn99)
  • Home (github.io)

10 releases (6 breaking)

0.7.0 Sep 12, 2022
0.6.1 Apr 19, 2021
0.6.0 Sep 16, 2020
0.5.0 Feb 18, 2020
0.2.2 Feb 19, 2019

#72 in Emulators

26 downloads per month

MIT license

46KB
938 lines

brainhug

Build Status Build status Crates.io Download crate Documentation

brainhug is a crate that is used to interpret brainf*ck code to any other language

Current languages covered are :

  • C
  • C++
  • C#
  • Python
  • Golang
  • Haskell
  • Lua
  • JavaScript

Why the name brainhug ?

Inspired from link

Usage

Add this to your Cargo.toml:

[dependencies]
brainhug = "*"

and this to your crate root:

extern crate brainhug;

use brainhug::Lang;

Contributing

Read contributing for Details

Example

extern crate brainhug;

use brainhug::Lang;

fn main() {
    // will print `Hello World!`
    let input = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";

    // `brainhug::generate` will generate a `String`
    println!("{}", brainhug::generate(Lang::C, input));
}

It will produce

#include "stdio.h"

int main() {
    char tape[20000] = {0};
    char *ptr = tape;
        *ptr += 8;
        while (*ptr) {
                ptr += 1;
                *ptr += 4;
                while (*ptr) {
                        ptr += 1;
                        *ptr += 2;
                        ptr += 1;
                        *ptr += 3;
                        ptr += 1;
                        *ptr += 3;
                        ptr += 1;
                        *ptr += 1;
                        ptr -= 4;
                        *ptr -= 1;
                }
                ptr += 1;
                *ptr += 1;
                ptr += 1;
                *ptr += 1;
                ptr += 1;
                *ptr -= 1;
                ptr += 2;
                *ptr += 1;
                while (*ptr) {
                        ptr -= 1;
                }
                ptr -= 1;
                *ptr -= 1;
        }
        ptr += 2;
        putchar(*ptr);
        ptr += 1;
        *ptr -= 3;
        putchar(*ptr);
        *ptr += 7;
        putchar(*ptr);
        putchar(*ptr);
        *ptr += 3;
        putchar(*ptr);
        ptr += 2;
        putchar(*ptr);
        ptr -= 1;
        *ptr -= 1;
        putchar(*ptr);
        ptr -= 1;
        putchar(*ptr);
        *ptr += 3;
        putchar(*ptr);
        *ptr -= 6;
        putchar(*ptr);
        *ptr -= 8;
        putchar(*ptr);
        ptr += 2;
        *ptr += 1;
        putchar(*ptr);
        ptr += 1;
        *ptr += 2;
        putchar(*ptr);
}

License

Licensed under

  • MIT license (LICENSE.md or http://opensource.org/licenses/MIT)

No runtime deps

  • dev criterion 0.4
See also: fucker, brainf-ck-rs, bee_hive, cambridge-pseudocode-interpreter, sieve-rs, kz80_lisp, waspy, wright, brainfoamkit, mblf, brim

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.