A command-line expression evaluator written in C++. Type math expressions and get instant results — supports variables, functions, constants, and expression history.
- Basic arithmetic:
+,-,*,/,^,% - Functions:
sqrt,sin,cos,tan,log,log2,ln,abs,floor,ceil - Constants:
pi,e - Variable assignment:
x = 10 - Reuse last result with
ans - Expression history
g++ -std=c++17 main.cpp tokenizer.cpp parser.cpp evaluator.cpp variables.cpp history.cpp -o mathshell
./mathshell
>> 3 + 5 * 2
= 13
>> sqrt(144)
= 12
>> x = 5
x = 5
>> x^2 + 2*x + 1
= 36
>> ans / 2
= 18
>> sin(90)
= 1
- Language: C++17
- Concepts: Object-oriented programming, operator overloading, exception handling
- Data structures: Stack (STL), unordered_map (STL), vector (STL)
- Algorithm: Dijkstra's Shunting-Yard algorithm for parsing infix expressions into postfix (RPN)
| File | What it does |
|---|---|
token.h |
Defines the Token struct and TokenType enum |
tokenizer.h/cpp |
Reads raw input string and splits it into tokens |
parser.h/cpp |
Converts infix token list to postfix using Shunting-Yard |
evaluator.h/cpp |
Evaluates postfix expression using a stack |
variables.h/cpp |
Stores and retrieves user-defined variables |
history.h/cpp |
Keeps track of past expressions and results |
main.cpp |
Handles user input, commands, and ties everything together |
tan(90)returns a very large number instead of an error (undefined mathematically)- Trig functions take input in degrees, not radians
- No support for multi-argument functions like
max(a, b)