Learn Tekst.

Everything you need to understand the language, write your first program, and start experimenting with the interpreter.

Introduction

Tekst is a lightweight interpreted programming language designed around readable syntax and simple programming concepts.

Tekst is currently an experimental language. Syntax and features may change as the interpreter evolves.
hello.tekst
print("Hello, World!")

Installation

The Tekst interpreter is currently built from source using a C++17-compatible compiler.

Requirements

  • G++ or another C++17 compiler
  • Git
  • Windows, Linux, or macOS

Build

terminal
g++ -std=c++17 -O2 -o Tekst src/main.cpp src/lexer.cpp src/parser.cpp -I.

Variables

Variables are created by assigning a value to a name. Tekst does not require explicit type declarations for basic values.

variables.tekst
name = "Tekst"
age = 14
price = 9.99
active = True

numbers = [1, 2, 3]
config = {"port": 8080}

Functions

Functions are declared with the fn keyword.

functions.tekst
fn greet(name):
  print("Hello, " + name)

greet("Tekst")

Default arguments

defaults.tekst
fn greet(name, greeting = "Hello"):
  print(greeting + ", " + name)

greet("World")
greet("World", "Welcome")

Control flow

Conditions

conditions.tekst
x = 10

if x > 15:
  print("Large")
elif x > 5:
  print("Medium")
else:
  print("Small")

Loops

loops.tekst
count = 0

while count < 5:
  print(count)
  count = count + 1

items = [1, 2, 3, 4]

for item in items:
  print(item)

Classes

Tekst supports classes, constructors, methods, and inheritance.

classes.tekst
class Counter:
  def __init__(self, start):
    self.value = start

  def increment():
    self.value = self.value + 1

  def display():
    print(self.value)

Counter counter
counter.increment()
counter.display()

Error handling

Runtime errors can be handled using try and catch blocks.

errors.tekst
try:
  x = 1 / 0

catch error:
  print("Something went wrong")

Running Tekst

Once the interpreter has been built, pass a Tekst source file to the executable.

terminal
Tekst script.tekst

Debug output can be enabled when supported by the interpreter.

terminal
./Tekst --debug script.tekst