GATE | GATE-CS-2002 | Question 43
The C language is:
(A) A context free language
(B) A context sensitive language
(C) A regular language
(D) Parasble fully only by a Turing machine
Answer: (B)
Explanation: C and C++ are context-sensitive languages.
There are several reasons:
- To parse C and C++, you start by using a very powerful preprocessor. These preprocessors are inevitably written by hand (they are not based on a theoretic foundation like regular expressions or context-free grammars).
- The grammar is ambiguous: it has LR conflicts, such as the if-then-else conflict. Parsers typically resolve this using context (an “else” matches the closest “if”).
- C and C++ lexers require lexical feedback to differentiate between typedef names and identifiers. That is, the context-sensitive lexer needs help from the “context-free” parser to distinguish between an identifier “foo” and a typedef name “foo”. In this snippet,
int foo; typedef int foo; foo x;
the first “foo” is an identifier while the second and third are typedef names. You need to parse typedef declarations to figure this out (and since types have nested parentheses, this is definitely at least as hard as parsing a context-free language).
This means that the parser and lexer are mutually recursive, so it doesn’t make sense to say that the parser is context free while the lexer is context sensitive.
Ref: C and C++ are not context free
Recommended Posts:
- GATE | GATE-CS-2015 (Mock Test) | Question 2
- GATE | GATE-CS-2015 (Mock Test) | Question 17
- GATE | GATE-CS-2015 (Mock Test) | Question 4
- GATE | GATE-CS-2015 (Mock Test) | Question 5
- GATE | GATE-CS-2015 (Mock Test) | Question 10
- GATE | GATE-CS-2015 (Mock Test) | Question 10
- GATE | GATE-CS-2015 (Mock Test) | Question 8
- GATE | GATE-CS-2015 (Mock Test) | Question 9
- GATE | GATE-CS-2015 (Mock Test) | Question 10
- GATE | GATE-CS-2015 (Mock Test) | Question 11
- GATE | GATE-CS-2015 (Mock Test) | Question 17
- GATE | GATE-CS-2015 (Mock Test) | Question 13
- GATE | GATE-CS-2015 (Mock Test) | Question 14
- GATE | GATE-CS-2015 (Mock Test) | Question 17
- GATE | GATE-CS-2015 (Mock Test) | Question 16



