Not legally, and if you're not careful it can go from a suicide cord to a homicide cord. If you're still connected to the grid while you use one, it can backfeed and fry a lineman who was working on what they thought was a disconnect line.
The proper way to do it is to get a transfer switch, which disconnects you from mains before you can connect to a generator.