check validity of arithmetic expression using stack