K is a custom programming language designed as a cleaner, more readable alternative to C++, while still leveraging C++'s performance and memory model.
Instead of modifying existing compilers, K is implemented as a transpiler:
- K source code → converted to C++
- C++ → compiled using a standard compiler (e.g., Clang)
This allows K to remain lightweight while still producing efficient native binaries.
- Simplify C++ syntax
- Improve readability
- Provide better error messages
- Retain low-level control (pointers, manual memory management)
- Build a structured compiler pipeline from scratch
cout("hello world")
cin(x)x:int = 5
x:intx:ptr(int)
x:ptr(int) = y
x:ptr(int) = *yh = new int[10]
delete hfn add(x:int, y:int) {
}lambda[cpy]() {}
lambda[ref]() {}vector(int) = {}
map(str, int)#{
this is a multiline comment
#}Statements are separated by structure, not ;.
The project follows a standard compiler front-end pipeline:
K Source Code
↓
Lexer (tokenization)
↓
Parser (AST generation)
↓
Transpiler (C++ generation)
↓
Clang / g++
↓
Executable
- Token-based parsing structure
- Statement detection system
- Variable declaration parsing
- Pointer type parsing (
ptr(int)) - Basic dereference handling (
*x)
- Expression parsing
- Function parsing
- Lambda parsing
- Type system expansion (vector, map)
- Error reporting improvements
- AST node structure (VariableDeclaration, PtrType, Deref)
- Full expression grammar
- Function bodies and scope handling
- Advanced type system
- Better diagnostics with line/column tracking
- Code generation (K → C++)
x:ptr(int) = *y
fn hello() {
}VariableDeclaration(
name = "x",
type = PtrType("int"),
value = Deref("y")
)
FunctionDeclaration(
name = "hello",
params = []
)
/lexer == token generation
/parser == AST construction
/ast == node definitions
/transpiler == C++ code generation
Modifying compilers like GCC or Clang is extremely complex.
K instead:
- acts as a frontend language
- reuses existing compiler infrastructure
- stays flexible and easier to iterate on
- Minimal syntax noise
- Explicit types
- Predictable behavior
- Close-to-metal control
- Incremental complexity (start simple, grow gradually)
K aims to evolve into a fully usable systems-level language with:
- Clean syntax
- Strong typing
- Modern diagnostics
- Efficient compilation via C++ backend
This project is licensed under the terms specified in the LICENSE file.
Kairav