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 A → x y z | x y | x w | x y v u; B → p B | p | q, how many productions (alternatives) does the resulting grammar have? An empty alternative counts as one production.
- A. 7
- B. 11
- C. 10
- D. 13
Correct answer: C. 10
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 10 productions.
More Compiler Design questions
- A DAG is built for r = (p − q) (p − q) + (q − p) (p − q) − (p − q), with commutative and − not commutative. How many interior (operator)…
- For the grammar S → C C; C → c C | d (augmented with S′), the canonical LR(1) automaton is built and then the states with identical LR(0)…
- Using the backpatching scheme (each relation gives 'if r goto ' then 'goto ', no fall-through optimisation, numbering from 100), the code…
- For the nested-loop code 1: s = 0; 2: i = 0; 3: L1: if i >= n goto L5; 4: j = 0; 5: L2: if j >= i goto L4; 6: s = s + j; 7: j = j + 1; 8…
- For the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id, what is FOLLOW(T)?
- Which of the following about iterative data-flow analyses is/are true? I. Live-variable analysis is a backward problem whose meet operator…