GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Which of the following are true? I. Every LL(1) grammar is LR(1). II. Every LL(1) grammar is LALR(1). III. Every LALR(1) grammar is LR(1). IV. Every LR(0) grammar is SLR(1).
- A. I, III and IV only
- B. I, II, III and IV
- C. I and III only
- D. III and IV only
Correct answer: A. I, III and IV only
I, III and IV are standard inclusions. II fails: S → a A | b B; A → C a | D b; B → C b | D a; C → E; D → E; E → ε is LL(1) (the alternatives of A and of B are told apart by a/b after the empty C or D), but the LR(1) states {C → E·, D → E·} reached after a (C on a, D on b) and after b (C on b, D on a) share a core with the lookaheads swapped; merging them gives reduce-reduce conflicts on a and b in the LALR(1) table.
More Compiler Design questions
- Available-expressions analysis (expressions compared textually, so a b and b a differ; assigning an operand kills an expression) is run on…
- Nested procedures: main (depth 1) contains A (depth 2); A contains B (depth 3); B contains C (depth 4). C also calls itself recursively…
- void p(int x, int y) { x = x + 1; y = y + x; } is called as p(a, a) with a = 2. What is a after the call when the parameters are passed by…
- How many distinct LR(0) items does the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id have (do not augment it…
- Dead-code elimination deletes every assignment whose target is not live immediately after it (live-variable analysis), and is repeated…
- Same function f(n) = 1 for n ≤ 2, else f(n − 1) + f(n − 2) + f(n − 3). Each activation record takes 28 bytes. What is the maximum stack…