m_calc
m_calc
is a Rust crate for calculating mathematical expressions in strings.
For instance, a string like "2*3^(4-2)+14%3"
should be calculated to 20
It also supports mathematical functions like: \sqrt(3.14159)
is approximately 0
And variables: "a=10;5+a"
-> 15
Usage
Add to cargo project
Parse a string into a vector of tokens, and calculate the vector of tokens.
use ;
use HashMap;
let tokens = tokenize.unwrap;
let mut context = new; // The `context` is where variable assignments are stored
let res = calculate.unwrap;
println!; // `display` is a method of `Token`s that displays it as a simple expression (like `10`, or `a`)
assert_eq!;