Tekst is an indentation-based programming language with a small, readable syntax and a native LLVM backend.
Tekst source files use the .tk extension. The compiler frontend lexes and parses Tekst directly into an AST, lowers that AST to LLVM IR, and then uses LLVM/Clang to produce a native executable.
Tekst source (.tk)
↓
Lexer
↓
Parser
↓
AST
↓
LLVM IR backend
↓
LLVM / Clang
↓
native executable
The native compiler currently supports:
- Variables and assignment
- Integers, floating-point numbers, booleans, strings, and
None - Arithmetic and comparison operators
- Logical
and/or - Lists, tuples, and dictionaries
- Indexing and indexed assignment
if,elif, andelsewhileloopsfor ... in ...loopsrange(...)- List comprehensions
fnfunctions (defis also accepted for older programs)- Default function arguments
- Classes, inheritance with
extends, constructors, methods, andself - Object fields and attribute access
- Built-ins including
print,input,int,str,bool,float, andlen - Basic string interpolation
- Local modules and packages
- Explicit pointers and low-level memory operations
- Native LLVM code generation
- A C++17 compiler
- LLVM/Clang with
clang++available onPATH - CMake 3.16 or newer for the recommended build
cmake -S . -B build
cmake --build build --config ReleaseThe compiler executable is tekst on Linux/macOS or tekst.exe on Windows.
CMake also places runtime.cpp and runtime.h beside the compiler executable.
g++ -std=c++17 -O2 src/main.cpp src/lexer.cpp src/parser.cpp src/codegen.cpp -Isrc -o tekstFor a direct build, keep src/runtime.cpp and src/runtime.h beside the resulting compiler executable.
The Windows native compiler uses Clang with the MinGW-w64 GNU target rather than Visual Studio or MSBuild.
MSYS2 UCRT64 is a supported way to provide the MinGW-w64 toolchain. Make its bin directory available on PATH so g++.exe can be found, or set MINGW_ROOT to the MinGW installation root.
If clang++ is not on PATH, set TEKST_CXX to its path.
The compiler automatically uses the MinGW GNU target on Windows.
Compile a Tekst program:
tekst main.tkChoose an output name:
tekst main.tk -o helloGenerate LLVM IR without linking:
tekst main.tk --emit-ir > main.llCompile and immediately run:
tekst main.tk --runCheck the compiler version:
tekst --versionSuccessful native compilation is silent unless an option such as --emit-ir produces output.
Tekst uses indentation-based syntax.
print("Hello, World!")
age = int(input("Enter your age: "))
if age < 18:
print("NO")
else:
print("YES")
fn add(a, b):
return a + b
print(add(5, 3))
Default arguments are supported:
fn welcome(name, greeting = "Hello"):
print(greeting + ", " + name)
welcome("Ayaan")
welcome("Ayaan", "Hi")
class Counter:
fn __init__(self, start=0):
self.value = start
fn increment(self, amount=1):
self.value += amount
return self.value
counter = Counter(10)
print(counter.increment())
print(counter.increment(5))
numbers = [10, 20, 30]
numbers[1] = 25
print(numbers[1])
person = {"name": "Ayaan", "age": 14}
print(person["name"])
for i in range(5):
print(i)
count = 0
while count < 5:
print(count)
count += 1
name = "Tekst"
print("Running {name}")
Tekst also exposes an explicit low-level memory layer:
x = 41
p = &x
*p = 42
print(*p)
mem = alloc(8)
store_int(mem, 123456)
print(load_int(mem))
q = mem + 4
store_int(q, 99)
print(load_int(q))
free(mem)
&x creates a pointer to a variable, *p dereferences a pointer, and alloc / free provide explicit heap allocation. Raw pointer arithmetic and memory access are bounds checked by the runtime.
See POINTERS.md and README_LLVM.md for more details.
Tekst includes native standard-library modules. They are built into the runtime, so no .tk files are needed for them:
use math
use random
use fs
use time
use os
print(math.sqrt(144))
print(random.randint(1, 10))
fs.write("hello.txt", "Hello from Tekst")
print(fs.read("hello.txt"))
print(time.now())
print(os.cwd())
Available modules:
math:sqrt,cbrt,pow,abs,floor,ceil,round,sin,cos,tan,asin,acos,atan,log,log10,exp,min,max, pluspi,e, andtau.random:random,randint,randrange,uniform,choice, andseed.fs:exists,is_file,is_dir,read,write,append,mkdir,remove, andlist.time:timestamp,now, andsleep.os:cwd,chdir, andenv.
Standard-library modules also support aliases and from ... use ... imports:
use math as m
print(m.sqrt(81))
from random use randint as r
print(r(1, 6))
Local Tekst modules and packages are resolved at compile time.
For example:
from mathpkg use square as sq
print(sq(9))
The compiler can resolve local .tk modules, lib/<name>.tk, and package directories containing .tk files. A package's dec.tk file is loaded first when present.
Imported Tekst source is compiled into the same LLVM module, so it is not interpreted at runtime.
The LLVM backend covers the core execution model, including values, arithmetic, comparisons, logical operations, variables, functions, default arguments, conditionals, loops, collections, object fields, constructors, methods, built-ins, indexing, list comprehensions, imports, and basic string interpolation.
Explicit pointer and manual memory operations are also available through the native runtime.
Some interpreter-era functionality still requires dedicated LLVM lowering or runtime work. In particular, full exception unwinding and try / catch are not yet part of the native backend. break and continue also require dedicated lowering work.
When a feature is not supported by the native backend, the compiler reports an explicit error rather than silently changing the program's semantics.
src/
├── main.cpp CLI and compiler driver
├── lexer.h/cpp indentation-aware lexer
├── parser.h/cpp Tekst parser
├── ast.h/cpp AST definitions
├── codegen.h/cpp LLVM IR backend
├── runtime.h/cpp native Tekst runtime
├── builtins.h/cpp built-in operations
├── class.h/cpp class support
├── function.h/cpp function support
├── environment.h/cpp runtime environment
├── interpreter.h/cpp interpreter support
└── ...
tests/ organized compiler, module, standard-library, and networking tests
examples/ example `.tk` programs
docs/ website documentation
contributing/ contribution documentation
download/ distribution/download assets
setup/ Windows installer assets
tk/ Tk utility source
README_COMPILER.md- native compiler details and supported syntaxREADME_LLVM.md- LLVM backend, pointers, memory, and importsPOINTERS.md- low-level pointer and memory documentationFEATURES_NEXT.md- planned language and platform directionCOMPILER_CHANGELOG.md- compiler development historyCONTRIBUTING.md- contribution guidelines
See LICENSE for the repository license.