# kafmws/fakeyacc architecture

> Architecture diagram of the GitHub repository kafmws/fakeyacc, 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/kafmws/fakeyacc
- Repository: https://github.com/kafmws/fakeyacc

## Overview

##### Project Type and Purpose
- This is a parser generator tool (a simplified or “fake” version of Yacc) that takes grammar definitions for different languages (ANSIC and Lua5.3) and processes them to compute parsing tables, FIRST/FOLLOW sets, production rules, and similar artifacts.
- The README’s title (“FakeYacc”) confirms that this project centers on generating parser components from language grammars.

##### File Structure
- Top-level files such as Candidate.java, FakeYACC.java, NonTerminal.java, Terminal.java, and Symbol.java indicate core logic and data structure definitions to support grammar parsing.
- Directories “ANSIC” and “Lua5.3” show that the project supports at least two grammatical domains. Each of these directories contains subdirectories (like “grammar”, “out”, “terminalSet”, “verification”) which suggest separation between source definitions, computed artifacts, and verification modules.
- A “pre” folder under Lua5.3, which may represent a pre-processing phase unique to that language.

##### Main Components of the System
- Driver/Core Module: Represented by FakeYACC.java; the main entry point that orchestrates the parsing generation process.
- Grammar Input Modules: For both ANSIC and Lua5.3, use “grammar” folders as the sources of grammar definitions.
- Language-specific Processors: Separate modules (or pipelines) that process the grammar for each language. This may include:
- Computation of Bison-style BNF representations (BisonBNF directory)
- Calculation of FIRST and FOLLOW sets
- Generation of parsing tables and production rules.
- Data Structure Components: Classes like NonTerminal.java, Terminal.java, and Symbol.java; these support representing grammar symbols and productions.
- Pre-processing and Verification Modules: The “pre” directory for Lua5.3 and “verification” directories in both language modules suggest an initial pre-processing phase and a validation phase respectively.
- Output Modules: The “out” directories (and their subdivisions) store results such as parsing tables, computed sets (FIRST, FOLLOW), production rules, and terminal sets.

##### Relationships and Interactions Between Components
- A user or external system provides grammar definitions (input) through the “grammar” directories.
- The FakeYACC core module reads these grammar inputs and then routes them through a processing pipeline which is split into several stages:
- The first stage parses the grammar, generating intermediate representations (BisonBNF, production rules, etc.).
- Next, the system computes necessary sets (FIRST, FOLLOW) and builds data structures using the NonTerminal, Terminal, and Symbol classes.
- Any pre-processing (for Lua5.3) and verification steps are applied to ensure correctness.
- Finally, the system outputs artifacts (parsing tables, production rules, etc.) into the “out” directories.

##### Architectural Patterns and Design Principles
- Modularity: Separate directories and modules for each language grammar signify modular design.
- Pipeline/Layered Architecture: The separate stages—input, processing (computation of FIRST/FOLLOW, parsing table generation), data structure manipulation, verification, and output generation—are best represented as sequential layers or connected modules.
- Separation of Concerns: Clearly isolate language-specific processes (ANSIC vs. Lua5.3) while using common core components.

##### Relevant Technologies and Libraries
- While the file tree does not show external frameworks, note that the project is Java-based. Emphasize that the system uses object-oriented design principles evident from the .java files.
- If the tool generates artifacts for parser generation (similar to Yacc), any conventions or libraries borrowed from classical compiler construction techniques should be noted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        A1["ANSIC Grammar Input"]:::input
        L1["Lua5.3 Grammar Input"]:::input
    end

    %% Core and Data Structures
    subgraph "Core & Data Structures"
        F["FakeYACC Core Orchestrator"]:::core
        subgraph "Data Structures"
            D1["NonTerminal"]:::data
            D2["Terminal"]:::data
            D3["Symbol"]:::data
            D4["Candidate"]:::data
        end
    end

    %% ANSIC Processing Pipeline
    subgraph "ANSIC Processing Pipeline"
        B1["BisonBNF Parsing"]:::process
        P1["Production Rules"]:::process
        FST1["FIRST Set Computation"]:::process
        FOL1["FOLLOW Set Computation"]:::process
        PT1["Parsing Table Generation"]:::process
        N1["NonTerminal Processing"]:::process
        T1["Terminal Set Output"]:::process
        TS1["Terminal Set Resource"]:::resource
        V1["Verification"]:::verification
    end

    %% Lua5.3 Processing Pipeline
    subgraph "Lua5.3 Processing Pipeline"
        PP["Pre-Processing"]:::preprocess
        B2["BisonBNF Parsing"]:::process
        P2["Production Rules"]:::process
        FST2["FIRST Set Computation"]:::process
        FOL2["FOLLOW Set Computation"]:::process
        PT2["Parsing Table Generation"]:::process
        N2["NonTerminal Processing"]:::process
        T2["Terminal Set Output"]:::process
        TS2["Terminal Set Resource"]:::resource
        V2["Verification"]:::verification
    end

    %% Connections from Input to Core
    A1 -->|"provides grammar"| F
    L1 -->|"provides grammar"| F

    %% Core to Data Structures linkage (dashed to denote support)
    F --- D1
    F --- D2
    F --- D3
    F --- D4

    %% Core initiating ANSIC Pipeline
    F -->|"processes ANSIC"| B1
    B1 --> P1
    P1 --> FST1
    FST1 --> FOL1
    FOL1 --> PT1
    PT1 --> N1
    N1 --> T1
    T1 --> TS1
    TS1 --> V1

    %% Core initiating Lua5.3 Pipeline
    F -->|"processes Lua5.3"| PP
    PP --> B2
    B2 --> P2
    P2 --> FST2
    FST2 --> FOL2
    FOL2 --> PT2
    PT2 --> N2
    N2 --> T2
    T2 --> TS2
    TS2 --> V2

    %% Styling Classes
    classDef input fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef core fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef data fill:#AED6F1,stroke:#2874A6,stroke-width:2px;
    classDef process fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef verification fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef preprocess fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef resource fill:#D1F2EB,stroke:#16A085,stroke-width:2px;

    %% Click Events for Core and Data Structures
    click F "https://github.com/kafmws/fakeyacc/blob/master/FakeYACC.java"
    click D1 "https://github.com/kafmws/fakeyacc/blob/master/NonTerminal.java"
    click D2 "https://github.com/kafmws/fakeyacc/blob/master/Terminal.java"
    click D3 "https://github.com/kafmws/fakeyacc/blob/master/Symbol.java"
    click D4 "https://github.com/kafmws/fakeyacc/blob/master/Candidate.java"

    %% Click Events for Input Components
    click A1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/grammar"
    click L1 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/grammar"

    %% Click Events for ANSIC Processing Outputs
    click B1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/out/BisonBNF"
    click P1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/out/production"
    click FST1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/out/FIRST"
    click FOL1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/out/FOLLOW"
    click PT1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/out/parsingTable"
    click N1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/out/NonTerminal"
    click T1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/out/terminal"
    click TS1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/terminalSet"
    click V1 "https://github.com/kafmws/fakeyacc/tree/master/ANSIC/verification"

    %% Click Events for Lua5.3 Processing Outputs
    click PP "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/pre"
    click B2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/out/BisonBNF"
    click P2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/out/production"
    click FST2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/out/FIRST"
    click FOL2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/out/FOLLOW"
    click PT2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/out/parsingTable"
    click N2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/out/NonTerminal"
    click T2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/out/terminal"
    click TS2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/terminalSet"
    click V2 "https://github.com/kafmws/fakeyacc/tree/master/Lua5.3/verification"
```
