How ashitomw/scripto works
Project Type and Purpose
• Scripto Lang is an interpreted toy programming language implemented in TypeScript.
• It provides a simple CLI REPL, a classic compile-and-interpret pipeline (lexer → parser → AST → interpreter), and basic runtime types (number, null).
Top-Level Modules and Components
• main.ts (REPL entry point): Handles user I/O.
• core/
• lexer.ts – Converts input strings into tokens.
• parser.ts – Builds an AST from tokens.
• ast.ts – Defines AST node structures.
• utils.ts – Shared helper functions (e.g., token utilities, error formatting).
• runtime/
• interpreter.ts – Walks the AST and produces runtime values.
• values.ts – Defines the runtime value types and type-checking logic.
• Config & Build
• tsconfig.json, package.json – TypeScript/Node build settings (not in the execution pipeline but can be shown as a side note).
Key Architectural Pattern
• A linear “compiler pipeline” (lexer → parser → AST → interpreter) inside a single process.
• A REPL wrapper around that pipeline orchestrates input/output.
• All modules run in the Node.js runtime with ES module loading.
Main Components & Data Flows
A. REPL Interface (main.ts)
B. Lexer Module (core/lexer.ts)
C. Parser Module (core/parser.ts)
D. AST Definitions (core/ast.ts)
E. Utilities (core/utils.ts) – support both the lexer and parser
F. Interpreter (runtime/interpreter.ts)
G. Runtime Values (runtime/values.ts)
H. Console/Stdout
1. User enters code → REPL Interface
2. REPL passes raw input → Lexer
3. Lexer outputs Token Stream → Parser
4. Parser references AST Definitions → produces AST
5. Parser/Interpreter may call Utils (error handling, helper routines)
6. AST → Interpreter
7. Interpreter references Runtime Values → evaluates, returns a Value
8. Value → REPL Interface → Console output
Technologies and Files
• “Lexer (core/lexer.ts): tokenize numbers, operators, parentheses”
• “Parser (core/parser.ts): recursive descent with precedence”
• “Interpreter (runtime/interpreter.ts): AST walker, operation implementations”
• In the environment container, list “TypeScript, ES modules, ts-node/tsx, Node.js”.
Essential Details
• Where errors/exceptions could bubble up (e.g., lexical errors, parse errors).