Show the activation tree and activation record contents for the following code at the point when factorial(1) is executing:
int factorial(int n) {
if (n <= 1)
return 1;
return n * factorial(n-1);
}
int main() {
int x = factorial(3);
Which is most efficient and why?
Show hash table implementation for storing the following identifiers using hash function h(x) = (sum of ASCII values) mod 7:
Identifiers: {sum, count, avg, total, temp}
Use chaining for collision resolution.
E → E + T | T
T → T * F | F
F → (E) | idBuild the complete operator-precedence table. Parse the string id + id * id using this table showing all stack operations.
I₀ = {[S’ → •S, $]}
Grammar:
S → AB
A → aA | b
B → c
Then compute GOTO(I₀, a) showing all steps.
Show the complete macro expansion for:
#define SQUARE(x) ((x) * (x))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define CUBE(x) (SQUARE(x) * (x))
result = MAX(SQUARE(3), CUBE(2));
Write an L-attributed syntax-directed definition for the following grammar that builds a syntax tree:
E → E₁ + T
E → T
T → T₁ * F
T → F
F → (E)
F → id
Draw the annotated parse tree showing all attribute values for the input: id₁ + id₂ * id₃
Compute the LR(1) items and construct the LR(1) parsing table for:
S’ → S
S → AA
Show the parsing actions for the input string “aab”.
a) Error recovery in parsing (panic mode, phrase-level recovery) b) Parameter passing mechanisms (call by value, call by reference, call by name)
Variables: a, b, c, d, e
Live ranges overlap:
– a and b overlap
– b and c overlap
– c and d overlap
– d and e overlap
– a and c don’t overlap
– b and e overlap
Draw the interference graph and assign registers.
Share this link via
Or copy link