1.5 Phases of a Compiler

Most of the modern compilers have the following phases:

  • Pre-processing: Usually, this phase is implemented as a macro processor, with its own macro language. It provides for file inclusion, conditional compilation control of segments of the source code, definition of literals, “pragma” commands to the compiler, etc.
  • Lexical analysis: (Scanner) – checks for correct use of the input character set, identifies language atoms and tags them as the type of atom, e.g. NUMBER, IDENTIFIER, OPERATION.
  • Syntax analysis: (Parser) – processes output of the Scanner, detects syntactic constructs and types of statements, generates a parse tree.
  • Semantic analysis: (Mapper) – processes the parse trees, detects the “meaning” of statements ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.