# sebastianzapatar/compi architecture

> Architecture diagram of the GitHub repository sebastianzapatar/compi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sebastianzapatar/compi
- Repository: https://github.com/sebastianzapatar/compi

## Overview

##### Main Components
- Main Entry Point:
- main.py – Initializes the system and likely starts the REPL or main loop.
- Language Core (located under the "lenguaje" directory):
- lexer.py – Contains the lexical analyzer (tokenizer) that reads input strings and produces tokens.
- token.py – Defines the token types and possibly token attributes used by the lexer.
- parser.py – Implements the parser which converts the stream of tokens into a syntactic structure.
- ast.py – Constructs and manages the Abstract Syntax Tree (AST) that represents the parsed program.
- object.py – Likely contains definitions for runtime objects and possibly mechanisms for evaluation.
- repl.py – Provides an interactive Read-Eval-Print Loop interface for the language.
- __init__.py – Initializes the module for easier imports.

##### Relationships and Data Flow
- The program starts in main.py, which probably sets up the system environment and invokes the REPL.
- The REPL (repl.py) receives user input and passes it to the lexer (lexer.py), which produces a series of tokens (using definitions from token.py).
- Tokens are then fed into the parser (parser.py) to build an AST (constructed via ast.py).
- The AST is either evaluated directly—using mechanisms in object.py—or further processed.
- There might be feedback from the evaluation to the REPL for displaying results.

##### Architectural Patterns and Design Principles
- Modularization: The project is broken down into distinct components (lexer, parser, REPL, etc.) to separate concerns.
- Pipeline Structure: Data flows sequentially—source code input → lexing → parsing → AST creation → evaluation.
- Interpreter Pattern: The design suggests interpreting the language as input is processed (especially given the presence of a REPL).
- Clear separation between language definition parts (lexer, parser, ast) and the execution environment (repl, object handling).

##### Relevant Technologies or Libraries
- Standard Python modules and conventions since the project is implemented in Python.
- Although there’s no explicit listing of external libraries, note that Python’s dynamic and interpreted nature is a design choice here.

##### Instructing the Software Engineer
- Use callouts or annotations where necessary to explain that the REPL is the interactive component bridging user input and the language engine.
- Separation between the system’s core language processing components and the external interface (REPL/main.py).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Main["Main Entry Point (main.py)"]:::external

    subgraph "Language Core"
        I["Module Init (__init__.py)"]:::core
        R["REPL (repl.py)"]:::core
        L["Lexer (lexer.py)"]:::core
        T["Token Definitions (token.py)"]:::core
        P["Parser (parser.py)"]:::core
        A["AST Builder (ast.py)"]:::core
        O["Object Evaluator (object.py)"]:::core
    end

    Main -->|"initiates"| R
    I -.->|"initializes"| R
    R -->|"sendsInput"| L
    L -.->|"usesTokens"| T
    L -->|"generatesTokens"| P
    P -.->|"usesTokens"| T
    P -->|"buildsAST"| A
    A -->|"evaluates"| O
    O -->|"returnsResult"| R

    classDef external fill:#ffdead,stroke:#cd853f,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#3399ff,stroke-width:2px;

    click Main "https://github.com/sebastianzapatar/compi/blob/main/main.py"
    click I "https://github.com/sebastianzapatar/compi/blob/main/lenguaje/__init__.py"
    click R "https://github.com/sebastianzapatar/compi/blob/main/lenguaje/repl.py"
    click L "https://github.com/sebastianzapatar/compi/blob/main/lenguaje/lexer.py"
    click T "https://github.com/sebastianzapatar/compi/blob/main/lenguaje/token.py"
    click P "https://github.com/sebastianzapatar/compi/blob/main/lenguaje/parser.py"
    click A "https://github.com/sebastianzapatar/compi/blob/main/lenguaje/ast.py"
    click O "https://github.com/sebastianzapatar/compi/blob/main/lenguaje/object.py"
```
