use stack to check whether all brackets matched