Pay attention. Say something. Ask what you can do to help. Remember that a woman who has given birth to a dead child has given birth and is recovering physically, too. Don't be afraid of grieving parents.
For me, one of the things that really helped was other people's actual grief, the friends who made it clear that they weren't sad for me, but sad for themselves. They were looking forward to meeting this kid. They missed him.
In retrospect, I can see how brave those people were -- it's easy to worry about claiming one's own grief in the face of greater grief -- but it was the immediacy of the feelings that meant so much to me, that, and seeing that if other people were sad, then I had the right to be really sad.
Above all, don't try to hurry them into feeling better or suggest that you hope they're over it.