Language Reference › Language Rulesv0.1
Language Reference

Language Rules

Variables, types, scope, functions, operators - all the rules in one place.

Variables

Naming

  • Must start with a letter or underscore
  • Can contain letters, numbers, underscores
  • Case-sensitive: myVar ≠ myvar ≠ MYVAR
  • Cannot be a keyword, builtin name, or defined function name

Assignment Operators

SyntaxExample
x = 5Standard equals
x := 5Walrus-style
x <- 5Arrow assignment
set x to 5English style
let x be 5English style
store 5 in xEnglish style
x is 5Valid only at top level (not inside conditions)

Types

TypeExampleNotes
number42, 3.14, -1Integers and floats - no distinction
string"hello", 'world'Both quote styles accepted
booltrue, falseLowercase only
nullnullAbsence of value
list[1, 2, 3]Ordered, mixed types ok

Scope

pseudo
x = 10        # global

myFunc()
    print x   # ✓ reads global (fine)
    x = 20    # creates a NEW local x - does NOT touch global

myFunc()
x             # → still 10

Global keyword

pseudo
counter = 0

increment()
    global counter      # explicit declaration
    counter = counter + 1

increment()
increment()
counter               # → 2

Functions

Definition

pseudo
# All equivalent function definitions:
bubbleSort(arr)
func bubbleSort(arr)
function bubbleSort(arr)
define bubbleSort(arr)
algorithm bubbleSort(arr)
recursive fibonacci(n)

Define vs Call

pseudo
sort(arr)           # CALL - if sort is in symbol table, no body follows
sort(arr)           # DEFINITION - if indented body follows below
sort([3,1,2])       # always CALL - literal argument

Two-pass parsing

Pass 1 scans all function names before execution. This enables mutual recursion - functions can call each other without forward declarations:

pseudo
isEven(n)
    if n == 0: return true
    return isOdd(n - 1)

isOdd(n)
    if n == 0: return false
    return isEven(n - 1)

isEven(4)    # → true

Operators

CategoryOperators
Arithmetic+ - * / // % ** (also ^ and power)
Comparison> < >= <= == != - also greater than, equals, etc.
Logicaland or not - also && || !
Ternarycond ? true_val : false_val
String+ concat, * repeat, str[i], str[a:b]
List+ concat, arr[i], arr[-1], arr[a:b]

Ternary

pseudo
x = n > 10 ? "big" : "small"
print (n > 0 ? "positive" : "non-positive")

String Interpolation

pseudo
name = "Alice"
print "Hello, {name}!"              # → Hello, Alice!
print "Result: {score * 2}"        # → Result: 190
print "Pi: {round(pi, 2)}"         # → Pi: 3.14
# Escape: \{ \} → literal braces

Comments

pseudo
# single line comment
x = 5   # inline comment

# multi-line: just stack them
# line 1
# line 2

Indentation

  • Spaces or tabs - never mixed in the same file
  • Any consistent size: 2, 4, or 8 spaces
  • Mixed tabs/spaces → IndentationError

Auto-print

pseudo
x = 42
x              # → prints 42 (bare variable)

len([1,2,3])   # → prints 3 (bare function call)

# These are SILENT:
result = func()   # assignment
x = 5             # assignment

Error Handling

pseudo
try
    x = 1 / 0
catch ZeroDivisionError
    print "cannot divide by zero"
finally
    print "this always runs"

Built-in Error Types

ErrorWhen
ZeroDivisionErrorDividing by zero
IndexErrorList index out of bounds
TypeErrorWrong type for operation
ValueErrorRight type, wrong value
NameErrorUndefined variable or function
RecursionErrorMax recursion depth (1000) exceeded