Syntax reference¶
This page is the fuller language reference for the syntax you use in real Novus projects.
It is intentionally practical rather than academic: it focuses on the syntax and patterns that appear in the compiler docs, the standard ecosystem libraries, and the example applications linked from this guide.
Files and modules¶
Every Novus source file starts with a module declaration:
The root file you compile should define a main function. In simple apps that is usually:
In larger applications, that root main.nov is usually just the entrypoint and import hub. Most of the real code can live under src/ and its subfolders.
CLI apps may also expose an argument-taking entrypoint:
Statement style¶
Novus code in this ecosystem uses semicolons to end statements:
Blocks use braces:
Comments¶
Novus documentation describes support for both single-line and block comments:
Types¶
Novus uses explicit types.
| Type | Meaning |
|---|---|
i32 |
32-bit signed integer |
i64 |
64-bit signed integer |
u32 |
32-bit unsigned integer |
u64 |
64-bit unsigned integer |
f32 |
32-bit floating-point |
f64 |
64-bit floating-point |
bool |
boolean |
str |
string |
void |
no return value |
[]T |
dynamic array of T |
Important rule: there is no plain int. Use explicit widths like i32 and i64.
Literals¶
Integer literals¶
Boolean literals¶
String literals¶
The ecosystem currently uses string literals heavily. Existing projects show both quoted styles in practice:
Array literals¶
Variables¶
Variables are declared with let:
In current Novus code, variables are mutable:
Type annotations are written at declaration time:
Global variables¶
Projects often keep app state in globals:
This pattern is common in current Novus examples, especially where the code is small and explicit state is preferred over abstraction.
Assignment and update operators¶
Basic assignment:
Compound assignment:
Increment / decrement:
These are used as statements in current code, not as expression values.
Functions¶
Function syntax:
Void-style function:
Parameters¶
Every parameter is typed:
Returning values¶
Use return:
Overloading¶
Novus supports overloaded functions when the parameter list differs:
The return type is not what distinguishes overloads; the parameters do.
Calls¶
Control flow¶
if, else if, else¶
while¶
Current examples rely heavily on while.
Operators¶
Arithmetic¶
+-*/%
Comparison¶
==!=<<=>>=
Logical¶
&&||!
Bitwise¶
Current library and application code also uses bitwise operators for things like input masks:
&|
Example:
Strings¶
Strings are used heavily across the ecosystem.
Concatenation¶
Indexing¶
Projects index strings directly:
Common string patterns¶
You will often see:
len(s)substr(...)substr_len(...)str_find(...)- conversion helpers from
std
Some of these are builtin patterns, others come from std.
Arrays¶
Declaration¶
Indexing¶
Append¶
Empty arrays¶
Imports¶
Common import forms:
Alias import¶
Unaliased import¶
That brings exported names directly into the current module.
Package entrypoints¶
Modern Novus libraries usually expose a stable main.nov loader. That is why imports such as these are common:
Conditional compilation¶
Novus uses #if(...) to include platform-specific code at compile time.
OS selection¶
#if(os == "darwin") {
import platforms/darwin/arm64;
}
#if(os == "linux") {
import platforms/linux/common;
}
#if(os == "windows") {
import platforms/windows/common;
}
Architecture selection¶
The most common conditions in the current ecosystem are:
os == "darwin"os == "linux"os == "windows"arch == "arm64"arch == "amd64"arch == "x86"
Builtins¶
Common compiler-provided builtins:
len(...)array_append(...)ptr(...)mov(...)getreg(...)syscall()push(...)pop()win_call(...)
These do not require imports.
Low-level syntax¶
Low-level Novus libraries use register operations directly:
mov(x0, fd);
mov(x1, ptr(buf));
mov(x2, len(buf));
mov(x16, 0x2000000 + 4);
syscall();
let rc: u64 = getreg(x0);
Windows-specific wrappers often use:
Program entrypoints¶
You will see two main styles:
Simple program¶
CLI program¶
CLI usage¶
Typical compiler command:
Cross-compile:
Build artifacts are written into build/<target>/.
Nox project syntax in practice¶
Typical project flow:
That gives you:
main.novlibraries.conflib/<package>/...src/...
Practical style notes¶
Current Novus projects in this ecosystem generally follow these conventions:
- use explicit integer sizes (
i32,i64) - prefer alias imports for larger libraries
- use root
main.novas the entrypoint and keep larger app code insrc/ - keep cross-platform branching in libraries via
#if, not in app code when possible - use explicit loops and explicit state rather than heavy abstraction
Where to go next¶
- For a quicker introduction, go back to the Language Tour.
- For real code, read the Platformer walkthrough and Todo app walkthrough.
- For package surfaces, use the Library Reference overview.