Lexigram
About
Lexigram is a lexer/parser generator. It is written in Rust and generates Rust code.
It currently generates a predictive, non-recursive LL(1) parser. However, you may write a non-LL(1) grammar, as long as Lexigram can transform it into LL(1). Left-recursive and ambiguous rules are supported, and left factorization is performed automatically. These transformations are made as transparent as possible in the generated code.
The listener pattern allows your code to interact with the parser by executing user-implemented methods when rules are processed, as in ANTLR. It is also somewhat similar to the code written next to each rule in tools like Yacc and Bison, but it’s cleaner and more flexible.
The project is hosted on GitHub.
This Documentation
This documentation consists of several chapters.
The introduction gives a general overview of parsers, their components, how they are designed, how they can be used, and the main parser types. If you’re not familiar with the design of parsers and the limitations of LL(1) grammars, it is recommended to read it, otherwise it can be skipped.
The tutorial shows how to build a small parser step by step. It helps you familiarize yourself with Lexigram using a hands-on approach.
The quick overview of the crates presents the main crates of this project.
The lexer generator reference and the parser generator reference describe more formally the lexicon and grammar language, the grammar transformations, and the generated code.
The Lexigram Book covers version 0.9.1 and has been last updated on 30 March 2026.
Installation and Dependencies
The lexigram crate contains the executable. You’ll find information on how to install it and its main command-line options in the Lexigram Crates chapter.
The lexigram-core crate is the only dependency you need with the generated code. There are more details about it in the relevant Lexigram Crates chapter.
Generating the Code
lexigram -h shows the available options.
For example, to create a parser from the combined lexicon/grammar in ./grammar/calc.lg, and to write the generated code to ./src/lexer.rs and ./src/parser.rs, use this command:
lexigram -c grammar/calc.lg -l src/lexer.rs -p src/parser.rs --log
You can also generate a parser from Rust code instead of using the command-line tool. In that case, you need the full library; see the Lexigram Crates chapter and the tutorial for more information.
Don’t miss the examples in the repository, under the examples directory (they’re briefly listed at the end of the tutorial).