Skip to content
Official PYQ · 2008

GATE CS 2008 Q51 — Regular and Context-free Languages

Explain with AI

Match the following:
E.Checking that identifiers are declared before their useP.L = {anbmcndm∣n ≥1,m≥1}F.Number of formal parameters in the declaration of a Q.X →XbX∣XcX∣dXf∣gfunction agrees with the number of actual parametersin a use of that functionG.Arithmetic expressions with matched pairs of R.L ={wcw∣w ∈(a∣b)∗}parenthesesH.PalindromesS.X → bXb∣ cXc ∣ϵ\small{\begin{array}{|ll|ll|}\hline \text{E.} & \text{Checking that identifiers are declared before their use} & \text{P.} & \text{$L \: = \: \left\{a^nb^mc^nd^m \mid n\: \geq1, m \geq 1\right\}$} \\ \hline \text{F.} & \text{Number of formal parameters in the declaration of a } & \text{Q.} & \text{$X\: \rightarrow XbX \mid XcX \mid dXf \mid g$} \\ \text{} & \text{function agrees with the number of actual parameters} \\ \text{} & \text{in a use of that function} \\ \hline \text{G.} & \text{Arithmetic expressions with matched pairs of } & \text{R.} & \text{$L\: = \left\{wcw\mid w \: \in \left(a\mid b\right)^* \right\}$} \\ \text{} & \text{parentheses} \\ \hline \text{H.} & \text{Palindromes} & \text{S.} & \text{$X \: \rightarrow \: bXb \mid \:cXc \: \mid \epsilon $} \\ \hline \end{array}}

Choose one option
View worked solution

Answer: C

To find the correct match, we analyze each programming language concept and its corresponding formal language representation:

  1. E → R (Checking that identifiers are declared before their use):
    Checking if an identifier is declared before its use requires matching the exact name of the identifier at two different places in the program. This is modeled by the non-context-free language: L={wcw∣w∈(a∣b)∗}L = \{w c w \mid w \in (a \mid b)^*\} where the first ww represents the declaration, cc represents the intermediate code, and the second ww represents the usage.
  2. F → P (Matching formal and actual parameters):
    When matching the number of formal parameters to actual parameters across multiple or nested function calls, we need to maintain multiple independent counts in a cross-serial manner. This is modeled by the non-context-free language: L={anbmcndm∣n≥1,m≥1}L = \{a^n b^m c^n d^m \mid n \geq 1, m \geq 1\} where the count of aa's matches cc's, and the count of bb's matches dd's.
  3. G → Q (Arithmetic expressions with matched parentheses):
    The context-free grammar: X→XbX∣XcX∣dXf∣gX \rightarrow XbX \mid XcX \mid dXf \mid g generates arithmetic expressions where bb and cc act as binary operators, gg acts as an operand, and dd and ff act as matching opening and closing parentheses (like ( and )).
  4. H → S (Palindromes):
    The grammar: X→bXb∣cXc∣ϵX \rightarrow bXb \mid cXc \mid \epsilon is the standard context-free grammar that generates even-length palindromes over the alphabet {b,c}\{b, c\}.

Thus, the correct matching is E-R, F-P, G-Q, H-S, which corresponds to option C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular and Context-free Languages questions