I'll build a complete interactive compiler explorer for a custom language called "TinyLang". Let me create all the files.
Let me fix the type errors in codegen.ts:
Now let me create all the React components. First, let me set up the directory structure:
Now let me create the components. I'll build them all:
Now let me create the AST Viewer:
Now let me create the main App component that brings everything together:
Let me try building to check for remaining type errors:
The project builds successfully. Let me update the HTML title:
Let me verify the final project structure:
The project is complete and builds successfully! Here's what was built:
TinyLang Compiler Explorer
Language (TinyLang)
A custom imperative programming language with:
- Variables:
let x = 42;
- Arithmetic:
+, -, *, /
- Comparisons:
==, !=, <, >, <=, >=
- Conditionals:
if (cond) { ... } else { ... }
- Loops:
while (cond) { ... }
- Print:
print expr;
- Comments:
// line comments
- Booleans:
true, false
- Strings:
"hello"
Architecture (6 compiler files + 6 components)
Compiler Pipeline (src/compiler/):
types.ts — All shared types: tokens, AST nodes (13 node types), bytecode opcodes (18 instructions), diagnostics, VM state
lexer.ts — Tokenizer with string/number/identifier handling, comments, and error reporting
parser.ts — Recursive descent parser producing a full AST with error recovery (synchronization)
codegen.ts — Generates stack-based bytecode with jump patching for if/while
vm.ts — Virtual machine with runAll() and single-step execution, full register/memory simulation
examples.ts — 10 curated example programs
UI Components (src/components/):
CodeEditor.tsx — Textarea with transparent caret over syntax-highlighted HTML overlay, line numbers with error/current-line markers
ASTViewer.tsx — Color-coded tree visualization showing AST structure
BytecodeViewer.tsx — Address/opcode/operand table with current-instruction highlighting
DiagnosticsPanel.tsx — Error/warning/info list with counts and line locations
VMViewer.tsx — Register file (AX, BX, CX, DX, SP, BP, IP, flags), value stack (TOS marker), memory map, and output
Examples.tsx — Clickable example library
Features
- Step-by-step execution: Watch the bytecode pointer advance and VM state update
- Shareable URLs: Encoded source code in URL params via
?code=... (base64)
- Catppuccin Mocha dark theme throughout
Files built: src/compiler/types.ts, src/compiler/lexer.ts, src/compiler/parser.ts, src/compiler/codegen.ts, src/compiler/vm.ts, src/compiler/examples.ts, src/components/CodeEditor.tsx, src/components/ASTViewer.tsx, src/components/BytecodeViewer.tsx, src/components/DiagnosticsPanel.tsx, src/components/VMViewer.tsx, src/components/Examples.tsx, src/App.tsx, index.html