GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 that the grammar belongs to?
- A. 7 states; LR(0)
- B. 6 states; SLR(1) but not LR(0)
- C. 7 states; SLR(1) but not LR(0)
- D. 8 states; not SLR(1)
Correct answer: C. 7 states; SLR(1) but not LR(0)
Building the item sets gives 7 states. The state containing A → a· and A → a· A has a shift/reduce conflict if reductions ignore lookahead, so it is not LR(0). FOLLOW(A) = {b} does not contain a, so SLR(1) resolves the conflict.
More Compiler Design questions
- 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 ++…
- A generated scanner for the token set { a, abcd, b, c, d } always returns the longest accepting prefix, and if the DFA reaches the dead…