GATE Computer ScienceVery hardGATE CS (PYQ pattern)
After applying left factoring repeatedly (each time extracting the longest common prefix of alternatives that share a first symbol, introducing a new non-terminal each time) to the grammar S → a b c | a b d | a e | f g | f h | k, how many productions (alternatives) does the resulting grammar have? An empty alternative counts as one production.
- A. 6
- B. 9
- C. 10
- D. 11
Correct answer: B. 9
Each extraction of a common prefix replaces k alternatives by one and adds a new non-terminal with k alternatives (possibly ε); repeating until no two alternatives share a first symbol leaves 9 productions.
More Compiler Design questions
- 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)?
- 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]…