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

Discussion

The dangling else ambiguity is normally resolved by

  • A.requiring the programmer to insert explicit parentheses
  • B.letting the semantic analyser decide which if is meant
  • C.a rule matching each else with the nearest unmatched if
  • D.forbidding the nesting of if statements in the language

Answer: C

Either the grammar is rewritten to distinguish matched from unmatched statements, or the parser generator is told to prefer shifting the else. Both realise the same nearest if rule. Languages requiring an explicit end keyword avoid the ambiguity altogether.

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

Post your comment

Please log in or register to post a comment.