A library to handle Reverse Polish notated
expressions.
Ripin can also evaluate variable expressions and is not limited to string tokens, it can handle any iterator type, the only limit is your imagination. There is examples
to understand how to implement your own expression from custom types.
Ripin is available on crates.io and can be included in your Cargo enabled project like this:
toml
[dependencies]
ripin = "0.1"
Then include it in your code like this:
rust
extern crate ripin;
Ripin can evaluate Reverse Polish Notated
expressions.
```rust use ripin::expression::FloatExpr;
let exprstr = "3 4 + 2 *"; // (3 + 4) * 2 let tokens = exprstr.split_whitespace();
let expr = FloatExpr::
println!("Expression {:?} gives {:?}", expr_str, expr.evaluate()) ```
It is also possible to use variables in your expressions to make them more "variable".
```rust use std::collections::HashMap; use ripin::evaluate::VariableFloatExpr; use ripin::variable::IndexVar;
let mut variables = HashMap::new(); // using a Vec is the same variables.insert(0, 3.0); variables.insert(1, 500.0);
let exprstr = "3 $1 + 2 * $0 -"; // (3 + $1) * 2 - $0 let tokens = exprstr.split_whitespace();
let expr = VariableFloatExpr::
let result = expr.evaluatewithvariables(&variables);
println!("Expression {:?} gives {:?}", expr_str, result); // Ok(1003) ```