# kartik-balaji/compiler-design-lab-kartik architecture

> Architecture diagram of the GitHub repository kartik-balaji/compiler-design-lab-kartik, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kartik-balaji/compiler-design-lab-kartik
- Repository: https://github.com/kartik-balaji/compiler-design-lab-kartik

## Overview

##### Project type & purpose (from file tree + README)
This repository is not a “system” in the web/service sense; it’s a **set of standalone C programs** (Experiment1.c … Experiment8.c) for a **Compiler Design Lab**. Each file is likely an independent “experiment” implementing one compiler-construction concept (e.g., lexical analysis, parsing, FIRST/FOLLOW, symbol tables, intermediate code, etc.). The README provides only the title, so the **actual architecture must be inferred by inspecting each Experiment*.c**.

##### How to analyze the file structure (what matters here)
Top level:
- `Experiment1.c … Experiment8.c`: likely **independent executables** (each compiled separately).
- `README.md`: minimal documentation.

There are **no obvious shared modules** (no `src/`, `include/`, `lib/`, `tests/`). That implies:
- No shared build system in-repo (no Makefile/CMake); compilation is likely manual: `gcc ExperimentX.c -o expX`.
- Each experiment probably contains its own `main()` and internal helper functions.

##### Concept-level: how each experiment maps onto a typical compiler pipeline stage.

Before drawing, open each `ExperimentN.c` and capture:
- **Inputs**: stdin vs file input (`fopen`, command-line args), grammar files, token lists, etc.
- **Core functions**: e.g., `lexer()`, `parse()`, `computeFirst()`, `computeFollow()`, `reduce()`, `generateICG()`.
- **Data structures**: token struct, parse stack, symbol table (hash table/array), parse table (2D array), AST nodes.
- **Outputs**: printed tokens, parse result, parse tree, intermediate code, errors.
- **External dependencies**: typically just C standard library (`stdio.h`, `ctype.h`, `string.h`), unless something special appears.

##### Repository / Execution-Level Architecture (high level)
Purpose: show how the repo is used and what runs.

Recommended components:
- **Developer/Student**
- **Compiler toolchain** (GCC/Clang) used to compile each `.c`
- **8 independent executables** (one per experiment)
- **Input source** (stdin / input file)
- **Console output / result artifacts** (stdout; maybe generated files if any)

Relationships:
- Developer compiles each `ExperimentN.c` with GCC → produces `expN` binary
- User runs `expN` → consumes input → produces output

Purpose: show how the experiments relate to a canonical compiler pipeline even if implemented separately.

A canonical compiler pipeline:
- Source Program
→ **Lexical Analysis**
→ **Syntax Analysis (Parsing)**
→ **Semantic Analysis**
→ **Intermediate Representation (IR) / ICG**
→ **Optimization** (maybe absent)
→ **Code Generation**
→ Target Code

- “Experiment1 → Lexical Analyzer” (if true)
- “Experiment2 → FIRST/FOLLOW / parsing utilities” (if true)
- …
- Tokens
- Parse tree / AST
- Symbol table
- IR (three-address code)
- Errors/warnings

- **Input** (file/stdin)
- **Main** (`main()`)
- Major internal modules (functions grouped by responsibility)
- Core data structures
- Output

- `main()`
→ `readInput()` (or direct file read)
→ `tokenize()` / `scan()` (if lexer)
→ `processTokens()` / `parse()` / `buildTable()` etc.
→ `printResult()` / `writeOutputFile()`

This is where you “separate the project into as many components as possible” without inventing non-existent folders/services.

Because these are single-process C programs, the interactions are mostly:
- **Function call flow** (main → subsystems)
- **Data flow** (input buffer → tokens array → parse stack → output)
- **Stateful structures** (symbol table updated during scan/parse)

- “reads” (file → buffer)
- “produces” (lexer → token stream)
- “consumes” (parser consumes token stream)
- “updates” (semantic analyzer updates symbol table)
- “emits” (ICG emits TAC)

Even in simple C labs, common patterns appear:

- **Pipeline / staged processing** (scan → parse → generate)
- **Table-driven logic** (parse tables, FIRST/FOLLOW sets)
- “Grammar/Table” as a data component feeding the parser.
- **State machine** (lexer DFA-like logic)
- “Lexer (FSM)” with input chars flowing through.

