#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

#277 in Programming languages

Download history 29/week @ 2024-11-18 259/week @ 2024-11-25 104/week @ 2024-12-02 14/week @ 2024-12-09

406 downloads per month

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–12MB
~156K SLoC