GATE Computer ScienceVery hardGATE CSE · UGC NET
How many of these four grammars are LL(1)? (1) S → a S b | ε; (2) S → A B; A → a | ε; B → a | b; (3) S → a A | b; A → S c | ε; (4) S → S a | b.
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Grammar 1 and 3 are LL(1); grammar 2 has A → a and A → ε both predicted on a (FOLLOW(A) contains a), and grammar 4 is left-recursive.
More Compiler Design questions
- Statements: 1: a = 1; 2: b = 2; 3: c = a + b; 4: d = c 2; 5: if d > 10 goto 8; 6: e = a + d; 7: goto 9; 8: e = b + 1; 9: print e. Which…
- A C lexer applies the maximal-munch rule (always take the longest possible token). How many tokens does it produce for the input…
- How many basic blocks does this three-address code contain? 1: i = 0; 2: s = 0; 3: if i >= n goto 9; 4: t = a[i]; 5: if t < 0 goto 7; 6: s…
- Using Sethi–Ullman numbering (a leaf that is a left operand needs 1 register, a leaf that is a right operand can be used from memory and…
- Grammar: S → A B D; A → a A | ε; B → b B | A c | ε; D → d D | ε. What is |FOLLOW(A)| + |FOLLOW(B)| + |FOLLOW(D)|? (FOLLOW sets may contain…
- Grammar: E → T X; X → + T X | − T X | ε; T → F Y; Y → F Y | / F Y | ε; F → ( E ) | id | num | − F. How many non-empty cells does its LL(1)…