Lecture 9 review  Compute FIRST(X)

advertisement
Lecture 9 review

What is in the First (X Y Z) and Follow (A)?

Compute FIRST(X)




If X is a terminal then FIRST(X) = {X}
If X->  , add  to FIRST(X)
If X  Y1 Y2 ... Yk and Y1 Y2 ... Yi 1   add every none  in
FIRST( Yi ) to FIRST(X). If Y1 Y2 ... Yk   , add  to FIRST(X).
Compute Follow(A).



5/29/2016
If S is the start symbol, add $ to Follow(S).
If A->aBb, add First(b)-{ } to Follow(B).
If A->aB or A->aBb and b=>  , add Follow(A) to Follow(B).
COP4020 Spring 2014
1

Construct the LL(1) parsing table?
 With first(a) and follow(A), we can build the
parsing table. For each production A->a:


Add A->a to M[A, t] for each t in First(a).
If First(a) contains empty string



Add A->a to M[A, t] for each t in Follow(A)
if $ is in Follow(A), add A->a to M[A, $]
Make each undefined entry of M error.
Download