#lexer #brainfuck #interpreter #parser

bin+lib fck

A simple Brainfuck parser, lexer and interpreter

3 releases

0.1.2 Dec 7, 2024
0.1.1 Nov 25, 2024
0.1.0 Nov 24, 2024

#11 in #brainfuck

29 downloads per month
Used in 2 crates (via hecate-bf)

MIT/Apache

17KB
331 lines

FCK

Fck is a simple Brainfuck lexer, parser, and interpreter. It includes a library crate that exports most of the functionality, and an executable that provides a CLI for lexing, parsing, and executing Brainfuck programs.

Fck binary

To see a list of all commands, use:

fck --help

Examples

Using run and run_file.

use fck::{run, run_file};

fn main() -> fck::Result<()> {
  run("+++++++++.[->+<]")?;
  run_file("path/to/file")?;
}

Using the individual modules.

use fck::lexer::lex;
use fck::parser::parse;
use fck::interpreter::Interpreter;

fn main() -> fck::Result<()> {
  let tokens = lex("source code")?;
  let ast = parse(&tokens)?;
  let mut interpreter = Interpreter::new();
  interpreter.run(&ast)?;
}

lib.rs:

FCK

A simple Brainfuck lexer, parser, and interpreter.

Examples

Using run and run_file.

use fck::{run, run_file};

fn main() -> fck::Result<()> {
  run("+++++++++.[->+<]")?;
  run_file("path/to/file")?;
}

Using the individual modules.

use fck::lexer::lex;
use fck::parser::parse;
use fck::interpreter::Interpreter;

fn main() -> fck::Result<()> {
  let tokens = lex("source code")?;
  let ast = parse(&tokens)?;
  let mut interpreter = Interpreter::new();
  interpreter.run(&ast)?;
}

Dependencies

~3–13MB
~163K SLoC