Context Sensitivity
Informatics 2A: Lecture 26 Stuart Anderson & Bonnie Webber
School of Informatics University of Edinburgh [soa,bonnie]@inf.ed.ac.uk20 November 2008
Informatics 2A: Lecture 26 Context Sensitivity 1 Context Sensitive Grammars Context in Programming Languages Context in Natural Languages 1 Context Sensitive GrammarsChomsky Hierarchy Example of a CSG
2 Context in Programming LanguagesContext: Scope of variables Overloading
3 Context in Natural LanguagesBounded Context Unbounded Context Recommended Reading: J&M, Chapter 16.1; Kozen, Lecture 36
Informatics 2A: Lecture 26 Context Sensitivity 2 Context Sensitive Grammars Context in Programming Languages Context in Natural Languages Chomsky Hierarchy Example of a CSGProductions and the Chomsky Hierarchy
We’ve spent several weeks talking about CFGs, whose productions in A ǫ N and γ ǫ (N ∪ Σ)+ have the form: A → γ More general are context-sensitive productions in A and γ that can have the canonical, non-decreasing form: αAβ → αγβ where α, β ǫ (N ∪ Σ)* Here, α and β provide context to record what must precede and/or follow A, if it’s to be expanded in this particular way.
Informatics 2A: Lecture 26 Context Sensitivity 3 Context Sensitive Grammars Context in Programming Languages Context in Natural Languages Chomsky Hierarchy Example of a CSGContext Sensitivity and Complexity
By virtue of this extra memory, context-sensitive grammars can generate more complex languages than CFGs. For example, we know the language anbn can be produced by a CFG: S → aSb | ab But the more complex languages anbncn (and anbncndn, etc)
- cannot. For example, the grammar
S → WT W → aWb | ab T → Tc | c won’t do, because the expansion of T cannot take account of how W is expanded.
Informatics 2A: Lecture 26 Context Sensitivity 4