# cristox1/pele architecture

> Architecture diagram of the GitHub repository cristox1/pele, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cristox1/pele
- Repository: https://github.com/cristox1/pele

## Overview

1. **What this repository is**
   - PELE is a programming language runtime, not an application framework.
   - Its architecture centers on a custom language front end plus a native standard library written in PELE itself for data science, machine learning, and deep learning workflows.

2. **Primary execution path**
   - A PELE source file is parsed by ANTLR-generated lexer/parser code.
   - The parse tree is evaluated by a Python-based visitor/interpreter.
   - Before user code runs, the interpreter injects the PELE native library prelude so language-level functions are available.

3. **Language front end**
   - `PELE.g4` is the source grammar and defines syntax and operator precedence.
   - `PELELexer.py`, `PELEParser.py`, `PELEListener.py`, `PELEVisitor.py`, plus the `.tokens` and `.interp` files are generated ANTLR artifacts.
   - This means the repository keeps both the grammar source and its generated parser runtime in version control.

4. **Interpreter boundary**
   - `pele.py` is the executable entry point that coordinates compilation/execution.
   - `visitorPELE.py` contains the AST/semantic evaluator logic.
   - The README emphasizes a strict boundary: Python is only the low-level VM/interpreter; domain logic is intentionally implemented in PELE, not Python libraries.

5. **Native standard library layer**
   - The `.pele` files form the language’s “stdlib” and are the core of the architecture.
   - These modules implement reusable capabilities in a functional style and are loaded by the interpreter in dependency order.

6. **Core utility modules**
   - `pele_math.pele` provides base math and activations such as power, exp, log, min/max, sigmoid, and ReLU.
   - `pele_random.pele` provides deterministic pseudo-random generation for reproducible experiments.
   - `pele_data.pele` handles preprocessing helpers such as normalization and z-score standardization.

7. **Data structure subsystem**
   - `pele_structs.pele` provides in-language immutable/pure data structures: stacks, queues, sets, trees, and graphs.
   - These structures support recursion-heavy operations such as traversals, BFS, and DFS.
   - This subsystem is foundational for the rest of the runtime because it avoids relying on Python containers for core language features.

8. **Numerical computation subsystem**
   - `pele_numpy.pele` and `pele_tensor.pele` define tensor/array abstractions and linear algebra operations.
   - The README highlights matrix transpose, addition, subtraction, dot/matrix multiplication, and shape handling.
   - This layer is the numerical backbone for ML and neural-network code.

9. **Data ingestion and feature engineering**
   - `pele_pandas.pele` is the ETL-like layer.
   - It includes CSV parsing, column selection/projection, null handling, and one-hot encoding.
   - In diagram terms, this is the bridge from raw text input to model-ready feature matrices.

10. **Machine learning and model layer**
   - `pele_ml.pele` contains classic algorithms such as perceptron, linear regression, KNN, and k-means.
   - `pele_nn.pele` handles neural-network primitives like layer initialization and forward propagation.
   - These modules consume data/tensors from the numerical and preprocessing layers and produce predictions or embeddings.

11. **Training objectives and evaluation**
   - `pele_losses.pele` provides loss functions such as BCE and MSE.
   - `pele_metrics.pele` provides accuracy, precision, recall, F1, confusion matrix, and R².
   - This creates a clear training/evaluation pipeline: model output -> loss/metrics -> reported results.

12. **Visualization output**
   - `pele_plot.pele` generates SVG output for learning curves and scatter plots.
   - The plotting layer is an output boundary: it converts computed results into a portable visual artifact rather than displaying through a GUI framework.

13. **Demonstration and validation assets**
   - `programa.txt` appears to be the integration/demo script or dashboard used to exercise the language end to end.
   - The sample `.pele` files (`pele_math.pele`, `pele_ml.pele`, `pele_pandas.pele`, etc.) act as modular tests/examples for each library area.

14. **Development/runtime tooling**
   - The repo is built around Python 3 and ANTLR4; Java is only relevant if the grammar is regenerated.
   - The checked-in `env/` directory is a local virtual environment, not part of the language architecture itself.
   - Architecturally, the important external dependency is the ANTLR Python runtime; the language features themselves are intended to live inside the PELE ecosystem.

