Fix parseExpression to check for invalid expressions.