The Zenith Language
Zenith is a modern, high-performance interpreted language designed for simplicity, readability, and power. Built with Rust, it bridges the gap between easy-to-learn scripting languages and robust systems programming.
Why Zenith?
English-like keywords (`set`, `is`, `define`) make code self-documenting.
Single binary executable. No runtime environments to install.
Built-in IDE with autocomplete, syntax highlighting, and instant run.
Quick Start
Here is a complete program that demonstrates the core features of Zenith.
// 1. Variables
set name = "Zenith User"
set level = 1
// 2. Functions
fn level_up(current) {
return current + 1
}
// 3. Control Flow
if level less 10 {
print("Beginner Mode")
set level = level_up(level)
} else {
print("Expert Mode")
}
// 4. Collections
set items = ["Sword", "Shield"]
array_push(items, "Potion")
set i = 0
while i less array_len(items) {
print("Item: " + items[i])
set i = i + 1
}
// 5. Structures
structure Hero with name, hp
set player = create Hero with name = name, hp = 100
print(player.name)
Installation
Zenith is distributed as a portable executable. No installation wizard required.
Steps
- Download the latest release (`.zip`) for your OS (Windows/Linux/macOS).
- Extract the folder to a location of your choice (e.g., `C:\Zenith`).
- Add the folder to your system `PATH` if you want to use the CLI globally.
Running the IDE
Double-click `ide.exe` (Windows) or run `./ide` (Linux/Mac) to start the integrated environment.
Using the IDE
The Zenith IDE is a terminal-based tool designed for rapid prototyping.
Keyboard Shortcuts
| Key | Action |
|---|---|
F5 / Ctrl+R |
Run current code |
Ctrl+S |
Save file |
Ctrl+O |
Open file |
Esc |
Close popup / menus |
Tab |
Autocomplete / Indent |
Syntax Basics
Zenith syntax is minimal and whitespace-agnostic (mostly). It uses clear keywords to avoid ambiguity.
Comments
// This is a single-line comment.
// Multi-line comments are not supported yet.
Blocks
You can use C-style braces or Ruby-style keywords.
// Style 1: Braces (Recommended)
if true {
print("Hello")
}
// Style 2: Keywords
if true then
print("Hello")
end
Identifiers
Must start with a letter or underscore. Case-sensitive.
-
Valid:
userName,_id,item1 -
Invalid:
1item,user-name(hyphens not allowed)
Variables & Types
Zenith is dynamically typed. Variables are declared with
set.
Variable Naming Rules
Identifiers in Zenith must follow these rules:
-
Must start with a letter (
a-z,A-Z) or an underscore (_). -
Can contain letters, numbers (
0-9), and underscores. -
Cannot contain hyphens (
-) or other special characters. -
Case-sensitive:
myVaris different frommyvar.
set, to, define,
fn, return, if,
elif, else, then,
end, while, repeat,
times, structure, create,
with, import, true,
false, null, and,
or, not, is.
Declaration
set x = 10 // Number
set _temp = 0 // Valid identifier
set user_id = 1 // Valid identifier
set 1st = "no" // Invalid (starts with number)
Data Types
| Type | Description |
|---|---|
Number |
64-bit float (double). Covers integers and decimals. |
String |
UTF-8 text sequence. |
Bool |
true or false. |
Array |
Dynamic list of values. |
Map |
Key-value pairs (String keys). |
Struct |
User-defined object. |
Operators
Arithmetic
+ |
Add / Concatenate |
- |
Subtract |
* |
Multiply |
/ |
Divide |
Comparison
Zenith supports both symbols and words for readability.
== / is |
Equality |
!= |
Inequality |
< / less |
Less than |
> / greater |
Greater than |
Logic
and, or, not.
if (x greater 5) and (y is not null) { ... }
Control Flow
If / Else
if score greater 90 {
print("A")
} elif score greater 80 {
print("B")
} else {
print("C")
}
While Loop
set count = 0
while count less 5 {
print(count)
set count = count + 1
}
Repeat Loop
A simplified loop for iterating N times.
repeat 3 times {
print("Knock")
}
Functions
Functions are reusable blocks of code that perform specific tasks. In Zenith, functions are first-class citizens, meaning they can be assigned to variables, passed as arguments, and returned from other functions.
Basic Syntax
fn greet(name) {
return "Hello, " + name
}
print(greet("Zenith")) // Output: Hello, Zenith
Parameters and Return Values
Functions can take any number of parameters. If a function does
not explicitly return a value using the
return keyword, it returns null by
default.
fn add(a, b) {
return a + b
}
fn log(msg) {
print("[LOG] " + msg)
// Returns null implicitly
}
Higher-Order Functions
Since functions are values, you can pass them to other functions. This is powerful for creating flexible APIs.
fn apply(func, value) {
return func(value)
}
fn square(x) {
return x * x
}
print(apply(square, 5)) // Output: 25
Closures
Functions defined inside other functions "capture" the variables from their surrounding scope. This allows for data privacy and factory patterns.
fn make_counter() {
set count = 0
fn increment() {
set count = count + 1
return count
}
return increment
}
set counter = make_counter()
print(counter()) // 1
print(counter()) // 2
Arrays & Maps API
Arrays API
Arrays are ordered, dynamic lists of values.
Returns the number of elements in the array.
Adds val to the end of the array.
Removes and returns the last element. Returns
null if empty.
Adds val to the beginning of the array.
Removes and returns the first element. Returns
null if empty.
Inserts val at index idx. Throws if
index out of bounds.
Removes element at idx. Throws if index out of
bounds.
Overwrites element at idx with val.
Returns a new array from start (inclusive) to
end (exclusive).
Returns a new array containing elements of
a followed by b.
Reverses the array in-place.
Creates a new array of size len filled with
val.
Joins elements into a string using delim.
Returns true if the array contains
val.
Array Examples
// 1. Creating and Modifying
set numbers = [10, 20, 30]
array_push(numbers, 40)
array_set(numbers, 0, 99)
print(numbers) // [99, 20, 30, 40]
// 2. Iterating
set i = 0
while i less array_len(numbers) {
print("Value: " + numbers[i])
set i = i + 1
}
// 3. Stack Operations
set stack = []
array_push(stack, "A")
array_push(stack, "B")
set top = array_pop(stack) // "B"
Maps API
Maps are key-value stores (dictionaries). Keys must be strings.
Creates and returns a new empty map.
Sets key to val. If key exists, it
is overwritten.
Returns the value for key, or
null if not found.
Returns true if the map contains
key.
Returns an array of all keys in the map (order not guaranteed).
Returns the number of entries in the map.
Map Examples
// 1. Creating and Accessing
set user = map_new()
map_set(user, "name", "Alice")
map_set(user, "role", "Admin")
if map_has(user, "name") {
print("User: " + map_get(user, "name"))
}
// 2. Iterating Keys
set keys = map_keys(user)
set i = 0
while i less array_len(keys) {
set key = keys[i]
set val = map_get(user, key)
print(key + ": " + val)
set i = i + 1
}
Structures
Structs are lightweight data containers.
structure Point with x, y
set p1 = create Point with x = 10, y = 20
print(p1.x)
Imports (NOT FULLY IMPLIMENTED YET)
The import statement allows you to include other
Zenith files.
import "utils.zen"
Currently, imports are shallow (copy-paste mechanism). Namespaces are not yet supported.
Input / Output
Writes a value to standard output with a newline.
Reads a line from standard input.
Math Library
All math functions accept and return numbers (64-bit floats).
Constant: 3.14159...
Constant: 2.71828...
Absolute value.
Rounds down to nearest integer.
Rounds up to nearest integer.
Rounds to nearest integer.
Returns the smaller of two numbers.
Returns the larger of two numbers.
Constrains x between min and
max.
Raises base to the power of exp.
Square root.
Natural logarithm (ln).
Base-10 logarithm.
Sine (radians).
Cosine (radians).
Tangent (radians).
Arc sine.
Arc cosine.
Arc tangent.
Euclidean distance (hypotenuse).
Linear interpolation between a and
b.
Returns 1, -1, or 0.
Pseudo-random number between min and max.
Returns true if x is Not-a-Number.
Returns array of numbers from start to end (exclusive).
Parses string to integer number, or null if failed.
Strings
Utilities for text manipulation.
Returns length of string (bytes).
Splits string by delimiter.
Replaces all occurrences of old with
new.
Returns substring from start to end indices.
Checks if string contains substring.
Returns index of first occurrence, or -1.
Returns true if string starts with substring.
Returns true if string ends with substring.
Converts string to uppercase.
Converts string to lowercase.
Removes whitespace from both ends.
Repeats string count times.
Returns character at index.
Returns true if string contains only digits.
Returns true if string contains only letters.
File System
Reads entire file contents as a string.
Writes content to file, overwriting if exists.
Returns true if path exists.
Returns true if path is a directory.
Creates directory recursively. Returns true on success.
Deletes file or directory. Returns true on success.
Returns array of file names in directory.
Returns file size in bytes, or -1 on error.
Renames/moves a file or directory.
Copies a file. Returns true on success.
Returns absolute canonical path.
Returns map with keys like readonly.
System & OS Library
Executes a shell command (via cmd /C or
sh -c) and returns the stdout output.
Pauses execution for ms milliseconds.
Returns the current timestamp (seconds since Unix Epoch).
Terminates the program immediately with the given exit code.
Returns the operating system name (e.g., "windows", "linux").
Returns command-line arguments as an array of strings.
Returns the value of an environment variable, or
null if unset.
Returns the current working directory path.
Returns the number of logical CPU cores.
Returns the current process ID.
Throws a runtime error with msg if
cond is false.
Immediately stops execution with a runtime error message.
OS Examples
// 1. Executing Shell Commands
set output = system("echo Hello")
print(output)
// 2. Environment Variables
set path = os_env("PATH")
if path is not null {
print("PATH found")
}
// 3. System Info
print("OS: " + os_name())
print("Cores: " + os_cpu_count())
Type Conversion
Runtime Errors
Common errors you might encounter while running Zenith programs.
| Error | Description | Common Fix |
|---|---|---|
Type Mismatch |
Operation performed on incompatible types (e.g., adding Number to Map). |
Check variable types using type_of(). Ensure
correct types for operators.
|
Index Out of Bounds |
Accessing an array index that does not exist. |
Check array_len() before accessing. Arrays are
0-indexed.
|
Unknown Identifier |
Using a variable or function that hasn't been defined. |
Check for typos. Ensure variable is declared with
set before use.
|
Invalid Argument Count |
Calling a function with too few or too many arguments. | Check function definition and provide correct number of arguments. |
Division by Zero |
Dividing a number by 0. |
Add a check: if divisor != 0 before dividing.
|
Stack Overflow |
Infinite recursion or too many nested function calls. | Ensure recursive functions have a base case (exit condition). |
File Not Found |
Trying to read a file that doesn't exist. |
Check file path. Use fs_exists() before
reading.
|
Permission Denied |
OS blocked file access (e.g., writing to system folder). | Run IDE as Administrator or check file permissions. |
Parse Error |
Syntax error in code (e.g., missing brace). |
Check line number reported. verifying matching
{} and ().
|
Struct Field Missing |
Creating a struct without initializing all fields. |
Provide values for all fields defined in
structure.
|
Troubleshooting
IDE not running?
Ensure you have `ide.exe` and `compiler.exe` in the same folder.
Known Bugs
input() does not work inside the IDE output window.
Use an external terminal.