How danielrajchristeen/py-calculator works
Project type and purpose
• This is a standalone, command-line Python calculator application (“Py Calculator”).
• It lives entirely in a single script (main.py), with no frontend/backend split, no external services, and no persistent database. Its purpose is to read user input, compute results (basic and advanced arithmetic), maintain in-session history and memory, then print output.
File structure
• Top‐level files:
• .gitignore, LICENSE, README.md – metadata
• main.py – the entire application
• No subdirectories or modules; all logic is in main.py.
• This implies a monolithic, in-process architecture.
README for additional insights
• Features list reveals five logical capabilities:
• Basic arithmetic
• Advanced operations (exponent, modulus, sqrt)
• Memory storage (last result)
• Calculation history (session log)
• Continuous operation (loop)
• No external dependencies or services are described beyond Python’s standard library.
a. Main Components
1. CLI Interface (Input/Output)
2. Input Handler (reads/parses user commands)
3. Expression Parser (validates and tokenizes input)
4. Calculation Engine (performs arithmetic, advanced ops via math module)
5. Memory Store (holds last result for “M+”/“MR” operations)
6. History Manager (appends each calculation and result to session log)
b. Relationships & Interactions
• User types expression → CLI Interface
• CLI Interface forwards raw text → Input Handler
• Input Handler calls Expression Parser → produces AST or tokens
• Parser passes tokens → Calculation Engine → returns numeric result
• Calculation Engine updates Memory Store (if requested)
• Calculation Engine notifies History Manager to log expression+result
• CLI Interface retrieves result (and optional memory/history output) → prints to screen
• Loop back to CLI Interface for next input
c. Architectural Patterns/Design Principles
• Monolithic, single-process design
• Clear separation of concerns (parsing vs. computing vs. state management)
• Stateless engine logic with small mutable stores (memory/history)
• Synchronous, sequential flow in a REPL-style loop
d. Technologies/Frameworks
• Python 3.x runtime
• Standard library (math module for sqrt, exponent, modulus)
• No external services or frameworks
Detail without over-splitting
• This will make future refactoring (into modules/packages) or the addition of features (e.g., persistent history, GUI frontend) easier to overlay on the same architecture.