# gustavoeso/linguagem-programacao architecture

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

- Interactive diagram: https://gitdiagram.com/gustavoeso/linguagem-programacao
- Repository: https://github.com/gustavoeso/linguagem-programacao

## Overview

##### Main Components and Their Roles
- Lexical Analyzer:
- Two implementations: one built with Flex (lexer.l in Flex_Bison, generating lex.yy.c) and another in Python (lexer.py).
- This component as responsible for tokenizing the input source code.
- Syntactic Analyzer (Parser):
- Again two versions: a C implementation using Bison (parser.y leading to parser.tab.c and parser.tab.h) and a Python version (parser.py).
- That the parser uses the EBNF grammar provided in the README.
- Interpreter / Execution Engine:
- The Python files (interpreter.py, main.py, and prepro.py) serve as the runtime to execute commands defined in ProductivityLang (like task management commands, control structures, function definitions, etc.).
- Build Automation Component:
- The Makefile (located in Flex_Bison) is essential for automating Flex and Bison processing and compiling the final C executable (“productivitylang”).
- Testing and Validation:
- “tests” directories inside both “linguagem” (with test*.org files) and “linguagem/Flex_Bison/tests” (with input_file* samples). Show how these feed into the interpreters/analyzers to validate the language’s behavior.
- External/Supporting Artifacts:
- Configuration files like tasks.json and tasks_test.json are used for saving/loading task data in ProductivityLang.

##### Relationships and Data Flow
- Input (ProductivityLang source code) is fed into the Lexical Analyzer.
- The Lexical Analyzer outputs tokens that pass to the Parser.
- The Parser builds an Abstract Syntax Tree (AST) based on the EBNF and defined grammar rules.
- The Interpreter then evaluates this AST to perform operations (defining tasks, setting deadlines, etc.) and interacts with the underlying task data structures.
- The Makefile coordinates the build processes, ensuring that modifications in the lexical/syntax modules lead to automatic regeneration of the C components.
- Testing modules/interface: Test input files (from “tests” directories) are used to drive the interpreters and verify system behavior.

##### Architectural Patterns and Design Principles
- Layered Architecture:
- Clearly separate the “front end” (lexer and parser, regardless of implementation language) from the “execution” layer (interpreter).
- Dual Implementation Path:
- Use of Makefile for Build Automation:
- That the build system uses typical Unix build procedures, coordinating Flex, Bison, and GCC commands.
- Modularity:
- Each component (lexical analysis, syntax analysis, interpretation, testing, and build automation) is self-contained and interacts via well-defined interfaces (e.g., token definitions shared via types.h).

##### Relevant Technologies, Frameworks, and Libraries
- Flex and Bison for C-based lexical and syntactic analysis.
- GCC as the compiler for the generated C code.
- Python for a more dynamic, scripting-based interpreter approach.
- Standard build tools (Make) to automate the compilation process.

##### Detailing the Essential Architectural Elements
- Maintain a focus on how each component collaborates to enforce the language specifications outlined in the EBNF grammar and the example use cases provided in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    PS["ProductivityLang Source Code"]:::exstyle

    subgraph "C Implementation"
        C1["Flex-based Lexical Analyzer (C)"]:::cstyle
        C2["Bison-based Parser (C)"]:::cstyle
        C3["Generated Lexical Analyzer (lex.yy.c)"]:::cstyle
        C4a["Generated Parser Source (parser.tab.c)"]:::cstyle
        C4b["Generated Parser Header (parser.tab.h)"]:::cstyle
        C5["Shared Types Definition (types.h)"]:::cstyle
        C6["Build Automation (Makefile)"]:::cstyle
        C7["ProductivityLang Executable (C)"]:::cstyle
        C1 -->|"token stream"| C2
        C1 --> C3
        C2 --> C4a
        C2 --> C4b
        C3 --> C6
        C4a --> C6
        C4b --> C6
        C5 --> C6
        C6 --> C7
    end

    subgraph "Python Implementation"
        P1["Python Lexer"]:::pythonstyle
        P2["Python Parser"]:::pythonstyle
        P3["Interpreter Engine (Python)"]:::pythonstyle
        P4["Main Module (main.py)"]:::pythonstyle
        P5["Preprocessor (prepro.py)"]:::pythonstyle
        P6["ProductivityLang Interpreter Execution"]:::pythonstyle
        P1 -->|"token stream"| P2
        P2 --> P3
        P3 --> P4
        P4 --> P5
        P5 --> P6
    end

    CF1["Configuration File (tasks.json)"]:::exstyle
    CF2["Configuration File (tasks_test.json)"]:::exstyle
    E1["Syntactic Diagram (grammar)"]:::exstyle

    T1["C Test Suite"]:::teststyle
    T2["Python Test Suite"]:::teststyle

    %% Data Flow Connections
    PS --> C1
    PS --> P1
    CF1 --> P3
    CF2 --> P3
    E1 --> C2
    T1 --> C7
    T2 --> P6

    %% Click Events for C Implementation
    click C1 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/Flex_Bison/lexer.l"
    click C2 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/Flex_Bison/parser.y"
    click C3 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/Flex_Bison/lex.yy.c"
    click C4a "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/Flex_Bison/parser.tab.c"
    click C4b "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/Flex_Bison/parser.tab.h"
    click C5 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/Flex_Bison/types.h"
    click C6 "https://github.com/gustavoeso/linguagem-programacao/tree/main/linguagem/Flex_Bison/makefile"

    %% Click Events for Python Implementation
    click P1 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/lexer.py"
    click P2 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/parser.py"
    click P3 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/interpreter.py"
    click P4 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/main.py"
    click P5 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/prepro.py"

    %% Click Events for External Artifacts
    click E1 "https://github.com/gustavoeso/linguagem-programacao/blob/main/imgs/DS_organ_lang.png"
    click CF1 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/tasks.json"
    click CF2 "https://github.com/gustavoeso/linguagem-programacao/blob/main/linguagem/tasks_test.json"

    %% Styles
    classDef cstyle fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef pythonstyle fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef teststyle fill:#FFFF99,stroke:#B8860B,stroke-width:2px;
    classDef exstyle fill:#D3D3D3,stroke:#696969,stroke-width:2px;
```
