Skip to content

Term Conversion

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

Term conversion is when a resolved term object is converted into the external-facing DDExpression objects. The process is very straight-forward, and with one exception, it's a one-to-one conversion.

  • Number terms become number expressions
  • Variable terms become variable expressions
  • Function terms become function expressions
  • Group terms are eliminated and return the expression of their single subterm

Group expressions do no exist, since group terms can only have a single subterm after they've been resolved. For example, consider the string:

@"1 + 2 + (3 + 4) * 5"

This will get parsed into the following terms:

(add(1, add(2, multiply((add(3, 4)), 5))))

Notice how there are two extra sets of parentheses that can be removed without introducing any ambiguity in the order of operations:

add(1, add(2, multiply(add(3, 4), 5)))

Those two extra sets of parentheses correspond to the root group term and the group term around the "(3 + 4)".

With the built expression object, we're ready to evaluate it or rewrite it.