Consider a Grammar E \(\rightarrow \) E +n | Exn | n for a sentence n + n x n,…
2023
Consider a Grammar E \(\rightarrow \) E +n | Exn | n for a sentence n + n x n, the handles in the right-sentential form of the reduction are ?
- A.
n,E+n and E+nxn
- B.
n,E+n and E+Exn
- C.
n,n+n and n+nxn
- D.
n,E+n and Exn
Attempted by 150 students.
Show answer & explanation
Correct answer: D
Key insight: handles are the substrings that match the right-hand side of a production and whose reduction (in reverse of a rightmost derivation) yields the previous right-sentential form.
For the grammar E -> E + n | E x n | n and the sentence:
n + n x n
First handle: "n" (the leftmost n). Reduce this "n" to E using E -> n to get the sentential form E + n x n.
Second handle: "E+n" (the prefix in E + n x n). Reduce "E+n" to E using E -> E + n to get E x n.
Third handle: "Exn" (E x n). Reduce "Exn" to E using E -> E x n to reach the start symbol E.
Therefore the sequence of handles encountered during the reduction is: n, E+n, Exn.
A video solution is available for this question — log in and enroll to watch it.