How somespi/lumen works
1. What this repository is
- Lumen is not a typical web app; it is a small language/runtime implemented in PHP.
- The repo contains the language engine, a command-line entry point, standard/native libraries, and example programs.
2. Top-level runtime entry point
- lumen.php is the main executable/bootstrap file.
- It likely wires together CLI handling and the interpreter pipeline so a .lumen source file can be executed from the command line.
3. CLI layer
- src/cli.php is the user-facing interface for running Lumen programs.
- This boundary is where command-line arguments, file selection, and execution mode are handled before control passes into the language pipeline.
4. Lexing: source text to tokens
- src/lexer.php converts raw Lumen source text into tokens.
- Token definitions and related structures live in src/structures/tokens.php.
- src/structures/cursor.php likely tracks position in the input stream for scanning and error reporting.
5. Parsing: tokens to program structure
- src/parser.php turns token streams into a structured syntax tree.
- Abstract syntax tree or node types are defined in src/structures/nodes.php.
- This is the main boundary where language syntax is interpreted into executable semantic structure.
6. Optimization pass
- src/optimizer.php sits between parsing and execution.
- Its role is likely to simplify or transform the AST before interpretation, improving runtime efficiency or normalizing constructs.
7. Execution engine
- src/interpreter.php is the core evaluator for Lumen programs.
- It consumes the parsed/optimized node structure and executes language semantics.
- This is the central runtime boundary where expressions, statements, variables, and function-like behavior are resolved.
8. Native/library surface
- src/nativelib/ contains built-in functionality exposed to Lumen code.
- The modules are split by domain:
- core.php for language/runtime primitives
- std.php for general standard utilities
- array.php for array operations
- math.php for numeric/math functions
- These files represent the bridge between interpreted Lumen code and PHP-hosted capabilities.
9. Diagnostics and error handling
- src/structures/diagnostic.php suggests structured error or warning reporting.
- Together with cursor/token/node structures, this indicates the language pipeline is designed to produce source-aware diagnostics rather than generic PHP errors.
10. Data flow through the system
- The main flow is:
- source .lumen file
- lexer
- tokens
- parser
- AST nodes
- optimizer
- interpreter
- native library calls when needed
- This is the key architecture to draw: a classical interpreter pipeline implemented in PHP.
11. Examples as language contracts
- The examples/ directory (hello.lumen, add.lumen, object.lumen, population.lumen, example.lumen) demonstrates language features and likely serves as a regression/usage set.
- These examples help define the supported surface area of the language: basic I/O, arithmetic, objects, and possibly data processing.
12. Repository shape and intended use
- The project is organized around a single-purpose language runtime rather than a general framework.
- The architecture is compact: one bootstrap, one CLI interface, one front-end compiler-like pipeline, one interpreter, and a small standard library layer.
- For an architecture diagram, the important boundaries are between CLI, language front end, optimization, execution, and native PHP-backed libraries.
Main entry points: interpreter.php Interpreter · lexer.php Lexer · parser.php Parser · cli.php CLI
Components 15
Runtime
Bootstrap, CLI, and execution pipeline
- lumen.php · Main executable that wires CLI handling to the language runtime
lumen.php - CLI · Command-line interface for selecting and running Lumen programs
src/cli.php - Interpreter · Executes optimized language nodes and resolves runtime semantics
src/interpreter.php
Front End
Source processing and program structure
- Lexer · Converts source text into tokens
src/lexer.php - Cursor · Tracks source position during scanning and diagnostics
src/structures/cursor.php - Tokens · Token definitions and token structures used by the lexer and parser
src/structures/tokens.php - Parser · Turns token streams into structured syntax trees
src/parser.php - AST Nodes · Abstract syntax tree node definitions for the language
src/structures/nodes.php - Optimizer · Simplifies or normalizes the parsed program before execution
src/optimizer.php - Diagnostics · Structured source-aware errors and warnings
src/structures/diagnostic.php
Native Libs
PHP-backed built-in functionality
Examples
Sample Lumen programs
- Examples · Representative Lumen programs demonstrating language features
examples/example.lumen
Connections 15
- lumen.php → CLI: launches · Bootstrap hands control to the CLI entry point
- CLI → Lexer: reads source · CLI provides source text for lexing
- Lexer → Cursor: tracks position · Lexer uses cursor state while scanning input
- Lexer → Tokens: emits · Source text is converted into tokens
- Lexer → Diagnostics: reports issues · Lexing problems are emitted as structured diagnostics
- Tokens → Parser: consumes · Parser consumes token streams
- Parser → AST Nodes: builds · Parser produces syntax tree nodes
- Parser → Diagnostics: reports issues · Parsing problems are emitted as structured diagnostics
- AST Nodes → Optimizer: transforms · Optimizer rewrites parsed nodes
- Optimizer → Interpreter: feeds · Optimized program structure is executed by the interpreter
- Interpreter → Core: uses · Interpreter relies on core runtime primitives
- Interpreter → Std: uses · Interpreter can call standard utilities
- Interpreter → Array: uses · Interpreter can call array helpers
- Interpreter → Math: uses · Interpreter can call math helpers
- Examples → CLI: run through · Example programs are executed via the CLI/runtime path