The Phases of Compiler
The Phases of Compiler
Lexical Analysis:
In a compiler, Linear analysis is called lexical analysis or scanning. For example, in lexical analysis the
characters in the assignment statement
position: = initial + rate * 60
would be grouped in to the following tokens
1. The identifier position
2. The assignment symbol: =
3. The identifier initial
4. The plus sign
5. The identifier rate
6. The multiplication sign
7. The number 60
The blanks are usually eliminated during lexical analysis
Syntax Analysis:
The second phase of the compiler is syntax analysis or parsing. The parser uses the first components of
the tokens produced by the lexical analyzer to create a tree-like intermediate representation that depicts the
grammatical structure of the token stream.
A typical representation is a syntax tree in which each interior node represents an operation and the
children of the node represent the arguments of the operation.
Semantic Analysis:
The semantic analysis checks the source program for semantic errors and gathers type information for
the subsequent code-generation phase. It uses the hierarchical structure determined by the syntax-analysis
phase to identify the operators and operands of expressions and statements.
The first and second operands of each instruction specify a source and destination, respectively. The F
in each instruction tells us that instruction deal with floating point numbers.
Symbol-Table Management:
The symbol table is a data structure containing a record for each variable name, with fields for the
attributes of the name. The data structure should be designed to allow the compiler to find the record for each
name quickly and to store or retrieve data from that record quickly.