


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Fall ' Final Exam Decemb er 16, 1997. Duration: 2 hours, 45 minute s.
Read the following carefully b efore answer ing any que stion. The exam for graduate students i s di erent f rom the exam for the undergraduate students. Make sure you are reading the correct que stion pap er. Doubts ab out the que stions will b e answere d only in the rst 15 minute s of the exam. So, read the que stions carefully at the b eginning of the exam. Keep your answers br ief and preci s e. Answer each que stion on a s eparate sheet of pap er. Wr ite your name and your id numb er on the rst sheet. Wr ite your id numb er on the top r ight hand cor ner of each additional sheet. There are 8 que stions in all, in 4 page s, for a total of 105 p oints. The maximum score i s 100.
GOOD LUCK!
(a) [5 p oints] Wr ite a lex sp eci cation to convert each o ccurrence of ++" in a C program to + 1 ". (b) [5 p oints] Wr ite a lex sp eci cation to convert every continuous s equence of blank line s (a blank line contains only white space characters) into a s ingle line containing <P>".
This is a sample latex document. A list of bullet items can be created as follows.
(^) 3. [Total: 10 p oints]
(a) [5 p oints] Let L b e the s et of all bit str ings (i.e, str ings over alphab et = f 0 ; 1 g) that are divi s ible by 4. Can L b e repre s ente d by a regular expre ss ion? Justify. (b) [5 p oints] Let L^0 b e the s et of all bit str ings (i.e, str ings over alphab et = f 0 ; 1 g) that are divi s ible by 3. Can L^0 b e repre s ente d by a regular expre ss ion? Justify.
E ! E + E E ! E E E ! id
(a) [5 p oints] Compute the FIRST and FOLLOW s ets for E. (b) [5 p oints] Is G 4 an LL(1) grammar? Justify. (c) [5 p oints] Compute the LR(0) s ets of items for G 4. (d) [5 p oints] Which state s in the SLR(1) action table for G 4 has re duce actions? On what symb ols are the s e re duce actions done?
(a) [5 p oints] Cons ider the following grammar G 5 that generate s binary numb ers repre s enting integers:
S ! L L ! L B L ! B B ! 0 B ! 1
Let an attr ibute val give the value of the binary numb er generate d by S. For example, on input 110 , S.val = 6. Determine S.val us ing syntax-directe d de nitions. (b) [5 p oints] Is val an inher ite d attr ibute of S? Is it an inher ite d attr ibute of L or B? Justify.
(a) [3 p oints] Explain why eld and metho d name s in Decaf cannot b e re solve d until typ e s are known. That i s, why cannot one determine which entity i s repre s ente d by a[i].x until the typ e of a[i] i s known? (b) [4 p oints] When pars ing Decaf programs, we can encounter a var iable x in some expre ss ion such that x i s not declare d in the current scop e, nor in any enclos ing scop e. Explain why thi s i s not an error.
(^) (c) [5 p oints] Cons ider the grammar G^008 der ive d by adding
E ! E + = E
to grammar G^09. Mo dify the syntax directe d de ntion in (b) to include co de generation for expre ss ions of the form x += y.