Skip to content

NSL Language Overview

NSL (Nox Scripting Language) is the programming language executed by the Nox runtime. It is intentionally familiar — borrowing syntax from C, Java, and JavaScript — but its semantics are strictly controlled by the sandbox.

Every .nox file represents a single program that can optionally import other .nox files as namespaced libraries.

GoalHow NSL Achieves It
Easy to learn and generateC-family syntax, no unusual constructs which makes it familiar to developers and trivial for code generators
Safe by defaultStatic types, no implicit permissions, no escape hatches
Developer-friendlyRich error messages with suggestions, string interpolation, UFCS for ergonomic APIs
Expressive enoughStructs, flexible json type, UFCS, streaming with yield
No unnecessary complexityNo classes, no inheritance, no generics, no closures
@tool:name "data_processor"
@tool:description "Downloads a JSON report, validates it, and yields progress."
@tool:author "Data Engineering"
type ReportItem {
double value;
string name;
}
boolean isSignificant(ReportItem item, double threshold) {
return item.value > threshold;
}
main(string url, double minThreshold = 10.5) {
yield `Initializing connection to ${url}`;
try {
json data = Http.getJson(url);
int totalProcessed = 0;
double sumValues = 0.0;
for (int i = 0; i < data.size(); i++) {
ReportItem item = data[i] as ReportItem;
if (item.isSignificant(minThreshold)) {
sumValues = sumValues + item.value;
totalProcessed = totalProcessed + 1;
}
if (i % 10 == 0) {
yield `Analyzed ${i + 1} items...`;
}
}
return `Processed ${totalProcessed} significant items. Total value: ${sumValues}`;
} catch (err) {
yield `Error during processing: ${err}`;
return "Task Failed";
}
}

A .nox file follows a strict top-down structure:

┌─────────────────────────────┐
│ 1. Metadata Headers │ @tool:name, @tool:description, etc.
│ (optional) │
├─────────────────────────────┤
│ 2. Import Declarations │ import "math.nox" as m;
│ (optional) │
├─────────────────────────────┤
│ 3. Type Definitions │ type Point { int x; int y; }
│ (optional) │
├─────────────────────────────┤
│ 4. Helper Functions │ int add(int a, int b) { ... }
│ (optional) │
├─────────────────────────────┤
│ 5. main() Entry Point │ main(string arg1) { ... }
│ (optional for libraries)│
└─────────────────────────────┘

Every variable has a known type at compile time. Type mismatches are caught during semantic validation, before any code runs.

int x = 42; // Correct
int y = "hello"; // SemanticError: Cannot assign 'string' to 'int'

Template literals with backticks are the idiomatic way to build strings:

int count = 42;
string msg = `Found ${count} items.`; // "Found 42 items."

Functions can be called as if they were methods of their first argument:

double dist1 = calculateDistance(origin); // Standard call
double dist2 = origin.calculateDistance(); // UFCS, identical semantics

Programs can send intermediate results, enabling progress updates for long-running operations:

yield "Step 1 complete...";
yield "Step 2 complete...";
return "All done.";

All external operations go through namespaced libraries with permission checks:

string content = File.read("/data/input.txt"); // Requires file.read permission
json response = Http.getJson("https://api.com"); // Requires http.get permission
double root = Math.sqrt(144); // No permission needed

Reuse code across files by importing other .nox files as namespaced libraries:

import "utils/math_helpers.nox" as mh;
import "formatting.nox" as fmt;
main() {
double result = mh.calculate(42);
yield fmt.prettyPrint(result);
}

Imported files can have their own main() for standalone testing, it is simply not exported when imported. The namespace must be explicitly specified and cannot clash with built-in library names (Math, File, Http, etc.).

int, double, boolean, string, json, void,
true, false, null,
if, else, while, for, foreach, in,
return, yield, break, continue,
try, catch, throw,
type, main, as, import
PrecedenceOperatorsAssociativity
1 (highest)!, -, ~ (unary), ++, --Right
2*, /, %Left
3+, -Left
4<<, >>, >>>Left
5<, <=, >, >=Left
6==, !=Left
7&Left
8^Left
9|Left
10&&Left
11 (lowest)||Left

Assignment operators: =, +=, -=, *=, /=, %=

// Single-line comment
/*
Multi-line
comment
*/