We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Tekst

From Esolang
Jump to navigation Jump to search

Tekst is a general-purpose programming language designed around readable, indentation-based syntax and a relatively small language surface. It is implemented with a compiler written in C++17 and uses LLVM for native code generation.

The language is designed to make program structure visible through indentation while retaining features for larger programs, including functions, classes, collections, modules, packages, pointers, and native compilation.

Overview

Tekst uses indentation to define blocks rather than braces. Its syntax is influenced by Python, while providing its own language features and compiler architecture.

Tekst source files commonly use the .tk extension, with .tekst also supported by the compiler.

A minimal Tekst program is:

print("Hello, World!")

A function can be written as:

fn greet(name):
    return "Hello {name}!"

message = greet("World")
print(message)

Syntax

Variables

Variables can be assigned directly:

x = 42
name = "Tekst"
active = true
nothing = null

Tekst supports values including integers, floating-point values, booleans, strings, lists, dictionaries, and null.

Functions

Functions are declared with fn. Default arguments, return values, and variadic arguments are supported.

fn add(a, b = 0):
    return a + b

print(add(10, 5))

Control flow

Tekst provides conditional statements and loops.

score = 85

if score >= 90:
    print("A")
elif score >= 80:
    print("B")
else:
    print("C")

for n in range(5):
    print(n)

Classes and objects

Tekst supports classes, constructors, fields, methods, inheritance, and method overriding.

class Animal:
    fn init(name):
        self.name = name

    fn speak():
        return "animal"

class Dog extends Animal:
    fn speak():
        return "woof"

Collections

Lists and dictionaries are supported, including indexing and mutation.

numbers = [10, 20, 30, 40]

print(numbers[-1])
numbers[0] += 5
numbers.append(50)

Modules and packages

Tekst supports importing modules and packages with import, from, and as.

import math

print(math.sqrt(16))

from math import sqrt 
print(sqrt(9))

Pointers and memory

Tekst includes lower-level memory features, including pointers and address operations.

x = 41
p = &x
*p = 42

print(*p)

Compiler

The Tekst compiler is written in C++17 and uses LLVM for native code generation.

The compiler pipeline is:

Tekst source
    ↓
Lexer
    ↓
Parser
    ↓
Abstract syntax tree
    ↓
LLVM IR
    ↓
LLVM / Clang
    ↓
Native executable

The lexer converts source text into tokens. The parser builds an abstract syntax tree from those tokens. The compiler then lowers the AST into LLVM IR before producing native code.

Tooling

Tekst provides a command-line compiler and development workflow.

For example:

tekst hello.tk
./hello

The compiler can also emit LLVM IR for inspection:

tekst examples/hello.tk --emit-ir

The project provides documentation covering getting started, basics, control flow, functions, classes and objects, collections, modules and packages, memory, compiler and CLI usage, and the language reference.

Examples

Hello World

print("Hello, World!")

Function

fn multiply(a, b):
    return a * b

print(multiply(3, 7))

Class

class Counter:
    fn init(start = 0):
        self.value = start

    fn increment():
        self.value += 1
        return self.value

counter = Counter(10)

for i in range(3):
    print(counter.increment())

Implementation

The reference Tekst implementation and compiler are written in C++17. The compiler uses CMake and LLVM/Clang as part of its build and native-code toolchain.

The language's documentation and implementation are maintained as part of the Tekst project.

History

Tekst was created by Ayaan Dhalait as a programming-language project. It is implemented from scratch and is designed around readable source code, indentation-based structure, and native compilation.

External resources