# chenjuntong/simple-caculator architecture

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

- Interactive diagram: https://gitdiagram.com/chenjuntong/simple-caculator
- Repository: https://github.com/chenjuntong/simple-caculator

## Overview

##### Project type and purpose
- This is a simple command-line calculator tool provided in two language implementations (Python and C).
- Its purpose is to read a user‐entered arithmetic expression (supporting integers, plus and minus), parse it, evaluate it, and print the result.

##### File structure
- Top level:
- README.md: project overview and detailed Python design
- caculator.py: full Python implementation
- caculator.c: full C implementation
- No subdirectories—each implementation is a self-contained module.

##### README for additional insights
- The README describes the Python version in four functional stages:
a. Input handling (Buffer class)
b. Tokenization (IntToken, OperatorToken)
c. Parsing into an expression tree (Node, IntNode, BinaryOpNode)
d. Evaluation (recursive traverse of the tree)

##### Elements
- Clear labels for each component (e.g., “Tokenizer”, “Parser”)
- Rectangles for processing modules

##### Detailed capture of essential elements
- Do not overcomplicate—focus on the five pipeline stages plus input/output.
- Helper classes or functions in small text under each stage if desired (e.g., under “Tokenizer”: IntToken, OperatorToken).
- That the AST nodes (IntNode, BinaryOpNode) form the central data representation.

## Diagram (Mermaid)

```mermaid
graph TD
    README["Project Documentation\nREADME.md"]:::doc
    click README "https://github.com/chenjuntong/simple-caculator/blob/master/README.md"

    subgraph "Python Implementation"
        UI_P["User Interface\n(caculator.py)"]:::process
        click UI_P "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.py"
        Buffer["Input Buffer\n(Buffer class)"]:::process
        click Buffer "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.py"
        Tokenizer["Tokenizer\n(IntToken, OperatorToken)"]:::process
        click Tokenizer "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.py"
        Parser["Parser\n(Node, IntNode, BinaryOpNode)"]:::process
        click Parser "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.py"
        AST["Expression Tree (AST)\n(Node hierarchy)"]:::data
        click AST "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.py"
        Evaluator["Evaluator\n(AST evaluation methods)"]:::process
        click Evaluator "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.py"
        Output_P["Output Printer\n(caculator.py)"]:::process
        click Output_P "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.py"
    end

    subgraph "C Implementation"
        UI_C["User Interface\n(main, scanf/printf)"]:::process
        click UI_C "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.c"
        BufferC["Input Buffer"]:::process
        click BufferC "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.c"
        TokenizerC["Tokenizer"]:::process
        click TokenizerC "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.c"
        ParserC["Parser"]:::process
        click ParserC "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.c"
        ASTC["Expression Tree (AST)"]:::data
        click ASTC "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.c"
        EvaluatorC["Evaluator"]:::process
        click EvaluatorC "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.c"
        Output_C["Output Printer\n(printf)"]:::process
        click Output_C "https://github.com/chenjuntong/simple-caculator/blob/master/caculator.c"
    end

    README --> UI_P
    UI_P --> Buffer
    Buffer --> Tokenizer
    Tokenizer --> Parser
    Parser --> AST
    AST --> Evaluator
    Evaluator --> Output_P

    README --> UI_C
    UI_C --> BufferC
    BufferC --> TokenizerC
    TokenizerC --> ParserC
    ParserC --> ASTC
    ASTC --> EvaluatorC
    EvaluatorC --> Output_C

    classDef process fill:#f9f,stroke:#333,stroke-width:1px;
    classDef data fill:#ccf,stroke:#333,stroke-width:1px;
    classDef doc fill:#cfc,stroke:#333,stroke-width:1px;
```
