GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 51

Matching language patterns to compiler requirements

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2008 paper

GATE 2008, Q51 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 51, GATE 2008: Match E: checking identifiers are declared before use; F: agreement of numbers of formal and actual function parameters; G: arithmetic expressions with matched parentheses; H: palindromes. Models: P={a^n b^m c^n d^m | n,m≥1}; Q: X→XbX|XcX|dXf|g; R={wcw | w∈{a,b}*}; S: X→bXb|cXc|ε.

(A) E–P,F–R,G–Q,H–S
(B) E–R,F–P,G–S,H–Q
(C) E–R,F–P,G–Q,H–S
(D) E–P,F–R,G–S,H–Q
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. The matching is E–R, F–P, G–Q, H–S, option C. E requires the same identifier string in declaration and use, modeled by the copy language wcw.
2. F matches counts of formal and actual parameters; an bm cn dm models the two cross-referenced counts. G is modeled by X→XbX | XcX | dXf | g: b and c act as binary operators, d/f as matched opening/closing parentheses, and g as an operand.
3. H is modeled by X→bXb | cXc | ε, which generates even-length palindromes. These are structural analogies, not claims that the small grammars capture every feature of a programming language or all odd-length palindromes.

Original paper, page 9