A header-only C++ library for writing compiler/interpreter frontends.
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.
Based on the toy language Let, either
- create a new repository from a template, or
- fork it.
- [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.
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.
-
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
- If your compiler project is already on GitHub, do this:
-
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 yourCXXFLAGS
, if you want to use Abseil.
- Add
- If you use CMake, add something like this to your
-
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
-
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 yourCXXFLAGS
, if you want to use Abseil. In the case of CMake, add something like this to yourCMakeLists.txt
:target_compile_definitions(my_compiler PUBLIC FE_ABSL)