Homework 2: Flow Graphs, DFST, Dominators

Lab Assigned Due
(in class)
11 Sep 18 Sep
For each program shown below
  1. 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.
  2. Draw a depth-first spanning tree (DFST) for your control flow graph.
  3. Draw the dominator tree for your control flow graph.

Programs:

  1.      func1() {
            if (p) {
               a;
               if (q) {
                  b;
               }
               else {
                  c;
                  if (r) {
                     d;
                  }
                  else {
                     e;
                  }
               }
               f;
            }
            else {
               g;
            }
            h;
         }
      
  2.       func2() {
             while(p) {
                while(q) {
                   while(r) {
                      a;
                   }
                }
             }
          }
      
  3. 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)
         }
      
  4. 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.
         func4() {
            try {
               a;
               b;
               c;
            }
            catch (Except1) {
               d;
            }
            catch (Except2) {
               e;
            }
            finally {
               f;
            }
         }
      


Last modified 07:52:48 CDT 11 September 2007 by Ron K. Cytron