I'm sure you could interpret certain laws that state your car should be in a fit state to drive especially on motorways. If it could be proved that you purposely went on the motorway knowing you didnt have enough petrol to complete your journey you could get done for stopping on the motorway - doubt it though! Be interesting to know if anyone has been done for such a thing!
Not against the law, just careless. If it happened on a motorway, apart from the potential danger you put yourself and others in, it will cost you a small fortunr to get a gallon out to you or get your vehicle removed.
I
But think what happens when the engine stops at 70mph or descending a winding hill. First thing you notice is NO STEERING (not quite true but it sure as heck feels like it). So you hit the brakes, the car starts to slow. You try the brakes again - this time NO BRAKES (again not quite true but almost).
If you then can bring the car to a halt safely without damage / injury / or scaring someone else to death then you have still broken no laws. However you will then have to prepare yourself for buying the most expensive gallon of petrol in a lifetime.
Actually there is a worse case - my daughter's boyfriend did a similar thing and bought a gallon of diesel by mistake.