# amansingh-13/cs316-sclp-compiler architecture

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

- Interactive diagram: https://gitdiagram.com/amansingh-13/cs316-sclp-compiler
- Repository: https://github.com/amansingh-13/cs316-sclp-compiler

## Overview

##### Main Components
- Compiler Frontend:
- Lexical Analyzer: Represented by lexer.l files (found in A1, A2, A3, A4, A5, and within group7 directories). This module scans source code and converts the input into tokens.
- Parser: Based on parser.y in several group7 directories, this component takes tokens from the lexer and builds a parse tree.
- AST (Abstract Syntax Tree) Builder: The ast.hpp files and possibly tac.hpp (in A5) illustrate where the AST is defined and subsequently processed.
- Semantic Analyzer: Items like semantics.hpp (present in A2, A3, A4, A5/group7) indicate the semantic checking phase.
- Compiler Backend (if applicable):
- There are hints (e.g., “sm.cpp” in A3 and additional “tac.hpp” in A5) that further phases such as intermediate code generation or transformation are incorporated.
- Test & Resource Management:
- Resources are organized in “*-Resources” directories for each assignment (A1, A2, etc.), which include test cases (separated into levels) and reference implementations (L1-sclp to L4-sclp).
- Example programs and their corresponding tokens, input files, etc., serve as the input test corpus for verifying the compiler’s functionality.
- Build & Configuration:
- Makefiles at the top level in A1 and within the group7 directories indicate how the different components are compiled and linked.

- From the AST node creation, link to the Semantic Analyzer which verifies correctness and performs type checking.
- A separate “Testing Framework” component (or “Test Case Repository”) that interacts with the compiler core by feeding sample test cases (from the resource directories) into the overall pipeline.
- The Makefiles and configuration files can be represented as the “Build/Integration” layer that assembles all these components.

##### Architectural Patterns and Design Principles
- Modularity: Each phase (lexing, parsing, semantic analysis, etc.) is encapsulated in its own module across the project structure.
- Incremental Development: The progression from A1 through A5 (and similarly the levels of test cases) suggest that the compiler was built in incremental phases—each assignment extending or refining previous functionality.
- Reusability and Extensibility: Separate implementations in “reference-implementations” and “group7” suggest that the design is meant to be compared, extended, or benchmarked.

##### Relevant Technologies and Frameworks
- Lex & YACC: With lexer.l and parser.y present, clearly indicate the use of classic compiler generators.
- C/C++: The files (e.g., *.c, *.cpp, *.hpp) point to C-family languages.

##### Elements
- External resources like the online info at https://www.cse.iitb.ac.in/~uday/sclp-web/ which might provide additional context.

