nrk (/ˈanɑːrki/
) is a small programming language with a bytecode interpreter implementation written entirely in C99.
The language is inspired by Bob Nystrom's "Crafting Interpreters" with modifications and enhancements.
- Bytecode Virtual Machine: Executes instructions efficiently with a stack-based architecture
- C99 Implementation: Written in standard C99 for maximum portability
- REPL: Interactive Read-Eval-Print Loop for quick testing and experimentation
- File Execution: Run
nrk
script files directly - Expression Evaluation: Currently supports arithmetic expressions
The language currently supports:
- Basic arithmetic operations (
+
,-
,*
,/
) - Numeric literals
- Unary negation
Additional custom features implemented in nrk
:
- Template (and nested!) strings (
`This is a ${${"nested"} str}} with ${1+1} levels of nesting.`
) - Extended constant pool (via
OP_CONSTANT_LONG
for more than 256 constants)
- VM: Stack-based virtual machine that executes bytecode
- Compiler: Turns source code into bytecode
- Scanner: Tokenizes source code for the compiler
- Chunk: Represents bytecode and related metadata
- Value: Represents runtime values (currently double-precision floating point)
- Debug: Tools for inspecting bytecode and execution
- C compiler (clang recommended)
- Make
make all
./main
./main path/to/script.nrk
1 + 2 * (3 + 4) / 5
Will produce:
3.8
nrk
is currently in early development. The focus has been on implementing the core bytecode VM, scanner, and compiler for arithmetic expressions. Future plans include:
- Variables and assignment
- String support and operations
- Control flow (if/else, loops)
- Functions and closures
- Classes and inheritance
The interpreter includes several debugging features that can be enabled by uncommenting the corresponding define statements in common.h
:
DEBUG_PRINT_CODE
: Disassembles and prints bytecode after compilationDEBUG_TRACE_EXECUTION
: Traces VM execution step by step, showing stack stateDEBUG_COMPILE_EXECUTION
: Provides detailed compilation process logs