Skip to content

ClauuG21/Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧮 Calculator

Interactive calculator written in C with operation history and a custom expression processing pipeline.

C CMake

✨ Features

  • TUI
  • Full expression evaluation with operator precedence
  • Operation history tracking
  • Input validation and sanitization
  • Division by zero detection

⚙️ Processing pipeline

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

🧪 Example

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

📁 Project structure

├── 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

🔢 Supported operations

Operation Symbol
Addition +
Subtraction -
Multiplication *
Division /
Nested parentheses ()
Unary negation -

Precedence order: () > unary - > * / > + -

🚀 Build and run

mkdir build && cd build
cmake ..
cmake --build .
./Calculator

📋 Requirements

  • CMake 3.x+
  • C11 compiler

About

A simple calculator from String developed in C language.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors