GATE Computer ScienceVery hardGATE CSE
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 3 $ 4 $ 5 $ 6, what is E.val at the root? (The grammar is left-recursive, so the parse groups from the left.)
- A. 56
- B. 30
- C. 55
- D. 60
Correct answer: A. 56
Evaluate left to right: 3 → 3·2+4 = 10 → 10·2+5 = 25 → 25·2+6 = 56. (A right-grouping would give 30.)
More Compiler Design questions
- 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…
- Grammar: S → a S b | S S | ε. How many distinct strings of length exactly 10 belong to the language it generates?