##### Final Touches
- That each assignment (A1 up to A5) might have slight variations in implementation and could be represented as “modules” or “layers” built atop a common core.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Phase A1"
        A1_LEX["Lexical Analyzer (lexer.l)"]:::frontend
        A1_PAR["Parser (parser.y)"]:::frontend
        A1_TEST["Test Resources (A1-Resources)"]:::test
        A1_MAKE["Makefile"]:::build
        A1_LEX -->|"feeds"| A1_PAR
    end

    subgraph "Phase A2"
        A2_LEX["Lexical Analyzer (lexer.l)"]:::frontend
        A2_PAR["Parser (parser.y)"]:::frontend
        A2_AST["AST Builder (ast.hpp)"]:::frontend
        A2_SEM["Semantic Analyzer (semantics.hpp)"]:::frontend
        A2_TEST["Test Resources (A2-Resources)"]:::test
        A2_MAKE["Makefile"]:::build
        A2_LEX -->|"feeds"| A2_PAR
        A2_PAR -->|"builds"| A2_AST
        A2_AST -->|"analyzes"| A2_SEM
    end

    subgraph "Phase A3"
        A3_LEX["Lexical Analyzer (lexer.l)"]:::frontend
        A3_PAR["Parser (parser.y)"]:::frontend
        A3_AST["AST Builder (ast.hpp)"]:::frontend
        A3_SEM["Semantic Analyzer (semantics.hpp)"]:::frontend
        A3_IR["IR/CodeGen (sm.cpp)"]:::backend
        A3_TEST["Test Resources (A3-Resources)"]:::test
        A3_MAKE["Makefile"]:::build
        A3_LEX -->|"feeds"| A3_PAR
        A3_PAR -->|"builds"| A3_AST
        A3_AST -->|"validates"| A3_SEM
        A3_SEM -->|"generates"| A3_IR
    end

    subgraph "Phase A4"
        A4_LEX["Lexical Analyzer (lexer.l)"]:::frontend
        A4_PAR["Parser (parser.y)"]:::frontend
        A4_AST["AST Builder (ast.hpp)"]:::frontend
        A4_SEM["Semantic Analyzer (semantics.hpp)"]:::frontend
        A4_TEST["Test Resources (A4-Resources)"]:::test
        A4_MAKE["Makefile"]:::build
        A4_LEX -->|"feeds"| A4_PAR
        A4_PAR -->|"builds"| A4_AST
        A4_AST -->|"validates"| A4_SEM
    end

    subgraph "Phase A5"
        A5_LEX["Lexical Analyzer (lexer.l)"]:::frontend
        A5_PAR["Parser (parser.y)"]:::frontend
        A5_AST["AST Builder (ast.hpp)"]:::frontend
        A5_SEM["Semantic Analyzer (semantics.hpp)"]:::frontend
        A5_IR["IR/CodeGen (tac.hpp)"]:::backend
        A5_TEST["Test Resources (A5-Resources)"]:::test
        A5_MAKE["Makefile"]:::build
        A5_LEX -->|"feeds"| A5_PAR
        A5_PAR -->|"builds"| A5_AST
        A5_AST -->|"validates"| A5_SEM
        A5_SEM -->|"generates"| A5_IR
    end

    %% Vertical progression between phases for overall evolution
    A1_LEX --- A2_LEX
    A2_LEX --- A3_LEX
    A3_LEX --- A4_LEX
    A4_LEX --- A5_LEX

    %% Click Events for Phase A1 components
    click A1_LEX "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A1/lexer.l"
    click A1_PAR "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A1/parser.y"
    click A1_TEST "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A1/A1-Resources"
    click A1_MAKE "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A1/Makefile"

    %% Click Events for Phase A2 components
    click A2_LEX "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A2/group7/lexer.l"
    click A2_PAR "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A2/group7/parser.y"
    click A2_AST "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A2/group7/ast.hpp"
    click A2_SEM "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A2/group7/semantics.hpp"
    click A2_TEST "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A2/A2-Resources"
    click A2_MAKE "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A2/group7/Makefile"

    %% Click Events for Phase A3 components
    click A3_LEX "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A3/group7/lexer.l"
    click A3_PAR "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A3/group7/parser.y"
    click A3_AST "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A3/group7/ast.hpp"
    click A3_SEM "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A3/group7/semantics.hpp"
    click A3_IR "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A3/sm.cpp"
    click A3_TEST "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A3/A3-Resources"
    click A3_MAKE "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A3/group7/Makefile"

    %% Click Events for Phase A4 components
    click A4_LEX "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A4/group7/lexer.l"
    click A4_PAR "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A4/group7/parser.y"
    click A4_AST "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A4/group7/ast.hpp"
    click A4_SEM "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A4/group7/semantics.hpp"
    click A4_TEST "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A4/A4-Resources"
    click A4_MAKE "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A4/group7/Makefile"

    %% Click Events for Phase A5 components
    click A5_LEX "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A5/group7/lexer.l"
    click A5_PAR "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A5/group7/parser.y"
    click A5_AST "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A5/group7/ast.hpp"
    click A5_SEM "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A5/group7/semantics.hpp"
    click A5_IR "https://github.com/amansingh-13/cs316-sclp-compiler/blob/master/A5/group7/tac.hpp"
    click A5_TEST "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A5/A5-Resources"
    click A5_MAKE "https://github.com/amansingh-13/cs316-sclp-compiler/tree/master/A5/group7/Makefile"

    %% Styling
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#ff9,stroke:#333,stroke-width:2px;
    classDef test fill:#9ff,stroke:#333,stroke-width:2px;
    classDef build fill:#fc9,stroke:#333,stroke-width:2px;
    classDef input fill:#bbf,stroke:#333,stroke-width:2px;
```
