# panagiotisptr/calculator-cpp architecture

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

- Interactive diagram: https://gitdiagram.com/panagiotisptr/calculator-cpp
- Repository: https://github.com/panagiotisptr/calculator-cpp

## Overview

This is a small C++ expression calculator. A user supplies an expression through the command-line app; the Calculator interface tokenizes it, converts the tokens from infix to postfix, builds an AST, and evaluates that tree to produce a numeric result. Tokens and calculator exceptions support those stages. The README documents this workflow; relationships among the core stages are also visible in the sampled implementation. The lexer implementation was read, but its caller’s orchestration is documented in the README and Calculator header rather than a sampled implementation file.

Main entry points: [`src/Calculator.h`](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Calculator.h) (Calculator interface), [`src/Lexer.cpp`](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Lexer.cpp) (Lexer), [`src/Parser.cpp`](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Parser.cpp) (Shunting-yard parser), [`src/AST.h`](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/AST.h) (AST builder and evaluator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_cli["Command-line app<br/>[main.cpp]"]
  node_calculator["Calculator interface<br/>[Calculator.h]"]
end

subgraph group_expression["Expression processing"]
  node_lexer["Lexer<br/>[Lexer.cpp]"]
  node_tokens["Tokens<br/>[Token.h]"]
  node_parser["Shunting-yard parser<br/>[Parser.cpp]"]
end

subgraph group_evaluation["Tree evaluation"]
  node_ast["AST builder and evaluator<br/>[AST.h]"]
  node_exceptions["Calculator exceptions<br/>[Exceptions.h]"]
end

node_user(("User"))

node_user -->|"enters expression"| node_cli
node_cli -->|"calls"| node_calculator
node_calculator -->|"tokenizes input"| node_lexer
node_lexer -->|"produces"| node_tokens
node_calculator -->|"parses tokens"| node_parser
node_parser -->|"uses"| node_tokens
node_calculator -->|"builds and evaluates"| node_ast
node_ast -->|"builds from"| node_tokens
node_lexer -->|"throws syntax errors"| node_exceptions
node_parser -->|"throws syntax errors"| node_exceptions
node_ast -->|"throws evaluation errors"| node_exceptions
node_calculator -->|"returns result"| node_user

click node_cli "https://github.com/panagiotisptr/calculator-cpp/blob/master/src/main.cpp"
click node_calculator "https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Calculator.h"
click node_lexer "https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Lexer.cpp"
click node_tokens "https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Token.h"
click node_parser "https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Parser.cpp"
click node_ast "https://github.com/panagiotisptr/calculator-cpp/blob/master/src/AST.h"
click node_exceptions "https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Exceptions.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_calculator,node_user toneBlue
class node_lexer,node_tokens,node_parser toneAmber
class node_ast,node_exceptions toneMint
```

## Components

### User interface

- [Command-line app](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/main.cpp): `src/main.cpp`
- [Calculator interface](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Calculator.h): `src/Calculator.h`

### Expression processing

- [Lexer](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Lexer.cpp): `src/Lexer.cpp`
- [Tokens](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Token.h): `src/Token.h`
- [Shunting-yard parser](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Parser.cpp): `src/Parser.cpp`

### Tree evaluation

- [AST builder and evaluator](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/AST.h): `src/AST.h`
- [Calculator exceptions](https://github.com/panagiotisptr/calculator-cpp/blob/master/src/Exceptions.h): `src/Exceptions.h`

### Other components

- **User**

## Connections

- User → Command-line app: enters expression (evidence: `README.md`)
- Command-line app → Calculator interface: calls (evidence: `src/main.cpp`)
- Calculator interface → Lexer: tokenizes input (evidence: `src/Calculator.h`)
- Lexer → Tokens: produces
- Calculator interface → Shunting-yard parser: parses tokens (evidence: `src/Calculator.h`)
- Shunting-yard parser → Tokens: uses
- Calculator interface → AST builder and evaluator: builds and evaluates (evidence: `src/Calculator.h`)
- AST builder and evaluator → Tokens: builds from (evidence: `src/AST.h`)
- Lexer → Calculator exceptions: throws syntax errors (evidence: `src/Lexer.cpp`)
- Shunting-yard parser → Calculator exceptions: throws syntax errors (evidence: `src/Parser.cpp`)
- AST builder and evaluator → Calculator exceptions: throws evaluation errors (evidence: `src/AST.h`)
- Calculator interface → User: returns result (evidence: `README.md`)
