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
A → aA | b
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.
Apply all applicable optimizations to:
x = 3;
y = x;
z = x + 5;
a = y * 2;
b = 8;
c = b / 2;
d = a + 0;
if (a < b && c > d || e == f)
x = 1;
else
x = 0;
a = b * (-c) + d / e
E → E + T | T
T → T * F | F
F → (E) | id
Show the handle at each step for reducing the string: id + id * id
Share this link via
Or copy link