# miguelamato/compiladorpl architecture

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

- Interactive diagram: https://gitdiagram.com/miguelamato/compiladorpl
- Repository: https://github.com/miguelamato/compiladorpl

## Overview

##### Main Components
- Compiler Driver (DomJudge.java): Acts as the starting point that reads the input source code and coordinates the process.
- Lexical Analyzer: Implements token generation. Note that there are several versions (located under directories like “implementacion_cup”, “implementacion_jflex”, “implementacion_manual”, and “implementacion_semantica”). Each comes with its own lexer (e.g., AnalizadorLexico.java) and its specification (.jflex or corresponding Cup spec).
- Syntactic Analyzer: Handles parsing based on the input tokens. Again, multiple implementations exist (e.g., “AnalizadorSintacticoEval”, “AnalizadorSintacticoTiny”, “ASTS_A” and “ASTS_D” for ascendant and descendant parsing). These are generated by tools like JavaCC, CUP, or even manually.
- Semantic Analyzer / Processing: Found in directories like “implementacion_semantica” and “procesamiento” within “implementacion_final” that handle the semantic checking (e.g., ClaseSemanticaEval, Procesamiento, Tipado, Vinculacion).
- Error Management: Dedicated modules for error reporting and handling (for example, GestionErroresEval in various parts of the project).
- Test Cases and Input Files: Multiple directories such as “pruebas_tiny”, “pruebas_tiny_0”, and “casos_prueba_correctos”/“casos_errores” to simulate inputs to the overall compiler.

##### Relationships and Interactions
– The driver, DomJudge.java, first reads the input source code (often provided in input.txt files or test files from “pruebas_tiny”).
– It then passes the input to the Lexical Analyzer which, using the specifications from JFlex, Cup, or JavaCC, tokenizes the code.
– The tokens are then passed to the Syntactic Analyzer, which could be implemented as a parser generated by JavaCC (using spec.jj) or CUP (using spec.cup) or manually.
– Post parsing, control is transferred to semantic analysis and other processing modules responsible for type-checking, memory management (like GestorPilaActivaciones or GestorMemoriaDinamica), and code generation steps (if any).
– Error management components are invoked at various stages (both lexical and syntactic scanning) to log or output error files, as reflected in the “casos_errores” directories.

##### Architectural Patterns and Design Principles
– The project is structured into clearly separated phases (lexer, parser, semantic analyzer), reflecting a typical multi-stage compiler architecture.
– The use of separate directories for different implementations (Cup, JavaCC, JFlex, manual, semantic) suggests an experimental or modular approach – allowing interchangeable components based on technology.
– Both dependency injection (via the use of external jars like java-cup-11b-runtime.jar and javacc.jar) and layered design (input -> lexical analysis -> syntactic analysis -> semantic processing) are apparent.

##### Relevant Technologies, Frameworks, and Libraries
– Parser generators: JavaCC, CUP, and JFlex.
– External libraries: java-cup-11b-runtime.jar and javacc.jar for parser runtime support.
– Standard Java libraries (given the .java files and the project structure).

##### Elements
– Nodes for each major component (Driver, Lexical Analyzer, Syntactic Analyzer, Semantic Analyzer, Error Manager, and Test Cases).
- From “Input (Source Code)” ➔ “Driver (DomJudge.java)”
- From “Driver” ➔ “Lexical Analyzer”
- Then “Lexical Analyzer” ➔ “Syntactic Analyzer”
- Next “Syntactic Analyzer” ➔ “Semantic Analyzer/Processing”
- And feedback connections from “Error Manager” back to each stage.
– Use clear labels for alternate implementations (e.g., internal modules labeled “Cup-based”, “JavaCC-based”, “JFlex-based”, “Manual”).
– Include technology notes as annotations next to the components (e.g., “spec.jflex”, “spec.cup”, “spec.jj”).

