summaryrefslogtreecommitdiff
path: root/src/rpn.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpn.rs')
-rw-r--r--src/rpn.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/rpn.rs b/src/rpn.rs
index 19d62ed..6ac0dec 100644
--- a/src/rpn.rs
+++ b/src/rpn.rs
@@ -1,5 +1,6 @@
use std::collections::HashMap;
+/// Available RPN operations
pub enum RpnOperation {
Add,
Subtract,
@@ -23,6 +24,11 @@ fn rpn_match_op(c: char) -> Option<RpnOperation> {
_ => None,
}
}
+
+/// Evaluates an expression in Reverse Polish Notation
+///
+/// Returns `f32` arithmetic result if the expression can be parsed
+/// Returns `Err` with a message if the RPN expression is malformed
pub fn eval(rpn_str: String, var_map: HashMap<char, f32>) -> Result<f32, String> {
let mut stack: Vec<f32> = vec![];
for (_i, ch) in rpn_str.chars().enumerate() {