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.
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
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.
name = "Tekst"
age = 14
price = 9.99
active = True
numbers = [1, 2, 3]
config = {"port": 8080}
Functions
Functions are declared with the fn keyword.
fn greet(name):
print("Hello, " + name)
greet("Tekst")
Default arguments
fn greet(name, greeting = "Hello"):
print(greeting + ", " + name)
greet("World")
greet("World", "Welcome")
Control flow
Conditions
x = 10
if x > 15:
print("Large")
elif x > 5:
print("Medium")
else:
print("Small")
Loops
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.
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.
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.
Tekst script.tekst
Debug output can be enabled when supported by the interpreter.
./Tekst --debug script.tekst