Except that the PHB, page 193-194 only has three steps to an attack, and the final step includes both the roll to hit and dealing damage.
MAKING AN ATTACK
Whether you're striking with a melee weapon, firing a weapon at range, or making an attack roll as part of a spell, an attack has a simple structure.
1. Choose a target. Pick a target within your attack's range: a creature, an object, or a location.
2. Determine modifiers. The DM determines whether the target has cover and whether you have advantage or disadvantage against the target. In addition, spells, special abilities. and other effects can apply penalties or bonuses to your attack roll.
3. Resolve the attack. You make the attack roll. On a hit, you roll damage, unless the particular attack has rules that specify otherwise. Some attacks cause special effects in addition to or instead of damage.
It stand to reason that since Uncanny Dodge does not specify that it interrupts in the same way that the Shield spell does, it would only be allowed after the final step, based upon what the DMG specifies about timing...but by that point, the special effect from Shocking Grasp has rendered the target unable to take a reaction, so Uncanny Dodge cannot be used.
If you scroll up to my post at the top of the page,
#73, you'll see that I've highlighted the same excerpt, but from the Basic Rules document.
Step 3 - Resolve the attack - is broken down as "You make the attack roll. On a
hit, you roll damage,
unless the particular attack has rules that
specify otherwise.
Some attacks cause special effects in addition to or instead of damage."
If I were to nitpick, I could say the grammar of the entry determines the order of sequence, with periods indicating stops in the sequence and commas indicating pauses: roll the attack [stop], determine whether it hit [pause], roll damage, if applicable [stop], apply special effects, if applicable [stop]. In that interpretation, there are clear breaks in the sequence that would provide instances for a triggered reaction to occur.
Another way to look at it is with the three reaction spells in 5e that trigger off an attack in some way (excluding
Counterspell, as it is triggered by the casting of a spell, prior to attack rolls and damage):
Absorb Elements,
Hellish Rebuke, and
Shield. I'll get to
Uncanny Dodge after.
Absorb Elements, from the Elemental Evil Players Companion, is cast as a reaction when triggered by specifically by
damage of types indicated in the casting time. The description goes further to indicate the effects of the spell
retroactively resisting the damage that triggered the casting of the spell.
Hellish Rebuke, on the other hand, is triggered by
damage, and the casting time specifies that the spell is cast in
response to the damage.
Shield is cast as a reaction when triggered by a
hit. The spell's effect goes on to stipulate that if the AC boost would increase the AC higher than the attack roll that had hit the caster, it
retroactively negates the hit.
As shown above,
Shield is triggered specifically by a
hit, while
Absorb Elements and
Hellish Rebuke are both triggered by
damage -- as such, they can be considered separate events. To go further,
Shield, being triggered by the
hit event, takes effect a mere millisecond before the
damage and effects event is resolved,
retroactively negating the
hit before the subsequent results occur.
Absorb Elements is, on the otherhand, triggered by a
damage event, which occurs after the
hit event, and
retroactively resists the
damage that has occurred.
Hellish Rebuke is also triggered by a
damage event, which occurs after the
hit event, and is cast in response to the
damage event, as specified by the spell.
Meanwhile,
Uncanny Dodge is another reaction triggered by a
hit event, much like
Shield, in that being triggered by the
hit event, takes effect a mere millisecond before the
damage and effects is resolved, with the effect halving the damage of the subsequent
damage included in the
damage and effects event in the sequence.
When the attack potentially triggering the reaction is
Shocking Grasp, I would consider them in this way at my table:
A tiefling wizard 1/rogue 5
hit with
Shocking Grasp, could react to the
hit event trigger with either
Shield or
Uncanny Dodge, since both trigger off of the
hit event, prior to the occurrence of the
damage and effects event. However, if said character did not use or could not use an available reaction prior to the
damage and effects event subsequently taking place, that character would not be able to use a reaction to activate either
Absorb Elements or
Hellish Rebuke, as their Casting Time entries specify that their triggers are that the
damage event, as included in the
damage and effects event has already taken place -- at which point, the results of the
Shocking Grasp prevent the target from taking subsequent reactions.
But that's just my table -- another DM might interpret it differently, and that ruling would stand at that DM's table.