An LR(1) parser generator for Rust.
Note
This is an experimental project created for learning LR parsing algorithms (IELR(1), LALR(1), etc.). It is not intended for production use.
Generates Rust parser code from grammar definition files (.lll). Supports both IELR(1) and LALR(1) algorithms.
- Rust 1.93.0 or later
- lelele - Parser generator core (library + CLI tool)
- lelele-runtime - Runtime library for generated parsers
lelele [--algorithm IELR|LALR] [-o output.rs] input.lll--algorithm: Algorithm to use (default: IELR)-o: Output file path (defaults to input file with.rsextension)
To generate parser code in build.rs:
use lelele::{codegen::Codegen, ielr, syntax};
let grammar = syntax::parse_file(&input_path)?;
let table = ielr::compute(&grammar.cfg, Default::default())?;
let codegen = Codegen::new(&grammar, &table);
std::fs::write(&output_path, codegen.to_string())?;Define grammars in .lll files.
@terminal- Declare terminal symbols@nonterminal- Declare nonterminal symbols (optional)@rule- Define production rules@start- Specify the start symbol@prec- Define operator precedence@error- Error recovery token
@prec { assoc = left } add;
@prec { assoc = left } mul;
@prec { assoc = right } neg;
@terminal LPAREN RPAREN NUM;
@terminal { prec = add } PLUS MINUS;
@terminal { prec = mul } STAR SLASH;
@rule Expr :=
| Expr PLUS Expr
| Expr MINUS Expr
| Expr STAR Expr
| Expr SLASH Expr
| @{ prec = neg } MINUS Expr
| NUM
| LPAREN Expr RPAREN
| @error
;
The examples/ directory contains the following samples:
- arithmetic - Four arithmetic operations parser
- json - JSON parser
- min-caml - A parser of MinCaml syntax.
To run:
cargo run -p lelele-example-json [filepath]MIT
This README was auto-generated with the assistance of Claude (claude-opus-4-5-20250514).