Errata and Clarifications

Remember that you can get extra credit for finding bugs in the reference implementation or project materials before we do. In this page, we will post any bug fixes that have been made to any of the project materials.

PA5. 12/7/2004

Here is an example to help you understand the fields overriding better.
class A {
 	int blah;
 	void run() {
 		blah = 0; // uses A's instance blah

		print(blah); // prints 0
 		return;
	}

}
class B extends A {
	static int blah;
	
	void run() {
		blah = 30; // B's static blah, defined in the closest class
		print(blah); // prints B's static - 30
		print(B.blah); // prints B's static - 30


		 // it's illegal to do this.blah = 30; here

		return;

	}
}
class C extends B {

 	void run() {
 		blah = 10; // uses A's instance blah
		print(blah); // prints A's instance, 10
		print(B.blah); // prints B's static
		
		B.blah = 20; // uses B's static blah
		print(blah); // prints A's instance
		print(B.blah); // prints B's static


		this.blah = 40; // uses A's instance blah

 		return;
	}
}
class Program {
	static void main() {
		A a;
		B b;
		C c;
		a = new A();
		b = new B();
		c = new C();
		a.run();
		b.run();
		c.run();
		return;
	}
}

PA5. 12/6/2004

  1. When an integer exceeds the range of an int32, just keep the lower 32 bits in the register, that means, it will become an negative int. (hint, use BigInteger)
  2. You may have seen a clarification at this bullet sometime in the past. but that clarification is no longer valid.

PA5. 12/4/2004

  1. See 11/17/2004 RED text for update.

PA5. 12/2/2004

  1. Clarification on overriding

Instance methods can be overridden.

Instance fields can not be overridden due to semantic check 8.

The overriding issue does not apply to static fields and static methods.  Because they are not inherited.

Below are some examples:

 

The code below does not contain a semantic error.

class A{

    int foo(){

        return 1;

    }

}

class B extends A{

    int foo(){

         return 2;

    }

}

 

The code below contains a semantic error.

class A{

    int foo;

}

class B extends A{

    int foo;

}

 

The code below does not contain a semantic error.

class A{

    static int foo;

}

class B extends A{

    static int foo;

}

 

The code below does not contain a semantic error.

class A{

     static int foo(){

         return 1;

     }

}

class B extends A{

     static int foo(){

         return 2;

     }

}

 


 

 

 

PA5. 11/27/2004

  1. Illegal String related operations:
    When you see the following:
    1. new String();
    2. extends String
    3. class String { }

Use DecafSemanticError.error_10_StringComparison() to report it.

PA5. 11/26/2004

1.      When <id> can be both variable/field name or class name, always resolve it as class name.

A.x = 50; // if there is a class called A and a local variable called A, just treat A.x as accessing A's static field.

For example, the code below should give a semantic error about A.cc.

  1. FIx to previous clarification (see red text in 11/24/2005 item 3)

PA5. 11/24/2004

  1. Small fix to starter kit (DecafSemanticError.java):
 
public static void error_5_IllegalLocation(ErrorPosition pos, String idName) {
  outputError(null, "Identifier '" + idName + "' cannot be used as a location.");
}
  

2.             Static methods and fields are not inherited.

3.             DecafSemanticError #5 is a special case of PA4's SemanticError #2
In general, when accessing an undeclared local varialbes or fields in implicit way (foo = 30; ), you should report PA4's SemanticError #2. When accessing undeclared field in explicit FIeldAccess form (something.foo = 30;), report DecafSemanticError #2. However, if the name of the undeclared local variable or field also happens to be a method's name, you are required to report DecafSemanticError #5. The methods that can cause this collision are the
1) instance methods defined in the enclosing class and its superclasses 2) static methods in the enclosing class. Reference solution has been updated to reflect this change. Please check the result for your testcases carefully.

 
class Program {
 
  static void main() {
         Program p;
         p.foo = 50; // foo is a method name. Report PA5's error #5
         foo = 300; // foo is a method name. Report PA5's error #5
         return;
  }
  static void foo() {
         return;
  }
}
  

PA5. 11/17/2004

1.             Mix overriding for methods is not allowed. It's ok for fields.
Add the sentence in red to handout:
However, static method can not override instance method, you should use DecafSemanticError #9 to report this kind of mix overriding. Instance methods override static methods can not happen because static methods from parent are not inherited, therefore, no error needed.

2.             Continue to use semantic error from PA4 to report related errors. For example, using a class that is not defined belongs to PA4's semantic error #2 - "undeclared identifier"

3.             Clarification: please add the following item to the list of rules on page 4 of the PA5 handout. Logically, this new rule relates to the 7th item on this page. (The PA5 handout on the course web site has been updated.)

§                             A reference to a static field x of a class T is legal in both instance and static methods of class
T (and its subclasses), and is internally translated to T.x.

PA4. 11/7/2004

  1. Semantic Checks  
    You should only implement the 13 semantic checks listed in step 3.  There are semantic errors that do not fit any of them.  You should not implement extra semantic checks to catch the errors that fall out of the scope of the 13 semantic checks.  Below are a few example errors that your semantic checker should not catch:
  • Using types other than int, boolean, and String: static MyOwnType t;
  • String comparison: s1 == s2 where s1 and s2 have type String

