University College London: Module Code
University College London: Module Code
ASSESSMENT COMP2010C
PATTERN
DATE 15-May-15
TIME 14:30
2014/15-COMP2010C-001-EXAM-95
©2014 University College London TURN OVER
Section A (Answer BOTH Questions)
1. Finite State Automata and Lexical Analysis
(a) S++ uses':' as the type specification operator and also to map keys to values in dictionaries, ': :'
as concatenation, and ': =' as assignment. All share the prefix': '.
i. How does a lexer differentiate the ':', ': : " and': =' tokens from each other? [4]
ii. How does a lexer differentiate the two uses of ' : '? [2]
(b) Your parser supported multiline comments, but not nested multiline comments.
1. Describe a partial solution using JFlexj sketch your solution in JFlex' syntax to demonstrate
your familiarity with JFlex. [4]
]1. Why is this solution partial? [2]
111. Describe how you would change your parser to solve it generally. [4]
(c) For ~ = {a,b,c}, produce an NFA that accepts the following regular expression: [8J
(d) Consider the following NFA over the alphabet ~ = {a, b}. Convert this NFA to a DFA that
recognizes the same language.
b,C:
[10]
Total for Question 1: [34]
c [b+ 1] 7 - a;
a = c [b] + 2;
[10]
Total for Question 2: [34]
3. Syntax Analysis
(a) Explain the role nondeterminism plays in the parsing of an arbitrary context-free grammar.
[5]
(b) LR(l) parsing contends with three types of conflicts, shift/shift, shift/reduce and reduce/reduce.
i. True/False. [3]
ii. Justify. [5]
(c) Most parser generators use LALR(l), not LR(l).
1. In terms of item sets, define LALR(l) parsing and explain how it differs from LR(l). [5]
ii. What is the principal disadvantage of LALR(l) relative to LR(l)? [2]
iii. What is the principal advantage of LALR(l) over LR(l) parsing? [2]
(d) LALR compresses two closed LR(l) states (item sets) that contain co=on cores. Create LR( 1)
states whose LALR compression introduces a reduce/reduce conflict.
[5]
(e) Prove that LALR state compression cannot introduce a shift/reduce conflict.
[5]
Total for Question 3: [32]
c = a + bi
return c;
}
fdef or (a: bool, b: boo 1 ) bool {
else return b;
Draw a UML class diagram for the classes that are required to build ASTs that correspond to
declarations like this. Include the association notation (i.e. multiplicity). Assume a reasonable
Context Free Grammar for this language to decide types of AST nodes. Use class B to represent
the body of the functions. [10]
(c) Consider the following code fragment written in a fictional language.
int x = 10 ;
int A(){
int Y = x + 5',
return
Yi
}
int B(){
int x = 5',
return A()i
int main () {
print BO;
When 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. [6]
(d) Explain what forward reference is, and its impact on semantic analysis. [6]
Total for Question 4: [32]