# abdoadel123/compiler architecture

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

- Interactive diagram: https://gitdiagram.com/abdoadel123/compiler
- Repository: https://github.com/abdoadel123/compiler

## Overview

##### Project Type Analysis
This is a compiler project implemented in Java, consisting of two distinct phases:
- Phase 1: Appears to be focused on lexical analysis (tokenization)
- Phase 2: Appears to be focused on parsing and syntax analysis

##### Main Components

A. Compiler Phase-1 Components:
- Tokenizer/Lexical Analyzer (represented by Token.java)
- Pattern Matcher (represented by Matched.java)
- Main Compiler Controller (Compiler.java)

B. Compiler Phase-2 Components:
- Abstract Syntax Tree (AST) components:
- Node-based structure (Node.java as base)
- Various node types (Expression.java, Statement.java, etc.)
- Parser components:
- Class declarations
- Method declarations
- Variable declarations
- Type system components
- Symbol table handlers

**[Phase 1: Lexical Analysis]**

- Input Stream
- Tokenizer
- Token Stream

- ▼
**[Phase 2: Syntax Analysis]**

- Parser
- AST Builder
- Symbol Table

##### Specific Elements

A. Phase 1 Section:
- Input file handler (input.txt)
- Token generator
- Pattern matcher
- Output generator (output.txt)

B. Phase 2 Section:
- Parser components:
- Class structure parser
- Method parser
- Expression parser
- AST node hierarchy
- Symbol table manager
- Multiple output handlers (output1.txt through output8.txt)

##### Important Relationships to Highlight

- Pipeline flow from input through Phase 1 to Phase 2
- Hierarchical relationship between different AST nodes
- Demonstrate the interaction between the parser and symbol table
- How the various declaration handlers (Class, Method, Variable) interact

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Phase 1: Lexical Analysis"
        Input["Input File"]:::io
        Compiler["Main Compiler Controller"]:::processor
        Token["Tokenizer"]:::processor
        Pattern["Pattern Matcher"]:::processor
        Output["Output File"]:::io
        
        Input --> Compiler
        Compiler --> Token
        Token --> Pattern
        Pattern --> Output
    end

    subgraph "Phase 2: Syntax Analysis"
        P2Controller["Phase 2 Controller"]:::processor
        
        subgraph "Parser Components"
            ClassParser["Class Declaration Parser"]:::parser
            MethodParser["Method Declaration Parser"]:::parser
            VarParser["Variable Declaration Parser"]:::parser
            MainClassParser["Main Class Handler"]:::parser
            FuncCallParser["Function Call Handler"]:::parser
        end
        
        subgraph "AST Components"
            BaseNode["AST Base Node"]:::ast
            Expression["Expression Handler"]:::ast
            Statement["Statement Handler"]:::ast
        end
        
        TypeSystem["Type System"]:::system
        
        Output --> P2Controller
        P2Controller --> ClassParser
        P2Controller --> MethodParser
        P2Controller --> VarParser
        P2Controller --> MainClassParser
        P2Controller --> FuncCallParser
        
        ClassParser --> BaseNode
        MethodParser --> BaseNode
        VarParser --> BaseNode
        MainClassParser --> BaseNode
        FuncCallParser --> BaseNode
        
        BaseNode --> Expression
        BaseNode --> Statement
        
        ClassParser --> TypeSystem
        MethodParser --> TypeSystem
        VarParser --> TypeSystem
    end

    %% Click events for component mapping
    click Input "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-1/input.txt"
    click Output "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-1/output.txt"
    click Compiler "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-1/src/compiler/Compiler.java"
    click Token "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-1/src/compiler/Token.java"
    click Pattern "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-1/src/compiler/Matched.java"
    click BaseNode "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/Node.java"
    click Expression "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/Expression.java"
    click Statement "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/Statement.java"
    click ClassParser "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/ClassDeclaration.java"
    click MethodParser "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/MethodDeclaration.java"
    click VarParser "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/VarDeclaration.java"
    click TypeSystem "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/Type.java"
    click MainClassParser "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/MainClass.java"
    click FuncCallParser "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/FunctionCall.java"
    click P2Controller "https://github.com/abdoadel123/Compiler/blob/master/Compiler Phase-2/src/compiler/phase/pkg2/CompilerPhase2.java"

    %% Styling
    classDef io fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef processor fill:#98fb98,stroke:#333,stroke-width:2px
    classDef parser fill:#ffb366,stroke:#333,stroke-width:2px
    classDef ast fill:#ff9999,stroke:#333,stroke-width:2px
    classDef system fill:#dda0dd,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["I/O Components"]:::io
        L2["Processors"]:::processor
        L3["Parsers"]:::parser
        L4["AST Components"]:::ast
        L5["System Components"]:::system
    end
```
