Tyr Language Tutorial
The third layer of the Tyre language ecosystem
Introduction
Tyr is a natural-language-inspired programming language. It has no parentheses, no braces, no indentation — the nesting of expressions is determined entirely by the word type of each word, which is recognizable from its consonant structure.
Tyr compiles to Ty, which compiles to T, which compiles to C. Each layer removes a level of explicit syntax:
| T | Ty | Tyr | |
|---|---|---|---|
| Abstraction | C level | Rust level | Natural language |
| Syntax | C-like / SLN | C-like / SLN | No brackets |
| Functions | fn | type + impl | Relations (words) |
| Types | Newtypes | Generic newtypes | Specifier words |
| Arguments | Positional | Type-based | Word-type-based |
| Definitions | fn, type, let | type, impl, let | Only binding |
Word Types
Every word belongs to exactly one of four categories, determined by its consonant structure:
| Word Type | Structure | Effect | Example |
|---|---|---|---|
| Object (O) | Consonants before and after vowel | Closes one level | van, zan, nam |
| Specifier (S) | Consonants only before vowel | Level stays (qualifies next Object) | na, fa, vi |
| Relation (R) | Consonants only after vowel | Opens one level | an, un, is |
| Modifier (M) | Starts with a stop (b, c, d) | Level stays (modifies previous word) | da, ba |
The word type is always unambiguous. You can tell what any word does just by looking at its consonant pattern.
Phonotactics
Tyr uses a small, precise phoneme inventory:
| Category | Sounds |
|---|---|
| Vowels | i, a, u |
| Approximants | y, v |
| Liquids | l |
| Nasals | n, m |
| Fricatives | f, s, z, h |
| Stops | b, c, d |
Each word has one syllable: an optional onset (consonants before the vowel), a vowel, and an optional coda (consonants after the vowel). A word needs at least one consonant, so a bare vowel such as a or i is rejected. A leading stop is a Modifier marker; the rest of the word is checked like any other.
Onset order: fricative → liquid/nasal → approximant → vowel. Each slot holds at most one sound, and a slot may be skipped (svan, slva, nya).
Coda order: vowel → approximant/liquid → nasal/fricative. Each slot holds at most one sound (alf).
Valid words: an, van, sli, uvh, da, nam, alf.
Invalid: mn, vy, lna, nfa, alfn, a.
Phonotactics only decides a word's type; the word must also exist in the vocabulary (below) unless it is a number or a variable name. Words are separated by a space, a newline, - or ' (ul-zan-zan. works), and a sentence separator must be followed by one of these.
Auto-Bracketing
A level counter determines nesting. It starts at 0:
- Relation → level + 1 (opens a clause)
- Object → level − 1 (closes a clause)
- Specifier → level stays (waits for its Object)
- Modifier → level stays (transforms previous word)
A sentence is complete when an Object arrives while the level is 0. A further word after that is an error (nan van.), and so is an end of sentence while a Relation is still waiting for its second argument (an nan.).
S O → S(O) Specifier applied to Object R O O → R(O, O) Relation with two arguments R S O O → R(S(O), O) First argument qualified R O R O O → R(O, R(O, O)) Nested relation R M O O → M(R)(O, O) Modifier changes Relation
A Relation always takes exactly two arguments: the first from its subordinate clause (level + 1), the second as the main object (closing the Relation's own level).
Nested Relations
Multiple Relations chain naturally from right to left. Each one opens a level, each Object closes one:
R₁ R₂ R₃ O₁ O₂ O₃ O₄ 0 → 1 → 2 → 3 → 2 → 1 → 0 Result: R₁(R₂(R₃(O₁, O₂), O₃), O₄)
This is right-to-left currying. Each Relation with only one argument is partial — it waits for the second. The rightmost Object completes all pending Relations.
Arithmetic
The four basic arithmetic operations are Relations:
| Word | Meaning | Result |
|---|---|---|
an | add | an(a, b) = a + b |
un | subtract | un(a, b) = a − b |
ul | multiply | ul(a, b) = a × b |
il | divide | il(a, b) = a / b |
Number words (nan = 0, van = 1, yan = 2, lan = 3, man = 4, san = 5, zan = 6):
an van van → add(1, 1) = 2 un zan van → sub(6, 1) = 5 ul yan lan → mul(2, 3) = 6
Nested arithmetic:
ul an van van zan → mul(add(1, 1), 6) = 12 Step by step: ul: Relation, level 0 → 1 an: Relation, level 1 → 2 van: Object, level 2 → 1 (first arg of an) van: Object, level 1 → 0 (second arg of an, first arg of ul) zan: Object, level 0 → sentence complete (second arg of ul)
Numeric Literals
In addition to named number words, Tyr supports decimal integer literals directly:
an 3 7 → add(3, 7) = 10 ul 6 7 → mul(6, 7) = 42
Numeric literals are always Objects. They can appear anywhere a named Object word would.
The Specifier la prints a value:
la an van van. → print(add(1, 1)) outputs: 2 la ul 6 7. → print(mul(6, 7)) outputs: 42
la is a Specifier, so it qualifies the next Object expression and prints it. Every useful Tyr program will have la somewhere.
Specifiers
A Specifier qualifies an Object. It's like a type constructor or unary operation applied to a value:
na van → i64(1) = integer 1 fa van → f64(1) = float 1.0 la an van van → print(add(1, 1)) = outputs 2
Specifiers chain right-to-left:
S₁ S₂ O → S₁(S₂(O)) la na van → print(i64(1))
Current Specifiers:
| Word | Meaning |
|---|---|
na | integer type (i64) |
fa | float type (f64) |
la |
na and fa convert their object to i64 / f64: la na il fa 7 fa yan. prints 3, la il fa 7 fa yan. prints 3.5.
Modifiers
Modifiers start with a stop consonant (b, c, d) and transform the word they follow. They don't change the bracket structure.
Opposite
da inverts a Relation's meaning. It is placed after the Relation it modifies:
an da van van → sub(1, 1) = 0 ul da van zan → div(1, 6)
da on an (add) gives subtraction. On ul (multiply) gives division. On us (less) gives greater, and on as (greater) gives less. On is (equal) it gives not-equal: la is da van zan. prints true. A da directly after la modifies the print Specifier instead and has no effect, so la da is van zan. prints false. On uvh (power) it gives root.
Passive
ba swaps the two arguments of a Relation. It takes effect after the Relation's first argument:
un van zan → sub(1, 6) = −5 un van ba zan → sub(6, 1) = 5
Normally, the first Object after a Relation is the first argument (subordinate clause), and the second Object is the main argument. ba reverses this. Placed directly after the Relation (un ba van zan), it has the same effect: the result is 5.
Binding
The Relation in binds a value to a name:
in na van val → let val = na(1) in: Relation (bind), level 0 → 1 na: Specifier, level stays 1 van: Object, level 1 → 0 (first arg: the value na(1)) val: Object, level 0 → sentence complete (second arg: the name)
This is Tyr's only definition mechanism. There's no type, no fn, no impl. You can only bind values to names for later reuse.
in an van van sum. → let sum = add(1, 1) la an sum sum. → print(add(sum, sum)) = print(4)
Mutable State
By default, bindings are immutable. The Modifier bu on in creates a mutable binding (var instead of let):
in bu nan val. → var val = 0
The Relation um assigns a new value to a mutable variable:
um val van. → val := 1
um takes the variable name as first argument and the new value as second: um name value.
in bu nan val. var val = 0 um val an val van. val := val + 1 um val an val van. val := val + 1 um val an val van. val := val + 1 la val. print(val) → 3
Comparison
Comparisons are Relations that return boolean values:
| Word | Meaning | Opposite (da) |
|---|---|---|
is | equal | not equal |
us | less than | greater than |
as | greater than | less than |
is van van → equal(1, 1) = true us van zan → less(1, 6) = true as zan van → greater(6, 1) = true
Conditionals
The Relation if takes a condition (first argument) and a result (second argument):
if us van zan van → if(less(1, 6), 1) if: Relation, level 0 → 1 us: Relation, level 1 → 2 van: Object, level 2 → 1 (first arg of us) zan: Object, level 1 → 0 (second arg of us, first arg of if) van: Object, level 0 → sentence complete (second arg of if: result)
There is no else. If the condition is false, the expression produces no value. For an else branch, write a second sentence with the negated comparison:
if us van zan la van. → if less(1, 6) then print(1) if us da van zan la nan. → if greater(1, 6) then print(0)
da on us (less) gives greater. Booleans sun (true) and nun (false) can also be used as conditions.
Loops
The Relation uf creates a while loop. Like if, it takes a condition and a body:
in bu nan val. uf us val 10 um val an val van. la val. → prints 10
uf condition body repeats body while condition is true.
Sequence
For loop bodies with multiple statements, the Relation am (sequence) combines two expressions into a block:
am stmt1 stmt2 → { stmt1; stmt2; }am chains naturally: am stmt1 am stmt2 stmt3 flattens to { stmt1; stmt2; stmt3; }.
in bu nan sum. in bu van val. uf us val 11 am um sum an sum val um val an val van. la sum. → prints 55 (sum of 1..10)
Sentences
A sentence is a complete expression — the level counter starts at 0 and the last Object closes it back down. Sentences are separated by punctuation marks: . , ; : ! ?
la an van van. → sentence 1: print(add(1, 1)) la ul zan zan. → sentence 2: print(mul(6, 6))
Each sentence becomes one statement in the compiled output. Multiple sentences in a program execute in order. A sentence whose value is never used, such as a bare an van van., is rejected by the C compiler (statement with no effect) in a file; only the REPL prints bare expressions for you.
No Definitions
Tyr removes one more definition layer compared to Ty:
| T | Ty | Tyr |
|---|---|---|
fn twice(n: i32) -> i32 { n * 2 } | type n = i32; | Relations are words. No definition in code. |
type x = f32; | type x = f32; | Types are Specifier words. No definition in code. |
let sum = a + b; | let sum = a + b; | in an lum him sum |
Types and operations exist because words exist. The vocabulary (dictionary) defines all types and their behavior. Tyr programs compose existing words; they never define new ones.
New concepts arise through:
- Specifier chains:
S₁ S₂ Ocomposes type constructors - Modifiers:
an daderives subtraction from addition - Binding:
innames intermediate results for reuse
Build & Run
cargo run -p tyre-tyr -- run examples/tyr/hello.tyr # compile and run cargo run -p tyre-tyr -- build examples/tyr/hello.tyr # compile to binary cargo run -p tyre-tyr -- c examples/tyr/hello.tyr # output generated C cargo run -p tyre-tyr -- ty examples/tyr/hello.tyr # print the Ty AST (debug) cargo run -p tyre-tyr -- repl # interactive mode
The package is tyre-tyr; the binary it builds is tyr. Tyr source files use the .tyr extension.
Interactive Mode
The REPL compiles and runs each line through the full pipeline. Expressions are auto-printed — no need to write la:
→ an van van. 2 → :lines 1 la an van van. → :c #include <stdint.h> ...
Commands: :q (or :quit) quit, :c show C output, :lines show all entered lines, :reset clear state.
A binding typed into the REPL is kept: in ul 6 7 sum. prints nothing, and a later sum. prints 42. Variable names follow the same phonotactics as all words, so a name like answer is rejected (Character 'w' is not allowed).
Compilation
Tyr compiles through three stages:
- Tyr → Ty — word types become Ty AST nodes. Relations become binary operations or callable tuples. Specifiers become type constructions.
inbecomeslet.ifbecomesif. - Ty → T — generics are monomorphized, impl blocks become functions.
- T → C — the final output is standard C, compiled with
cc.
Vocabulary Reference
Objects (O) — Values
| Word | Value |
|---|---|
nan | 0 |
van | 1 |
yan | 2 |
lan | 3 |
man | 4 |
san | 5 |
zan | 6 |
sun | true |
nun | false |
| integers | 42, 100, etc. |
| unknown words | variable names (sum, val, etc.) |
Relations (R) — Binary Operations
| Word | Meaning | Opposite (da) |
|---|---|---|
an | add | subtract |
un | subtract | add |
ul | multiply | divide |
il | divide | multiply |
uvh | power (computed as a float) | root |
ivh | root (computed as a float) | power |
is | equal | not equal |
us | less than | greater than |
as | greater than | less than |
in | bind (let) | — |
um | assign (:=) | — |
if | conditional | — (unless is not implemented) |
uf | while loop | — |
am | sequence (block) | — |
Specifiers (S) — Type Constructors
| Word | Meaning |
|---|---|
na | integer type (i64) |
fa | float type (f64) |
la |
Modifiers (M) — Word Transformers
| Word | Effect |
|---|---|
da | Opposite: inverts the meaning of a Relation |
ba | Passive: swaps the two arguments of a Relation |
bu | Mutable: in bu = mutable binding (var) |