## CSE 531S (Fall 2011) Homework 2: Flow Graphs, DFST, Dominators

Lab Assigned Due
(in class)
13 Sep 20 Sep
Solution write up here.
1. For each program shown below
• Draw a control flow graph for the program. You are welcome to make basic blocks as large as you like, provided all explicit control flow is shown between nodes of your graph. Label your nodes (or show contents) using the appropriate predicate or statement name. You need not include all the syntax (braces) in your flow graph. Just include what is necessary to show the structure and single-letter contents of the program.
• Draw a depth-first spanning tree (DFST) for your control flow graph.
• Draw the dominator tree for your control flow graph.

#### Programs:

• ```     func1() {
if (p) {
a;
if (q) {
b;
}
else {
c;
if (r) {
d;
}
else {
e;
}
}
f;
}
else {
g;
}
h;
}
```
• ```      func2() {
while(p) {
while(q) {
while(r) {
a;
}
}
}
}
```
• I know the syntax below isn't C but the repeat....until construct executes its contents and then tests if the predicate is true, in which case the loop is done. Otherwise the loop repeats.
```     func3() {
repeat
repeat
repeat
a;
until(r)
until(q)
until(p)
}
```
• The Java try...catch...finally syntax is described here. A more detailed explanation appears here . Tricky part: According to the Java standard, you must Assume that any exception could be thrown by the contents of the try, catch, and finally blocks. See this.
```     func4() {
try {
a;
b;
c;
}
catch (Except1) {
d;
}
catch (Except2) {
e;
}
finally {
f;
}
}
```
2. Chapter 14 problems:
• 5 (page 636)
• 6 (page 636)
• 9 (page 637) (read over problem 8 to prepare)