---
# System prepended metadata

title: Evaluating Mathematical Expressions

---

# Evaluating Mathematical Expressions

```
for char c in expression
    if c is operator
        push to 'op stack'
    else if c is number
        if next operator has higher priority
            push to 'number stack'
        else
            a, b = pop 2 numbers from 'number stack'
            op = pop 1 operator from 'op stack'
            result = a op b
            push result to 'number stack'
    else
        do nothing
```