# ayush-that/small-compiler architecture

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

- Interactive diagram: https://gitdiagram.com/ayush-that/small-compiler
- Repository: https://github.com/ayush-that/small-compiler

## Overview

##### Project type and purpose
- This is a small compiler (language-to-language translator) whose purpose is to read a Lisp‐style function call string, parse it into an AST, transform that AST to match JavaScript call‐syntax, and emit JavaScript code.
- The README confirms it: input is something like `(add 2 (subtract 4 2))` and the output is `add(2, subtract(4, 2));`.

##### File structure
- Top‐level files correspond to each compilation stage:
- tokenizer.js – splits source text into tokens
- parser.js – builds an initial Abstract Syntax Tree (AST) from tokens
- traverser.js – walks the AST (visitor pattern)
- transformer.js – converts the original Lisp AST to a JavaScript‐style AST
- codeGenerator.js – emits final JavaScript code from the transformed AST
- compiler.js – likely ties these modules together into a single compile() function
- main.js – CLI or script entry point that reads input, invokes compiler.js, writes output
- package.json + package-lock.json: Node.js project
- No external services, databases, or frontend–backend separation—everything is local and sequential.

##### README for additional insights
- The project follows a classic compiler pipeline (tokenize → parse → transform → codegen).

##### Detailed checklist
- Title: “Small Lisp‐to‐JS Compiler Architecture”
- Module name
- Source filename
- Brief description (e.g., “tokenizer.js – splits input into tokens”)
- Entry point (main.js) at the far left, output sink at the far right.
- License and runtime environment in a side note.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External entities
    Input["Input Source\nLisp code string"]:::external
    Output["Output Sink\nJavaScript code"]:::external

    %% CLI and orchestrator
    main["main.js\nCLI entry point"]:::orchestration
    Compiler["compiler.js\ncompile() orchestrator"]:::orchestration

    subgraph "Compiler Process"
        direction TB
        Tokenizer["tokenizer.js\nsplits input into tokens"]:::parsing
        Parser["parser.js\nbuilds AST from tokens"]:::parsing
        Traverser["traverser.js\nwalks AST (visitor)"]:::processing
        Transformer["transformer.js\nconverts AST"]:::processing
        CodeGen["codeGenerator.js\nemits JS code"]:::emitting
    end

    %% Data flow
    Input -->|string| main
    main -->|"calls compile()"| Compiler
    Compiler -->|"input string"| Tokenizer
    Tokenizer -->|"tokens"| Parser
    Parser -->|"AST"| Traverser
    Traverser -->|"AST"| Transformer
    Transformer -->|"JS AST"| CodeGen
    CodeGen -->|"JavaScript code"| Output

    %% Click events
    click Tokenizer "https://github.com/ayush-that/small-compiler/blob/main/tokenizer.js"
    click Parser "https://github.com/ayush-that/small-compiler/blob/main/parser.js"
    click Traverser "https://github.com/ayush-that/small-compiler/blob/main/traverser.js"
    click Transformer "https://github.com/ayush-that/small-compiler/blob/main/transformer.js"
    click CodeGen "https://github.com/ayush-that/small-compiler/blob/main/codeGenerator.js"
    click Compiler "https://github.com/ayush-that/small-compiler/blob/main/compiler.js"
    click main "https://github.com/ayush-that/small-compiler/blob/main/main.js"

    %% Styles
    classDef parsing fill:#D0E8FF,stroke:#004E9E,color:#000
    classDef processing fill:#DFF7D6,stroke:#2E7D32,color:#000
    classDef emitting fill:#FFE0B2,stroke:#E65100,color:#000
    classDef orchestration fill:#E0E0E0,stroke:#616161,color:#000
    classDef external fill:#F5F5F5,stroke:#9E9E9E,color:#000
```
