klang is a small C++20 compiler project I am building from the ground up. It is intentionally modest in scope: the goal is to keep the codebase easy to read while the pieces of a real language toolchain are put together one by one.
Right now the repository is organized as a few focused modules:
lexer/for turning source text into tokensparser/for building syntax structure from those tokensast/for the abstract syntax tree layercompiler/for lowering the AST into something executablevm/for running compiled outputdebug/for inspection and disassembly helperscli/for the command-line entry pointtests/for smoke tests and build verification
The CLI already exposes the command names I want to grow into:
helpversionlexruncheckparsedisastfmtcompileexecrepl
Only a few of those commands do real work today, and that is by design. The project is being built in the open, so the README should reflect the actual state of the code rather than a future version of it.
This repo uses CMake presets and a small helper script.
Build only the CLI:
bash ./build.sh cliBuild everything and run the test suite:
bash ./build.shIf you prefer to work directly with the CMake preset, the debug preset is the one in use.
After a build, the CLI binary is available at:
./build/debug/klang_cliRun the help output:
./build/debug/klang_cli helpTry the lexer command against a source file:
./build/debug/klang_cli lex path/to/file.klAt the moment, lex checks that the file exists and feeds its contents into
the lexer. Token printing is still a work in progress, so do not expect a full
token stream yet.
The current layout is simple on purpose. klang_core is the library target
that ties the modules together, and klang_cli is the executable that gives
the project a usable front door.
The lexer interface currently exposes tokenization only, and the surrounding modules are mostly scaffolding for the next stages of the compiler pipeline.
This repository is in active development. The safest way to think about it is:
- the build works
- the CLI scaffolding works
- the language pipeline is being filled in module by module
If you are reading this to understand how to contribute, the best starting point is whichever module you want to make real next.