Context-sensitive languages (CSLs) are a class of formal languages that are more powerful than context-free languages (CFLs) but less powerful than recursively enumerable languages (RELs). They form an important class within the Chomsky hierarchy of formal languages, which classifies languages based on the complexity of the grammar used to generate them.
A context-sensitive language is a language that can be generated by a context-sensitive grammar (CSG). A context-sensitive grammar is a formal grammar where the production rules are restricted in the following way:
Each production rule in a context-sensitive grammar must have the form:
Where:
This means that the left-hand side of any production can contain both terminals and non-terminals, and the right-hand side must either be of the same length or longer than the left-hand side.
Important rule: No production may shorten the string (i.e., the length of the string on the left side of a production must not be greater than the length of the string on the right side).
Non-contracting Production Rules: The key characteristic of a context-sensitive grammar is that it doesn't allow string shortening. The length of the string on the right-hand side of any production is always greater than or equal to the length on the left-hand side.
More Powerful than CFLs: Context-sensitive languages are strictly more powerful than context-free languages. That is, all context-free languages are context-sensitive, but there exist context-sensitive languages that cannot be described by context-free grammars.
Equivalence to Linear Bounded Automata: A language is context-sensitive if and only if it can be recognized by a linear bounded automaton (LBA). An LBA is a type of Turing machine that operates within a space bound that is linearly proportional to the input size. This makes context-sensitive languages exactly the class of languages that are decidable by a linear bounded automaton.
Decidability: Context-sensitive languages are decidable. There is an algorithm that can decide whether a given string is a member of a context-sensitive language. This is in contrast to recursively enumerable languages, where there may not be an algorithm to decide membership in the language (as is the case with the halting problem).
Here is an example of a context-sensitive grammar:
Let’s consider the language , which consists of strings of the form "a's followed by b's followed by c's", where the number of a's, b's, and c's are all equal.
A context-sensitive grammar for this language might look like this:
Notice that this grammar is context-sensitive because the left-hand side of the rules may involve more than just a single non-terminal, and the length of the string on the right-hand side is at least as long as the string on the left-hand side.
Here is an example of a rule that shows context sensitivity:
This demonstrates the need for a "context" to determine the replacement of symbols, which is the distinguishing feature of context-sensitive grammars compared to context-free grammars.
An important aspect of context-sensitive languages is that they are recognizable by Linear Bounded Automata (LBA), which are Turing machines with a space bound. An LBA is similar to a Turing machine but with the restriction that it can only use an amount of tape that is linearly proportional to the size of the input. This restriction ensures that the language is decidable.
An LBA simulating the context-sensitive language might work by:
The fact that the LBA only uses a linear amount of space (proportional to the input size) is a key constraint that ties the language to context-sensitive grammars.
Context-Sensitive Languages vs Context-Free Languages: Context-sensitive languages are strictly more powerful than context-free languages (CFLs). There are languages that can be described by context-sensitive grammars but cannot be described by context-free grammars. For example, the language cannot be generated by any context-free grammar but can be generated by a context-sensitive grammar.
Context-Sensitive Languages vs Recursively Enumerable Languages: Context-sensitive languages are a proper subset of recursively enumerable languages. While all context-sensitive languages are recursively enumerable, not all recursively enumerable languages are context-sensitive. Recursively enumerable languages can be generated by unrestricted grammars (also known as type 0 grammars), which have no restrictions on the form of their production rules.
Context-sensitive languages are decidable, meaning there exists an algorithm to decide membership for any string in a context-sensitive language. However, the decision problem for context-sensitive languages is computationally more complex than for regular or context-free languages.
Time Complexity: While context-sensitive languages are decidable, the decision process typically takes exponential time. This makes their practical use limited for large-scale computations compared to regular and context-free languages, which have more efficient decision algorithms.
Space Complexity: Since context-sensitive languages can be recognized by a linear bounded automaton (LBA), the space complexity of recognizing a CSL is linear in the size of the input.
Context-sensitive languages (CSLs) represent a class of languages that are more complex than context-free languages but still decidable. They are defined by context-sensitive grammars, where the productions are constrained to prevent string shortening. CSLs are equivalent to languages recognized by linear bounded automata, and they form a key part of the Chomsky hierarchy, bridging the gap between context-free languages and the more powerful recursively enumerable languages. Despite their theoretical importance, their practical use is limited due to the high computational complexity of recognizing such languages.
Open this section to load past papers