World Library  
Flag as Inappropriate
Email this Article

Context-sensitive grammar

Article Id: WHEBN0000006211
Reproduction Date:

Title: Context-sensitive grammar  
Author: World Heritage Encyclopedia
Language: English
Subject: Context-free grammar, Chomsky hierarchy, Context-sensitive language, Embedded pushdown automaton, Noam Chomsky
Collection:
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Context-sensitive grammar

A context-sensitive grammar (CSG) is a formal grammar in which the left-hand sides and right-hand sides of any production rules may be surrounded by a context of terminal and nonterminal symbols. Context-sensitive grammars are more general than context-free grammars, in the sense that there are some languages that cannot be described by context-free grammars, but can be described by CSG. Context-sensitive grammars are however less general (in the same sense of the term) than unrestricted grammars, i.e. CSG occupy the intermediate position between context-free and unrestricted grammars in the Chomsky hierarchy.

A formal language that can be described by a context-sensitive grammar, or, equivalently, by a noncontracting grammar or a linear bounded automaton, is called a context-sensitive language. Some textbooks actually define CSG as non-contracting,[1][2][3][4] although this is not how Noam Chomsky defined it in 1959.[5][6] This choice of definition makes no difference in terms of the languages generated (i.e. the two definitions are weakly equivalent), but it does make a difference in terms of what grammars are structurally considered context-sensitive; the later issue was analyzed by Chomsky in 1963.[7][8]

Chomsky introduced context-sensitive grammars as a way to describe the syntax of natural language where it is indeed often the case that a word may or may not be appropriate in a certain place depending upon the context. Walter Savitch has criticized the terminology "context-sensitive" as misleading and proposed "non-erasing" as better explaining the distinction between a CSG and an unrestricted grammar.[9]

Although it is well-known that certain features of languages (e.g. cross-serial dependency) are not context-free, it is an open research question how much of CSG' expressive power is actually needed to capture the context sensitivity found in natural languages. Subsequent research in this area has focused on the more computationally tractable mildly context-sensitive languages.

Formal definition

A formal grammar G = (N, Σ, P, S), where N is a set of nonterminal symbols, Σ is a set of terminal symbols, P is a set of production rules, and S is the start symbol, is context-sensitive if all rules in P are of the form

αAβ → αγβ

where AN,[note 1] α,β ∈ (N∪Σ)* [note 2] and γ ∈ (N∪Σ)+.[note 3]

A string u ∈ (N∪Σ)* directly yields, or directly derives to, a string v ∈ (N∪Σ)*, denoted as uv, if u can be written as lαAβr, and v can be written as lαγβr, for some production rule (αAβ→αγβ) ∈ P, and some context strings l, r ∈ (N∪Σ)*. More generally, u is said to yield, or derive to, v, denoted as u* v, if u = u1 ⇒ ... ⇒ un = v for some n≥0 and some strings u2, ..., un-1 (N∪Σ)*. That is, the relation (⇒*) is the reflexive transitive closure of the relation (⇒).

The language of the grammar G is the set of all terminal symbol strings derivable from its start symbol, formally: L(G) = { w ∈ Σ*: S* w }. Derivations that do not end in a string composed of terminal symbols only are possible, but don't contribute to L(G).

The only difference between this definition of Chomsky and that of unrestricted grammars is that γ can be empty in the unrestricted case.[9]

Some definitions of a context-sensitive grammar only require that for any production rule of the form u → v, the length of u shall be less than or equal to the length of v. This seemingly weaker requirement is in fact weakly equivalent,[10] see Noncontracting grammar#Transforming into context-sensitive grammar.

In addition, a rule of the form

S → λ

where λ represents the empty string and S does not appear on the right-hand side of any rule is permitted. The addition of the empty string allows the statement that the context sensitive languages are a proper superset of the context free languages, rather than having to make the weaker statement that all context free grammars with no →λ productions are also context sensitive grammars.

