Operator precedence needs to get applied at parsing time, before you get a tree. 1 + 2 * 1 needs to get parsed to
(+)
/ \
(1) (*)
/ \
(2) (1)
The tree representation is unambiguous and once you get that there's no need to think about precedence.There's many ways to do this parsing, e.g. https://matklad.github.io/2020/04/13/simple-but-powerful-pra...