GATE Computer ScienceVery hardGATE CSE
With Sethi–Ullman numbering (left leaf = 1, right leaf = 0, internal node = max(l,r) if l ≠ r else l+1), what is the label of the root of ((a+b)*(c+d)) − (((e+f)*(g+h)) / ((i+j)*(k+l)))?
- A. 2
- B. 4
- C. 5
- D. 3
Correct answer: D. 3
Each product (x+y)*(z+w) has label 2; the division of two products has label 3; the root has children labelled 2 and 3, so its label is max(2,3) = 3.
More Compiler Design questions
- Syntax-directed definition: E → E1 T { E.val = E1.val 2 + T.val }; E → T { E.val = T.val }; T → num { T.val = num.lexval }. For the input…
- Grammar: E → E + T | T; T → T F | F; F → id. An SLR(1) parser parses id + id id + id id (followed by ). Counting each shift and each…
- Grammar: S → A B C; A → a | ε; B → a | b | ε; C → a | c | ε. How many cells of the LL(1) table contain more than one production?
- A lexer uses longest match, with ties broken in favour of the rule listed first. Rules in order: IF = "if"; ELSE = "else"; ID =…
- Three-address code: 1: x = 0; 2: if a > b goto 8; 3: x = x + 1; 4: if x > 5 goto 7; 5: y = y 2; 6: goto 2; 7: y = y + 1; 8: if y < 100…
- Grammar: S → L = R | R; L → R | id; R → L, augmented with S' → S. How many distinct LR(1) items (production, dot position, lookahead) does…