Main entry points: [`pele_ml.pele`](https://github.com/cristox1/pele/blob/main/pele_ml.pele) (ML models), [`pele.py`](https://github.com/cristox1/pele/blob/main/pele.py) (pele.py), [`pele_pandas.pele`](https://github.com/cristox1/pele/blob/main/pele_pandas.pele) (Pandas layer), [`pele_nn.pele`](https://github.com/cristox1/pele/blob/main/pele_nn.pele) (Neural net)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front_end["Front end"]
  node_pele_g4["PELE.g4<br/>grammar<br/>[PELE.g4]"]
  node_lexer["Lexer<br/>[PELELexer.py]"]
  node_parser["Parser<br/>[PELEParser.py]"]
  node_visitor_iface["Visitor API<br/>generated ANTLR interfaces<br/>[PELEVisitor.py]"]
end

subgraph group_runtime["Runtime"]
  node_runtime_entry["pele.py<br/>execution entrypoint<br/>[pele.py]"]
  node_visitor_impl["visitorPELE.py<br/>interpreter/evaluator<br/>[visitorPELE.py]"]
  node_prelude_load(("Prelude load<br/>stdlib injection"))
end

subgraph group_stdlib["PELE stdlib"]
  node_core_math["Math core<br/>numerical primitives<br/>[pele_math.pele]"]
  node_core_random["Random core<br/>deterministic RNG<br/>[pele_random.pele]"]
  node_core_data["Data core<br/>preprocessing helpers<br/>[pele_data.pele]"]
  node_structs["Structs<br/>in-language data structures<br/>[pele_structs.pele]"]
  node_tensor["Tensor math<br/>array/tensor algebra<br/>[pele_tensor.pele]"]
  node_numpy_mod["NumPy layer<br/>numeric arrays<br/>[pele_numpy.pele]"]
  node_pandas_mod["Pandas layer<br/>ETL/feature prep<br/>[pele_pandas.pele]"]
  node_ml_mod["ML models<br/>classic ML<br/>[pele_ml.pele]"]
  node_nn_mod["Neural net<br/>NN primitives<br/>[pele_nn.pele]"]
  node_losses["Losses<br/>training objectives<br/>[pele_losses.pele]"]
  node_metrics["Metrics<br/>[pele_metrics.pele]"]
  node_plot["Plotting<br/>SVG output<br/>[pele_plot.pele]"]
end

subgraph group_examples["Examples"]
  node_programa["Demo script<br/>integration program<br/>[programa.txt]"]
  node_readme["README<br/>project guide<br/>[README.md]"]
end

subgraph group_tooling["Tooling"]
  node_antlr4["ANTLR4<br/>external parser runtime"]
  node_python["Python VM<br/>host runtime"]
end

node_pele_g4 -->|"generates"| node_lexer
node_pele_g4 -->|"generates"| node_parser
node_pele_g4 -->|"generates"| node_visitor_iface
node_antlr4 -->|"supports"| node_lexer
node_antlr4 -->|"supports"| node_parser
node_runtime_entry -->|"uses"| node_lexer
node_runtime_entry -->|"uses"| node_parser
node_runtime_entry -->|"dispatches to"| node_visitor_impl
node_visitor_impl -->|"initializes"| node_prelude_load
node_prelude_load -->|"loads"| node_structs
node_prelude_load -->|"loads"| node_core_math
node_prelude_load -->|"loads"| node_core_random
node_prelude_load -->|"loads"| node_core_data
node_prelude_load -->|"loads"| node_numpy_mod
node_prelude_load -->|"loads"| node_tensor
node_prelude_load -->|"loads"| node_pandas_mod
node_prelude_load -->|"loads"| node_ml_mod
node_prelude_load -->|"loads"| node_nn_mod
node_prelude_load -->|"loads"| node_losses
node_prelude_load -->|"loads"| node_metrics
node_prelude_load -->|"loads"| node_plot
node_core_math -->|"feeds"| node_nn_mod
node_core_math -->|"feeds"| node_losses
node_core_random -->|"feeds"| node_ml_mod
node_core_data -->|"feeds"| node_pandas_mod
node_structs -->|"supports"| node_ml_mod
node_structs -->|"supports"| node_pandas_mod
node_numpy_mod -->|"builds on"| node_tensor
node_pandas_mod -->|"produces"| node_numpy_mod
node_pandas_mod -->|"feeds"| node_ml_mod
node_tensor -->|"feeds"| node_nn_mod
node_tensor -->|"feeds"| node_ml_mod
node_ml_mod -->|"optimizes with"| node_losses
node_nn_mod -->|"optimizes with"| node_losses
node_ml_mod -->|"reports to"| node_metrics
node_nn_mod -->|"reports to"| node_metrics
node_metrics -->|"visualized by"| node_plot
node_programa -->|"drives"| node_runtime_entry
node_readme -->|"documents"| node_runtime_entry
node_readme -->|"documents"| node_prelude_load

click node_pele_g4 "https://github.com/cristox1/pele/blob/main/PELE.g4"
click node_lexer "https://github.com/cristox1/pele/blob/main/PELELexer.py"
click node_parser "https://github.com/cristox1/pele/blob/main/PELEParser.py"
click node_visitor_iface "https://github.com/cristox1/pele/blob/main/PELEVisitor.py"
click node_runtime_entry "https://github.com/cristox1/pele/blob/main/pele.py"
click node_visitor_impl "https://github.com/cristox1/pele/blob/main/visitorPELE.py"
click node_core_math "https://github.com/cristox1/pele/blob/main/pele_math.pele"
click node_core_random "https://github.com/cristox1/pele/blob/main/pele_random.pele"
click node_core_data "https://github.com/cristox1/pele/blob/main/pele_data.pele"
click node_structs "https://github.com/cristox1/pele/blob/main/pele_structs.pele"
click node_tensor "https://github.com/cristox1/pele/blob/main/pele_tensor.pele"
click node_numpy_mod "https://github.com/cristox1/pele/blob/main/pele_numpy.pele"
click node_pandas_mod "https://github.com/cristox1/pele/blob/main/pele_pandas.pele"
click node_ml_mod "https://github.com/cristox1/pele/blob/main/pele_ml.pele"
click node_nn_mod "https://github.com/cristox1/pele/blob/main/pele_nn.pele"
click node_losses "https://github.com/cristox1/pele/blob/main/pele_losses.pele"
click node_metrics "https://github.com/cristox1/pele/blob/main/pele_metrics.pele"
click node_plot "https://github.com/cristox1/pele/blob/main/pele_plot.pele"
click node_programa "https://github.com/cristox1/pele/blob/main/programa.txt"
click node_readme "https://github.com/cristox1/pele/blob/main/README.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pele_g4,node_lexer,node_parser,node_visitor_iface toneBlue
class node_runtime_entry,node_visitor_impl,node_prelude_load toneAmber
class node_core_math,node_core_random,node_core_data,node_structs,node_tensor,node_numpy_mod,node_pandas_mod,node_ml_mod,node_nn_mod,node_losses,node_metrics,node_plot toneMint
class node_programa,node_readme toneRose
class node_antlr4,node_python toneIndigo
```

## Components

### Front end

Grammar and generated ANTLR parser artifacts

- [PELE.g4](https://github.com/cristox1/pele/blob/main/PELE.g4): grammar · Source grammar defining PELE syntax and precedence · `PELE.g4`
- [Lexer](https://github.com/cristox1/pele/blob/main/PELELexer.py): generated ANTLR lexer · Tokenizes PELE source · `PELELexer.py`
- [Parser](https://github.com/cristox1/pele/blob/main/PELEParser.py): generated ANTLR parser · Builds parse trees for PELE programs · `PELEParser.py`
- [Visitor API](https://github.com/cristox1/pele/blob/main/PELEVisitor.py): generated ANTLR interfaces · Parse-tree listener and visitor interfaces · `PELEVisitor.py`

### Runtime

Python entrypoint and interpreter boundary

- [pele.py](https://github.com/cristox1/pele/blob/main/pele.py): execution entrypoint · Starts compilation and execution of PELE programs · `pele.py`
- [visitorPELE.py](https://github.com/cristox1/pele/blob/main/visitorPELE.py): interpreter/evaluator · Evaluates parse trees and drives semantic execution · `visitorPELE.py`
- **Prelude load**: stdlib injection · Injects the PELE native library before user code runs

### PELE stdlib

Native language modules loaded by the runtime

- [Math core](https://github.com/cristox1/pele/blob/main/pele_math.pele): numerical primitives · Base math, activations, and scalar utilities · `pele_math.pele`
- [Random core](https://github.com/cristox1/pele/blob/main/pele_random.pele): deterministic RNG · Pseudo-random generation for reproducible experiments · `pele_random.pele`
- [Data core](https://github.com/cristox1/pele/blob/main/pele_data.pele): preprocessing helpers · Normalization and z-score style helpers · `pele_data.pele`
- [Structs](https://github.com/cristox1/pele/blob/main/pele_structs.pele): in-language data structures · Immutable stacks, queues, sets, trees, and graphs · `pele_structs.pele`
- [Tensor math](https://github.com/cristox1/pele/blob/main/pele_tensor.pele): array/tensor algebra · Array abstractions and linear algebra operations · `pele_tensor.pele`
- [NumPy layer](https://github.com/cristox1/pele/blob/main/pele_numpy.pele): numeric arrays · Matrix and tensor operations built for computation workflows · `pele_numpy.pele`
- [Pandas layer](https://github.com/cristox1/pele/blob/main/pele_pandas.pele): ETL/feature prep · CSV parsing, selection, null handling, and one-hot encoding · `pele_pandas.pele`
- [ML models](https://github.com/cristox1/pele/blob/main/pele_ml.pele): classic ML · Perceptron, linear regression, KNN, and k-means · `pele_ml.pele`
- [Neural net](https://github.com/cristox1/pele/blob/main/pele_nn.pele): NN primitives · Layer setup and forward propagation · `pele_nn.pele`
- [Losses](https://github.com/cristox1/pele/blob/main/pele_losses.pele): training objectives · BCE and MSE loss functions · `pele_losses.pele`
- [Metrics](https://github.com/cristox1/pele/blob/main/pele_metrics.pele): evaluation metrics · Accuracy, precision, recall, F1, confusion matrix, and R² · `pele_metrics.pele`
- [Plotting](https://github.com/cristox1/pele/blob/main/pele_plot.pele): SVG output · Generates SVG charts for curves and scatter plots · `pele_plot.pele`

### Examples

Demo and integration scripts

- [Demo script](https://github.com/cristox1/pele/blob/main/programa.txt): integration program · End-to-end exercise of the language and libraries · `programa.txt`
- [README](https://github.com/cristox1/pele/blob/main/README.md): project guide · Architecture and usage overview · `README.md`

### Tooling

External runtime and environment support

- **ANTLR4**: external parser runtime · Python runtime support for generated grammar artifacts
- **Python VM**: host runtime · Executes the interpreter and generated parser code

## Connections

- PELE.g4 → Lexer: generates · ANTLR grammar source generates lexer code
- PELE.g4 → Parser: generates · ANTLR grammar source generates parser code
- PELE.g4 → Visitor API: generates · ANTLR grammar source generates visitor/listener interfaces
- ANTLR4 → Lexer: supports · ANTLR Python runtime executes generated lexer
- ANTLR4 → Parser: supports · ANTLR Python runtime executes generated parser
- pele.py → Lexer: uses · Entry point starts tokenization
- pele.py → Parser: uses · Entry point builds parse trees
- pele.py → visitorPELE.py: dispatches to · Entrypoint hands parsed programs to the evaluator
- visitorPELE.py → Prelude load: initializes · Interpreter loads native prelude before user code
- Prelude load → Structs: loads · Native library dependencies are loaded in order
- Prelude load → Math core: loads · Native library dependencies are loaded in order
- Prelude load → Random core: loads · Native library dependencies are loaded in order
- Prelude load → Data core: loads · Native library dependencies are loaded in order
- Prelude load → NumPy layer: loads · Native library dependencies are loaded in order
- Prelude load → Tensor math: loads · Native library dependencies are loaded in order
- Prelude load → Pandas layer: loads · Native library dependencies are loaded in order
- Prelude load → ML models: loads · Native library dependencies are loaded in order
- Prelude load → Neural net: loads · Native library dependencies are loaded in order
- Prelude load → Losses: loads · Native library dependencies are loaded in order
- Prelude load → Metrics: loads · Native library dependencies are loaded in order
- Prelude load → Plotting: loads · Native library dependencies are loaded in order
- Math core → Neural net: feeds · Math primitives support neural-network operations
- Math core → Losses: feeds · Math primitives support objective calculations
- Random core → ML models: feeds · Deterministic randomness supports ML algorithms
- Data core → Pandas layer: feeds · Preprocessing helpers underpin data ingestion
- Structs → ML models: supports · Language data structures support algorithmic routines
- Structs → Pandas layer: supports · Core structures support parsing and transformation workflows
- NumPy layer → Tensor math: builds on · Tensor layer extends array math
- Pandas layer → NumPy layer: produces · Feature engineering outputs numeric matrices
- Pandas layer → ML models: feeds · Prepared data flows into model training
- Tensor math → Neural net: feeds · Tensor abstractions feed neural-network primitives
- Tensor math → ML models: feeds · Tensor operations support classic ML workflows
- ML models → Losses: optimizes with · Model outputs are evaluated by loss functions
- Neural net → Losses: optimizes with · Neural outputs are evaluated by loss functions
- ML models → Metrics: reports to · Predictions are summarized by evaluation metrics
- Neural net → Metrics: reports to · Predictions are summarized by evaluation metrics
- Metrics → Plotting: visualized by · Evaluation results can be turned into SVG plots
- Demo script → pele.py: drives · Demo script exercises the runtime end to end
- README → pele.py: documents · Project guide describes execution path
- README → Prelude load: documents · Project guide describes stdlib injection boundary
