You are on page 1of 1

a compiler is divided into 7 phases, basically from the original character stream, to the

target machine code, assuming you want to run it on a machine, or virtual machine for
that matter.
Which is shown in the following diagram:
Lexical Analyzer lexical analysis breaks
down the entire text of the program into the
smallest atomic units, called tokens, at the
same time throwing out unnecessary
information such as white space and
comments.
Syntax Analyzer syntax analysis,
otherwise known as parsing, takes the tokens
produced from lexical analysis and groups
them into grammatical structures.
Semantic Analyzer semantic analysis
utilizes the syntax tree and information in the
symbol table to check the semantic
consistency of the source program with the
language definition. This is also where typechecking is done.
Intermediate Code Generator generates
an explicit low-level or machine-like
intermediate representation, having two
properties: it should be easy to produce and it
should be easy to translate into the target machine.
Code Optimization code optimization attempts to improve the intermediate code so
a better target code will result. Usually better means faster, but other objectives may be
desired, such as shorter code, or target code that consumes less power.
Code Generator code generation takes as input the intermediate representation as a
result of code optimization, and produces the target code (e.g. machine code) to be
executed by the machine (or virtual machine).

You might also like