PA4. 11/5/2004

  1. Actual Argument Evaluation for Method Calls
    Actual arguments to a method call should be evaluated in the reverse order.  For foo(e1, e2), e2 should be evaluated before e1.  Below is an example, the code should print out 1:
class Program{
  static int count;
 
  static int increment(){
     count = count + 1;
     return count;
  }
 
  static int subtract(int a, int b){
     return a-b;
  }
 
  static void main () {
      print(subtract(increment(), increment()));
            return;
        }
      }

 

PA4. 11/1/2004

  1. Scoping rule for decaf
    Each open brace opens a new scope; each close brace closes the inner-most scope. Arguments are in an outer scope relative to the method body. Shaddowing is allowed. For example:
 
static void foo (int a) {
  int a; // this a shadows the argument a
  a = 30;
  {
         int a; // this a shadows both of the a's above.
         a = 50;
         print(a); // prints out 50;
  }
  print (a); // prints out 30;
  return;

 

PA4. 10/31/2004

  1. No need to handle divide-by-zero
    In the case of dividing zero, just generate code as if it's dividng a non-zero expression.
  2. Initialize local varialbes and static fields.
    You are requried to initialize local variables and static fields implicitly. Integers have default value of zero, and booleans have a default value of false. You should initialize the strings with something that will cause segmentation fault when they are dereferenced. The easiest way to trigger segfault is dereferencing address zero. Samples:
    int i;
    print(i); // prints out 0
    boolean b;
    print(b); // prints out 0 for false
    String str;
    print(str); // Segmentation fault. The system will print out "Segmentation fault".
    You don't need to worry about it.

PA4. 10/30/2004

  1. No need to report missing static keyword
    We didn't include an semantic error for missing static keyword for method and fields, the reference solution won't emit errors for it, your solution shouldn't emit it either.
  2. main not Main
    Although simple.decaf contains static void Main(), it should trigger semantic error #3. The only signatures that main can have are these:
    static void main()
    or
    void main()
    due to the first mistake we made. However, conceptually, you should understand that all methods and fields in PA4 are static.
  3. Short-circuit evaluation is required for AND and OR
    You x86 code have to do short circuit evaluation for logical AND and OR.

PA1. 9/8/2004

  • Parenthesis around assignment expressions
    A couple of bugs have been fixed over the last couple of days in the reference implementation concerning the pretty printing of assignment expressions. The rule is that assignments should be parenthesized except when they are a statement. Here are a few examples of assignment expressions and how they should be pretty printed.
    Examples:

The expressions in this column:

Should be printed like this:

y = (x = z = 1) +5;

y = ((x = (z = 1))+5);

y = x = z = 1 +5;

y = (x = (z = (1+5)));

print(x=5);

print( (x=5) );

if( x=5 ){
-- print( x );
}

if( (x=5) ){
-- print( x );
}

while( x=x-1 ){
--print(x);
}

while( ( x = (x-1) ) ) {
--print(x);
}

PA1. 9/5/2004

  • Disable ASTPrinter before you submit
    Please comment out the code to pretty print before you make you last submit.
    // To print the AST, remove comments in the next three lines.
    // ASTPrinter debug = new ASTPrinter();
    // System.out.println("*** AST ***");
    // astRoot.accept(debug);
  • Don't modify ASTPrinter.java
    Please don't modify ASTPrinter.java in your starter kit. The reference solution once AST-printed something different from the starter kit's ASTPrinter. Now, the reference solution is using the exact ASTPrinter.java as the one in starter kit.
  • PrettyPrinter shouldn't print out unnecessary braces. SkimDecaf doens't handle scope.
    Example:

    Your pretty printer shouldn't output the extra braces inside main(). Here is the reference output:

    Notice the interpreter outputs 50 twice. That's saying, SkimDecaf doesn't have the notion of scope. The second assignment to variable a overwrites the first one.
  • You can create new files. Make sure you commit them into CVS.
    In section 4 "Requirements" in the PA1 spec, it says "You may not create new files". This is a mistake. The correction is, you are allowed to create new files, but please make sure you commit them into your CVS.
  • Enable assert in JVM
    By default, JRE doesn't throw AssertionError when assert statements in PA1 is false. To enable assertion checking JVM, go to Eclipse->Run->Run... Then select the instance of run configuration you are going to use, click "Arguments". In the "VM arguments" section, put: -ea
    Then JVM will throw AssertionError when an assertion is false.

PA1. 9/4/2004

  • Indentation for if statements and while loops without curly braces.
    There was a bug in the reference implementation that caused a statement like:
    ----if(x) exp;
    to be pretty printed as:
    ----if(x){
    exp;
    ----}
    instead of the correct:
    ----if(x){
    --------exp;
    ----}
    The problem has been fixed, and the implementation now prints the right thing.
  • Handling of asociative operators.
    There was a bug in the reference implementation that caused an expression like
    5+5+5
    to be pretty printed as
    5+5
    and to evaluate to 10, which was clearly incorrect. The bug has been fixed.
    In order to avoid making the same error in your implementation, keep in mind that the AST for the expression
    5+5+5
    actually looks like
    (+ 5 5 5)
    and NOT like
    (+ 5 (+ 5 5)).