Interactive calculator written in C with operation history and a custom expression processing pipeline.
- TUI
- Full expression evaluation with operator precedence
- Operation history tracking
- Input validation and sanitization
- Division by zero detection
Every expression goes through a multi-stage pipeline before producing a result:
Raw Input → Sanitizer → Lexer → Parser → Result
| Stage | Description |
|---|---|
| Sanitizer | Validates and cleans input — only digits, spaces, +-*/() allowed |
| Lexer | Tokenizes the expression using strtod for number parsing |
| Parser | Recursive descent parser with operator precedence, evaluates directly |
Input: 12 + 35 * (4 - 2)
Tokens: NUMBER(12) PLUS NUMBER(35) MULTIPLY LEFT_PAREN NUMBER(4) MINUS NUMBER(2) RIGHT_PAREN
Evaluation:
4 - 2 = 2
35 * 2 = 70
12 + 70 = 82
Result: 82
├── main.c # Entry point
├── cli.c / cli.h # User interface (interactive menu)
├── sanitizer/ # Input validation
├── lexer/ # Tokenization
├── parser/ # Parsing and evaluation
├── history/ # Operation history
└── CMakeLists.txt # Build configuration
| Operation | Symbol |
|---|---|
| Addition | + |
| Subtraction | - |
| Multiplication | * |
| Division | / |
| Nested parentheses | () |
| Unary negation | - |
Precedence order: () > unary - > * / > + -
mkdir build && cd build
cmake ..
cmake --build .
./Calculator- CMake 3.x+
- C11 compiler