🎓 NIT Jalandhar | 3rd Year
💻 Leetcode Knight | Codeforces Specialist | CodeChef 4★
This project brings together:
SHORT SUMMARY: I built my own compiler, that compiles programs written in my own language (BroLang), into bytecode that runs on my own virtual CPU, which executes using my own virtual machine — all from scratch in C++.
No libraries. No frameworks. Just raw logic, control, and architecture.
- 🧾 A full compiler for a custom toy language: BroLang
- 🧠 A custom virtual machine (RohitVM) to execute compiled code
- ⚙️ A 16-bit Virtual CPU with registers, RAM, and an instruction set
Everything — from the lexer to the VM — is handcrafted in modern C++, with no compiler frameworks or dependencies.
A beginner-friendly language with C-like vibes and meme syntax:
letbro a = 10;
letbro b = 3;
printbro(a + b);
letbro a = 10;
letbro b = 3;
printbro(a / b);
letbro a = 10;
letbro b = 3;
printbro(a - b);
letbro a = 10;
letbro b = 3;
printbro(a * b);
ifbro (a > b) {
printbro(999);
} elsebro {
printbro(111);
}
ifbro (a < b) {
printbro(222);
} elsebro {
printbro(888);
}
ifbro (a == b) {
printbro(333);
} elsebro {
printbro(777);
}
letbro counter = 0;
whilebro (counter < 3) {
printbro(counter);
letbro counter = counter + 1;
}
g++ broc.cpp lexer.cpp parser.cpp codegen.cpp emitter.cpp -o broc
./broc test.bro -o prog.cpp
g++ compiler_test.cpp RohitVM.cpp RohitUtils.cpp -o run_bro
./run_bro
-Variable declarations with letbro -Arithmetic operations: +, -, *, / -Control flow: ifbro, elsebro, whilebro -Output with printbro(expr);
The BroLang Compiler is a multi-phase pipeline:
| Phase | Description |
|---|---|
| Lexer | Converts source into tokens |
| Parser | Builds AST (Abstract Syntax Tree) |
| Codegen | Converts AST to VM instructions |
| Emitter | Writes instructions to a .cpp file |
| Executor | Runs code on the custom VM |
The compiler outputs C++ bytecode instructions that run on RohitVM.
A stack-based virtual machine that executes bytecode generated by the compiler.
-Executes compiled programs from BroLang -Stack-based architecture (PUSH/POP logic) -Built-in print, memory access, halt, arithmetic -No use of system VM libraries — 100% custom
AX, BX, CX, DX — General purpose SP — Stack Pointer PC — Program Counter (internally tracked)
The virtual CPU that powers RohitVM.
Specs: RAM: 65 KB
Instruction Set: Over 30+ instructions MOV, PUSH, POP, ADD, SUB, MUL, DIV, PRN, HLT, STL, STG, etc.
Stack Operations supported Custom memory operations (zeroing, copying, hex dump)
✅ Compiler design (lexer → parser → AST → bytecode)
✅ Instruction set architecture & stack machines
✅ Memory layout, stack handling, and execution flow
✅ Writing interpreters & VMs from scratch
Support for forbro loops
Function calls with local stack frames
String literals & input
Optimized IR (intermediate representation)
Add .brobin binary format
I'm Rohit Yadav, an undergrad at NIT Jalandhar, passionate about:
🧠 Compiler and VM internals
🔥 Building OS & low-level system tools
🏁 Creating everything from the ground up
