Iran has warned that it would have no alternative but to acquire a nuclear weapon if attacked by the United States or its allies.