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

Discussion

The dangling else grammar is problematic for LL(1) parsing because

  • A.the statement rule happens to recurse upon its own left
  • B.the FIRST sets belonging to the two alternatives are always disjoint
  • C.after the statement the parser cannot tell whether an else belongs here
  • D.the keyword else cannot be recognised by the scanner

Answer: C

Both continuing the inner statement and returning to the outer one are possible when else is the lookahead. The usual convention attaches the else to the nearest unmatched if. Languages with an explicit end keyword sidestep the whole difficulty.

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

Post your comment

Please log in or register to post a comment.