How hussein-saad/tslox works
tslox is a TypeScript tree-walk interpreter. A user supplies a script or enters REPL input; the Lox entry point scans and parses it, resolves lexical scopes, then invokes the interpreter to evaluate statements and expressions. The interpreter uses environments for variables and closures, and callable functions for calls and returns. The README also documents short-circuit logic, loops, ternary expressions, native clock(), and error reporting. Relationships below are limited to the README and source excerpts or index references; unsampled implementation details are not assumed.
Main entry points: interpreter.ts Tree-walk interpreter · lox.ts CLI and REPL · parser.ts Parser · scanner.ts Scanner
Components 17
Language Front End
- Scanner
src/scanner.ts - Tokens and kinds
src/token.ts - Token kinds
src/token-type.ts - Parser
src/parser.ts - Expression AST
src/expression.ts - Statement AST
src/stmt.ts - AST printer
src/printer.ts
Scope and Runtime
- Scope resolver
src/resolver.ts - Environments
src/environment.ts
Execution and I/O
- CLI and REPL
src/lox.ts - Tree-walk interpreter
src/interpreter.ts - Callable protocol
src/callable.ts - Lox functions
src/function.ts - Return signal
src/return.ts - Runtime errors
src/runtimeerror.ts
Other components
- Lox user
- Terminal output
Connections 27
- Lox user → CLI and REPL: provides input
README.md - CLI and REPL → Scanner: scans source
src/lox.ts - Scanner → Tokens and kinds: emits tokens
src/scanner.ts - Scanner → Token kinds: tags tokens
src/scanner.ts - Scanner → CLI and REPL: reports scan errors
src/scanner.ts - CLI and REPL → Parser: parses tokens
src/lox.ts - Parser → Expression AST: builds expressions
src/parser.ts - Parser → Statement AST: builds statements
src/parser.ts - Parser → Tokens and kinds: reads tokens
src/parser.ts - Parser → Token kinds: matches kinds
src/parser.ts - Parser → CLI and REPL: reports parse errors
src/parser.ts - CLI and REPL → Scope resolver: resolves statements
src/lox.ts - Scope resolver → Tree-walk interpreter: records local depth
src/resolver.ts - CLI and REPL → Tree-walk interpreter: interprets statements
src/lox.ts - Tree-walk interpreter → Expression AST: visits expressions
src/interpreter.ts - Tree-walk interpreter → Statement AST: executes statements
src/interpreter.ts - Tree-walk interpreter → Environments: reads and updates
src/interpreter.ts - Tree-walk interpreter → Callable protocol: checks and invokes
src/interpreter.ts - Tree-walk interpreter → Lox functions: creates functions
src/interpreter.ts - Lox functions → Environments: captures closure
src/function.ts - Lox functions → Tree-walk interpreter: executes function body
src/function.ts - Lox functions → Return signal: catches return
src/function.ts - Tree-walk interpreter → Return signal: throws return signal
src/interpreter.ts - Tree-walk interpreter → Runtime errors: raises runtime errors
src/interpreter.ts - Tree-walk interpreter → CLI and REPL: reports runtime errors
src/interpreter.ts - CLI and REPL → Terminal output: prints results and errors
src/lox.ts - AST printer → Expression AST: prints expressions
src/printer.ts