# pipluppp/interpreter architecture

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

- Interactive diagram: https://gitdiagram.com/pipluppp/interpreter
- Repository: https://github.com/pipluppp/interpreter

## Overview

##### Main Components Identification
The system should be represented as a multi-stage compiler pipeline with these key components:

a. Scanner (Lexical Analyzer)
- Input: Source code (.core files)
- Output: Symbol table (symbol_table.txt)
- Key files: scanner.c, token.h

b. Parser (Syntax Analyzer)
- Input: Symbol table
- Output: Parse tree (parse_tree_output.ebnf)
- Key files: parser.c

**Input Files (.core) → Scanner → Symbol Table → Parser → Parse Tree**

**Grammar Files**
- grammar.ebnf
- implemented_grammar.ebnf
- grammar_derivations/

##### Detailed Component Breakdown

Scanner Component:
**[Source Files] → [Scanner]**
- ↓
- Token recognition
- Error handling
- Comment filtering
- Line/Column tracking
- ↓
- [Symbol Table]

Parser Component:
**[Symbol Table] → [Parser]**
- ↓
- Recursive Descent Parsing
- Grammar rule validation
- Error recovery
- Parse tree generation
- ↓
- [Parse Tree]

##### Testing Framework Integration

Test components as a parallel structure:
**[Test Files]**
- ↓
**test_lexer/**
**test_parser/**
- ↓
**[Test Results]**

##### Important Notes

- Grammar files as a reference database
- One-token-at-a-time processing flow
- Recursive descent parsing strategy
- Error handling paths
- File format specifications (.core, .ebnf, .txt)

##### Implementation Notes

- Single-pass nature of the scanner
- Token stream processing
- Grammar-driven parsing
- Error handling and recovery mechanisms
- Test integration points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SRC["Source Files (.core)"]:::input
    end

    subgraph "Scanner Layer"
        SCAN[Scanner]:::processor
        TOK[Token Processing]:::component
        ERR1[Error Handling]:::component
        SCAN --> TOK
        SCAN --> ERR1
    end

    subgraph "Symbol Table Layer"
        SYMTAB[(Symbol Table)]:::storage
    end

    subgraph "Parser Layer"
        PARS[Parser]:::processor
        RDP[Recursive Descent]:::component
        ERR2[Error Recovery]:::component
        PARS --> RDP
        PARS --> ERR2
    end

    subgraph "Output Layer"
        PTREE[(Parse Tree)]:::output
    end

    subgraph "Grammar Reference"
        GRAM[Grammar Files]:::reference
        GDER[Grammar Derivations]:::reference
    end

    subgraph "Testing Framework"
        STEST[Scanner Tests]:::test
        PTEST[Parser Tests]:::test
    end

    %% Main Flow
    SRC --> SCAN
    SCAN --> SYMTAB
    SYMTAB --> PARS
    PARS --> PTREE

    %% Grammar References
    GRAM -.-> SCAN
    GRAM -.-> PARS
    GDER -.-> PARS

    %% Test Connections
    STEST -.-> SCAN
    PTEST -.-> PARS

    %% Click Events
    click SCAN "https://github.com/Pipluppp/interpreter/blob/main/scanner.c"
    click TOK "https://github.com/Pipluppp/interpreter/blob/main/token.h"
    click SYMTAB "https://github.com/Pipluppp/interpreter/blob/main/symbol_table.txt"
    click PARS "https://github.com/Pipluppp/interpreter/blob/main/parser.c"
    click PTREE "https://github.com/Pipluppp/interpreter/blob/main/parse_tree_output.ebnf"
    click GRAM "https://github.com/Pipluppp/interpreter/blob/main/grammar.ebnf"
    click GDER "https://github.com/Pipluppp/interpreter/tree/main/grammar_derivations"
    click STEST "https://github.com/Pipluppp/interpreter/tree/main/test_lexer"
    click PTEST "https://github.com/Pipluppp/interpreter/tree/main/test_parser"

    %% Styling
    classDef processor fill:#2374ab
    classDef component fill:#74a9d8
    classDef storage fill:#ffb347
    classDef input fill:#90ee90
    classDef output fill:#ff7f50
    classDef reference fill:#d3d3d3
    classDef test fill:#dda0dd

    %% Legend
    subgraph Legend
        L1[Processor]:::processor
        L2[Component]:::component
        L3[(Storage)]:::storage
        L4[Input]:::input
        L5[Output]:::output
        L6[Reference]:::reference
        L7[Testing]:::test
    end
```
