Machine-translated by Google. Questions are authored in English.
Top

Discussion

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

  • A.2 - 4 - 1 - 3
  • B.3 - 1 - 4 - 2
  • C.4 - 2 - 1 - 3
  • D.2 - 1 - 4 - 3

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.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.