GATE Computer ScienceHardGATE CS (PYQ pattern)
Consider the grammar S → A B c, A → a A | ε, B → b B | A d | ε. How many terminals are in FOLLOW(A), and is the grammar LL(1)?
- A. 3; not LL(1)
- B. 4; not LL(1)
- C. 4; LL(1)
- D. 2; LL(1)
Correct answer: B. 4; not LL(1)
FOLLOW(A) gets FIRST(B) − ε = {a, b, d}, plus c because B is nullable, plus d from B → A d; so it is {a, b, c, d}. Since A → ε must be chosen on a and A → a A also starts with a, the table has a conflict and the grammar is not LL(1).
More Compiler Design questions
- For the grammar S → A B, A → a A | a, B → b, the augmented canonical LR(0) collection has how many states, and what is the strongest class…
- In the expression a = (b + c) (b + c) - d / (b + c), the numbers of operator (internal) nodes in the syntax tree for the right-hand side…
- A C lexer applies the longest-match (maximal munch) rule. The number of tokens in the statement x = a---bc++; is:
- Which of the following grammars are LL(1)? (I) S → a S b | ε. (II) S → a S a | a. (III) S → A B, A → a | ε, B → a | b. (IV) S → a S | b S…
- Consider this pseudo-code (arrays are 1-based): i = 1; a = [5, 6, 7]; procedure P(x, y) { x = x + 1; y = y 2; } P(i, a[i]); print(i, a[1]…
- A C-like scanner uses maximal munch with these tokens: identifiers (letters and digits, starting with a letter) and the operators ++…