Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Compiler design


Published on

  • Be the first to comment

Compiler design

  1. 1. COMPILER DESIGN RUN-TIME ENVIRONMENTS Shashwat Shriparv InfinitySoft
  2. 2. Run-time mainly deals with the actions that must occur to implement the program • The allocation and deallocation of data objects is managed by the run-time support package • The representation of data objects at run-time is determined by its type
  3. 3. Source Language Issues Procedures A procedure definition is a declaration that, in its simplest form, associates an identifier with a statement. identifier is the procedure name & statement is the procedure body
  4. 4. A Pascal pgm for reading & sorting integers program sort(input,output); var a : array [0…10] of integer; procedure readarray; var i: integer; begin for i := 1 to 9 do read (a[i]) end; function partition (y, z: integer) : integer; var i,j,x,v : integer; begin… end; procedure quicksort (m,n : integer); var i : integer; begin if( n > m) then begin i := partition(m,n); quicksort(m,i-1); quicksort(i+1,n); end end; begin a[0] := -9999; a[10] := 9999; readarray; quicksort(1,9) end
  5. 5. Activation Trees Assumptions about the flow of control among procedures during the execution of a program: Control flows sequentially Each execution of a procedure starts at the beginning of the procedure body and eventually returns control to the point immediately following the place where the procedure was called
  6. 6. Execution of a procedure body is referred to as an activation of the procedure The “lifetime” of an activation of a procedure is the sequence of steps b/w the first and last steps in the execution of the procedure body including the time spent for execution Lifetimes are either non-overlapping or nested
  7. 7. A procedure is recursive if a new activation can begin before an earlier activation of the same procedure has ended An “activation tree” is used to depict the way control enters and leaves activations
  8. 8. In an activation tree: Each node represents an activation of a procedure The root represents the activation of the main program The node for a is the parent of the node for b iff control flows from activation a to b The node for a is to the left of the node for b iff the lifetime of a occurs before the lifetime of b
  9. 9. Output suggesting the activations of procedures enter readarray leave readarray enter quicksort(1,9) enter partition(1,9) leave partition(1,9) enter quicksort(1,3) leave quicksort(1,3) enter quicksort(5,9) leave quicksort(5,9) leave quicksort(1,9) execution terminated
  10. 10. Shashwat Shriparv InfinitySoft