GATE Computer ScienceVery hardGATE CS · ISRO
How many distinct strings of length at most 6 (including the empty string) are generated by the grammar S → ( S ) | S S | ε?
- A. 5
- B. 13
- C. 9
- D. 15
Correct answer: C. 9
The language is all balanced parenthesis strings; the counts by length 0, 2, 4, 6 are 1, 1, 2, 5, so 9.
More Compiler Design questions
- For the ambiguous grammar S → S S | a, how many distinct parse trees does the string aaaaaa (six a's) have?
- A DFA over {0, 1} has states 0–8 with start state 0 and accepting states {5, 6, 7, 8}. Transitions (on 0, on 1): 0:(1,2), 1:(3,4)…
- In a language with Algol-style call by name, int i = 1 and A = [10, 20, 30] (1-indexed) are global, and procedure P(p, q) { i = i + 1; p =…
- Indirect left recursion is removed from S → A a | b; A → A c | S d | ε by ordering the non-terminals S, A, substituting S into A's rules…
- In S → A B C | C a; A → a A | ε; B → b B | A c | ε; C → d | B e, how many symbols (including ) does FOLLOW(B) contain?
- How many of these four grammars are LL(1)? (1) S → a S b | ε; (2) S → A B; A → a | ε; B → a | b; (3) S → a A | b; A → S c | ε; (4) S → S a…