Nova is a small interpreted programming language, implemented in Python. It has its own lexer, parser, AST, bytecode compiler, and stack-based virtual machine.
let score = 100
let bonus = 25
let totalScore = score + bonus
if totalScore > 100 {
print "You are a winner!"
} else {
print "Keep trying!"
}
fun factorial(n) {
if n < 2 {
return 1
}
return n * factorial(n - 1)
}
print factorial(5)
Source code goes through four stages:
- Lexer (
lexer.py) — turns source text into a stream of tokens. - Parser (
parser.py) — turns tokens into an AST (node types defined intree.py). - Compiler (
compiler.py) — walks the AST and emits stack-based bytecode (PUSH,ADD,JUMP_IF_FALSE,CALL, etc.). - VM (
vm.py) — executes the bytecode on a stack machine with call frames, so functions and recursion work.
python main.py # runs examples/test.nova
python main.py path/to/file.nova- Variables:
let name = value - Arithmetic:
+ - * / - Unary minus:
-x - Boolean logic:
and,or,not - Comparisons:
== != < > - Strings and booleans (
true/false) if/elsewhileloops- Functions with
fun,return, and recursion - Single-line comments with
//
Nova is a work in progress and mainly a learning project for building an interpreter/VM from scratch. Contributions and issue reports are welcome.