Laboratory Exercise for February 26


Constructing LL(1) Tables Precisely


Note:  You might want to listen to Justin Hart's talk on DirectX in EPS 103 at 5:00 today (Thursday, February 26).  Justin is one of our students and has constructed a new visual virtual machine for our compiler class, among other things.

Objectives

The objectives of this laboratory exercise are

Preparing for Lab

For this lab you will need your browser set to view the mPascal context free grammar on the resources page.

To Do

Your main tasks today are the application of the algorithms involved in constructing an LL(1) table.  You will be building just a portion of the LL(1) table for mPascal today.  First, You will be doing the parts of the LL(1) table that correspond to AssignmentStatement and all subsequent rules that are needed to parse an assignment statement. 
Prepare an empty LL(1) table using a word processor.
Prepare an empty First Set table using a word processor.  Put your team names and group number at the top left, along with the title "Compute First Sets for Nonterminals" at the top centered.  The table should look like the following for your subgrammar.
 
                                           Pass 1        Pass 2              . . .                Pass M
First(NonTerminal 1)
First(NonTerminal 2)
    . . .
First(NonTerminal N)

Prepare a third sheet exactly as above, except that the row headings should be Follow(NonTerminal) instead of First(Nonterminal).  If there is room on your First Set sheet, you may use it.

for each nonterminal A in grammar G 
   Follow(A) := {}
end for loop
Follow(S) := {eof}, where S is the start symbol of G
while there are changes to any Follow set loop
   for each rule A --> X1 X2 ... Xn in grammar G loop
     for each Xi in the current rule that is a nonterminal loop
        Follow(Xi) := Follow(Xi) union First(Xi+1 Xi+2 ... Xn) - {e}
        -- if i = n, First(Xi+1 Xi+2 ... Xn) = {e} (the set containing the empty string)
        if e is in First(Xi+1 Xi+2 ... Xn) then
           Follow(Xi) := Follow(Xi) union Follow(A)
        end if
     end for
   end for
end while

 


You now have all of the information you need to fill in the LL(1) table.

To Turn In

Staple the three tables together and turn them in.  They should be in the following order:
  1. First Sets Table
  2. Follow Sets Table
  3. LL(1) Table