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

  1. A.

    n, E + n and E + n × n

  2. B.

    n, E + n and E + E × n

  3. C.

    n, n + n and n + n × n

  4. D.

    n, E + n and E × n

Attempted by 123 students.

Show answer & explanation

Correct answer: D

Rightmost derivation:

  1. E ⇒ E × n (apply production E → E × n)

  2. E × n ⇒ E + n × n (apply production E → E + n)

  3. 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.

Explore the full course: Gate Guidance By Sanchit Sir