COMS W4115
Programming Languages and Translators
Lecture 6: Context-Free Languages
February 6, 2012

Lecture Outline

1. Pumping Lemma for Regular Languages

2. Properties of Regular Languages

3. Context-Free Grammars (CFG's)

4. Derivations and Parse Trees

5. Ambiguity

6. Practice Problems

  1. Let G be the grammar S → a S b S | b S a S | ε.
    1. What language is generated by this grammar?
    2. Draw all parse trees for the sentence abab.
    3. Is this grammar ambiguous?
  2. Let G be the grammar S → a S b | ε. Prove that L(G) = { anbn | n ≥ 0 }.
  3. Consider a sentence of the form id + id + ... + id where there are n plus signs. Let G be the grammar in section (5) above. How many parse trees are there in G for this sentence when n equals
    1. 1
    2. 2
    3. 3
    4. 4
    5. m?
  4. Consider the grammar in section (5) above. How many sentences does this grammar generate having n left parentheses where n equals
    1. 1
    2. 2
    3. 3
    4. 4
    5. m?

7. Reading



aho@cs.columbia.edu