Skip to content
/ fe Public

A header-only C++ library for writing compiler/interpreter frontends.

License

Notifications You must be signed in to change notification settings

leissa/fe

Repository files navigation

FE

docs linux macos windows

A header-only C++ library for writing compiler/interpreter frontends.

What is FE?

FE provides a set of utilities that helps you writing your own compiler or interpreter frontend. FE is not a lexer or parser generator. Instead, it will give you the blueprint to easily hand-write your own lexer and parser.

Get Started Now!

Based on the toy language Let, either

Features

  • [Arena](@ref fe::Arena) allocator for efficient memory management.
  • Efficient [symbol pool](@ref fe::SymPool) that internalizes C and C++ strings into [symbols](@ref fe::Sym). Checking for equality/inequality is only a pointer comparisons!
  • Keep track of [source code locations](@ref fe::Loc).
  • Blueprint for a [lexer](@ref fe::Lexer) with [UTF-8](@ref fe::utf8) support.
  • Blueprint for a [parser](@ref fe::Parser).
  • Optional Abseil support.
  • You need at least C++-20.

Building

FE optionally supports Abseil's excellent hash containers. In order to enable Abseil support, you have to define FE_ABSL. Otherwise, FE will fall back to the hash containers of the C++ standard library.

Option #1: Include FE as Submodule (Recommended)

  1. Add FE as external submodule to your compiler project:

    • If your compiler project is already on GitHub, do this:
      git submodule add ../../leissa/fe external/fe
    • Otherwise:
      git submodule add [email protected]:leissa/fe.git external/fe
  2. Integrate into your build system:

    • If you use CMake, add something like this to your CMakeLists.txt:
      set(FE_ABSL ON) # remove this line, if you don't want to use Abseil
      add_subdirectory(external/fe)
      
      target_link_libraries(my_compiler PUBLIC fe)
    • Otherwise:
      • Add external/fe/include as include directory.
      • Furthermore, add -DFE_ABSL to your CXXFLAGS, if you want to use Abseil.

Option #2: Directly include FE in your Source Tree

  1. Copy over the headers from FE to your compiler project:

    git clone [email protected]:leissa/fe.git
    mkdir -p my_compiler/include/fe
    cp -r fe/include/fe/*.h my_compiler/include/fe
  2. Integrate into your build system:

    Since your build system most likely already has my_compiler/include/ as an include directory, nothing more needs to be done. In addition, add -DFE_ABSL to your CXXFLAGS, if you want to use Abseil. In the case of CMake, add something like this to your CMakeLists.txt:

    target_compile_definitions(my_compiler PUBLIC FE_ABSL)

Other Projects using FE

  • Let: A simple demo language that builds upon FE
  • GraphTool: A small tool that reads a subset from Graphviz' DOT language and calculates several dominance-related properties
  • MimIR: MimIR is my intermediate representation
  • SQL: Small and simple SQL parser