Precedence and associativity

In the above table, the precedence is listed as 1st, 2nd etc. However when implementing this algorithm, we might represent the precedence as integers where the highest (1st) precedence is the largest integer. This can cause confusion, so I would recommend abstracting this into a separate function, like isHigherPrecedence(a, b) which should say that e.g. * has a higher precedence than + but lower than ^.

Infix to Postfix

You can download and play this powerpoint to watch/hear me explain how this works.

Also, even though we do some of the additions before the division, the expression is still correctly evaluated. It is possible to intermix operations like this as long as the end result is the same.


A non-terminating example