previous | start | next

## Mutual Recursion

- To compute the value of an expression, we implement three functions `expression_value`, `term_value`, and `factor_value`.
- The `expression_value` function calls `term_value`, checks to see if the next input is `+` or `-`, and if so calls `term_value` again to add or subtract the next term.
- The `term_value` function calls `factor_value` in the same way, multiplying or dividing the factor values.
- The `factor_value` function checks whether the next input is `'('` or a digit, calling either `expression_value` recursively or returning the value of the digit.
- The termination of the recursion is ensured because the `expression_value` function consumes some of the input characters, ensuring that the next time it is called on a shorter expression.

previous | start | next