I try to unterstand the Chomsky hierarchy with the different levels.
I checked some examples and here is one I don't really understand. Maybe someone knows why this one is not a context-sensitive language:
S → aA
A → aA | ε
B → bA
I try to unterstand the Chomsky hierarchy with the different levels.
I checked some examples and here is one I don't really understand. Maybe someone knows why this one is not a context-sensitive language:
S → aA
A → aA | ε
B → bA
The grammar
Gthat you provide is, beyond any doubt, context free (each rule has one non-terminal in the LHS and a string of terminals and non-terminals in the RHS). Therefore, the languageLthat it generates is context free. Therefore, as the category of context-free languages is a proper subset of that of context-sensitive languages, languageLis context sensitive. (I don't know where you read that languageLis not context sensitive. Either you misread this or what you read is simply wrong.)I will make a guess about the reason of this confusion. Let us suppose that you had claimed that grammar
G(not languageL) is not context sensitive. Now, perhaps curiously enough, if a language is context sensitive this does not mean that all grammars producing this language are context sensitive (and the same is true for the other categories as well, except of course the unrestricted one). If a language is context sensitive, this means that there is a context-sensitive grammar producing it. So, even ifLis context sensitive, this does not necessarily mean thatGis also context sensitive.It would however be weird if
G, a context-free grammar, were not context sensitive. Whether this is or is not true depends on your exact definition of a context-sensitive grammar. As you can read, e.g., in the related Wikipedia article, there are at least two alternative definitions for context-sensitive grammars:According to definition 1, grammar
Gis context sensitive (the context strings α and β being trivially empty). According to definition 2, however, grammarGis not, because of the empty production rule for non-terminal A, which is not the start symbol.It is however possible to provide an equivalent grammar
G', which is context sensitive according to both definitions and produces the same languageL. One such grammar can be constructed as follows:A produces strings of zero or more "a". We can replace its definition by:
where A' produces strings of one or more "a". Notice that the rules for A are not recursive. We can substitute the productions for A in the rules for S and B and then eliminate the non-terminal A. This gives us:
This grammar (which can be further simplified by noticing that A' and S produce the same language) is context sensitive according to both definitions above.