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!


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

    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
    ?- recognize_bottomup_any([the,man,dances],Cat).
    Cat = s
    ?- recognize_bottomup_any([the,man,dances,a],Cat).

Patrick Blackburn and Kristina Striegnitz
Version 1.2.4 (20020829)