Arrange these grammar transformations in the order they are normally applied when preparing a grammar for predictive parsing.
1. perform left factoring
2. remove ambiguity from the grammar
3. compute the FIRST and FOLLOW sets
4. eliminate left recursion
Answer: A
Correct answer: 2 - 4 - 1 - 3
Remove ambiguity first, since neither of the other transformations helps with it and the grammar must be unambiguous before either is worth doing. Then eliminate left recursion, which a top-down parser cannot tolerate at all. Then left factor, which removes the remaining need for lookahead beyond one token. Only then compute FIRST and FOLLOW, on the grammar that will actually be used.
Please log in or register to report this question.