Você está na página 1de 14

CSI 411 - Compiler

Lecture 1 - Introduction to Compiler

Adnan Ferdous Ashrafi

September 20, 2020

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 1 / 14
1 Introduction
Course Details
Marks Distribution

2 Starting to learn Compilers


What is a Compiler?
Compiled Languages Vs. Interpreted Languages
Phases of a Compiler
Example of Phases of a Compiler
Lexical Analyzer
Syntax Analyzer
Semantics Analyzer
Intermediate Code Generator
Code Optimizer
Target Machine Code Generator

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 2 / 14
Introduction

Course Code : CSI 411


Course Title : Compiler
Trimester : L4T1
Course Teacher : Adnan Ferdous Ashrafi
Batches : CSE-S-65-A,CSE-S-65-B,CSE-S-66-F

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 3 / 14
Marks Distribution

Attendance : 10%
Class Tests : 30% (Best 3 will be counted)
Midterm : 30%
Final : 30%
Total : 100%

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 4 / 14
What is a Compiler?

Definition of a Compiler
Programming languages are notations for describing computations to people
and to machines. The world as we know it depends on programming lan-
guages, because all the software running on all the computers was written
in some programming language. But, before a program can be run, it first
must be translated into a form in which it can be executed by a computer.
The software systems that do this translation are called compilers.

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 5 / 14
Compiled Languages Vs. Interpreted Languages

Figure 2: An Interpreter

Figure 1: A Language Processing


System
Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 6 / 14
Compiled Languages Vs. Interpreted Languages Contd.

Compiled Programming Languages Interpreted Languages


C JavaScript
C++ PHP
Java MATLAB
C# Python
etc. etc.

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 7 / 14
Structure of a typical Compiler

Figure 3: Phases of a typical Compiler


Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 8 / 14
An Example - Part I

1 Lexical Analyzer
x = a + b × c;

id = id + id × id ;

id a
Symbol Table id b
id c
id x

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to Compiler September 20, 2020 9 / 14
An Example - Part II
2 Syntax Analyzer
id = id + id × id ;

Table 1: Context Free Grammar -


CFG

E → E+T I T
T → T×F I F
F → id

Figure 4: Syntax/Parse Tree


Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to CompilerSeptember 20, 2020 10 / 14
An Example - Part III

3 Semantics Analyzer

Figure 6: Semantically modified Parse Tree


Figure 5: Syntax/Parse Tree

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to CompilerSeptember 20, 2020 11 / 14
An Example - Part IV

4 Intermediate Code Generator


Table 2: Intermediate/Three Address Code

t1 = b×c;
t2 = a+t1 ;
x = t2 ;
5 Code Optimizer
Table 3: Optimized Code

t1 = b×c;
x = a+t1 ;

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to CompilerSeptember 20, 2020 12 / 14
An Example - Part V

6 Target Machine Code Generator


Table 4: Target Machine Code

MUL R1,R2
ADD R2,R0
MOV x,R2

Table 5: Values saved in the Registers

R0 a
R1 b
R2 c

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to CompilerSeptember 20, 2020 13 / 14
Thank you.
Any Questions?

Adnan Ferdous Ashrafi CSI 411 - Compiler Lecture 1 - Introduction to CompilerSeptember 20, 2020 14 / 14

Você também pode gostar