CSC 330 Lecture Notes Week 7
Midterm Study Guide
Further Discussion of Operational Semantics, Topics from Chapters 4 & 5
Finish Topics from Week 6
The evalFormal method a conceptually important piece ... has the same semantics as evalIdentLValue ... Also, there is no need to do error processing ...to
The evalFormalLValue method is a conceptually important piece ... it has the same semantics as evalIdentLValue ... Also, there is no need to do error processing in ...
The last conceptually important step of bind to tos to nextTosto
The last conceptually important step of bind is to copy tos to < nextTos
This completes the officially entry into the callED function's stack frame.to
This officially completes the entry into the callED function's stack frame.
a 0: ----------------------------------------------------> 0: undef a3 1: -----> 0: undef 1: undef 1: undef 2: undef 2: undef 3: 3 3: -----------> 0: undef ... 4: undef 1: undef ... 2: undef 3: -----------> 0: undef 1: undef 2: undef 3: 3 ...
Some Additional Discussion Semantics; in EJay and Other Languages; These Topics are NOT on the Midterm (but maybe the final)
int i; string s; void main() { i = 10; s = "123"; print i + s; }
int i; char c; int main() { c = 'x'; i = (int) c; i = i + 1; c = (char) i; printf c; // Prints the value 'y' }
What's going on here?int i; string s; int main() { s = "x"; i = (int) s; i = i + 1; s = (string) i; print s; // Prints the empty string. Why? }
Pascal:
program
var i: integer;
var ip: pointer to integer;
begin
i = 10;
ip = new integer;
^ip = i;
print i, *ip;
end;
C:
int i;
int* ip;
int main() {
i = 10;
ip = (int*) malloc(sizeof(int));
*ip = i;
printf("%d, %d0, i, *ip);
}
int i,j; void swap(int* x, int* y) { int temp; temp = *x; *x = *y; *y = temp; } int main() { i = 10; j = 20; swap(&i, &j); printf("i=%d, j=%d", i, j); }
int i; ref int ip; void main() { ip = new int; f(); g(); ip = new int; // Garbagizes the first new int pointed to by ip } ref int f() { ref int fip = new int; ... } // Return from f garbagizes the int pointed to by fip ref int g() { ref int gip = new int; ... free gip; // This explicitly frees the int pointed to by gip } // thereby keeping it from becoming garbage
int i,j,k; void main() { i = 10; j = 20; k = eval("i + j"); }