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 \times n + 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 $\times$ will be pushed oops no match,
next n will be pushed, Stack elements $E \times n$ , where $n$ is on the top
This is a handle which will be reduced by $E \rightarrow E \times n$
Now stack contents are $E$
pushed $ + $ and $n$
Elements in stack are, $E + n$, where n is on the top
$E + n$ is a handle and will be reduced with $E \rightarrow E + n$.
So we got 3 handles in this reduction,
- $n$
- $E \times n$
- $E + n$