CSC 330 Problem Set 1

Problem Set 1: BNF



ISSUED: Monday, 28 March 2005
DUE: Monday, 4 April 2005, in class
POINTS POSSIBLE: 100
WEIGHT: 7% of total class grade
READING: Lecture Notes Week 1, Textbook Chapter 2

The following farmyard_animal grammar is referenced in the questions below.

        farmyard_animal  -> chick   |   bird
        chick  ->   peck   |   churp   |   peck   churp   |   churp   peck
        bird  ->    churp   |   'three steps'   |   'peck'   |   bird   bird
        peck  ->    'three steps'   |   'peck'   |   peck   peck
        churp  ->   'turn left'   |   'churp'


The grammar notation is the same as that used on Page 24 of the book, with one modification -- tokens are bracketed in single quotes. This is to clarify the extent of the two tokens that contain a blank character, i.e., 'three steps' and 'turn left'. The other difference between this grammar and the one on Page 24 is a matter of convention. Here non-terminal symbols start with lowercase letters, and use an underscore character to separate words, instead of case shifting. E.g., in the book's convention, the non-terminal farmyard_animal would be FarmyardAnimal. Again, this is just a matter of convention, that does not affect the formal definition of the grammar.


  1. (20 points) In the following table, indicate for each string if it can be derived from the non-terminal at the head of each column by placing "yes" or "no" in the appropriate table entry.

    string churp peck bird chick farmyard_animal
    turn left          
    three steps          
    three steps churp          
    three steps peck          
    turn left churp          
    turn left churp churp          
    three steps peck peck          
    turn left three steps three steps          
    turn left three steps peck          
    three steps turn left churp          

    Put your answers to questions 2 through 8 on additional sheets of paper.




  2. (6 points) Are there any birds that are not chicks? I.e., are there any strings derivable from bird that are not derivable from chick? If the answer is yes, give an example of one.

  3. (6 points) Are there any chicks that are not birds? If the answer is yes, give an example of one.

  4. (14 points Draw a parse tree for the following string:
    chirp peck three steps churp

    Use the simple style of trees as in Lecture Notes 1 and the figures through Page 32 in the book. Do not use the bulkier style with boxes, as in Figure 2.16 in the book.

  5. (14 points) Can you shorten the farmyard animal grammar such that the same strings are accepted and rejected by the new grammar? If the answer is yes, show how. Note: shortness here is measured by the number of symbols and number of rules. So, the shortest grammar is the one with the fewest number of symbols and rules that generate precisely the same set of strings as the original grammar. Your answer should be what you think is the shortest possible grammar, if it can be shortened.

  6. (14 points) Rewrite the original farmyard animal grammar in the extended BNF notation (EBNF) described in Section 2.2.2 of the book (pages 33-34). (The original grammar is the one on the first page of the assignment, not the shortened one you may have written for the previous question.)

  7. (14 points) Rewrite the original farmyard animal grammar using the syntax graph notation described in Section 2.2.2 of the book, and further illustrated in Lecture Notes 1. Provide a separate graph for each rule, as opposed to one large graph for the whole grammar

  8. (12 points) Does the original farmyard animal grammar give a unique parse tree for every input? If not, give an example where it is ambiguous by showing the trees for the ambiguous parse.




index | lectures | handouts | assignments | examples | doc | solutions | bin