Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

Nova

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)

How it works

Source code goes through four stages:

  1. Lexer (lexer.py) — turns source text into a stream of tokens.
  2. Parser (parser.py) — turns tokens into an AST (node types defined in tree.py).
  3. Compiler (compiler.py) — walks the AST and emits stack-based bytecode (PUSH, ADD, JUMP_IF_FALSE, CALL, etc.).
  4. VM (vm.py) — executes the bytecode on a stack machine with call frames, so functions and recursion work.

Running a program

python main.py                  # runs examples/test.nova
python main.py path/to/file.nova

Language features

  • Variables: let name = value
  • Arithmetic: + - * /
  • Unary minus: -x
  • Boolean logic: and, or, not
  • Comparisons: == != < >
  • Strings and booleans (true / false)
  • if / else
  • while loops
  • Functions with fun, return, and recursion
  • Single-line comments with //

Status

Nova is a work in progress and mainly a learning project for building an interpreter/VM from scratch. Contributions and issue reports are welcome.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages