Professional Documents
Culture Documents
Compiler is a translator program that translates a program written in High Level Language (HLL)
the source program and translates it into an equivalent program in assembly Language (LLL) the target
program. Compiler used to convert human readable program into assembly language program and also
finds error from the program.
• Pass : A pass refers to the traversal of a compiler through the entire program.
• Phase : A phase of a compiler is a distinguishable stage, which takes input from the previous stage,
processes and yields output that can be used as input for the next stage. A pass can have more than one
phase.
1.2 Phases of Compiler:
Phase Definition:
2. A phase is a logically interrelated operation that takes source program in one representation and
produces output in another representation.
Phases of a Compiler:
Phase 1:Lexical Analyzer:-
1. The first phase of compiler is Lexical analyzer
2. Lexical Analyzer reads the source program one character at a time, the source program into a
sequence of atomic units called lexemes. Then lexeme will be represented using tokens. It makes
the entry of the corresponding tickets into the symbol table and passes that token to next phase.
For Example :
Input: stream of characters
Output: Token
Token Template: <token-name, attribute-value>
c=a+b*5;
The above source program can be read by lexical analyzer, and that source program can be partitioned
into units, each unit can be considered as token.
1. The second phase of a compiler is Syntax Analyzer otherwise called as parser.Syntax Analyzing
is also called as Parsing.
2. The parser uses the tokens produced by the lexical analyzer to create a tree-like intermediate
representation – called syntax tree.
3. In this phase all the syntactical error will be identified using syntax tree.
4. Syntax tree is a compressed representation of the parse tree in which the operators appear as
interior nodes and the operands of the operator are the children of the node for that operator.
Input: Tokens
Output: Syntax tree
The output of Syntax Analyzer is:
2. The intermediate code generation representation called three-address code . it has consists of an
assembly like instructions with a maximum of three operands per instruction.
Error Handling:
1. In the compiler design process error may occur in all the below-given phases:
• Lexical analyzer: Wrongly spelled tokens
• Syntax analyzer: Missing parenthesis
• Code Optimizer: When the statement is not reachable
• Code Generator: Unreachable statements
• Symbol tables: Error of multiple declared identifiers
2. All of these errors will be reported to error handler which handles the error to perform the
compilation process.