A command-line calculator written in Rust. Evaluates mathematical expressions with support for arithmetic, trigonometry, implicit multiplication, and operator precedence.
cargo build --releaseInteractive mode:
cargo runType expressions at the -> prompt. Type quit or exit to stop.
One-shot mode:
cargo run -- -c "2+3*4"Debug mode (shows the full evaluation pipeline):
cargo run -- -c "sin(45deg)" debug-> 2+3*4
14
-> (2+3)*4
20
-> 2(3+1)
8
-> -5+3
-2
-> sin(45deg)
0.7071067811865475
-> 2^10
1024
| Operation | Syntax |
|---|---|
| Addition | a + b |
| Subtraction | a - b |
| Multiplication | a * b |
| Division | a / b |
| Power | a ^ b |
| Trig (sin, cos, tan, cot, sec, cosec) | sin(expr) |
| Degree mode | sin(45deg) |
| Radian mode | sin(pi rad) |
| Parentheses | (expr) |
| Implicit multiplication | 2(3) = 2*(3) |
cargo build # debug build
cargo build --release # optimized release build
cargo check # type-check only
cargo clean # remove build artifactssrc/
main.rs -- CLI parsing, REPL loop
eval.rs -- Lexer, parser, infix-to-postfix, evaluator
tokens.rs -- Token definitions and operator precedence
utils.rs -- Input utilities