check if an expression is legal