[TOC]
FE is a header-only C++20 toolkit for writing hand-rolled compiler and interpreter frontends. It does not generate lexers or parsers for you; instead, it gives you the reusable pieces that make handwritten frontends pleasant to build and maintain.
FE is built around a few small components that compose well:
fe::Arenafor arena allocation and arena-backed ownership.fe::Symandfe::SymPoolfor string interning and cheap identifier comparison.fe::Driverfor diagnostics and shared frontend state.fe::Posandfe::Locfor source positions and spans.fe::Lexer<K, S>for UTF-8-aware lexing with lookahead and token text accumulation.fe::Parser<Tok, Tag, K, S>for recursive-descent style parsing with token lookahead and span tracking.- Optional
FE_ABSLsupport for Abseil hash containers.
The best end-to-end example in this repository is tests/lexer.cpp.
Add FE as a subdirectory and link the fe interface target:
add_subdirectory(external/fe)
target_link_libraries(my_compiler PRIVATE fe)If you want Abseil-backed hash containers, enable FE_ABSL before adding the subdirectory:
set(FE_ABSL ON)
add_subdirectory(external/fe)
target_link_libraries(my_compiler PRIVATE fe)Since FE is header-only, you can also vendor include/fe/ directly into your project and add -DFE_ABSL if you want Abseil support.
- Define a token type that exposes
tag()andloc(). - Derive your lexer from
fe::Lexer<K, S>. - Derive your parser from
fe::Parser<Tok, Tag, K, S>. - Use
fe::Driverfor diagnostics and identifier interning. - Thread
fe::Locthrough tokens and AST nodes for precise error reporting.
If you want a concrete model to copy from, start with tests/lexer.cpp.
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build
ctest --test-dir build --output-on-failureRun one discovered test:
ctest --test-dir build -R '^Lexer$' --output-on-failureOr run a doctest case directly:
./build/bin/fe-test --test-case=Lexercmake -S . -B build -DFE_BUILD_DOCS=ON
cmake --build build --target docsThis requires Doxygen and Graphviz (dot).
- Let - a small demo language built on FE.
- GraphTool - a DOT-language tool using FE-style frontend infrastructure.
- MimIR - an intermediate representation project by the author.
- SQL - a small SQL parser.
FE is licensed under the MIT License.