next up previous contents
Next: TOP-DOWN PARSING Up: CONTEXT-FREE LANGUAGES Previous: The Closure of Context-Free   Contents

Decision Problems for Context-Free Languages

Based on the Pumping Lemma, we can state some decidability results for context-free languages.

Lemma: It is decidable whether or not a given string belongs to a context-free language.
Proof:
If we eliminate all $\varepsilon$-productions, and all unit productions from the context-free grammar for the language, then each time we apply a production rule we either:

-
make the sentential form grow longer
-
increase the number of terminal symbols in the sentential form
Therefore the number of production rules applied (and thus the height of the parse tree) will be bounded by the length of the input string. Since this is finite, an effective (though inefficient) decision algorithm need only enumerate all such parse trees, and check the leaves to see if they correspond to the string.
${\cal QED}$

Without examining the issue in detail, we also note the following:

Lemma: It is decidable whether or not a context-free language is empty.
Proof:
We need to show that the corresponding context-free grammar can generate a string.
If a CFG can generate a string, then it should be able to do so without using recursion (since we could just skip the recursion and generate a shorter string). If there are $m$ non-terminals altogether, then some tree of height less than $m$ must have leaves which are only terminals.
Thus we need only examine all such trees to see if the CFG generates a sentence.
${\cal QED}$

Some decision problems for CFGs (and accordingly for push-down automata) are not solvable.

We state, without proof, that the following problems are undecidable in general:

The proof of these theorems follows from a famous decision problem called Post's correspondance problem.


next up previous contents
Next: TOP-DOWN PARSING Up: CONTEXT-FREE LANGUAGES Previous: The Closure of Context-Free   Contents
James Power 2002-11-29