Assignment 1: Context Free Grammars
Due: 9/30/03


  1. Let G be defined by:

    < S > < A > < B >
    < A > < A > a
    < A > b < B >
    < B > a
    < B > < S > b


    1. Give a leftmost and a rightmost derivation of the string baabaab in the grammar G.

    2. Show a derivation tree for baabaab relative to G.


  2. (part of problem 4.2 from Aho, Sethi and Ullman) What language is generated by the grammar:

    < S > a < S > b < S >
    < S > b < S > a < S >
    < S >

    Justify your answer!


  3. Show that the grammar

    < S >

    ( < A > )
    < S > b
    < A > < S >
    < A > < A > , < A >

    is ambiguous and construct an unambiguous grammar for the same language. Include an informal description of the language generated by the grammar.


  4. (Problem 4.4 from Fischer and LeBlanc) A production of the form A A is said to be left-recursive Similarly, a production of the form B B is said to be right-recursive. Show that any grammar that contains both left and right recursive productions with the same left-hand side symbol must be ambiguous.

Computer Science 434
Department of Computer Science
Williams College