Also known as CSG. A grammar where every production satisfies .
Equivalent form: every production has the form
Here:
- single non-terminal on LHS surrounded by context
- non-empty replacement
- arbitrary context strings
The context and must be identical on both sides. The non-terminal is replaced only in that specific context.
Context-Sensitive Language
Also known as CSL. Languages generated by a CSG. Accepted by linear-bounded automata.
Every context-free language is context-sensitive. Not every CSL is context-free.
Example
The language is CSL but not CFL. A CSG generating :
Productions:
The key production allows s and s to swap positions, a context-sensitive rewrite that no CFG production can express, because the LHS has 2 non-terminals.