Which of the following features cannot be captured by context-free grammars?
View worked solution
Answer: C
To determine which feature cannot be captured by a context-free grammar (CFG), let us analyze each option:
- A. Syntax of if-then-else statements: This can be easily defined using a CFG. For example:
- B. Syntax of recursive procedures: CFGs naturally support recursion (self-nested structures), making them perfectly suited to define recursive procedure structures.
- C. Whether a variable has been declared before its use: This is a semantic check rather than a purely syntactic one. Formally, verifying that a variable of any arbitrary name is declared before it is used is equivalent to recognizing the language: By the pumping lemma, is a well-known non-context-free language. Thus, this feature cannot be captured by a CFG and is instead handled during the semantic analysis phase using a symbol table.
- D. Variable names of arbitrary length: This can be defined even by a regular grammar (which is a subset of CFGs). For example:
Therefore, the feature that cannot be captured by context-free grammars is C.
Free practice · Your answers on this page are not saved.
