Project images coming soon
Screenshots & demo previews will appear here
CVM++ Stack-Based Virtual Machine
Build a complete custom scripting language toolchain from scratch in C++ β including a Lexer, Recursive-Descent Parser, Bytecode Compiler, and a Stack-Based Virtual Machine. Write .cvm source files that get tokenized, parsed into an AST, compiled to proprietary bytecode with 16 custom opcodes, and executed on your own VM engine β with a CLI supporting file mode, REPL mode, and a --debug flag that prints tokens, AST, and disassembly.
Demo Video
YouTube β Coming soon
What You Will Build
A fully working custom scripting language called CVM that compiles down to proprietary bytecode and runs on your own stack-based Virtual Machine β all built in C++ with zero external libraries. You will write a Lexer that tokenizes raw .cvm source files into typed tokens with line numbers, a Recursive-Descent Parser that builds a typed Abstract Syntax Tree, a Bytecode Compiler that walks the AST and emits flat binary bytecode with 16 custom opcodes and jump back-patching for loops and branches, and a VM that fetches, decodes, and executes each instruction in a switch loop. The CLI supports three modes: run a .cvm script file, open an interactive REPL, or use --debug mode to print the full token list, indented AST, hex dump, and human-readable disassembly before executing.
Concepts You'll Learn
- How programming languages work end-to-end β from raw text to machine execution
- Lexical analysis: scanning source characters and producing typed tokens with line numbers
- Recursive descent parsing: translating tokens into a typed Abstract Syntax Tree (AST)
- Operator precedence climbing: correctly handling * / before + - before == <
- AST node design using polymorphism and std::unique_ptr for memory safety
- Designing a custom Instruction Set Architecture (ISA) with 16 opcodes
- Bytecode compilation: walking the AST and emitting flat uint8_t bytecode
- Jump back-patching: emitting placeholder offsets and fixing them after compiling blocks
- Building a stack-based VM with a fetch-decode-execute loop using a switch statement
- Tagged union value types to support both int and bool on the VM stack
- Variable slot allocation using a symbol table (map<string, int>)
- Runtime error handling: division by zero, stack underflow, unknown opcode
- Building a hex dump and human-readable bytecode disassembler
- Building a CLI in C++ with file mode, REPL mode, and debug mode
- Clean separation of concerns: each module in its own .h/.cpp pair
- Compiling a multi-file C++ project with CMake and g++
Study Resources
Learn before you build π
Free YouTube Videos
No account Β· No cost Β· Start now
No YouTube videos yet
Check back soon!
Recommended Courses
Udemy Β· Structured & Certified
Pro courses coming soon
CVM++ Stack-Based Virtual Machine
Full source code + guided walkthrough
What's Included
π Secure payment Β· Instant delivery
Tech Stack