# ai-r-ia/compiler architecture

> Architecture diagram of the GitHub repository ai-r-ia/compiler, 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/ai-r-ia/compiler
- Repository: https://github.com/ai-r-ia/compiler

## Overview

##### Main Components
- Input Module: Represent the “testcase” file(s) (e.g., testcase.txt) that is fed into the compiler.
- Driver/Main Module: Represented by driver.c, main.c, and possibly the “stage1exe” executable. This module handles command‐line arguments and orchestrates the flow.
- Lexer (Lexical Analysis): Capture files like lexer.c, lexer.h, lexical_token.c/h, and lexerDef.h. This component reads the source file and converts it into a stream of lexemes/tokens.
- Parser (Syntactic Analysis): Use parser.c, parser.h, parserDef.h, and supporting modules (grammar.txt, rules.c/h, rulesDef.h). This component takes the token stream from the lexer and builds the parse tree.
- Parse Tree Representation: Indicated by files such as parse_tree.txt and parseTreeOutFile.txt. This module represents the syntactic structure produced by the parser. Components like tree.c, tree.h, and treeDef.h support this.
- Utility Modules: Include additional support modules like strings, vectors (vectors.c/h, vectorDef.h), symbol table (symbol_table.c/h and symbol_tableDef.h), and utils. They play a role in managing memory, data structures, and additional computation.
- Testing & Debugging: The Test_Cases directory, as well as the “test” folder, indicate support for various test inputs and unit tests for discrete parts of the system (lexer, parser, etc.).

- Output of the Lexer to the Parser, indicating that the parser consumes tokens and builds the parse tree.
- From the Parser, show the production of the Parse Tree which is stored/output in files like parseTreeOutFile.txt.
- Interconnections from Utility Modules (such as the symbol_table and vector modules) to both the Lexer and Parser if they are used to manage dynamic data or support error handling.
- Link the Driver module to these core components to illustrate the overall control flow from input execution to output generation.
- Optionally, represent the Test modules as separate components that interact with the core components to validate their correctness.

##### Architectural Patterns and Design Principles
- Layered/Modular Architecture: Emphasize that the project is broken down into distinct components (lexer, parser, utilities, etc.), each in its own module with clear interfaces.
- Separation of Concerns: The design separates lexical analysis from parsing and from utility functions, resulting in improved maintainability.
- Testing as an Integral Part: The presence of separate testing directories reinforces that unit tests are a first-class citizen in the build process, ensuring each component’s correctness.
- Use of Header Files: Indicate that each major component is encapsulated with corresponding header files, enforcing module boundaries.

##### Relevant Technologies, Frameworks, and Artifacts
- Makefile: Include a “Build” or “Compilation” component that uses the Makefile, which drives the building of the entire compilation pipeline.
- Test Cases: Clearly detail the paths of the provided test cases and how they integrate into system testing.
- Documentation: Reference external documents like “Language specifications (1).pdf” and “coding details.pdf” as supporting artifacts shaping the design specs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    M("Makefile/Build System"):::build
    D("Driver/Main Module"):::driver
    I("Input Module (Testcase Files)"):::input
    L("Lexer (Lexical Analysis)"):::lexer
    P("Parser (Syntactic Analysis)"):::parser
    T("Parse Tree Representation"):::parsetree
    U("Utility Modules"):::utility
    X("Testing & Debugging Modules"):::testing

    M -->|"builds"| D
    D -->|"reads from"| I
    I -->|"feeds source code"| L
    L -->|"produces token stream"| P
    P -->|"generates parse tree"| T

    U -.->|"supports"| L
    U -.->|"supports"| P

    X -->|"validates"| L
    X -->|"validates"| P

    classDef input fill:#ffebcd,stroke:#daa520,stroke-width:2px
    classDef driver fill:#cce5ff,stroke:#004085,stroke-width:2px
    classDef lexer fill:#d4edda,stroke:#155724,stroke-width:2px
    classDef parser fill:#f8d7da,stroke:#721c24,stroke-width:2px
    classDef parsetree fill:#d1ecf1,stroke:#0c5460,stroke-width:2px
    classDef utility fill:#e2e3e5,stroke:#6c757d,stroke-width:2px
    classDef testing fill:#fdfd96,stroke:#ff8c00,stroke-width:2px
    classDef build fill:#f0e68c,stroke:#b8860b,stroke-width:2px

    click I "https://github.com/ai-r-ia/compiler/tree/main/Test_Cases"
    click D "https://github.com/ai-r-ia/compiler/blob/main/driver.c"
    click L "https://github.com/ai-r-ia/compiler/blob/main/lexer.c"
    click P "https://github.com/ai-r-ia/compiler/blob/main/parser.c"
    click T "https://github.com/ai-r-ia/compiler/blob/main/tree.c"
    click U "https://github.com/ai-r-ia/compiler/blob/main/vectors.c"
    click X "https://github.com/ai-r-ia/compiler/blob/main/test/test.c"
```
