We have been using the term context-free without explaining why such rules a in fact "free of context". The simple reason is that the nonterminals appears by themselves to the left of the arrow in context-free rules. Thus, a rule A -> α says that A may be replaced by α anywhere, regardless of where the A occurs. On the other hand, we could informally define context as a pair of strings(of terminals and nonterminals) β, γ, such that a rule would apply only if β occurs before and γ occurs after the nonterminal. We would write this as βAγ -> βαγ. Such a rule in which α != ε is called a context-sensitive grammar rule. Context sensitive grammar rule are more powerful than context-free grammar rules but are also more difficult to use as the basis for a parser.
展开
1
2