Faculty of Information Technology Philadelphia University Examination Paper

advertisement
Philadelphia University
Faculty of Information Technology
Lecturer
: Dr. M. Maouche
Coordinator
: Dr M. Maouche
Internal Examiner : Dr. N. Nameer
Department of Computer Science
Examination Paper
Course Name: Compiler Construction (750324)
Section: 1
Final Exam
First Semester
Academic Year: 2015/16
Date: February, 4th, 2016 Time: 120 minutes
Information for Candidates
1.This examination paper contains 5 questions, totaling 40 marks.
2.The marks for parts of questions are shown in round brackets.
Advice to Candidates
1. You should write your answers precisely, clearly and to the point .
I. Basic Notions
Objectives. The aim of the question in this part is to evaluate the required minimal student
knowledge and skills. Answers in the pass category represent the minimum acceptable
standard.
Question1: (6 marks)
Answer the following True/False questions
1. Lexical analysis is recursive in order to handle nested parentheses
2. Scanners don't know anything about the grammar of a language.
3. A successful parse means the input is semantically correct.
4. Finite State Machines can have an unlimited number of states.
5. A regular expression is a type of pattern used to classify lexemes.
6. You can change state in a DFA without reading any input character.
7. Transition Tables are indexed with current state and next state
8. Syntax analysis handles type checking and type conversions, e.g. int to float.
9. Regular expressions cannot be used to match strings of balanced parentheses
10. 0(00)* is a regular expression that matches only non-empty strings containing an odd
number of zeroes.
11. (000)* is a regular expression that matches only strings containing an odd number of
zeroes, including the empty string.
12. Finite State Machines can have only one edge leaving the same state labeled with the
same label (character)
Question2: (10 marks)
1. What is an activation record? When is it created? Where is it stored? (2 marks)
2. Where are stored parameters during a procedure call? Explain briefly (2 marks)
3. Who save and restore live registers during a procedure call? Explain briefly (2 marks)
4. Draw the memory layout associated with a loaded program in memory.
(2 marks)
5. Name three kinds of static semantic checks that may be done during the semantic
analysis?
(2 marks)
II. Familiar Problems Solving
Objectives. The aim of the question in this part is to evaluate that the student has some basic
knowledge of the key aspects of the lecture material and can attempt to solve familiar
problems
Question3: (6 marks)
Consider the following class:
Class Account {
int balance;
void deposit (int a)
{int tax;
if a > 10000
then {tax := (a * 10)/100; balance := balance +a - tax}
else balance := balance + a;
}
Draw the content of the class descriptor of the class Account. All associated
descriptors and symbol tables must be drawn too.
Question4: (12 marks)
Consider the following Context-Free Grammar G = ({S,A,B},S,{a,b},P) where P is
(1) S →Aa
(2) S →bAc
(3) S →dc
(4) S →bda
(5) A →d
Do not forget to use the augmented grammar with the additional production { S’→S $ }.
We want to construct a subset of the items of LR (0).
1. Compute First (A), First (S), Follow (A), Follow (S).
(4 marks)
Show the details of the computations.
2. Computer the item S0 (initial state) of the LR(0) associated with the above augmented
grammar. Detail your answer.
(4 marks)
3. Compute the following items: S1 = goto (S0, S); S2 = goto (S0, A). Detail your answers
(4 marks)
III. Unfamiliar Problems Solving
Objectives. The aim of the question in this part is to evaluate that the student has some basic
knowledge of the key aspects of the lecture material and can attempt to solve unfamiliar
problems.
Question5: (6 marks)
Build the intermediate representation associated with the code of the ‘deposit’
method defined in the Account class (question2). Adopt the same conventions used
in classroom for the code intermediate representation.
Download