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

Discussion

The lexical analyser normally reports the line number of an error by

  • A.reading the file a second time to locate the erroneous text
  • B.counting newline characters as it consumes them from the input
  • C.asking the parser which production it was attempting to apply
  • D.consulting the symbol table entry for the offending identifier

Answer: B

Counting newlines during scanning is cheap and gives every token a source position. Some compilers record a column as well so a diagnostic can point at the exact character. Accurate positions cost almost nothing to maintain and improve every message issued.

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

Post your comment

Please log in or register to post a comment.