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

Discussion

Left factoring an if statement rule whose two alternatives differ only in a trailing else clause has the effect of

  • A.removing the else clause from the language that the grammar generates
  • B.making the two original alternatives derive quite different constructs
  • C.turning the recursion in the statement rule from left into right form
  • D.postponing the choice until the parser has consumed the whole if part

Answer: D

The shared prefix is parsed once and the optional else becomes a two way choice in the auxiliary nonterminal. Nothing is removed from the language and nothing about recursion changes; only the moment at which the parser must commit has been moved later, which is exactly what one token of lookahead requires.

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

Post your comment

Please log in or register to post a comment.