# teobacher/interpreteur-c architecture

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

- Interactive diagram: https://gitdiagram.com/teobacher/interpreteur-c
- Repository: https://github.com/teobacher/interpreteur-c

## Overview

##### Project type and purpose
- This is a small command-line **interpreter** written in C. It reads source (either interactively or from a file), lexes it into tokens, parses those tokens into an abstract syntax tree (AST), and then evaluates (executes) that tree.

##### File structure
- Top-level: README.md, LICENSE, .gitignore, sujet.md
- src/: contains three pairs of modules—input, lexer, parser—and a tests/ subdirectory.
- input.c/h: handles reading from stdin or file
- lexer.c/h: converts raw characters to tokens
- parser.c/h: builds the AST and performs evaluation
- src/tests/: sample input programs for regression testing

##### README for additional insights
- Execution modes: interactive vs file mode
- Debug mode toggle in lexer.h to trace the lex/parse/AST steps
- Feature list: arithmetic, variables, precedence, conditions, loops, typing, comments, strings

##### Main components
a. **CLI Driver** (main)
- Entry point that parses command-line flags (mode, debug) and invokes the pipeline.
b. **Input Module**
- Reads raw text from stdin or file
- Passes a character buffer to the lexer
c. **Lexer Module**
- Tokenizes the character stream into a token stream
- Honors DEBUG flag to emit tokenization steps
d. **Parser Module**
- Consumes tokens, constructs an AST
- Performs syntax validation, type checking
e. **AST / Symbol Table**
- In-memory representation of program structure
- Symbol table to store variable names/values
f. **Evaluator / Interpreter**
- Walks the AST, executes statements and expressions
- Updates symbol table, handles control flow (if, while, for)
g. **Output**
- Prints results or error messages to stdout
h. **Test Suite**
- src/tests/*.txt supplies sample programs; CLI driver can load them in file mode for regression tests

##### Relationships and data flow
- CLI → Input Module → Lexer → Parser → AST/Symbol Table → Evaluator → Output
- The DEBUG flag branches inside the Lexer and Parser to emit logs.

##### Architectural patterns and principles
- **Modular pipeline** (lexer → parser → evaluator) follows classic compiler design
- Clear separation of concerns: each module has a single responsibility
- In-memory AST and symbol table support incremental evaluation

##### Technologies and languages
- C99 (gcc)
- No external dependencies
- Build script is a simple gcc command in README

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Modules
    CLI["CLI Driver\n(main)"]:::io
    InputModule["Input Module"]:::io
    LexerModule["Lexer Module"]:::analysis
    ParserModule["Parser Module"]:::analysis
    SymbolTable["Symbol Table"]:::runtime
    Evaluator["Evaluator / Interpreter"]:::runtime
    Output["Output\n(stdout / stderr)"]:::io
    Tests["Test Suite"]:::tests

    %% Data Flow
    CLI -->|"flags / mode"| InputModule
    InputModule -->|"character stream"| LexerModule
    LexerModule -->|"token stream"| ParserModule
    ParserModule -->|"AST"| Evaluator
    ParserModule --> SymbolTable
    Evaluator -->|"execution results"| Output
    CLI -->|"file mode"| Tests

    %% Debug Branch
    LexerModule -.->|"DEBUG log"| ParserModule

    %% Click Events
    click CLI "https://github.com/teobacher/interpreteur-c/blob/main/src/input.c"
    click InputModule "https://github.com/teobacher/interpreteur-c/blob/main/src/input.c"
    click InputModule "https://github.com/teobacher/interpreteur-c/blob/main/src/input.h"
    click LexerModule "https://github.com/teobacher/interpreteur-c/blob/main/src/lexer.c"
    click LexerModule "https://github.com/teobacher/interpreteur-c/blob/main/src/lexer.h"
    click ParserModule "https://github.com/teobacher/interpreteur-c/blob/main/src/parser.c"
    click ParserModule "https://github.com/teobacher/interpreteur-c/blob/main/src/parser.h"
    click SymbolTable "https://github.com/teobacher/interpreteur-c/blob/main/src/parser.h"
    click Evaluator "https://github.com/teobacher/interpreteur-c/blob/main/src/parser.c"
    click Tests "https://github.com/teobacher/interpreteur-c/tree/main/src/tests/"

    %% Styles
    classDef io fill:#9f6,stroke:#333,stroke-width:2px
    classDef analysis fill:#6cf,stroke:#333,stroke-width:2px
    classDef runtime fill:#f96,stroke:#333,stroke-width:2px
    classDef tests fill:#ccc,stroke:#333,stroke-width:2px
```