##### Final Advice
– Don’t shy away from splitting the system into as many components as possible (each implementation variant should be visible).
– Emphasize the modular and interchangeable nature of the different analysis implementations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layer: Test Cases / Input
    TestFinal["Test Cases (Final)"]:::test
    TestTiny["Test Cases (Tiny)"]:::test
    SC["Source Code/Input"]:::input

    %% Layer: Compiler Driver
    Driver["Compiler Driver (DomJudge.java)"]:::driver

    %% Layer: Lexical Analysis
    subgraph "Lexical Analysis"
        LexCup["Cup Lexical Analyzer"]:::lexer
        LexJFlex["JFlex Lexical Analyzer"]:::lexer
        LexManual["Manual Lexical Analyzer"]:::lexer
    end

    %% Layer: Syntactic Analysis
    subgraph "Syntactic Analysis"
        SynCup["Cup Syntactic Analyzer"]:::sint
        SynJavacc["Javacc Syntactic Analyzer"]:::sint
        SynManual["Manual Syntactic Analyzer"]:::sint
    end

    %% Layer: Semantic Analysis
    subgraph "Semantic Analysis"
        SemFinal["Semantic Analyzer (Final)"]:::semantic
        SemSemantica["Semantic Analyzer (Semantica)"]:::semantic
    end

    %% Layer: Error Management
    subgraph "Error Management"
        ErrCup["Error Management (Cup)"]:::error
        ErrJFlex["Error Management (JFlex)"]:::error
        ErrManual["Error Management (Manual)"]:::error
    end

    %% Connections across layers
    TestFinal --> SC
    TestTiny --> SC
    SC --> Driver

    Driver --> LexCup
    Driver --> LexJFlex
    Driver --> LexManual

    LexCup --> SynCup
    LexJFlex --> SynJavacc
    LexManual --> SynManual

    SynCup --> SemFinal
    SynCup --> SemSemantica
    SynJavacc --> SemFinal
    SynJavacc --> SemSemantica
    SynManual --> SemFinal
    SynManual --> SemSemantica

    %% Dashed error feedback arrows from Lexical and Syntactic stages to Error Management (alternatives)
    LexCup ---|error| ErrCup
    SynCup ---|error| ErrCup

    LexJFlex ---|error| ErrJFlex
    SynJavacc ---|error| ErrJFlex

    LexManual ---|error| ErrManual
    SynManual ---|error| ErrManual

    %% Click Events for Compiler Driver
    click Driver "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_cup/src/DomJudge.java"
    click Driver "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_javacc/src/DomJudge.java"
    click Driver "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_jflex/src/DomJudge.java"
    click Driver "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_manual/src/DomJudge.java"
    click Driver "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_semantica/src/DomJudge.java"

    %% Click Events for Lexical Analyzers
    click LexCup "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_cup/src/alex/AnalizadorLexico.java"
    click LexCup "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_cup/src/alex/spec.jflex"
    click LexJFlex "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_jflex/src/model/lexico/AnalizadorLexico.java"
    click LexJFlex "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_jflex/src/model/lexico/spec.jflex"
    click LexManual "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_manual/src/model/lexico/AnalizadorLexico.java"

    %% Click Events for Syntactic Analyzers
    click SynCup "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_cup/src/asint/AnalizadorSintacticoEval.java"
    click SynCup "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_cup/src/asint/spec.cup"
    click SynJavacc "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_javacc/src/asint/AnalizadorSintacticoTiny.java"
    click SynJavacc "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_javacc/src/asint/spec.jj"
    click SynManual "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_manual/src/model/sintactico/AnalizadorSintacticoEval.java"

    %% Click Events for Semantic Analyzers
    click SemFinal "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_final/src/asint/ClaseSemanticaEval.java"
    click SemFinal "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_final/src/asint/Procesamiento.java"
    click SemFinal "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_final/src/asint/SintaxisAbstractaEval.java"
    click SemSemantica "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_semantica/src/asint/ClaseSemanticaEval.java"
    click SemSemantica "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_semantica/src/asint/Procesamiento.java"
    click SemSemantica "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_semantica/src/asint/SintaxisAbstractaEval.java"

    %% Click Events for Error Management
    click ErrCup "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_cup/src/errors/GestionErroresEval.java"
    click ErrJFlex "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_jflex/src/model/errors/GestionErroresEval.java"
    click ErrManual "https://github.com/miguelamato/compiladorpl/blob/main/implementacion_manual/src/model/error/GestionErroresEval.java"

    %% Click Events for Test Cases
    click TestFinal "https://github.com/miguelamato/compiladorpl/tree/main/implementacion_final/casos_prueba_correctos"
    click TestFinal "https://github.com/miguelamato/compiladorpl/tree/main/implementacion_final/casos_errores"
    click TestTiny "https://github.com/miguelamato/compiladorpl/tree/main/pruebas_tiny"
    click TestTiny "https://github.com/miguelamato/compiladorpl/tree/main/pruebas_tiny_0"

    %% Styles
    classDef input fill:#FFF3B0,stroke:#E2B714,stroke-width:2px;
    classDef driver fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef lexer fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef sint fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef semantic fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef error fill:#FFAB91,stroke:#D84315,stroke-width:2px;
    classDef test fill:#FFE0B2,stroke:#EF6C00,stroke-width:2px;
```
