# accusitive/cyntax architecture

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

- Interactive diagram: https://gitdiagram.com/accusitive/cyntax
- Repository: https://github.com/accusitive/cyntax

## Overview

##### Project type and purpose
- This is a Rust‑based compiler toolchain (likely targeting C or a C‑like language), organized as a Cargo workspace.
- The presence of crates named cyntax_preprocessor, cyntax_lexer, cyntax_parser, cyntax_ast_lower, cyntax_hir, cyntax_consteval, cyntax_errors, and cyntax_common shows a clear pipeline from raw source to intermediate representations and error handling.

##### File structure
- Top‑level workspace.toml brings together multiple library crates and one binary crate (src/main.rs).
- Each cyntax_* directory is a standalone Cargo crate implementing one compilation phase or shared functionality.
- src/main.rs is the compiler driver/CLI that orchestrates all phases.
- test.c, test2.h serve as example inputs, and a tinycc directory hints at a code‑generation or integration with TinyCC.

##### (implicit) architecture
- There’s a linear data flow: Source files → Preprocessor → Lexer → Parser → AST Lowering → HIR → Constant Evaluator → (possibly further passes or codegen).
- cyntax_common provides shared AST definitions and utilities; cyntax_errors handles error reporting used by all phases.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Source files
    subgraph "Source Files"
        SF1["test.c"]:::source
        SF2["test2.h"]:::source
    end

    %% Entry point
    CLI["CLI Driver<br/>src/main.rs"]:::driver

    %% Compilation phases
    PRE["Preprocessor"]:::phase
    LEX["Lexer"]:::phase
    PAR["Parser"]:::phase
    AL["AST Lowering"]:::phase
    HIR["HIR"]:::phase
    CE["Constant Evaluation"]:::phase

    %% External backend
    EXT["tinycc"]:::external

    %% Shared libraries
    subgraph "Shared Libraries"
        COM["cyntax_common"]:::shared
        ERR["cyntax_errors"]:::shared
    end

    %% Data flow
    SF1 -->|"file paths"| CLI
    SF2 -->|"file paths"| CLI
    CLI -->|"raw text"| PRE
    PRE -->|"tokens"| LEX
    LEX -->|"token stream"| PAR
    PAR -->|"raw AST"| AL
    AL -->|"typed AST"| HIR
    HIR -->|"HIR"| CE
    CE -->|"final IR"| EXT

    %% Shared deps
    PRE -->|"uses"| COM
    PRE -->|"uses"| ERR
    LEX -->|"uses"| COM
    LEX -->|"uses"| ERR
    PAR -->|"uses"| COM
    PAR -->|"uses"| ERR
    AL -->|"uses"| COM
    AL -->|"uses"| ERR
    HIR -->|"uses"| COM
    HIR -->|"uses"| ERR
    CE -->|"uses"| COM
    CE -->|"uses"| ERR
    CLI -->|"uses"| ERR
    CLI -->|"uses"| COM

    %% Click Events
    click CLI "https://github.com/accusitive/cyntax/blob/master/src/main.rs"
    click PRE "https://github.com/accusitive/cyntax/tree/master/cyntax_preprocessor/"
    click LEX "https://github.com/accusitive/cyntax/tree/master/cyntax_lexer/"
    click PAR "https://github.com/accusitive/cyntax/tree/master/cyntax_parser/"
    click AL "https://github.com/accusitive/cyntax/tree/master/cyntax_ast_lower/"
    click HIR "https://github.com/accusitive/cyntax/tree/master/cyntax_hir/"
    click CE "https://github.com/accusitive/cyntax/tree/master/cyntax_consteval/"
    click ERR "https://github.com/accusitive/cyntax/tree/master/cyntax_errors/"
    click COM "https://github.com/accusitive/cyntax/tree/master/cyntax_common/"
    click EXT "https://github.com/accusitive/cyntax/tree/master/tinycc/"
    click SF1 "https://github.com/accusitive/cyntax/blob/master/test.c"
    click SF2 "https://github.com/accusitive/cyntax/blob/master/test2.h"

    %% Styles
    classDef driver fill:#FFD580,stroke:#E59400,color:#000;
    classDef phase fill:#B3E6B3,stroke:#339933,color:#000;
    classDef shared fill:#FFCCCC,stroke:#CC0000,color:#000;
    classDef external fill:#CCCCFF,stroke:#0000CC,color:#000;
    classDef source fill:#E6E6E6,stroke:#666666,color:#000;
```
