Assuming you are asking how to parse expressions built from operators with different priorities and associativity - absolutely.
One effective approach is called “top-down operator priority”, or maybe “operator priority” and parsing “priority”. Here are some good sources that explain the approach in detail:
Actually very neat is how little code it really takes.
Key concepts:
prefix vs infix vs mixfix
priority: 3 + 4 * 5 analyzed as (3 + 4) * 5 or 3 + (4 * 5) ?
associativity: x - y - z analyzed as x - (y - z) or (x - y) - z ?
By the way, I recently studied this material and eventually wrote an article on my blog about a similar approach to parsing operators, which you can find here . In my approach, I deal with the operations infix, prefix, postfix and mixfix (i.e. ? : ; priorities and associativity are indicated in the tables; I use the stack to track statements whose operands have not yet been found. The parser then creates a parse tree where each node is a subexpression.
source share