The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replaced with γ or not. This is different from a context-free grammar where the context of a nonterminal is not taken into consideration. Indeed, every production of a context free grammar is of the form Vw where V is a single nonterminal symbol, and w is a string of terminals and/or nonterminals; w can be empty.

If the possibility of adding the empty string to a language is added to the strings recognized by the noncontracting grammars (which can never include the empty string) then the languages in these two definitions are identical.

The left-context- and right-context-sensitive grammars are defined by restricting the rules to just the form αA → αγ and to just Aβ → γβ, respectively. The languages generated by these grammars are also the full class of context-sensitive languages.[11] The equivalence was established by Penttonen normal form.[12]

Examples

The following grammar, with start symbol S, generates the canonical non-context-free language { anbncn : n ≥ 1 } :

1.       S     →     a b c
2. S a S B c
3. c B W B
4. W B W X
5. W X B X
6. B X B c
7. b B b b

Rules 1 and 2 allow for blowing-up S to anbc(Bc)n-1; rules 3 to 6 allow for successively exchanging each cB to Bc (four rules are needed for that since a rule cBBc wouldn't fit into the scheme αAβ → αγβ); rule 7 allows for replacing a non-terminal B with its corresponding terminal b, provided it is in the right place. A generation chain for aaabbbccc is:

S
2 aSBc
2 a'Bc
1 aaabcBcBc
3 aaabWBcBc
4 aaabWXcBc
5 aaabBXcBc
6 aaabBccBc
3 aaabBcWBc
4 aaabBcWXc
5 aaabBcBXc
6 aaabBcBcc
3 aaabBWBcc
4 aaabBWXcc
5 aaabBBXcc
6 aaabBBccc
7 aaabbBccc
7 aaabbbccc

More complicated grammars can be used to parse { anbncndn: n ≥ 1 }, and other languages with even more letters.

A context-sensitive grammar for the language { a2i : i ≥ 1 } is constructed in Example 9.5 (p. 224) of (Hopcroft, Ullman, 1979).

Kuroda normal form

Every context-sensitive grammar which does not generate the empty string can be transformed into a weakly equivalent one in Kuroda normal form. "Weakly equivalent" here means that the two grammars generate the same language. The normal form will not in general be context-sensitive, but will be a noncontracting grammar.[13][14]

The Kuroda normal form is an actual normal form for non-contracting grammars.

Properties and uses

Equivalence to linear bounded automaton

A formal language can be described by a context-sensitive grammar if and only if it is accepted by some linear bounded automaton (LBA).[15] In some textbooks this result is attributed solely to Landweber and Kuroda.[6] Others call it the Myhill-Landweber-Kuroda Theorem.[16] (Myhill introduced the concept of deterministic LBA in 1960. Peter S. Landweber published in 1963 that the language accepted by a deterministic LBA is context sensitive. Kuroda introduced the notion of non-deterministic LBA and the equivalence between LBA and CSGs in 1964.[17][18])

As of 2010 it is still an open question whether every context-sensitive language can be accepted by a deterministic LBA.[19]

Closure properties

Context-sensitive languages are closed under complement. This 1988 result is known as the Immerman–Szelepcsényi theorem.[16] Moreover, they are closed under union, intersection, concatenation, substitution,[note 4] inverse homomorphism, and Kleene plus.[20]

Every recursively enumerable language L can be written as h(L) for some context-sensitive language L and some string homomorphism h.[21]

Computational problems

The decision problem that asks whether a certain string s belongs to the language of a given context-sensitive grammar G, is PSPACE-complete. Morever, there are context-sensitive grammars whose languages are PSPACE-complete. In other words, there is a context-sensitive grammar G such that deciding whether a certain string s belongs to the language of G is PSPACE-complete (so G is fixed and only s is part of the input of the problem).

The emptiness problem for context-sensitive grammars (given a context-sensitive grammar G, is L(G)=∅ ?) is undecidable.[22][note 5]

As model of natural languages

Savitch has proven the following theoretical result, on which he bases his criticism of CSGs as basis for natural language: for any recursively enumerable set R, there exists a context-sensitive language/grammar G which can be used as a sort of proxy to test membership in R in the following way: given a string s, s is in R if and only if there exists a positive integer n for which scn is in G, where c is an arbitrary symbol not part of R.[9]

It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but the whole class of CSG's seems to be much bigger than natural languages. Worse yet, since the aforementioned decision problem for CSG's is PSPACE-complete, that makes them totally unworkable for practical use, as a polynomial-time algorithm for a PSPACE-complete problem would imply P=NP.

It was proven that some natural languages are not context-free, based on identifying so-called cross-serial dependencies and unbounded scrambling phenomena. However this does not necessarily imply that all the class CSG is necessary to capture "context sensitivity" in the colloquial sense of these terms in natural languages. For example, the strictly weaker (than CSG) linear context-free rewriting systems (LCFRS) can account for the phenomenon of cross-serial dependencies; one can write a LCFRS grammar for {anbncndn | n ≥ 1} for example.[23][24][25]

Ongoing research on computational linguistics has focused on formulating other classes of languages that are "mildly context-sensitive" whose decision problems are feasible, such as tree-adjoining grammars, combinatory categorial grammars, coupled context-free languages, and linear context-free rewriting systems. The languages generated by these formalisms properly lie between the context-free and context-sensitive languages.

More recently, the class PTIME has been identified with range concatenation grammars, which are now considered to be the most expressive of the mild-context sensitive languages.[25]

See also

Notes

  1. ^ i.e., A is a single nonterminal
  2. ^ i.e., α and β are strings of nonterminals and terminals
  3. ^ i.e., γ is a nonempty string of nonterminals and terminals
  4. ^ more formally: if L ⊆ Σ* is a context-sensitive language and f maps each a∈Σ to a context-sensitive language f(a), the f(L) is again a context-sensitive language
  5. ^ This also follows from (1) context-free languages being also context-sensitive, (2) context-sensitive language being closed under intersection, but (3) disjointness of context-free languages being undecidable.

References

  1. ^
  2. ^
  3. ^
  4. ^
  5. ^
  6. ^ a b
  7. ^ Chomsky, N. 1963. Formal properties of grammar. Handbook of Mathematical Psychology. R.D. Luce, R.R. Bush, & E. Galanter (eds), New York: Wiley. pp. 360-363
  8. ^
  9. ^ a b c
  10. ^ ; p.223-224; Exercise 9, p.230. In the 2003 edition, the chapter on CSG has been omitted.
  11. ^ also at http://www.encyclopediaofmath.org/Grammar,_context-sensitive
  12. ^ citing
  13. ^
  14. ^ , Here: Theorem 2.2, p. 190
  15. ^ (Hopcroft, Ullman, 1979); Theorem 9.5, 9.6, p.225-226
  16. ^ a b http://www.cs.cmu.edu/~flac/pdf/ContSens.pdf
  17. ^
  18. ^
  19. ^
  20. ^ (Hopcroft, Ullman, 1979); Exercise S9.10, p.230-231
  21. ^ (Hopcroft, Ullman, 1979); Exercise S9.14, p.230-232. h maps each symbol to itself or to the empty string.
  22. ^ (Hopcroft, Ullman, 1979); Exercise S9.13, p.230-231
  23. ^ http://user.phil-fak.uni-duesseldorf.de/~kallmeyer/GrammarFormalisms/4nl-cfg.pdf
  24. ^ http://user.phil-fak.uni-duesseldorf.de/~kallmeyer/GrammarFormalisms/4lcfrs-intro.pdf
  25. ^ a b

Further reading

External links

  • Earley Parsing for Context-Sensitive Grammars
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.