check parentheses are valid