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

Discussion

Which of the following statements is/are true?

  • A.LL(1) parser uses backtracking
  • B.For a grammar to be LL(1), it must be left-recursive
  • C.For a grammar to be LL(1), it must be left-factored
  • D.The LL(1) parsers are more powerful than the SLR parsers

Answer: C

The true statement is For a grammar to be LL(1), it must be left-factored.

An LL(1) parser chooses a production by looking at one input symbol. If two alternatives of a non-terminal begin with the same prefix, their FIRST sets overlap and one symbol of lookahead cannot choose between them, so the grammar is not LL(1). Left factoring removes such common prefixes.

The other statements are false. An LL(1) parser is predictive and never backtracks. Left recursion is forbidden, not required, because it sends a top-down parser into an endless loop. And LL(1) parsers are not more powerful than SLR parsers: left-recursive grammars such as the usual expression grammar are SLR(1) but cannot be LL(1).

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

Post your comment

Please log in or register to post a comment.