Expand description
Brainfuck-like language library.
This library can define a variant of Brainfuck-like language parser and can run parsed program.
§Examples
use libbf::{parser::Parser, runtime, token::simple::SimpleTokenSpec};
use std::io::{self, Read};
// Create parser with token specification.
let parser = Parser::new(
SimpleTokenSpec {
// You can specify tokens with `ToString` (`char`, `&str`, `String`, etc.)
ptr_inc: '>', // char
ptr_dec: "<", // &str
data_inc: "+".to_string(), // String
data_dec: '-',
output: '.',
input: ',',
loop_head: '[',
loop_tail: ']',
}
.to_tokenizer(),
);
let source = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
let program = parser.parse_str(source).expect("Failed to parse");
let mut output = Vec::new();
let result = runtime::run(&program, io::stdin(), &mut output);
assert!(result.is_ok());
assert_eq!(output, b"Hello World!\n");
Modules§
- This module contains error definitions.
- This module provides a parser for the program.
- Predefined Brainfuck-like implementations.
use libbf::prelude::*
is easy way to use this library;- Parsed program of Brainfuck-like language and related definitions.
- Program runtime.
- Token related definitions.