[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] /12q.html [12q.txt(Text)] [Search ]
Thu May 10 16:40:03 PDT 2012
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS320/12 Questions on Chapter 10 - Subprograms

      Question 1a

      a. Fill in the blanks. The two places that variables and objects are usually stored in a running program are the S___________________ and the H_____________.

      Question 1bcd

      b. List the differences between data that is on the stack and data that is on the heap.

      c. Consider an activation record and an activation record instance. Which is like a class and which is an object?

      d. Using the UML draw a class diagram of the RunTimeStack, the ActivationRecords, and the relations between them in a typical high-level language. Show the normal stack operations in the RunTimeStack. Show no operations or attributes for the ActivationRecord.

      Answer: [ ole4.gif ]

      d. Give three(3) reasons why implementing subprograms in an ALGOL-like language is more difficult than implementing subprograms in a language like FORTRAN-77.

      Question 2 Activation records

      a. Draw a UML diagram of an activation record for a language like "Street" BASIC where a typical call of a subprogram looks like this:
       		100 GOSUB 1000
      (No parameters, no name, just a line number) and a typical subprogram ends
       		1099 RETURN
      (nothing returned... but the interpreter jumps back to the statement after the last GOSUB).

      Answer: [ ole3.gif ]

      b. Draw a UML diagram of an activation record for a language like FORTRAN-77.

      Answer: [ ole.gif ]

      c. Draw a UML diagram of an activation Record for a language like Algol, Pascal or Ada

      Answer: [ ole1.gif ]

      d. Draw a UML diagram of an activation record for a language like C or Java 1. (No functions declared inside functions...).

      Answer: [ ole2.gif ]

      Note: In JavaScript the activation record is explicit and available to the programmer!

      Question 3 Static Chains etc

      a. Explain with examples: static chain, static depth, nesting depth, chain offset.

      b. Explain how a static chain is used to bind an identifier occurrence to the correct non-local declaration.

      Question 4 Evolution of the Runtime Environment

      Explain (using diagrams in the UML) why subprograms in C and Java 1.0 are easier to implement than in Algol or Pascal but harder than in FORTRAN I thru 77.

      Template < L in C|BASIC|FORTRAN 77> Question

      a. Draw diagram (using the UML) of Programs, SubprogramCalls, SubprogramDefinitions (if any) in L. (Note. Draw classes and relations, no operations of attributes)

      b. Use the diagram to explain how subprogram calls can be implemented in L.

      Project Question

      Does your project language have subprograms? How complicated will the activation records be? Can you draw (using the UML) a diagram of how Programs, SubprogramCalls, SubprogramDefinitions are related in your language.

    Review

End