Robin Williams performed in cap and gown yesterday, with an impromptu address lampooning Jesse Helms and Dan Quayle at graduation ceremonies for the Juilliard School.

Mr. Williams, a former Juilliard student who received an honorary doctorate, opened his five-minute monologue with a parody of an actor on an audition. "Hello. My name is Robin Williams, and I would like to do something from 'Hamlet,' " he told the crowd in Alice Tully Hall. "To be or . . . Wait! I know this!"

Besides Mr. Williams, who left Juilliard in 1976 after spending three years in its drama division, the school awarded four other honorary doctorates at its 86th commencement. The recipients were United States Senator Daniel Patrick Moynihan, who delivered the commencement address; the violinist Issac Stern; Eliot Feld, the choreographer and director of the New Ballet School, and Jerome L. Greene, a Juilliard trustee and philanthropist. The five were recognized for their "distinguished contributions to the performing arts."

In a speech on artistic freedom, Senator Moynihan told the 220 graduates, "The answer to the danger of political interference, then, is not to deny that it exists, but rather to be prepared to resist it."

Mr. Williams, whose address replaced the traditional speech by Joseph W. Polisi, Julliard's president, performed an impression of Senator Jesse Helms examining Robert Mapplethorpe's photographs.

The comedian also provided his definition of "frightening times."

"That would be, 'President Quayle, raise your right hand. No, your other right hand,' "

He closed his talk by encouraging the students to stand up for their art. "You have that spark. Don't let them put it out. It's in there. You've got it."

Photo: The Julliard commencement featured a former student, Robin Williams, left in an impromptu performance. With him at ceremony were Senator Daniel Patrick Moynihan, right, and the violinist Isaac Stern. (Neal Boenzi/The New York Times)