Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

1

Lahore Garrison University


CSC373-Compiler Construction
Week-2 Lecture-3
Semester-#5 Fall 2019
Prepared by:

Eisha Tir Razia


2
Overview of previous lecture

 Introduction to Compiler
 Compiler History
 Properties of Compiler

Lahore Garrison University


3
Preamble of each lecture

 Compiler types in general


 Analysis
 synthesis

Lahore Garrison University


4
Lecture Outcomes

 Understanding related
 Compiler phases

Lahore Garrison University


5
Cont..

 Only few people write compiler, many people write pieces of


compiler.
 We deal large, complicated system in computer science by
breaking it into several smaller, easy-to-understand pieces.

Lahore Garrison University


6
The Structure of a Compiler

 Compilation can be done into two parts.


1. Analysis
2. Synthesis

Lahore Garrison University


7
Analysis

 Determine the operations implied by the source program which are recorded in a tree
structure.
 Break up the source program into constituent pieces and creates intermediate representation
of Source program
 During analysis, the operations implied by the source are determine and recorded in a
hierarchical structure called a tree.
 If the analysis part detects that the source program is either syntactically ill formed or
semantically unsound, then it must provide informative messages, so the user can take
corrective action
 The analysis part also collects information about the source program and stores it in a data
structure called a symbol table, which is passed along with the intermediate representation to
the synthesis part

Lahore Garrison University


8
Synthesis

 Construct the desired target program from the intermediate


representation & the information in the symbol table
 Take structure and translate the operations into the target program.
 Target program depends on the goal of the compilation
 For example, a compiler may first generate an intermediate code
after analysis and then generate target code that may be
assembly language code and machine code.

Lahore Garrison University


9
Phases of Compiler

 If we examine the compilation process in more detail, we see that it


operates as a sequence of phases, each of which transforms one
representation of the source program to another

Lahore Garrison University


10
Phases of Compiler

1. Lexical Analysis
2. Syntax Analysis
3. Sementic Analysis
4. Intermediate Code Representation
5. Code Optimization
6. Code Generation

Lahore Garrison University


11
Phases of Compiler

Lahore Garrison University


12
Cont..

 The symbol table, which stores information about the entire source
program, is used by all phases of the compiler

Lahore Garrison University


13

Q&A

Lahore Garrison University


14
References

 These lecture notes were taken from following source:


 Compilers: Principles, Techniques, and Tools By Alfred V. Aho, Ravi Sethi, Jeffrey D.
Ullman, Contributor Jeffrey D. Ullman, Addison-Wesley Pub. Co., 2nd edition, 2006

Lahore Garrison University

You might also like