check whether parentheses are balanced