skvadrik/re2c
FreeLexer generator for C, C++, D, Go, Haskell, Java, JS, OCaml, Python, Rust, Swift, V and Zig.
About skvadrik/re2c
re2c is a free and open-source lexer generator for C/C++, Go and Rust. Its main goal is generating fast lexers: at least as fast as their reasonably optimized hand-coded counterparts. Instead of using traditional table-driven approach, re2c encodes the generated finite state automata directly in the form of conditional jumps and comparisons. The resulting programs are faster and often smaller than their table-driven analogues, and they are much easier to debug and understand. re2c applies quite a few optimizations in order to speed up and compress the generated code. Another distinctive feature is its flexible interface: instead of assuming a fixed program template, re2c lets the programmer write most of the interface code and adapt the generated lexer to any particular environment.
Key Features
Pros & Cons
- Extremely fast output often matching or beating hand-coded lexers
- Smaller generated code compared to table-driven lexers
- Output is easily debuggable and auditable
- Supports a wide range of target languages
- Flexible to adapt to any input environment or framework
- Well-documented with examples and official website
- Only generates lexers (tokenizers), not full parsers
- Requires manual implementation of interface code (no fixed template)
- Learning curve for integrating re2c into existing projects
- Less mainstream than alternatives like Flex/Lex