Check validity of parentheses