7 releases (4 breaking)

✓ Uses Rust 2018 edition

0.5.0 Feb 18, 2020
0.4.0 Dec 28, 2019
0.3.0 Dec 20, 2019
0.2.2 Feb 19, 2019
0.1.0 Jan 4, 2019

#3 in Emulators

Download history 41/week @ 2019-12-09 8/week @ 2019-12-16 16/week @ 2019-12-23 5/week @ 2019-12-30 10/week @ 2020-01-06 26/week @ 2020-01-13 30/week @ 2020-01-20 1/week @ 2020-01-27 2/week @ 2020-02-03 7/week @ 2020-02-10 54/week @ 2020-02-17 21/week @ 2020-02-24 1/week @ 2020-03-02 16/week @ 2020-03-09 15/week @ 2020-03-16 23/week @ 2020-03-23

56 downloads per month

MIT license

39KB
763 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++
  • Python
  • Golang
  • Haskell
  • Lua

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

No runtime deps