7.7 Exercises

  1. Design a simple ambiguous context free grammar. Show that your grammar is ambiguous by giving an example of a string that has two distinct parse trees. Draw the two trees.

  2. What is the output produced by the following two queries? Note: it is probably a lot faster to do these by hand than to wait and see what Prolog produces!

    recognize_bottomup([jules,believed,the,robber,who,shot,the,robber,fell]).
     
    recognize_bottomup([jules,believed,the,robber,who,shot,the,robber,
                        who,shot,marsellus,fell]).

  3. The followin grammar contains a rule producing an empty terminal symbol: S \rightarrow \epsilon written as s --->[] in our Prolog notation.

    s ---> [].
    s ---> [left,s,right].
     
    lex(a,left).
    lex(b,left).

    Does this grammar admit the string a b? What happens if you try to use bottomup_recognizer.pl with this grammar to recognize the string a b? Why?

  4. Our naive bottom up recognizer only recognizes strings of category s. Change it, so that it recognizes strings of any category, as long as the whole string is spanned by that category, and returns the category that it found. For example:

    ?- recognize_bottomup_any([the,man],Cat).
    Cat = np
    yes
    ?- recognize_bottomup_any([the,man,dances],Cat).
    Cat = s
    yes
    ?- recognize_bottomup_any([the,man,dances,a],Cat).
    no


Patrick Blackburn and Kristina Striegnitz
Version 1.2.4 (20020829)