a rightmost derivation
The mirror image of the leftmost discipline: when several variables wait to be expanded, a rightmost derivation always rewrites the RIGHTMOST one first. If leftmost means filling the blanks strictly from the left, rightmost means always reaching for the last blank. It is the same idea of imposing order, just from the other end.
Formally, a derivation is rightmost if at every step the production is applied to the rightmost variable occurring in the current sentential form, sometimes marked =>rm. With E → E + E | a, one rightmost derivation of a + a is E =>rm E + E =>rm E + a =>rm a + a, where the right E is expanded before the left E. Just like the leftmost case, fixing 'rightmost' removes the freedom to reorder which variable to attack, leaving only the choice of which rule.
A rightmost derivation also corresponds one-to-one with a parse tree (for a given tree there is exactly one rightmost derivation), so it is an equally valid way to read off structure. Its special importance is in bottom-up parsing: an LR parser effectively constructs a rightmost derivation IN REVERSE, recognising the right-hand sides of rules (the handles) one at a time as it reduces the input back toward the start symbol. The rightmost derivation read backwards is why bottom-up parsing is often called 'canonical'. Do not assume the rightmost derivation of a string equals its leftmost one as a sequence — they usually differ as sequences while describing the same tree.
Grammar S → A B, A → a, B → b B | b. Rightmost derivation of 'abb': S =>rm A B =>rm A b B =>rm A b b =>rm a b b. Each step expands the rightmost variable (B fully before A).
Always rewrite the rightmost variable; bottom-up (LR) parsing builds a rightmost derivation in reverse.
Leftmost and rightmost are two disciplines for the SAME notion of derivation; both correspond one-to-one with parse trees. Their step sequences usually differ even when they describe the same tree.