CS 430 Midterm Exam
Form B
Name _________KEY___________________
procedure scope2 is a, b: integer; function p return integer is a : integer; begin –- point 1 a := 0; b := 1; return 2; end p;
procedure print is begin -- point2 put(a); new_line; put(b); new_line; put(p); new_line; end print;
procedure q is b, p : integer; begin – point 3 a:= 3; b := 4; p := 5; print; end q; begin a := p; q; end scope2; |
static scope
rules 3 1 2 |
dynamic scope rules 3 4 5 |
language design time |
type |
language implementation time |
size of a type (i.e. # of bits) |
compile time |
name type |
load time |
location |
run time |
value location of subprograms |
case
x-1 is when 0 => y := 0; z := 2; when 2..5 => y := 3; z := 1; when 7 | 9 => z := 10; when other => null; end case; |
switch (x-1) { case 0:
System.out.println (x); break; case 2: case 3: case 4: case 5: System.out.println (x); break; case 7: case 9: System.out.println (x); break; default:
System.out.println (" default "); break; } // end
switch |
num := 5; for i in 1..num loop ada.integer_text_io.put (i); num := 3; end loop; |
5 |
5
points
3 |
FORTRAN |
by reference |
Java |
by value |
Pascal |
by reference or by value |
Ada |
by reference, by value, by result,
by value/result |
S → 0A1
A → 0A1
A → ℇ
Generate 3
valid sentences in this language. 6 points
S / |
\ 0 A
1 | ℇ 01 |
S / |
\ 0 A
1 / | \ 0 A 1 | ℇ 0011 |
S / |
\ 0 A
1 / | \ 0 A 1 / | \ 0 A 1 | ℇ 000111 |
At least one 0 followed by one 1
but may be any number of 0’s followed by an equivalent number of 1’s OR 0n1n
where n >= 1 |
readability (which includes overall simplicity,
orthogonality, control structures, data types & structures and syntax) |
writability (which includes
simplicity and orthogonality, support for abstraction, expressivity) |
reliability (which includes type
checking, exception handling, aliasing, readability and writeability) |
cost (of training programmers, of
writing programs, of compiling, of executing, of the language implementation
systems, of poor reliability, of maintaining programs) |
FORTRAN |
compilation |
Java |
compilation and interpretation |
Pascal |
compilation |
InfoRecord = Record number : integer; earnings, tax : real; end; EmployeeRecords = Array [1..100] of InfoRecord; |
dimension number (100) dimension earnings (100) dimension tax (100) |
input |
output |
assignment |
iteration |
selection |
statement: FORTRAN assignment x = 5.2 |
comment: the value 5.2 is stored in the
location referenced by x |
statement: Pascal output
statement writeln (x); |
comment: the value stored in the location
referenced by x will be retrieved and printed to the screen. |
1234567898765432123456789
READ (5, 13) X, Y, I, Z 13 FORMAT (F3.2, 1X, F7.3, I4, F2.1) WRITE (6, 14) X,Y,I,Z 14 FORMAT (1X, F5.2, 2X, F7.2, 1X, I5, 1X, F3.1) STOP END |
X 1.23 |
Y 5678.987 |
|
I 6543 |
|
Z 2.1 |
Output 5 points
|
|
1 |
. |
2 |
3 |
|
|
5 |
6 |
7 |
8 |
. |
9 |
9 |
|
|
6 |
5 |
4 |
3 |
|
2 |
. |
1 |
the default for output is to the screen. Thus, all of the output will go to the file, even the prompts |
4 points
reserved
words: are words
that may not be used as identifiers |
key words: may be
used as identifiers. their meaning is
determined by context. |
Which does each
of the following languages use? 4 points
FORTRAN |
key words |
Pascal |
reserved
words and pre-defined terms |
Ada |
reserved
words |
Java |
reserved
words |
|
What is the output of an
XLST program? 1 point
|
Syntax analysis (consisting of lexical analysis and parsing) and translation |
4
points
functions return a single value –
their parameters are most often passed by value (i.e. copy) procedures or subroutines return 0, 1, or many values. Their values are returned through the parameter list and their parameters are generally passed by reference. |
Language |
feature |
opinion |