COMS W4115
Programming Languages and Translators
Lecture 7: Context-free Grammars and YACC
February 8, 2012

Outline

  1. Review
  2. Examples of context-free grammars
  3. Yacc: a language for specifying syntax-directed translators
  4. Noncontext-free constructs in languages
  5. Top-down parsing
  6. Transformations on grammars

1. Review

2. Examples of Context-Free Grammars

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

4. Noncontext-free Constructs in Languages

5. Top-down Parsing

6. Transformations on Grammars

7. 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.

8. Reading



aho@cs.columbia.edu