Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In which step of compilation are comments removed?

There are several steps in compilation of a program:

  • line reconstruction
  • lexical analysis
  • Preprocessing.
  • syntax analysis
  • semantic analysis

Is removal of comments in the first step "line reconstruction"?

like image 988
Tim Avatar asked Dec 05 '15 23:12

Tim


People also ask

In which phase comments line are removed?

[edit] Syntax All comments are removed from the program at translation phase 3 by replacing each comment with a single whitespace character.

Are comments compiled in C?

They are only used to separate different tokens. In the next steps, there is no concept for a comment or a whitespace, so yes, they are removed while compiling.

Do compilers compile comments?

No, they are simply ignored by the compiler. Comments' sole purpose is for human reading, not machine.


Video Answer


1 Answers

  • Preprocessing is a phase of its own with its own scanning and parsing, which precede lexical analysis.
  • I'm a compiler writer and I've never heard of 'line reconstruction'. Compilers don't process lines: they process token streams. Your citation specifically says this is a special case for a few odd languages.
  • You've left out flow analysis, optimization, register allocation, and code generation, and a few more.
  • Comments are ignored, not removed, during lexical analysis, which is sometimes conceptually described as 'screening' and 'scanning', in which case you can say comments are screened out, like white space.
like image 169
user207421 Avatar answered Oct 16 '22 08:10

user207421