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

Discussion

Nested comments are difficult for a conventional scanner because

  • A.a comment may span more than one line of the source program
  • B.counting the nesting depth is beyond the power of a finite automaton
  • C.comments may contain characters outside the alphabet of the language
  • D.the parser rather than the scanner must recognise a comment

Answer: B

Correct answer: counting the nesting depth is beyond the power of a finite automaton

A finite automaton has a fixed number of states and so cannot count to an arbitrary depth; matching nested comment delimiters is the same problem as matching nested brackets, which is not regular. Scanners therefore either forbid nesting, or handle it with an explicit counter written into the action code rather than in the pattern.

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

Post your comment

Please log in or register to post a comment.