Skip to content

Term Resolution

Dave DeLong edited this page Sep 13, 2015 · 1 revision

After grouping tokens into terms, the terms are resolved.

Resolution is the process during which the final order of operations is determined. The process is quite simple: the root group term is asked to resolve itself.

It does this by iterating all of its subterms and finding the indexes of the operators with the highest precedence. If multiple operators match, then one of the operators will be picked, depending on the associativity of the operator. (If the operator is left associative, then the leftmost occurrence is chosen. If the operator is right associative, then the rightmost occurrence is chosen.)

With the operator chosen, the term then finds the operands to the operator. Each operand is asked to resolve itself, if necessary. With the resolved operands in hand, the operator is transformed into a function term, with the operands as arguments, and marked as fully resolved.

This recursive process continues as long as root group term has more than one subterm (or it has no operators left).

This process varies slightly for function terms (such as the ones for "max(1, 2, 3+4)"), where the presence of the comma warrants some extra considerations. A function term is considered fully resolved if all of its subterms are resolved, but there can be as many subterms as necessary. This is in contrast to a group term, which only has one subterm after resolution completes.

After the terms are entirely resolved, the entire structure can be converted into an expression.