Skip to content

ubnt-intrepid/lelele

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

209 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lelele

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.

Overview

Generates Rust parser code from grammar definition files (.lll). Supports both IELR(1) and LALR(1) algorithms.

Requirements

  • Rust 1.93.0 or later

Crate Structure

  • lelele - Parser generator core (library + CLI tool)
  • lelele-runtime - Runtime library for generated parsers

Usage

As a CLI Tool

lelele [--algorithm IELR|LALR] [-o output.rs] input.lll
  • --algorithm: Algorithm to use (default: IELR)
  • -o: Output file path (defaults to input file with .rs extension)

As a Library

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())?;

Grammar Definition

Define grammars in .lll files.

Directives

  • @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

Example: Arithmetic Expressions

@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
    ;

Examples

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]

License

MIT


This README was auto-generated with the assistance of Claude (claude-opus-4-5-20250514).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages