NovaScript is a modern scripting language focused on speed and simplicity.
Version: v0.0.2
This repository contains a small reference interpreter for NovaScript.
- Simple, readable syntax
- Dynamic typing
- Functions
- Variables
- Arrays
- Conditionals
- While loops
- Built-in functions
- REPL
- Clean module layout
- For-in loops
breakandcontinuesupport- Script arguments via global
args - Maps / dictionaries
- First-class functions
- Anonymous function expressions
- Higher-order functions:
map,filter,reduce,each
let name = "Nova";
fn greet(who) {
return "Hello, " + who + "!";
}
print(greet(name));
From the project root:
python -m novascript examples/hello.novaOr install in editable mode:
pip install -e .
nova examples/hello.novapython -m novascriptExample:
nova> let x = 10;
nova> print(x * 2);
20
nova> exit
python -m unittest discover -s testslet x = 10;
let message = "hello";
fn add(a, b) {
return a + b;
}
print(add(2, 3));
if x > 5 {
print("big");
} else {
print("small");
}
let i = 0;
while i < 5 {
print(i);
i = i + 1;
}
let items = [1, 2, 3];
items[0] = 10;
print(items);
print(len(items));
for n in [1, 2, 3] {
print(n);
}
for ch in "Nova" {
print(ch);
}
for i in range(3) {
print(i);
}
let i = 0;
while i < 10 {
i = i + 1;
if i == 3 {
continue;
}
if i == 7 {
break;
}
print(i);
}
assert(1 == 1);
assert(2 + 2 == 4, "math should work");
let config = {
debug: true,
name: "NovaScript",
version: 3
};
print(config["name"]);
config["debug"] = false;
for key in config {
print(key, "=", config[key]);
}
let fruits = ["apple", "pear"];
push(fruits, "plum");
print(fruits);
print(pop(fruits));
print(contains(fruits, "pear"));
let user = {
name: "Nova",
version: 3
};
print(keys(user));
print(values(user));
print(entries(user));
print(upper("nova"));
print(lower("NOVA"));
print(trim(" padded "));
print(split("one,two,three", ","));
print(join(["one", "two", "three"], " | "));
print(replace("NovaScript", "Script", "Lang"));
print(starts_with("NovaScript", "Nova"));
print(ends_with("NovaScript", "Script"));
let double = fn(x) {
return x * 2;
};
print(double(21));
let nums = [1,2,3,4];
let doubled = map(nums, fn(n) {
return n * 2;
});
let evens = filter(nums, fn(n) {
return n * 2;
});
let total = reduce(nums, 0, fn(acc, n) {
return acc + n;
});
each(nums, fn(n) {
print(n);
});
Print tokens:
python -m novascript --tokens examples/hello.novaPrint the AST:
python -m novascript --ast examples/hello.novaPrint tokens and AST, then still run the program:
python -m novascript --tokens --ast --run examples/hello.novaCheck a file without running it:
python -m novascript --check examples/hello.novaUse -- to separate NovaScript CLI options from script arguments.
python -m novascript examples/args.nova -- alpha beta gammaInside NovaScript, arguments are available as an array called args:
print(args);
for arg in args {
print(arg);
}
print("Argument count:", len(args));
Stop execution normally:
exit();
Stop execution with a failure code:
exit(1);
From a shell:
python -m novascript examples/exit.nova -- --fail echo $?print(...)len(value)str(value)num(value)type(value)range(stop)range(start, stop)range(start, stop, step)input(prompt)clock()version()assert(condition)assert(condition, message)exit()exit(code)has(map, key)keys(map)values(map)entries(map)remove(map, key)push(array, value)pop(array)contains(collection, value)upper(string)lower(string)trim(string)split(string, separator)join(array, separator)replace(string, old, new)starts_with(string, prefix)ends_with(string, suffix)map(array, function)filter(array, function)reduce(array, initial, function)each(array, function)
- Bytecode compiler
- Faster VM
- Modules
- Error messages with source spans
- Standard library expansion
- Package manager
[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"
[project]
name = "novascript"
version = "0.0.2"
description = "A modern scripting language focused on speed and simplicity."
readme = "README.md"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [
{ name = "NovaScript" }
]
[project.scripts]
nova = "novascript.cli:main"
[tool.setuptools.packages.find]
include = ["novascript*"]