Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sn99/brainhug
A simple brainfuck translator crate in Rust
https://github.com/sn99/brainhug
brainfuck crate language rust
Last synced: 14 days ago
JSON representation
A simple brainfuck translator crate in Rust
- Host: GitHub
- URL: https://github.com/sn99/brainhug
- Owner: sn99
- License: mit
- Created: 2018-12-28T17:49:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-24T04:24:14.000Z (over 1 year ago)
- Last Synced: 2024-09-19T00:55:38.980Z (about 2 months ago)
- Topics: brainfuck, crate, language, rust
- Language: Rust
- Homepage: https://sn99.github.io/brainhug/
- Size: 64.5 KB
- Stars: 20
- Watchers: 4
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# brainhug
[![Build Status](https://travis-ci.com/sn99/brainhug.svg?branch=master)](https://travis-ci.com/sn99/brainhug)
[![Build status](https://ci.appveyor.com/api/projects/status/23dcr0k5u244qd3e?svg=true)](https://ci.appveyor.com/project/sn99/brainhug)
[![Crates.io Download](https://img.shields.io/crates/d/brainhug.svg)](https://crates.io/crates/brainhug)
[![crate](https://img.shields.io/crates/v/brainhug.svg)](https://crates.io/crates/brainhug)
[![Documentation](https://docs.rs/brainhug/badge.svg)](https://docs.rs/brainhug)`brainhug` is a crate that is used to interpret brainf*ck code to any other language
#### Current languages covered are :
- [x] C
- [x] C++
- [x] C#
- [x] Python
- [x] Golang
- [x] Haskell
- [x] Lua
- [X] JavaScript#### Why the name brainhug ?
Inspired from [link](https://lists.freedesktop.org/archives/dri-devel/2018-November/198581.html)
## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
brainhug = "*"
```and this to your crate root:
```rust
extern crate brainhug;use brainhug::Lang;
```## Contributing
Read [contributing](CONTRIBUTING.md) for Details
## Example
```rust
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
```c
#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](LICENSE.md) or http://opensource.org/licenses/MIT)