skvadrik/re2c logo

skvadrik/re2c

Free

Lexer generator for C, C++, D, Go, Haskell, Java, JS, OCaml, Python, Rust, Swift, V and Zig.

FreeFree tier
Type
Open Source

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

Generates fast lexers using conditional jumps and comparisons instead of tables
Supports C, C++, Go, Rust, D, Haskell, Java, JavaScript, OCaml, Python, Swift, V, and Zig
Flexible interface allowing custom integration with any environment
Applies optimizations for speed and code size reduction
Open source and free (MIT license)
Produces debug-friendly and understandable code

Pros & Cons

Pros
  • 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
Cons
  • 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

Best For

Building high-performance lexers for compilers and interpretersReplacing hand-written lexers to gain speed and reliabilityParsing structured text in resource-constrained environmentsEmbedded systems where small code footprint is critical

FAQ

What programming languages does re2c support as output?
re2c supports generating lexers for C, C++, Go, Rust, D, Haskell, Java, JavaScript, OCaml, Python, Swift, V, and Zig.
Is re2c free and open source?
Yes, re2c is free and open source software, licensed under the MIT license.
How does re2c generate lexers without tables?
Instead of a table-driven approach, re2c encodes the finite state automaton using conditional jumps and comparisons, resulting in faster and more debuggable code.
Where can I find documentation and examples?
Official documentation and examples are available on the re2c website at re2c.org.