1)In Pure LISP, given that the current values of the variables are as
follows (yes, I know there aren't supposed to be variables in a purely
functional language!):
A: 1
B: A
C: (+ 1 2 3 A B)
what are the results of evaluating the following expressions:
A
(QUOTE A)
B
(EVAL B)
(+ 1 (CAR (CDR C)))
C
(EVAL C)
(LET ((B 3)) (EVAL C))
Note: One of the expressions produces an error.
2)Using C precedence rules, draw the abstract syntax tree (also known
as the expression tree for the following two expressions (real
expressions, found in HUGS source code):
(i=(size_t)strlen(t)%BIGEXP)!=0
isAp(x) && followInd(fun(x)) == nameIntToInteger
You may assume that strlen, isAp, followInd, and fun are all function
names; size_t is a name of a type.
3)What is the value of the variable a after the execution of the
following (pseudo)code, if the language uses pointer semantics for
assignments? What is its value if value semantics is used? Note: In
this language, the lists are mutable objects.
a = (1 2 3 4 5 6); // a list
b = tail(a); // no copying, if pointer semantics
set third element of a to 17
set second element of b to 44
4)The operational semantics of the C for statement by translating it
into equivalent code that uses only conditional and unconditional goto
is to control the flow of execution. Give a similar translation for C
switch statement. Do not forget to explain what happens to break
statements in your translation.
C Statement
for (expr1; expr2; expr3) {
.....
}
Operational Semantics
expr1;
loop: if expr2 =0 goto out
.....
expr3;
goto loop
out: .....
i need the solution before 11/29 |