diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 8f0d4e6..06d650e 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -170,6 +170,9 @@ fn to_postfix(tokens: Vec<Token>) -> Result<Vec<Token>, String> { | |||
170 | Token::Num(_) => { | 170 | Token::Num(_) => { |
171 | postfixed.push(token); | 171 | postfixed.push(token); |
172 | }, | 172 | }, |
173 | Token::Function(_) => { | ||
174 | op_stack.push(token); | ||
175 | } | ||
173 | Token::Operator(current_op) => { | 176 | Token::Operator(current_op) => { |
174 | while let Some(top_op) = op_stack.last() { | 177 | while let Some(top_op) = op_stack.last() { |
175 | match top_op { | 178 | match top_op { |
@@ -185,6 +188,9 @@ fn to_postfix(tokens: Vec<Token>) -> Result<Vec<Token>, String> { | |||
185 | break; | 188 | break; |
186 | } | 189 | } |
187 | } | 190 | } |
191 | Token::Function(_) => { | ||
192 | postfixed.push(op_stack.pop().unwrap()); | ||
193 | } | ||
188 | _ => { | 194 | _ => { |
189 | return Err(format!("Unexpected match branch part 2")) | 195 | return Err(format!("Unexpected match branch part 2")) |
190 | } | 196 | } |
@@ -218,6 +224,7 @@ fn to_postfix(tokens: Vec<Token>) -> Result<Vec<Token>, String> { | |||
218 | while let Some(op) = op_stack.pop() { | 224 | while let Some(op) = op_stack.pop() { |
219 | postfixed.push(op); | 225 | postfixed.push(op); |
220 | } | 226 | } |
227 | println!("{:?}", postfixed); | ||
221 | Ok(postfixed) | 228 | Ok(postfixed) |
222 | } | 229 | } |
223 | 230 | ||
@@ -238,6 +245,11 @@ fn eval_postfix(postfixed: Vec<Token>) -> Result<f64, String> { | |||
238 | } else { | 245 | } else { |
239 | return Err(format!("Too many operators, Too little operands")) | 246 | return Err(format!("Too many operators, Too little operands")) |
240 | } | 247 | } |
248 | }, | ||
249 | Token::Function(funct) => { | ||
250 | if let Some(arg) = num_stack.pop() { | ||
251 | num_stack.push(funct.apply(arg)) | ||
252 | } | ||
241 | } | 253 | } |
242 | _ => { | 254 | _ => { |
243 | return Err(format!("Yo nibba how did this get here")) | 255 | return Err(format!("Yo nibba how did this get here")) |