Editors often put these two lines in quotation marks, as if it were a quotation from a ballad or other source, but I think Hamlet is just improvising a little verse for the occasion.