Exercise 4        Name __________________        Score __/26

  1. (8) Find FIRST and FOLLOW sets for the grammar:
    Given a non-terminal A, the set FOLLOW(A) consists of terminals and possibly $ is defined as:
    1. if A is a start symbol then $ is in Follow(A).
    2. if production B ® a A g , then First(g)-{є} is in Follow(A)
    3. if production B ® a A g , such that є is in First(g), then Follow(A) contains Follow(B); since whatever follows B can follow A when g=є
    4. if production B ® a A, then Follow(A) contains Follow(B); since whatever follows B can follow A
    S ® ABC              
    A ® a | Cb | є   
    B ® c | dA | є     
    C ® e | f             
  2. (4) Give the parse table for Question 1.
     
    Blank entries are error conditions. Rules for typical production X ® b are:
    1. For all terminals a in FIRST(b) except є, [X,a] = X ® b
    2. If b=є or if є is in FIRST(b) then: For all a in FOLLOW(X), [X,a]=X ® є


     

  3. (2) For grammar A ® Ac | Ad | e | f  which strings are valid?
    1. e
    2. ccce
    3. cdccd
    4. ecdccdf
    5. fcdcd
       
  4. (2) Remove left-recursion in the grammar:  A ® Ac | Ad | e | f

     
  5. (4) Using GRAMMAR 3.1 and the LR parsing TABLE 3.19, give a bottom-up parse with the following of: x:=a+3