'Is C# considered a context free language?
I have been looking for this, but there is a lot of different answers to this question on the MSDN forums.
Some people say that "All computer language grammars are context free" and others say that any language that has white-space sensitive syntax is likely context-sensitive and therefore not context-free (F# and Python).
Whould be nice a definitive answer and maybe some proof.
Solution 1:[1]
C# is not context free. Consider the input sequence '>>' in these contexts:
List<List<int>> foo;
int x = 1234 >> 1;
in the first case the lexer returns a separate token for each '>'. It's OK to put white space or even a comment between them. 'List<List /* comment */ >' is a perfectly valid type!
In the second case the lexer returns a single token for the operator '>>' (and also for '>>='). The expression '1234 > > 1' will produce a syntax error.
The lexer needs to know if the context is of a type or an expression, therefore C# is not context free grammar,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Itai Nahshon |
