e
Answer All Questions:
NAME:
LOGIN NAME:
This is an open book, open notes examination. There are eight questions.
All questions carry 15 points.
Some questions have a and b parts in which case they are weighed equally.
If you get 100 points, then you have max-ed the paper. It is possible that you get more than 100 points, which will be counted as extra points towards
your grade. Goodluck and have a happy summer.
Problem | Points Scored | Points Possible |
1 | 15 | |
2 | 15 | |
3 | 15 | |
4 | 15 | |
5 | 15 | |
6 | 15 | |
7 | 15 | |
8 | 15 | |
S -> ( S ) S | ) S ( S | epsilonThe terminal symbols are ( and ). Is the above grammar ambiguous and explain with examples.
b) Construct a SLR parsing table for the following grammar.
E -> E + T | T T -> T F | F F -> F * | a | b
b) What is the type of the following function (please derive the steps in the style of 6.12
fun member(a,x) = if null(x) then error else if a = hd(x) then x else member(a, tl(x));
Assume the type of error is void.
a)Suppose the procedure swap2 is declared as follows:
procedure swap2(x,y: integer); procedure f() : integer; var x:integer; begin (* f *) z := x; x: = y; return z end f; begin (* swap2 *) y := f() end swap2;Describe the effect of the procedure call swap2(i,A[i]) under each of the following parameter-passing methods:
main() { int i, a[5],b[5]; for (i=0;i<5;i++) a[b[i]] = b[a[i]]; }
for (i=0;i<10;i++) a[i] = random() % 2;
a:=b+c; d:=e; f:= a* c;b) For Fig 10.74 (page 713) Compute the live variables at the end of each block.