A right-sentential form is a sentential form that occurs in the rightmost derivation of some sentence.
$E \rightarrow E + n \mid E \times n \mid n$
$n + n \times n$
Deriving the above string with rightmost derivation,
$E$
$E \times n$
$E + n \times n $
$n + n \times n$
But right sentential form is the reverse of rightmost derivation,
$n + n \times n$
$E + n \times n$
$E \times n$
$E$
but why reverse?
While pushing terminals to the stack, handles appear at the top of stack which are reduced with appropriate production,
In this question n is pushed then reduced to E, so n is a handle, next + will be pushed oops no match,
next n will be pushed, Stack elements $E + n$ , where $n$ is on the top
This is a handle which will be reduced by $E \rightarrow E +n$
Now stack contents are $E$
pushed $ \times $ and $n$
Elements in stack are, $E \times n$, where n is on the top
$E \times n$ is a handle and will be reduced with $E \rightarrow E \times n$.
So we got 3 handles in this reduction,
- $n$
- $E \times n$
- $E + n$