Professional Documents
Culture Documents
ASSESSMENT COMP2010C
PATTERN
TIME 10 ; 00 AfV1
This paper is suitable for candidates who attended classes for this
module in the following academic year(s):
2014/2015 to 2016/2017
2016/17-COMP2010C-1-EXAM-1
© 2016 University College London TURN OVER
.. ,
Exam Rubric
• This is a 2.5 hour exam.
• Answer both questions from Section A (Ql 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.
• Grab the low-hanging fruit: make sure you solve all the problems whose answers are easy or obvious
to you before tackling the harder problems.
Good Luck!
b b b
a b
a
(b) The regex (a(bb)*(aa)*)* accepts all strings over {a, b} that have an odd number of as and an even
number of bs. True/False [2]. Justify [3]. [5]
(c) JFlex accepts only regular languages. True/False [21. Justify [3]. [5]
(d) For L: = {a,b,c}, produce an NFA that accepts the following regular expression: [10]
(e) Convert the following NFA over the alphabet L: = {a, b} into a DFA that recognizes the same
language. [10]
E
[5]
(e) The following is a Three Address Code (TAC) Intermediate Representation for a register machine:
it contains a function called foo, which takes an integer parameter n. Identify and describe what
the code does in plain English, and write down the high-level language counterpart in Java-like
pseudocode. '
1 faa:
2 tl = n EQ I
3 CJUMP tl labell
4 t2 = n - I
5 PARAM t2
6 t3 = CALL faa
7 t4 = n MULT t3
8 return t4
9 labeU:
10 return I
[10]
Total for Question 2: [34]
3. Syntax Analysis
(a) Remove 'left recursion from the following grammar. [8]
S -> Sa I Xx I y
X -> z I Sd
Y -> Yy I d I €
S -> xA
A -> Bx I D
B -> xS I CxD
C -> yD I €
D -> zD I €
i. Compute the FIRST and FOLLOW sets for the above grammar. [5]
ii. Construct the LL(l) parsing table for this grammar. [5]
(c) Create the closed LR(l) item set for the following grammar's start symbol. [7]
E -> (E) IA IB
A A+AIA*Alt
B ~B IB v Bit
3 int A() {
4 int y = X + 5;
5 return y;
6 }
8 int B(){
9 int X = 5;
10 returnA();
11 }
12
13 int main () {
14 print B();
15 }
vVhen executed, the function main is called; print B( ) will print the return value of function call
B() to the standard output. Write down the output when this language uses 1) static binding,
and 2) dynamic binding. If the output values are different, explain the reason why. [81
(c) Given the following scoping rules for a fictional language:
1. Use an identifier only if defined in the enclosing scope
2. Do not declare identifiers of the same kind with the same name more than once in the same
lexical scope
Define a Symbol Table data structure that a semantic analyser could use to check the above rules
in lava-like pseudocode. Illustrate how to use the Visitor pattern and the Symbol Table previously
defined to check the above rules.
[14]
Total for Question 4: [32]