Only include these if the code reflects them (e.g., explicit tables, stacks, FSM transitions).

##### Technologies/frameworks/libraries to mention explicitly
From the repo, it’s almost certainly:
- **C language**
- **Standard C library** headers
- **GCC/Clang** (external compiler used to build the experiments)
- OS shell/terminal for execution

If any experiment uses:
- file I/O (`fopen`, `fprintf`) → add “Input file” / “Output file” nodes
- regex/lex/yacc tools (unlikely given plain `.c`) → add those tools if present

##### Key point for this repo
- treat each `ExperimentN.c` as a separately runnable component
- A conceptual pipeline to show how the lab exercises relate

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Repository / Execution-Level (Build & Run)
  %% =========================
  subgraph "Repository: Compiler Design Lab (Standalone C Experiments)"
    Readme["README (project title/usage)"]:::doc

    subgraph "Source Programs (.c)"
      E1["Experiment1.c (standalone program source)"]:::source
      E2["Experiment2.c (standalone program source)"]:::source
      E3["Experiment3.c (standalone program source)"]:::source
      E4["Experiment4.c (standalone program source)"]:::source
      E5["Experiment5.c (standalone program source)"]:::source
      E6["Experiment6.c (standalone program source)"]:::source
      E7["Experiment7.c (standalone program source)"]:::source
      E8["Experiment8.c (standalone program source)"]:::source
    end
  end

  Student["Student / Developer"]:::actor
  Shell["Terminal / Shell"]:::external
  GCC["C Compiler Toolchain (GCC/Clang)"]:::tool

  In["Input (stdin / input file)"]:::io
  Out["Output (stdout / result artifacts)"]:::io

  Bin1(["exp1 (compiled executable)"]):::exe
  Bin2(["exp2 (compiled executable)"]):::exe
  Bin3(["exp3 (compiled executable)"]):::exe
  Bin4(["exp4 (compiled executable)"]):::exe
  Bin5(["exp5 (compiled executable)"]):::exe
  Bin6(["exp6 (compiled executable)"]):::exe
  Bin7(["exp7 (compiled executable)"]):::exe
  Bin8(["exp8 (compiled executable)"]):::exe

  Student -->|"reads"| Readme
  Student -->|"uses"| Shell
  Shell -->|"invokes"| GCC

  GCC -->|"compiles"| E1 -->|"produces"| Bin1
  GCC -->|"compiles"| E2 -->|"produces"| Bin2
  GCC -->|"compiles"| E3 -->|"produces"| Bin3
  GCC -->|"compiles"| E4 -->|"produces"| Bin4
  GCC -->|"compiles"| E5 -->|"produces"| Bin5
  GCC -->|"compiles"| E6 -->|"produces"| Bin6
  GCC -->|"compiles"| E7 -->|"produces"| Bin7
  GCC -->|"compiles"| E8 -->|"produces"| Bin8

  Shell -->|"runs"| Bin1
  Shell -->|"runs"| Bin2
  Shell -->|"runs"| Bin3
  Shell -->|"runs"| Bin4
  Shell -->|"runs"| Bin5
  Shell -->|"runs"| Bin6
  Shell -->|"runs"| Bin7
  Shell -->|"runs"| Bin8

  In -->|"feeds"| Bin1 -->|"prints/writes"| Out
  In -->|"feeds"| Bin2 -->|"prints/writes"| Out
  In -->|"feeds"| Bin3 -->|"prints/writes"| Out
  In -->|"feeds"| Bin4 -->|"prints/writes"| Out
  In -->|"feeds"| Bin5 -->|"prints/writes"| Out
  In -->|"feeds"| Bin6 -->|"prints/writes"| Out
  In -->|"feeds"| Bin7 -->|"prints/writes"| Out
  In -->|"feeds"| Bin8 -->|"prints/writes"| Out

  %% =========================
  %% Conceptual Compiler Pipeline (Mapping is intentionally non-committal)
  %% =========================
  subgraph "Conceptual Mapping: Typical Compiler Pipeline (Experiments implement parts independently)"
    Source["Source Program / Grammar / Token Input"]:::io

    Stage1["Lexical Analysis (concept)"]:::stage
    Tokens[/"Token Stream"/]:::artifact

    Stage2["Syntax Analysis / Parsing (concept)"]:::stage
    ParseTree[/"Parse Tree / AST"/]:::artifact

    Stage3["Semantic Analysis (concept)"]:::stage
    SymTab[("Symbol Table")]:::data

    Stage4["IR / Intermediate Code Generation (concept)"]:::stage
    IR[/"IR (e.g., TAC)"/]:::artifact

    Stage5["Optimization (optional/absent)"]:::stage
    Stage6["Target Code Generation (optional/absent)"]:::stage
    Target[/"Target Code / Output"/]:::artifact

    Source -->|"analyzed_by"| Stage1 -->|"produces"| Tokens -->|"consumed_by"| Stage2 -->|"produces"| ParseTree
    ParseTree -->|"checked_by"| Stage3 -->|"updates"| SymTab
    Stage3 -->|"drives"| Stage4 -->|"emits"| IR -->|"may_flow_to"| Stage5 -->|"may_flow_to"| Stage6 -->|"emits"| Target

    NoteMap["Note: Map each ExperimentN to stages based on actual functions/data found in code (avoid guessing)."]:::note
  end

  %% Link conceptual pipeline to repo reality (independent programs)
  Bin1 -.->|"implements_subset"| Stage1
  Bin2 -.->|"implements_subset"| Stage2
  Bin3 -.->|"implements_subset"| Stage3
  Bin4 -.->|"implements_subset"| Stage4
  Bin5 -.->|"implements_subset"| Stage1
  Bin6 -.->|"implements_subset"| Stage2
  Bin7 -.->|"implements_subset"| Stage3
  Bin8 -.->|"implements_subset"| Stage4

  %% =========================
  %% Per-Experiment Internal Structure (generic template; code-inspection required)
  %% =========================
  subgraph "Per-Experiment (Single-Process) Program Structure Template"
    PIn["Input Buffer / File Read"]:::io
    Main(["main()"]):::process
    Modules["Core Functions (e.g., scan/parse/compute/generate)"]:::process
    DS[("Core Data Structures (arrays/stacks/tables/symbols)")]:::data
    POut["Printed Results / Files"]:::io

    PIn -->|"read_into"| Main -->|"calls"| Modules
    Modules -->|"uses/updates"| DS
    Modules -->|"outputs"| POut
  end

  %% =========================
  %% Click Events (from component mapping)
  %% =========================
  click Readme "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/README.md"
  click E1 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment1.c"
  click E2 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment2.c"
  click E3 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment3.c"
  click E4 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment4.c"
  click E5 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment5.c"
  click E6 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment6.c"
  click E7 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment7.c"
  click E8 "https://github.com/kartik-balaji/compiler-design-lab-kartik/blob/main/Experiment8.c"

  %% =========================
  %% Styles
  %% =========================
  classDef actor fill:#0f172a,stroke:#1e293b,color:#e2e8f0,stroke-width:1.5px
  classDef external fill:#111827,stroke:#374151,color:#f9fafb,stroke-width:1.5px
  classDef tool fill:#4c1d95,stroke:#6d28d9,color:#f5f3ff,stroke-width:1.5px
  classDef source fill:#0b3b2e,stroke:#10b981,color:#ecfdf5,stroke-width:1.5px
  classDef exe fill:#1e3a8a,stroke:#60a5fa,color:#eff6ff,stroke-width:1.5px
  classDef io fill:#7c2d12,stroke:#fb923c,color:#fff7ed,stroke-width:1.5px
  classDef doc fill:#3f3f46,stroke:#a1a1aa,color:#fafafa,stroke-width:1.5px
  classDef stage fill:#1f2937,stroke:#9ca3af,color:#f9fafb,stroke-width:1.5px
  classDef artifact fill:#3b0764,stroke:#c084fc,color:#faf5ff,stroke-width:1.5px
  classDef data fill:#064e3b,stroke:#34d399,color:#ecfdf5,stroke-width:1.5px
  classDef process fill:#0b4a6f,stroke:#38bdf8,color:#e0f2fe,stroke-width:1.5px
  classDef note fill:#713f12,stroke:#fbbf24,color:#fffbeb,stroke-width:1.5px
```
