CS 3304 Homework #2

Date Assigned: September 10, 2003
Date Due: September 17, 2003, in class, before class starts
  1. (15 points) Problem 23 of Chapter 3 in your textbook.

  2. (10 points) Show that the following grammar does not satisfy the rules of predictive parsing.
    
    <stmt> -> <if-stmt> | <other>
    <if-stmt> -> if <stmt> [ else <stmt> ]
    

  3. (25 points) The following grammar generates declarations for a single identifier:
    
    <stmt> -> declare <id> <option_list>
    <option_list> -> <option_list> <option> | epsilon
    <option> -> <mode> | <scale> | <precision> | <base>
    <mode> -> real | complex
    <scale> -> fixed | floating
    <precision> -> single | double
    <base> -> binary | decimal
    
    where "epsilon" is the empty symbol.

    As you can see, this grammar permits redundant or contradictory declarations such as:
    
    declare zippy real fixed real floating
    
    Our goal is to revise the grammar so that it forbids such obviously incorrect declarations. Write a grammar for legal declarations, where legal means each option appearing at most once (so there can be at most one mode, one scale, one precision, and one base). It is legal to not have anything specified for one or more (or all) of the options. So, just
    
    declare zippy
    
    is legal.

Return Home