







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various programming concepts including notation systems (infix, prefix, and postfix), precedence rules, data types (primitive and abstract), memory management (compaction, static and dynamic allocation, and garbage collection), and related topics such as coroutines, assertions, and timing patterns. It also includes examples and exercises.
Typology: Exams
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Final Exam CMSC 330 Sections 0201, 0202 15 December 1998 Point total: 175
(please print)
The point value for each question is indicated (in parentheses). Do your own work; use your time wisely; enjoy semester break.
(15) 1. On the line provided write the letter corresponding to each statement below that
(20) 2. On the line provided, write the letter corresponding to each statement below that is TRUE.
a. A variation in subprogram control frequently used for error handling is coroutines. b. Exception handlers can not be explicitly invoked by the programmer. ^c. An assertion is a type of exception that states a relationship that must hold during program execution. xl. Propagation of an exception is along the dynamic chain. e. The advantage of coroutines is that when control returns to the coroutine it returns to the first statement of the coroutine. f. The variation on program control that is based on a real or simulated time scale is called a timing pattern. g. A synchronization approach commonly used for hardware devices is message passing. -h. Mutual exclusion is a principle that prohibits multiple tasks from accessing the same data object simultaneously. i. When critical regions are used to implement mutual exclusion, multiple tasks must be in the critical region at the same time. ^-j. When the rendezvous is used to communicate among concurrent tasks, multiple tasks must be in the rendezvous at the same time. sk. The global referencing environment is a subset of the nonlocal referencing environment. A. Compaction of memory is sometimes necessary to generate contiguous blocks of memory. m. Static memory allocation is necessary to enable recursion and dynamic data structures. In stack-based storage management, storage is freed in reverse order of allocation (i.e., LEFO). o. In heap management, storage is freed in reverse order of allocation (i.e., LIF'O). p. Two problems of memory management are garbage and dangling participles. Some languages (e.g., C) permit the programmer to directly control some aspects of dynamic memory management. ^r. Some languages (e.g., C) permit the programmer to directly control some aspects of static memory management. ^-s. During garbage collection, other processing is suspended. --1 Two approaches to direct reuse of memory are first fit and best fit; first fit is more time efficient.
var X: array [-2.. 0, 0.. 1] of integer;
for i := -2 to 0 do forj:=0to 1 do
Assume the following:
O d- o
£>
^
rJ r
,/n
(12) 9. Assume that the two-stage mark-sweep algorithm for garbage collection is used for this LISP example. A stack and heap are indicated for six points in the computation of the function combine. Indicate how garbage collection would proceed during execution of combine. Each word consists of two parts; the first part can either be an element of data or a pointer, the second part is a pointer. Shaded words indicate words that are not available as free space. Mark words by outlining them. (In LISP, the cons function concatenates two lists).
User-defined function: (defun combine (x) (cons '(q r s) x )) _ \ -^'^ 'V , *s ^ Function call: (combine '(a b)) ;, ..-^ f
stack heap
Prior to call
Call Mark Post sweep combine= '(q r s a b)
Post return
(12) 13. Give the output for the following program. The var preceding a parameter indicates pass by reference. The command writein prints the output and provides a carriage return.
program Main; var i, j: integer; / procedure Prod (var i: integer; function F (k : integer): integer); var h: integer; begin h:=1; writein ("i =", i. "j =", j, "h =", h, "in Prod"); h := F(i); writein ("i =", i, "j =", j, "h =", h, "in Prod"); end;
procedure Proc2; varj: integer; function G (varj: integer):integer; begin j := 2;
writein ("i =", i, "j =", j, "in G"); end; begin j := 3; writein ("i =", i, "j =", j, "in Proc2"); Prod G, G); writein ("i =", i, "j =", j, "in Proc2"); end;
begin i:=4; j:=5; Proc2; writein ("i =", i, "j =", j, "in Main"); end.
OUTPUT
f - "b.
C '
11
(15) 12. The following code is Pascal-like. Execute the program 4 times, each time assuming the parameters are passed using one of the following methods: call by name, call by reference, call by value, and call by value-result.
Program parameter var i: integer; A: array [1 ..3] of integer; Prod (j, k: integer); begin V- ;,,,.,
k:=k + 1; f^ Lu>
print ("i = ", i., "j = ", j, "k = ", k); i := 4; j:=j-2; ft£i> print ("i = ", i, "j = ", j, "k = ", k); end;
begin fori:= 1 to 3 do A[i] := i + 1; for i:= 1 to 3 do print ("A[", i, "] = ", A[i]); i:=2; Prod (i, A[i]); print ("i = ", i); for i:= 1 to 3 do print ("A[", i,"] =", A[i]); end.
Give the output for each method:
L
i
t
K flti^ .. ————"———
k_ _A_r£L--
_^£-J-—— jc^ j —— n&
A ^ 3. f-
A T-^M
Call by name
; - ' J = i K-^ L - z. ±--3 ^ L-Z
""'o.r'
Call by reference
i- 1 j-i y-.-l
L *-L y-i_ K=f
L'
flt*^
Call by value
L^ J=l K ^ <.--*
i -i j--b *=i t.^ J--' i*-- L- r
(7) 3. Use the BNF provided to develop a parse tree for a!2[b,c3].
3 ]
(6) 4. Generate the finite state automaton for the regular grammar below.
A -> aA | bC | c B -> aA | bB | cC C -> aB | bC | c
(14) 10. Use the Smalltalk subclass definitions and methods for each subclass to provide the indicated output.
Object subclass: # ClassA ClassA subclass: # ClassB ClassB subclass: # ClassC instance VariableNames:'' instance VariableNames:'' instance VariableNames:'' class VariableNames:'' class VariableNames:'' class VariableNames:'' poolDirectories:'' poolDirectories:'' poolDirectories:'' category: nil! category: nil! category: nil!
ICIassA methodsFor: 'basic'! picklt 'pick classA' printNl! peellt self picklt!! steamlt 'steam ClassA' printN!
jClassB methodsFor: 'basic'! picklt 'pickclassB' printNl! steamlt self peel It!!
iCIassC methodsFor: 'basic'! steamlt self peellt!!
Statement Output
x |x_ ClassA new.x picklt! x |x_ ClassA new.x peellt! ——P x |x_ ClassB new.x peellt! x |x_ ClassB new.x steamlt!
x |x_ ClassC new.x picklt! x |x_ ClassC new.x peellt! x |x_ ClassC new.x steamlt!
8
(10) ,15. The psuedo code for two Ada tasks is provided. Task A reads data from an input device into a buffer. Task B processes the data in the buffer. Following the tasks is a set of conditions. Indicate the statement number of both tasks that would be active for each condition.
task A; task B; begin begin A1 -input first data set loop loop B1 wait (StartB); A2 signal (StartB); B2 - process data set A3 wait (StartA); B3 signal (StartA); A4 - input next data set endloop; endloop; end task B; end A;
Condition task A task B
A is reading in the first data set N_
B is processing the first data set n A is reading in the third data set
B has completed processing the fourth data set / ,
13