Compilers Qualifying Examination
January 12th, 1999 -- 12-14pm
1. (40%)
Consider the following languages:
(a) Is L1 suitable for top-down parsing?
(b) Is L1 suitable for bottom-up parsing?
(c) Is L2 suitable for top-down parsing?
(d) Is L2 suitable for bottom-up parsing?
(e) Is L3 suitable for top-down parsing?
(f) Is L3 suitable for bottom-up parsing?
Briefly (informally) justify your answers.
2. (30%) Consider the programming language C. We define the `comment' token as a sequence of characters beginning with /* and ending with */. Comments cannot be nested. Give a regular expression for the `comment' token. You can give the expression in LEX.
3. (30%)
Consider the following program fragment:
while (!(x == y))
if (x > y) {
x = x-y;
if (x== y*5) {
break;
y=x+6;
}
}
else {
if (y==x*5) {
continue;
}
y = y-x;
}
return x;
Suppose we want to generate intermediate code for the above program. What are the basic blocks? What intermediate code is in each basic block?
Note: You do not have to apply optimization to the code in each basic block.