Written Assignment #3

Examine the following code snippet:

        x.y = a[n+1].b.c * d;

1.) Construct an abstract syntax tree for this code. The root of the tree should be an Assignment node. a is an array of structures. y, c, and d are integers. x and b are structures. Include a type field for each node that can have a type associated with it.

Hint: You can use your solution from lab 3 to help you with this part, though not everything in the above code can be found in that lab. All of the AST structures can be found in the text (Chapters 7, 8, and 9).

2.) Fill in the type field for each node using the type checking process described in class. Give a step by step walk through of the type checking process, similar to the example given on page 332 of the text that we went through in class.

Assume that all the appropriate information can be found in the appropriate symbol table. In other words, there are no type mismatches in the above code.

Hint: remember that it is possible for some type fields to be set during the creation of the Abstract Syntax Tree - do not forget to include this information.

3.) Examine the following method:

        public int method3(int x, String y) {
	  int a;
	  String[] b = new String[x];
	  a = 0;
	  
	  while(a < 20) {
	    if(a == 10)
	      break;
	    a++;
	  }
	  
	  try {
	    if (a > 2)
	      b[a] = y;
	    else
	      b[x] = y;
	  } catch (ArrayIndexOutOfBoundsException e) {
	    return -1;
	    a = -1;
	  }
	  return a;
	}


Determine the values of isReachable and terminatesNormally for each statement.

4.) Problem 11 on page 388 of the text. Give your answer in paragraph form - one or two paragraphs should suffice.