Checking whether paranthesizing in an expression is balanced