4 releases
0.1.3 | Apr 10, 2022 |
---|---|
0.1.2 | Apr 10, 2022 |
0.1.1 | Apr 10, 2022 |
0.1.0 | Apr 10, 2022 |
#651 in Programming languages
22 downloads per month
61KB
1.5K
SLoC
libbf
Brainfuck-like language library.
This library can define a variant of Brainfuck-like language parser and can run parsed program.
Examples
Use predefined Brainfuck interpreter
`bf' feature flag is needed to compile this example.
use libbf::{predefined::bf, runtime};
use std::io;
fn main() {
let source = " [> [> > > > <<<<-]> > >->> [<]<-]>>.>---. .. .>>.<-.<. .------.--------.>> .> .";
let program = bf::parser()
.parse_str(source)
.expect("Failed to parse");
runtime::run(&program, io::stdin(), io::stdout()).expect("Failed to run");
}
Define Brainfuck interpreter
use libbf::{parser::Parser, runtime, token::simple::SimpleTokenSpec};
use std::io;
fn main() {
// 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");
runtime::run(&program, io::stdin(), io::stdout()).expect("Failed to run");
}
Feature flags
all
- all featurespredefined
- predefined parsers belowbf
- predefined Brainfuck parserook
- predefined Ook! parser
Dependencies
~260–720KB
~17K SLoC