GATE Computer ScienceModerateGATE CS (PYQ pattern)
Which of the following is/are true? I. An LL(1) grammar can contain ε-productions. II. An LL(1) grammar is never ambiguous. III. If FIRST sets of the alternatives of every non-terminal are pairwise disjoint, the grammar is LL(1). IV. A left-recursive grammar can be LL(1) if its FOLLOW sets are disjoint.
- A. I, II and III only
- B. I and II only
- C. II and III only
- D. I, II and IV only
Correct answer: B. I and II only
I and II are true. III is false: nullable alternatives also need FIRST(α) ∩ FOLLOW(A) = ∅. IV is false: left recursion makes FIRST sets of alternatives overlap, so no left-recursive grammar is LL(1).
More Compiler Design questions
- For G: S → A S | b; A → S A | a, which statements are true? I. FOLLOW(A) ⊂ FOLLOW(S) (proper subset). II. The LL(1) table has exactly two…
- An LL(1) parser for S → A B C; A → a A | ε; B → b B | ε; C → c | ε reads the input "a b a c". At the moment it first detects the syntax…
- The ambiguous grammar E → E − E | E E | id derives "2 − 3 4 − 5 1" (each number is an id). How many distinct parse trees does the string…
- A yacc-generated parser for E → E op E | num uses the precedence declarations %right '+' '-'; %left ''; later declarations bind tighter…
- How many distinct LR(0) items does the grammar E → E + T | T; T → T F | F; F → ( E ) | id have (do not augment it; an ε-production gives…
- int f(int n) { if (n <= 2) return 1; return f(n − 1) + f(n − 2) + f(n − 3); } How many calls to f (including the first) does f(8) make as…