re2c is a free and open-source lexer generator for C and C++. 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.

For a step-by-step introduction, see examples. For complete overview, see the manual.


News & updates

Subscribe to receive the latest news and updates: feed

Bugs & feedback

The best place to report a bug is on github or in re2c-devel and re2c-general mailing lists. Note that re2c is hosted on both github and sourceforge: github serves as the main repository, bugtracker, and tarball hosting; sourceforge is used as a backup repository and for mail.


Contributions can come in various forms: bug reports, patches, pull requests, discussion. A very easy and valuable contribution is adding your lexer to the main re2c test suite (this is also a good way to make sure that re2c updated will not break your code). All contributions are welcome!

Projects that use re2c

  • PHP (general-purpose scripting language)
  • ninja (small build system with a focus on speed)
  • yasm (assembler)
  • spamasassin (anti-spam platform)
  • BRL-CAD (cross-platform solid modeling system)
  • … last but not least, re2c

This list is by no means complete. These are only the best-known and open source projects.