Smith is subpoenaed as a witness for the defense in a criminal case. The prosecution is allowed to treat the witness as hostile, and Smith is directed to limit his responses to yes and no. Assume that the defense attorney decides that Smith is not helping his client and sits silently during the cross-examination. Prosecution asks a question which Smith reasonably feels he lacks the legal acumen to answer without putting himself in jeopardy of prosecution for perjury. Smith invokes the 5th, but is granted immunity from prosecution and is ordered to testify. However, the one crime that immunity does not cover is perjury for that testimony. Smith clearly needs his own lawyer, but he is not "under arrest", and AFAIK has no right to an attorney to tell him whether to say "yes" or "no" to the question. Assume that the judge and the prosecutor are unsympathetic to Smith, and will only act as mandated by law on his behalf. Bear in mind that "yes" and "no" are not literally true or false taken in isolation, they only have truth value given an assumed context, which Smith fears he does not understand (but doesn't have the background to explain).
What legal mechanism exists under US law to protect Smith from placing himself in legal jeopardy in this situation? As always, case citations appreciated.