I will create the compiler type definitions file src/types/compiler.ts containing token kinds, AST node interfaces, opcode definitions, VM memory and snapshot structures, and diagnostics formats.
I will create src/compiler/lexer.ts to tokenize ViperScript code, handling keywords, identifiers, numbers, strings, multiline/single-line comments, operators, punctuators, and generating precise token location info.
I will update src/compiler/lexer.ts to clean up the unused import.
I will create src/compiler/parser.ts to implement a recursive descent parser that constructs an AST with full source location tracking and diagnostics for syntax errors.
I will edit src/compiler/parser.ts to remove the unused SourceLocation import.
I will create src/compiler/optimizer.ts to implement pass optimizations on the AST, including Constant Folding, Arithmetic Simplifications, and Dead Code Elimination.
I will create src/compiler/codegen.ts to transform the AST into a linear bytecode instruction stream with label patching, scope emission, built-in intrinsic support, and source location mapping.
I will create src/compiler/vm.ts to implement the Virtual Machine runner with step-by-step execution, stack & heap management, function stack frame mechanics, history snapshot capturing for execution time-travel, and runtime error reporting.
I will create src/examples/codeExamples.ts containing interactive source examples for learning and testing.
I will create src/utils/urlSharing.ts to encode and decode code snippets and editor parameters into clean, shareable base64 state URLs.
I will create src/components/Navbar.tsx for top application controls, example switching, run state, share URL trigger, and layout toggles.
I will edit src/components/Navbar.tsx to clean up the unused variable.
I will create src/components/CodeEditor.tsx featuring line numbering, gutter error markers, breakpoint toggling, active VM execution step highlighting, and instant synchronization.
I will create src/components/TokenViewer.tsx to visualize the token stream output from the lexical analysis step with filtering and search capabilities.
I will create src/components/AstViewer.tsx to display the Abstract Syntax Tree using both a collapsible nested node tree view and a graphical SVG node diagram.
I will create src/components/BytecodeViewer.tsx to display disassembled Virtual Machine instructions with opcode badges, source position mapping, comments, and current Program Counter (PC) indicator.
I will create src/components/VmDebugger.tsx to display CPU Registers, Evaluation Stack, Active Call Stack frames, Heap Memory inspection grid, and Execution Time-Travel Controls.
I will edit src/components/VmDebugger.tsx to remove the unused import.
I will create src/components/ConsoleOutput.tsx to serve as an interactive monospaced terminal stdout panel for print outputs and VM execution metrics.
I will create src/components/DiagnosticsPanel.tsx to list compiler syntax and semantic diagnostics with location references and fix recommendations.
I will create src/components/OptimizerPanel.tsx to display compiler optimization statistics and side-by-side pass analysis.
I will update index.html to give the application a title.
I will create src/App.tsx assembling the entire interactive compiler pipeline, VM debugger, editor, token stream, AST visualization, bytecode assembly, diagnostics, terminal output, and shareable encoded URLs.
I will update src/App.tsx to include export default App and remove the unused import.
I have built an interactive compiler & virtual machine explorer for the custom programming language ViperScript.
Key Features Included:
-
Monospaced Code Editor & Active Line Marker:
- Features line numbering, active execution line highlighting (during VM steps), gutter error markers, and breakpoint toggles.
- Pre-loaded with dynamic example programs: Variables & Flow Control, Recursive Fibonacci, Bubble Sort on Heap Memory, Binary Search, Compiler Optimizer Test, and Diagnostic Error Showcase.
-
Lexer & Token Stream Inspection:
- Tokenizes comments, numbers, strings, keywords, operators, and punctuators with position tracking (
line, column, index).
- Token stream view with search filtering, token type badges, and location metadata.
-
AST Parser & Dual Visualizer:
- Recursive descent parser supporting variables, recursive functions, arrays, index operations, conditional branches, loops, and math expressions.
- Dual inspection modes: Collapsible AST Tree View with scope details and a Visual Node Graph diagram.
-
AST Optimization Pipeline Pass:
- Implements Constant Folding, Dead Code Elimination, and Algebraic Identity Reductions.
- Side-by-side optimization pass metrics (Constant Folds count, Dead Code Removals count, and Instruction Savings %).
-
Bytecode Disassembler & Assembly View:
- Target stack-based opcode set (
PUSH_CONST, LOAD_VAR, STORE_VAR, JUMP, CALL, RETURN, ALLOC_ARRAY, LOAD_ELEM, STORE_ELEM, PRINT, HALT, etc.).
- Disassembly listing showing hexadecimal line offsets (
0x00), color-coded opcode badges, arguments, annotations, and jump arrow targets.
-
Virtual Machine Debugger & Time-Travel Execution:
- Step-by-step execution, continuous auto-play playback with speed controls (10ms to 500ms).
- Time Travel Control Panel: Step back / step forward in execution history using saved state snapshots.
- CPU Registers: Program Counter (
PC), Stack Pointer (SP), Frame Pointer (FP), Instruction Register (), Accumulator (), Cycles counter, and Status.
Files built: src/types/compiler.ts, src/compiler/lexer.ts, src/compiler/parser.ts, src/compiler/optimizer.ts, src/compiler/codegen.ts, src/compiler/vm.ts, src/examples/codeExamples.ts, src/utils/urlSharing.ts, src/components/Navbar.tsx, src/components/CodeEditor.tsx, src/components/TokenViewer.tsx, src/components/AstViewer.tsx, src/components/BytecodeViewer.tsx, src/components/VmDebugger.tsx, src/components/ConsoleOutput.tsx, src/components/DiagnosticsPanel.tsx, src/components/OptimizerPanel.tsx, index.html, src/App.tsx