encyclopegia.org

Re2c

re2c is a free and open-source lexer generator for C, C++, D, Go, Haskell, Java, JavaScript, OCaml, Python, Rust, V and Zig.[src] It compiles declarative regular expression specifications to deterministic finite automata.[src] Originally written by Peter Bumbulis and described in his paper, re2c was put in public domain and has been since maintained by volunteers.[src] It is the lexer generator adopted by projects such as PHP, SpamAssassin, Ninja build system and others.[src] Together with the Lemon parser generator, re2c is used in BRL-CAD.[src] This combination is also used with STEPcode, an implementation of ISO 10303 standard.[src]

re2c is a free and open-source lexer generator for C, C++, D, Go, Haskell, Java, JavaScript, OCaml, Python, Rust, V and Zig.[src] It compiles declarative regular expression specifications to deterministic finite automata.[src] Originally written by Peter Bumbulis and described in his paper, re2c was put in public domain and has been since maintained by volunteers.[src] It is the lexer generator adopted by projects such as PHP, SpamAssassin, Ninja build system and others.[src] Together with the Lemon parser generator, re2c is used in BRL-CAD.[src] This combination is also used with STEPcode, an implementation of ISO 10303 standard.[src] Rules have the form REGEXP { CODE } or REGEXP := CODE; where REGEXP is a regular expression and CODE is a block of C code.[src] When REGEXP matches the input string, control flow is transferred to the associated CODE .[src] There is one special rule: the default rule with * instead of REGEXP ; it is triggered if no other rules matches.[src] re2c has greedy matching semantics: if multiple rules match, the rule that matches longer prefix is preferred; if the conflicting rules match the same prefix, the earlier rule has priority.[src] Definitions have the form NAME = REGEXP; (and also NAME { REGEXP } in Flex compatibility mode).[src] Configurations have the form re2c:CONFIG = VALUE; where CONFIG is the name of the particular configuration and VALUE is a number or a string.[src] For more advanced usage see the official re2c manual.[src] include static int lex(const char YYCURSOR[]) { const char* YYMARKER; /*!re2c re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; end = "\x00"; hex = "0x" [0-9a-fA-F]+; * { printf("err\n"); return 1; } hex end { printf("hex\n"); return 0; } */ } int main(int argc, char* argv[]) { for (int i = 1; i Given that, re2c -is -o example.c example.re generates the code below (example.c).[src] The contents of the comment /*!re2c ...[src] */ are substituted with a deterministic finite automaton encoded in the form of conditional jumps and comparisons; the rest of the program is copied verbatim into the output file.[src] There are several code generation options; normally re2c uses switch statements, but it can use nested if statements (as in this example with -s option), or generate bitmaps and jump tables.[src] Which option is better depends on the C compiler; re2c users are encouraged to experiment.[src] /* Generated by re2c 1.2.1 on Fri Aug 23 21:59:00 2019 */ include static int lex(const char *YYCURSOR) { const char *YYMARKER; { char yych; yych = *YYCURSOR; if (yych == '0') goto yy4; ++YYCURSOR; yy3: { printf("err\n"); return 1; } yy4: yych = *(YYMARKER = ++YYCURSOR); if (yych != 'x') goto yy3; yych = *++YYCURSOR; if (yych >= 0x01) goto yy8; yy6: YYCURSOR = YYMARKER; goto yy3; yy7: yych = *++YYCURSOR; yy8: if (yych[src]

25 sentences · 25 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Re2c." encyclopegia.org, 2026, https://encyclopegia.org/wiki/re2c. Accessed 29 November 2026.

Chicago

"Re2c." encyclopegia.org. Accessed November 29, 2026. https://encyclopegia.org/wiki/re2c.

APA

encyclopegia.org. (2026). Re2c. Retrieved November 29, 2026, from https://encyclopegia.org/wiki/re2c

Accessed November 29, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1376309127 · 0.5 · snapshot enwiki-001376309127

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.