# geekforalgorithm/legacy-cc architecture

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

- Interactive diagram: https://gitdiagram.com/geekforalgorithm/legacy-cc
- Repository: https://github.com/geekforalgorithm/legacy-cc

## Overview

##### Project Type and Purpose
- Clearly, this is a compiler for the C language from the early days of the language’s evolution. Its purpose is to translate (a subset of) C into assembly code (targeting a PDP‑11 environment, as indicated by the links to a PDP‑11/unix emulator).
- The README highlights its historical significance and provides links for experimenting in an emulated environment.

##### File Structure
- There are two main directories: “last1120c” and “prestruct”. Each contains a set of C source files (with names like c00.c, c01.c, …, c11.c) and several assembly (’.s’) files.
- The naming convention (e.g., “c00”, “c01”, “c10”, “c11”, etc.) suggests that the compiler’s logic was divided into multiple phases or modules. For instance, modules under “c00- c03” might cover the initial phases (like lexical analysis and parsing) while “c10” and “c11” may handle later phases (such as code generation). Files like “cvopt.c” indicate a dedicated optimization module.
- The .s files (such as c0t.s, c1t.s, cctab.s, efftab.s, regtab.s, and sptab.s) serve as pre-defined tables or ancillary data needed by the compiler – likely used for token tables, optimization decision data, register allocation data, and so on.
- The “prestruct” directory appears to be an earlier or alternative implementation design (“prestruct” could refer to a non-structured, or “pre-structured” version) that might have its own variation of the compiler phases.

- Source Input Module: Representing the initial input phase of the compiler where C code is read.
- Lexical Analysis / Tokenization: Likely contained in modules such as the early “c00.c” files (parsing characters and converting them into tokens).
- Syntax/Parsing Phase: Possibly spread over files like “c01.c” and “c02.c”, handling the formation of the abstract syntax tree.
- Semantic Analysis: Although not explicitly labeled, later stages may incorporate semantic checks.
- Optimization Component: Highlight “cvopt.c” to show that some basic optimization strategies were implemented.
- Code Generation: Modules such as “c10.c” and “c11.c” are suggestive of the translation of the abstract syntax tree into assembly code.
- Assembly/Table Definitions: The .s files (c0t.s, c1t.s, cctab.s, etc.) that provide necessary static data and templates for code generation.
- Alternative/Legacy Structures: Separate the “prestruct” set as an alternative design variant of the compiler’s architecture.

b. Relationships and Interactions:
- From the Lexical Analyzer, show the flow into the Parsing/Syntax Analysis module.
- The output from parsing flows into semantic analysis (if applicable) and then onto the Code Generation phase.
- For the “prestruct” variant, you may set up a parallel flow that resembles the main system but highlights differences (if any) in design philosophy.

c. Architectural Patterns and Technologies:
- Each “cXX” module represents a specific point in the processing pipeline.
- That the project relies on plain C and assembly, targeting very early Unix/PDP‑11 environments.
- That historical design principles such as minimal separation of concerns and close integration between compilation phases are present.

d. Tailoring Guidelines:
- Since this is a compiler (a language processing tool), clarify each compilation stage: Lexical Analysis, Parsing, Optional Semantic Analysis, Optimization, and Code Generation.
- Be sure to capture the ancillary role of assembly templates/tables as separate yet connected components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Legacy Compiler Pipeline
    S("Source Input Module"):::source
    LEX("Lexical Analyzer"):::cSource
    SYNP1("Syntax Parser 1 (c01.c)"):::cSource
    SYNP2("Syntax Parser 2 (c02.c)"):::cSource
    SYNP3("Syntax Parser Support (c03.c)"):::cSource
    OPT("Optimizer"):::cSource
    CG1("Code Generator 1 (c10.c)"):::cSource
    CG2("Code Generator 2 (c11.c)"):::cSource

    S -->|"flows_to"| LEX
    LEX -->|"flows_to"| SYNP1
    SYNP1 -->|"flows_to"| SYNP2
    SYNP2 -->|"flows_to"| SYNP3
    SYNP3 -->|"flows_to"| OPT
    OPT -->|"flows_to"| CG1
    CG1 -->|"flows_to"| CG2
    CG2 -->|"references"| D1

    %% Assembly/Data Tables Subgraph
    subgraph "Assembly/Data Tables"
        D1("Token Table (c0t.s)"):::asm
        D2("Instruction Table (c1t.s)"):::asm
        D3("Control Table (cctab.s)"):::asm
        D4("Effect Table (efftab.s)"):::asm
        D5("Register Table (regtab.s)"):::asm
        D6("Sp Table (sptab.s)"):::asm
    end

    %% Alternative Prestructured Compiler Pipeline
    subgraph "Alternative Prestructured Compiler"
        ALT_LEX("Pre Lexical Analyzer (prestruct/c00.c)"):::alt
        ALT_SYNP1("Pre Syntax Parser 1 (prestruct/c01.c)"):::alt
        ALT_SYNP2("Pre Syntax Parser 2 (prestruct/c02.c)"):::alt
        ALT_SYNP_Sup("Pre Syntax Support (prestruct/c03.c)"):::alt
        ALT_CG1("Pre Code Generator 1 (prestruct/c10.c)"):::alt
        ALT_CG2("Pre Code Generator 2 (prestruct/c11.c)"):::alt
        ALT_LEX -->|"flows_to"| ALT_SYNP1
        ALT_SYNP1 -->|"flows_to"| ALT_SYNP2
        ALT_SYNP2 -->|"flows_to"| ALT_SYNP_Sup
        ALT_SYNP_Sup -->|"flows_to"| ALT_CG1
        ALT_CG1 -->|"flows_to"| ALT_CG2
    end

    %% Click Events for Legacy Components
    click LEX "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c00.c"
    click SYNP1 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c01.c"
    click SYNP2 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c02.c"
    click SYNP3 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c03.c"
    click OPT "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/cvopt.c"
    click CG1 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c10.c"
    click CG2 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c11.c"
    click D1 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c0t.s"
    click D2 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/c1t.s"
    click D3 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/cctab.s"
    click D4 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/efftab.s"
    click D5 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/regtab.s"
    click D6 "https://github.com/geekforalgorithm/legacy-cc/blob/master/last1120c/sptab.s"

    %% Click Events for Alternative Prestructured Compiler
    click ALT_LEX "https://github.com/geekforalgorithm/legacy-cc/blob/master/prestruct/c00.c"
    click ALT_SYNP1 "https://github.com/geekforalgorithm/legacy-cc/blob/master/prestruct/c01.c"
    click ALT_SYNP2 "https://github.com/geekforalgorithm/legacy-cc/blob/master/prestruct/c02.c"
    click ALT_SYNP_Sup "https://github.com/geekforalgorithm/legacy-cc/blob/master/prestruct/c03.c"
    click ALT_CG1 "https://github.com/geekforalgorithm/legacy-cc/blob/master/prestruct/c10.c"
    click ALT_CG2 "https://github.com/geekforalgorithm/legacy-cc/blob/master/prestruct/c11.c"

    %% Styles
    classDef source fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef cSource fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef asm fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef alt fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
```
