CS 355 TEST ONE Name__________________________________ Summer 2012 Due: July 26th ALL questions are valued at 10 points each. (1). Show the postfix of the following expression and using a stack show what the values would be if a=3, b=8, c=1. (** is raise to a power) a*a-b/(c**4**a+1)-a (2). Why were the early versions of the BASIC programming language interpreted? (3). Composite data types (arrays & records) can be a problem when they are passed as parameters or returned by functions. Why? What can the programmer do to solve the problems of passing and returning arrays and records in Pascal, C, and Fortran? (remember, the language may already have solved some of the issues). (4). Consider the following: procedure SWAP2 (x, y: integer); procedure F ( ) : integer; var z: integer; begin z := x; x := y; return z end F; begin y := F ( ) end SWAP2; On the back of this page, show a diagram of activation records on the runtime stack of the above procedures if the call to SWAP2 is made in the main program. (5). Rewrite the following program fragment using goto statements to explicitly show the flow control through the loop. for ( int i = n; i > 0; i-- ) if ( x != A[i] ) break; (6). In a language with strong typing, what advantage is offered by static checking rather than dynamic checking? (7). Given the following grammer: ::= | s ::= | ::= repeat until ::= while do ::= c1 | c2 Draw the parse tree for the following: repeat while c1 do s until c2 (8). Given the following ML function: fun f (x,A) = if null A then 0 else s + hd A + f (s, tl A); what is the output of f (10, [2, 3, 4, 5]); ? (9). Write an ML function "fourth" of 'a list -> 'a that returns the 4th element of a list. you may assume that ALL lists passed to this function have at least four elements. (10). Write an ML function "max" of type int list -> int that returns the largest element of a list of integers. don't worry about an empty list as input.