An interactive web-based playground for the Monkey programming language - a language designed for learning interpreters and compilers. Write, execute, and explore Monkey code right in your browser with real-time tokenization, AST visualization, and bytecode compilation. Find more information about MonkeyLang at https://monkeylang.org/.
For more details on the backend checkout my repo on monkey-lang, https://github.com/NavrajBal/monkey-lang.
- 🌐 Live Demo
- 🛠️ Technology Stack
- 🧠 Parser & Compiler
- 🎯 Features & Pages
- 🏗️ Architecture
- 🚀 Getting Started
- 🔧 Configuration
- 📚 Monkey Language Features
- 🚀 Deployment
- 🚧 Work in Progress & Known Issues
- Acknowledgments
Try it out @ https://monkey-playground.vercel.app/
- React 19 with TypeScript
- Vite for build tooling and development
- Monaco Editor for code editing with syntax highlighting
- React Flow for AST visualization
- React Router for navigation
- Tailwind CSS equivalent styling
- WebAssembly (WASM) support for in-browser execution
- Go HTTP server to be used locally
- Vercel Functions for serverless API endpoints
- RESTful API design
This playground is powered by the monkey-lang implementation - a complete interpreter and compiler for the Monkey programming language. Which I made and extended features to taking inspiration from Thorsten Ball books "Writing an Interpreter in Go" and "Writing a Compiler in Go".
The implementation includes:
- Lexical Analysis - Tokenization of source code
- Recursive Descent Parser - AST generation
- Tree-Walking Interpreter - Direct AST evaluation
- Bytecode Compiler - Compilation to virtual machine instructions
- Virtual Machine - Bytecode execution engine
For more details checkout my repo on monkey-lang, https://github.com/NavrajBal/monkey-lang.
- Interactive Read-Eval-Print Loop
- Real-time code execution
- Sample code library with examples:
- Fibonacci sequences
- Factorial calculations
- Array operations
- Closures and higher-order functions
- Hash maps
- Conditional logic
- Dual backend support (API/WASM)
- Monaco editor with syntax highlighting
- Real-time tokenization of Monkey source code
- Visual breakdown of code into tokens
- Token type identification (keywords, identifiers, operators, etc.)
- Helpful for understanding lexical analysis
- Interactive Abstract Syntax Tree visualization
- Node-based graph representation using React Flow
- Expandable/collapsible tree structure
- Visual understanding of how code is parsed
- Color-coded node types for different AST elements
- Bytecode compilation visualization
- Instruction breakdown
- Constants pool inspection
- Virtual machine execution steps
frontend/
├── src/
│ ├── components/ # React components
│ │ ├── Playground.tsx # Main REPL interface
│ │ ├── TokenizerPage.tsx # Tokenization viewer
│ │ ├── ASTPage.tsx # AST visualization
│ │ └── CompilerPage.tsx # Bytecode viewer
│ ├── contexts/ # React contexts
│ │ ├── CodeContext.tsx # Shared code state
│ │ ├── ThemeContext.tsx # Dark/light theme
│ │ └── ToastContext.tsx # Notifications
│ ├── services/ # API and WASM services
│ │ ├── apiService.ts # HTTP API client
│ │ ├── wasmService.ts # WebAssembly interface
│ │ └── monkeyService.ts # Unified service layer
│ └── wasm/ # Go-to-WASM compilation
│ └── main.go # WASM entry point
├── api/ # Vercel Functions
│ ├── tokenize.go # Tokenization endpoint
│ ├── parse.go # AST parsing endpoint
│ ├── compile.go # Bytecode compilation
│ └── execute.go # Code execution
└── public/
└── monkey.wasm # Compiled WebAssembly binary
backend/
├── main.go # HTTP server entry point
├── api/
│ └── handlers.go # API route handlers
└── go.mod # Dependencies (monkey-lang)
- Node.js 18+ and npm
- Go 1.22+ (for backend development)
cd frontend
npm install
npm run devcd backend
go mod tidy
go run main.gocd frontend
npm run build-wasmThe playground supports two execution backends:
- API Backend (Default) - Full-featured Go HTTP server
- WASM Backend (Limited Features) - In-browser WebAssembly execution
Switch between backends using the toggle in the navigation bar or modify frontend/src/config/config.ts.
- Compiler Page: Bytecode compilation visualization is currently under development
- Enhanced Error Handling: Improving error messages and debugging information
- Performance Optimization: Optimizing WASM execution for larger programs
- WASM Errors: Code with Arrays, Hashmaps failing
- WASM Tokenizer & AST Support: WASM errors when trying to tokenize or display AST
- Error Recovery: Parser error recovery could be more robust
Thorsten Ball for writing the excellent books on interpreters and compilers