Methods for checking validity of expressions