Consider the grammar E → E + n | E × n | n For a sentence n + n × n, the…
2005
Consider the grammar
E → E + n | E × n | n For a sentence n + n × n, the handles in the right-sentential form of the reduction are
- A.
n, E + n and E + n × n
- B.
n, E + n and E + E × n
- C.
n, n + n and n + n × n
- D.
n, E + n and E × n
Attempted by 123 students.
Show answer & explanation
Correct answer: D
Rightmost derivation:
E ⇒ E × n (apply production E → E × n)
E × n ⇒ E + n × n (apply production E → E + n)
E + n × n ⇒ n + n × n (apply production E → n)
Rightmost reductions (handles encountered):
First handle: the leftmost 'n'. Reducing this 'n' to E produces E + n × n.
Second handle: 'E + n'. Reducing 'E + n' to E produces E × n.
Third handle: 'E × n'. Reducing 'E × n' to E completes the reduction to the start symbol.
Therefore the handles (in the order encountered during rightmost reductions) are: n, E + n, and E × n.