COMS W4115
Programming Languages and Translators
Lecture 7: Parsing Context-Free Grammars
February 13, 2013

Outline

  1. Yacc: a language for specifying syntax-directed translators
  2. The pumping lemma for context-free languages
  3. The parsing problem for context-free grammars
  4. Top-down parsing
  5. Transformations on grammars

1. Yacc: a Language for Specifying Syntax-Directed Translators

2. The Pumping Lemma for Context-Free Languages

3. The Parsing Problem for Context-Free Grammars

4. Top-Down Parsing

5. Transformations on Grammars

6. Practice Problems

  1. Write down a CFG for regular expressions over the alphabet {a, b}. Show a parse tree for the regular expression a | b*a.
  2. Using the nonterminals stmt and expr, design context-free grammar productions to model
    1. C while-statements
    2. C for-statements
    3. C do-while statements
  3. Consider grammar G:
  4. 
          S →  S S + | S S * | a
        
    1. What language does this grammar generate?
    2. Eliminate the left recursion from this grammar.
  5. Use the pumping lemma to show that {anbncn | n ≥ 0 } is not context free.

7. Reading



aho@cs.columbia.edu