Tut4 - Prince Sultan University

advertisement
Prince Sultan University
College of Computer & Information Sciences
Department of Computer Science
CS421: Compiler Construction
New Tutorial 4
1- Given the grammar:
E  T E’
E’  Addop T E’ | 
Addop  + | T  F T’
T’  Mulop F T’| 
Mulop  *|/
F  (E) | number
Construct the parse tree for the expression 3+4*5
2- Given the grammar A(A)A |  , Construct First and Follow Sets and show that this
grammar is LL(1)
3- Given the grammar:
Lexp  Atom | List
Atom  number | identifier
List  (Lexp-seq)
Lexpseq  Lexpseq Lexp | Lexp
a- Remove left recursion
b- Construct First and Follow Sets for the resulting grammar
c- Show that the resulting grammar is LL(1)
d- Construct the LL(1) Parsing table for the resulting grammar
e- Show how the following string may be LL(1) parsed : (a (b (2)) (c))
4- Consider the following grammar:
abcd-
Declaration  Type Var-list
Type  int | float
Var-list  identifier, Var-list | identifier
Left factor the grammar
Construct First and Follow Sets
Construct the LL(1) Parsing Table
LL(1) Parse int x,y,z
Download