This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an Effect-based TypeScript implementation of the Monkey programming language interpreter from "Writing An Interpreter In Go", with extensions for symbolic differentiation. The project includes:
- A complete lexer, parser, and evaluator for the Monkey language
- Symbolic differentiation capabilities supporting constant, sum, power, product, quotient, and chain rules
- A web-based REPL interface built with React and Vite
- Trigonometric derivatives implementation
pnpm test- Run tests with Bunpnpm vitest- Run tests with Vitestpnpm coverage- Generate test coverage reportspnpm check- TypeScript type checkingpnpm lint- Run ESLint on codebasepnpm lint-fix- Auto-fix lint issues
pnpm repl- Start the CLI REPL interfacepnpm dev- Start Vite development server for web interfacepnpm build- Build the project
- Run single test file:
bunx vitest src/tests/vitest/eval/eval.test.ts - Run specific test pattern:
bunx vitest --grep "pattern"
The interpreter follows a traditional lexer → parser → evaluator pipeline, implemented using Effect-TS:
- Lexer (
src/services/lexer/) - Tokenizes input strings using state management services - Parser (
src/services/parser/) - Builds AST from tokens with precedence-based parsing - Evaluator (
src/services/evaluator/) - Interprets AST nodes and manages runtime environment
The codebase uses a comprehensive schema system in src/schemas/:
nodes/- AST node definitions (expressions, statements, program)objs/- Runtime object representationstoken/- Token type definitions- Built-in function schemas and differentiation schemas
- Effect Services: Core functionality implemented as Effect services with dependency injection
- Schema Validation: Extensive use of Effect Schema for type-safe parsing and validation
- Functional Programming: Immutable data structures and functional composition throughout
- Error Handling: Effect-based error handling with typed error channels
Located in src/services/diff/, implements symbolic differentiation:
obj.ts- Core differentiation logic for different object typeshelper.ts- Utility functions for differentiation operations- Supports polynomial objects and various mathematical operations
- Unit tests in
src/tests/vitest/organized by functionality - Parser tests focus on AST construction correctness
- Evaluator tests verify runtime behavior and differentiation accuracy
- Helper utilities in test directories for common test patterns
- CLI REPL:
src/services/cli.ts - Web interface:
src/vite/main.tsx - Core interpreter:
src/services/evaluator/index.ts