CpS 450 Language Translation Systems

Final Exam Review

The final exam will include the following questions:

  1. Give the phases of a compiler.

  2. Given a sample Dream program with multiple classes, inheritance, and overriding, draw the complete program runtime stack as it exists while inside the call to a selected function. For each entry in the stack, show its contents, as well as any identifiers that are bound to it. For entries in the current activation record, also show the offset from BP. For entries that reference an object, draw an arrow to an object layout diagram. Show the virtual function tables for each object.

  3. Give the assembly code an A-level Dream compiler would generate for the selected statements in a Dream program.

  4. Define optimization terms.

  5. Given a sample Dream program, discuss various optimizations that a Dream compiler could perform safely.

A sample review program

class Parent is
  x: int
 
  initP(newX: int): Parent is
  begin
    x := newX
    initP := me
  end init

  foo(a: int; b: int): boolean is
  begin
    out.writeint(a + b)
    foo := false
  end foo

  getX(): int is
  begin
    getX := x
  end getX

end Parent

class Child inherits from Parent is
  y: int

  initC(newX: int, newY: int): Child is
  begin
    initP(newX)
    y := newY
    initC := me
  end init

  getY(): int is
  begin
    getY := y
  end getY

  ~ overrides Parent's foo method
  foo(a: int; b: int): boolean is
  begin
    out.writeint(a*b)
    foo := true       <------------------
  end foo
end Child

class Main

  p: Parent
  
  start()
    a: int
  begin
    p := new Child.initC(3, 5)
    a := 10
    p.foo(a, 5)
  end