A stack can be used to check whether an arithmetic expression such as
has properly balanced parentheses. Break the expression into its individual parts.
3 * ( 4 + ( 5 - 6 ) ) / 7
Push each part on a stack as it is encountered. When a ) is encountered, pop everything until the matching (. If the stack is prematurely empty, then report an error.
At the end, there should be no parentheses left. Otherwise, report an error.