University College London: Module Code Assessment Patiern Module Name
University College London: Module Code Assessment Patiern Module Name
ASSESSMENT COMP2010C
PATIERN
TIME 2:30 pm
This paper is suitable for candidates who attended classes for this
module in the following academic year(s):
2014/15
2015/16-COMP2010C-001-EXAM-4
© 2015 University College London TURN OVER
COMP207P: Compilers, 2016
Exam Rubric
• Answer both questions from Section A (Q1 and Q2) and one question from Section B (Q3 or Q4).
Suggestions
• When in doubt, state any assumptions you make in solving a problem.
• Read the questions carefully. Be sure to answer all parts of each question.
Good Luck!
(d) Convert the following NFA over the alphabet ~ = {a, b} into a DFA that recognizes the same
language. [lOJ
a = 10
else{
a "'= i + b
}
i++
[10]
Total for Question 2: [34]
3. Syntax Analysis
(a) Remove left recursion from the following grammar. [8J
S -+ Xx I y I Sz
X -+ Xz I Sxd I yd It
(b) Consider the following grammar.
S -+ yzA
A -+ xB I D
B -+ xS I CxD
C -+ yzD I C
D -+ zD I t
i. Compute the FIRST and FOLLOW sets for the above grammar. [6J
ii. Construct the LL(l) parsing table for this grammar. [6]
(c) Create the closed LR(l) item set for the following grammar's start symbol. [7]
E -+ (E) I A I B
A-+A+Alt
B-+B*Blt
(d) LALR compresses two closed LR(l) states (item sets) that contain common cores. Create LR(l)
states whose LALR compression introduces a reduce/reduce conflict.
[5]
Total for Question 3: [32J
where fdef is a keyword; functionName is the name of the function; the formal parameters form a
comma separated list, with each parameter being defined as paramName:type, where paramName
is the name of the parameter and type can be int, bool or float. The body is enclosed in { } and
consists of local variable declarations followed by statements. Use non-terminal B as a placeholder
to refer to a function body (no need to define it further).
An example list of function declarations follows:
fdef add (a: int, b: int) : int {
c : int;
c = a + b;
return c;
}
fdef or (a: bool, b: bool) bool {
else return b;
[12]
(c) Consider the following fragment of pseudo code:
List the type rules that a plausible type checker would check when dealing with statements [lJ and
[2J. For each statement, state also whether the type checker would fire a type checking error and
why. [14]
Total for Question 4: [32]