Skip to content

ISRO Scientist/Engineer CSE 2018Compiler Design › Parsing

ISRO Scientist/Engineer CSE 2018 PYQ: A particular BNF definition for a "word is given by the following rules. <word> :: = <letter> | <letter>…

A particular BNF definition for a "word is given by the following rules.

<word>      :: = <letter> | <letter> <charpair> | <letter> <intpair>
<charpair>  :: = <letter> <letter> | <charpair> <letter> <letter>
<intpair>   :: = <integer> <integer> | <intpair> <integer> <integer>
<letter>    :: = a | b | c | ...... | Y | Z
<integer>   :: = 0 | 1 | 2 | ...... | 9

Which of the following lexical entries can be derived from $\textsf{< word >}?$

  1. pick
  2. picks
  3. $\textsf{c44}$
  1. A
    I, II and III
  2. B
    I and II only
  3. C
    I and III only
  4. D
    II and III only
    Correct answer

Answer

(D) II and III only

Approach

The grammar is:
<word> ::= <letter> | <letter><charpair> | <letter><intpair>
<charpair> ::= <letter><letter> | <charpair><letter><letter>
<intpair> ::= <integer><integer> | <intpair><integer><integer>

Key structural facts:

  1. <charpair> generates strings of letters whose length is always EVEN (2, 4, 6, ...). The base rule gives 2 letters; the recursive rule adds 2 more letters each time, preserving parity.
  2. <intpair> generates strings of digits whose length is always EVEN (2, 4, 6, ...), by the same parity argument.
  3. Consequently a <word> can be: (a) exactly one letter; (b) one letter followed by an even number (≥2) of letters, giving an ODD total letter count (1, 3, 5, ...); or (c) one letter followed by an even number (≥2) of digits. A word can never be an even-length all-letter string, and never mixes letters with digits except in the single-letter-then-digits form.

Now test each entry:
I. "pick" — 4 letters, which is even. It is not a single letter, and letter+charpair forces an odd total. Letters alone must be odd in number. So I is NOT derivable.
II. "picks" — 5 letters (odd ≥3). Derive as letter + charpair with a 4-letter charpair: p + (i c) + (k s) = p i c k s. Derivable.
III. "c44" — one letter followed by two digits. Derive as letter + intpair with the base intpair giving 4 and 4: c + 4 + 4. Derivable.

Only II and III are derivable, matching option D. The attached derivation confirms picks via <letter><charpair> and c44 via <letter><intpair>. Both prior passes were correct; the self-flag was unnecessary.

Reviewed by ISRO IQ Editorial Team.