Context-Sensitive Languages #
This file defines the class of context-sensitive languages via unrestricted grammars:
all rules are non-contracting, except for an optional distinguished start rule S → ε.
The start symbol does not occur on the right-hand side of any rule.
Equations
- initial_not_on_rhs g = ∀ r ∈ g.rules, symbol.nonterminal g.initial ∉ r.output_string
Instances For
An unrestricted grammar is context-sensitive if every rule is either the optional
distinguished rule S → ε or is non-contracting, and — whenever the S → ε rule is
present — the start symbol S never occurs on a right-hand side.
The right-hand-side restriction is part of the standard definition of a context-sensitive
grammar: it guarantees that S only ever appears as the initial sentential form, so that
the erasing rule S → ε contributes exactly the empty word (and nothing else). Without it,
rules such as S → SS together with S → ε would allow contracting derivations of
non-empty words, taking the grammar outside the context-sensitive (linear-bounded) class.
Equations
- grammar_context_sensitive g = ((∀ r ∈ g.rules, initial_epsilon_rule g r ∨ grule_noncontracting r) ∧ ((∃ r ∈ g.rules, initial_epsilon_rule g r) → initial_not_on_rhs g))
Instances For
Every non-contracting grammar is context-sensitive: it has no S → ε rule, so the
right-hand-side restriction is vacuous.
Every non-contracting language is context-sensitive.
Characterization of context-sensitive languages via ε-free context-preserving grammars.
Equations
- is_CS_via_csg L = ∃ (g : CS_grammar T), CS_language g = L