Precedence-Aware Evaluation

Categories: Java, Programming

Recently I needed to take an expression represented as a list of form (term OP term OP term OP ..) and evaluate it in memory, where some operators (OP) bind more tightly (have higher precendence) than others. While the answer I came up with isn’t terribly complicated, I didn’t find it trivial to build an efficient solution either, so I’ve documented it in case I run up against this myself in a few years time - and maybe you’ll find it useful or interesting too.

See: precedence-aware evaluation algorithm.

comments powered by Disqus