09/16/15 1
Iffat Anjum (IFF)
Formal Email:
iffat@bracu.ac.bd
iffat.16.cse@gmail.com
Submission Email:
iffat.submission@gmail.com
Phone: 01814928290
Google Group:
CompilerDesignBRACU
https://groups.google.com/forum/#
!forum/compilerdesignbracu
09/16/15 2
Theory Class Schedule:
Section 01: (UB30503)
Sunday, Monday
11.00 am - 12.20 pm
Section 02: (UB30501)
Sunday, Monday
08.00 am - 9.20 am
Lab Class Schedule:
Section 01: (UB40203)
NUM, MAZ
Monday, 08:00 am - 10:50 am
Section 02: (UB40203)
MAA, MKR
Thursday, 08:00 am-10:50 am 09/16/15 3
35% - Final Examination
25% - LAB performance
20% - MID Examination
8% - Assignment & Surprise Quizzes
7% - Declared Quizzes
5% - Attendance
No students will be allowed to sit for
final examination if he/she has less
than 70% attendance in LAB Class and
less than 75% attendance in Theory
Class
09/16/15 4
There will be surprise quizzes, given at the start of a lecture,
during any lecture.
NO LATE or MAKEUP SURPRISE QUIZZES, under any
circumstances whatsoever.
Surprise quizzes are completely individual efforts.
Your best strategy is to play it safe – attend every lecture.
Surprise Quizzes
09/16/15 5
Assignments need to be hand-written. I will not accept typed
up solutions.
Assignments are completely individual efforts.
If two written solutions are the same or similar, both will be
penalized (100% penalty for the entire assignment).
If a written solution is similar or same as an online or other
solution resource, you will be penalized (100% penalty for
the entire assignment).
Assignments
09/16/15 6
If you follow these 4 simple rules during the class, you'll make
sure that you do well in the course:
1. Attend every Theory and LAB classes.
2. Read the course material (textbook sections assigned + slides).
3. Submit everything (Assignments, Quizzes, Exams) on time -
don't be late.
4. Don't cheat.
Playing it safe in
CSE-420
09/16/15 7
Two Quizzes
Several Surprise Quizzes
If you fail to attend any exam you will get 0 (zero) on
that exam.
No makeup exams unless with documented medical
emergency.
Quizzes and Exams
09/16/15 8
Strong programming
background in C, C++ or
Java
Some background on
Automata Theory (NFA,
DFA, CFG) is
recommended…… ……not
mandatory
Assembly Language
Programming and
Machine Architecture
Pre-requisite
Knowledge
09/16/15 9
Aho, Lam, Sethi, Ullman:
Compilers: Principles,
Techniques, and Tools
(2nd Edition)
Recommended Books
09/16/15 10
Compiler Basics
Lexical Analysis
Syntax Analysis
Semantic Analysis
Runtime environments
Code Generation
Code Optimization
The Course covers
09/16/15 11
Programming problems are easier to solve in high-level
languages
 Languages closer to the level of the problem domain, e.g.,
 SmallTalk: OO programming
 JavaScript: Web pages
Solutions are usually more efficient (faster, smaller)
when written in machine language
 Language that reflects to the cycle-by-cycle working of a processor
Compilers are the bridges:
 Tools to translate programs written in high-level languages to efficient
executable code
What is a compiler?
09/16/15 12
Interpreters:
Compilers:
Introduction To Compilers
09/16/15 13
1954 IBM develops the 704
Successor to the 701
“Speedcoding”
FORTRAN I
Introduction To Compilers
09/16/15 14
The first compiler
Huge impact on computer science
Led to an enormous body of theoretical work
Modern compilers preserve the outline of FORTRAN I
Introduction To Compilers
09/16/15 15
1. Lexical Analysis
2. Parsing
3. Semantic Analysis
4. Optimization
5. Code Generation
Introduction To Compilers
09/16/15 16
 First step: recognize words.
 Smallest unit above letters
This is a sentence
Introduction To Compilers
09/16/15 17
ist his ase nte nce
Introduction To Compilers
09/16/15 18
 Lexical analysis divides program text into
“words” or “tokens”
if x == y then z = 1; else z = 2;
Introduction To Compilers
09/16/15 19
 Lexical analysis divides program text into
“words” or “tokens”
if x == y then z = 1; else z = 2;
Introduction To Compilers
09/16/15 20
 Second Step: Once words are understood, the
next step is to understand sentence structure
 Parsing = Diagramming Sentences
The diagram is a tree
Introduction To Compilers
09/16/15 21
This line is a longer sentence
Introduction To Compilers
09/16/15 22
if x == y then z = 1; else z = 2;
Introduction To Compilers
09/16/15 23
Third Step:
Once sentence structure is understood, we can
try to understand “meaning”
This is hard!
Compilers perform limited semantic analysis to
catch inconsistencies
Introduction To Compilers
09/16/15 24
Programming
languages define strict
rules to avoid such
ambiguities
Introduction To Compilers
{
int Jack = 3;
{
int Jack = 4;
cout << Jack;
}
}
{
int Jack = 3;
{
int Jack = 4;
cout << Jack;
}
}
09/16/15 25
Compilers perform many semantic checks
besides variable bindings
Example:
Jack left her homework at home.
A “type mismatch” between her and Jack;
we know they are different people
Introduction To Compilers
09/16/15 26
Optimization has no strong counterpart in
English
But a little bit like editing
X = Y * 0 is the same as X = 0
Automatically modify programs so that they
Run faster
Use less memory
Introduction To Compilers
09/16/15 27
Produces assembly code (usually)
A translation into another language
Analogous to human translation
Introduction To Compilers
09/16/15 28
Question?
09/16/15 29

Compiler Design - Introduction to Compiler

  • 1.
  • 2.
    Iffat Anjum (IFF) FormalEmail: iffat@bracu.ac.bd iffat.16.cse@gmail.com Submission Email: iffat.submission@gmail.com Phone: 01814928290 Google Group: CompilerDesignBRACU https://groups.google.com/forum/# !forum/compilerdesignbracu 09/16/15 2
  • 3.
    Theory Class Schedule: Section01: (UB30503) Sunday, Monday 11.00 am - 12.20 pm Section 02: (UB30501) Sunday, Monday 08.00 am - 9.20 am Lab Class Schedule: Section 01: (UB40203) NUM, MAZ Monday, 08:00 am - 10:50 am Section 02: (UB40203) MAA, MKR Thursday, 08:00 am-10:50 am 09/16/15 3
  • 4.
    35% - FinalExamination 25% - LAB performance 20% - MID Examination 8% - Assignment & Surprise Quizzes 7% - Declared Quizzes 5% - Attendance No students will be allowed to sit for final examination if he/she has less than 70% attendance in LAB Class and less than 75% attendance in Theory Class 09/16/15 4
  • 5.
    There will besurprise quizzes, given at the start of a lecture, during any lecture. NO LATE or MAKEUP SURPRISE QUIZZES, under any circumstances whatsoever. Surprise quizzes are completely individual efforts. Your best strategy is to play it safe – attend every lecture. Surprise Quizzes 09/16/15 5
  • 6.
    Assignments need tobe hand-written. I will not accept typed up solutions. Assignments are completely individual efforts. If two written solutions are the same or similar, both will be penalized (100% penalty for the entire assignment). If a written solution is similar or same as an online or other solution resource, you will be penalized (100% penalty for the entire assignment). Assignments 09/16/15 6
  • 7.
    If you followthese 4 simple rules during the class, you'll make sure that you do well in the course: 1. Attend every Theory and LAB classes. 2. Read the course material (textbook sections assigned + slides). 3. Submit everything (Assignments, Quizzes, Exams) on time - don't be late. 4. Don't cheat. Playing it safe in CSE-420 09/16/15 7
  • 8.
    Two Quizzes Several SurpriseQuizzes If you fail to attend any exam you will get 0 (zero) on that exam. No makeup exams unless with documented medical emergency. Quizzes and Exams 09/16/15 8
  • 9.
    Strong programming background inC, C++ or Java Some background on Automata Theory (NFA, DFA, CFG) is recommended…… ……not mandatory Assembly Language Programming and Machine Architecture Pre-requisite Knowledge 09/16/15 9
  • 10.
    Aho, Lam, Sethi,Ullman: Compilers: Principles, Techniques, and Tools (2nd Edition) Recommended Books 09/16/15 10
  • 11.
    Compiler Basics Lexical Analysis SyntaxAnalysis Semantic Analysis Runtime environments Code Generation Code Optimization The Course covers 09/16/15 11
  • 12.
    Programming problems areeasier to solve in high-level languages  Languages closer to the level of the problem domain, e.g.,  SmallTalk: OO programming  JavaScript: Web pages Solutions are usually more efficient (faster, smaller) when written in machine language  Language that reflects to the cycle-by-cycle working of a processor Compilers are the bridges:  Tools to translate programs written in high-level languages to efficient executable code What is a compiler? 09/16/15 12
  • 13.
  • 14.
    1954 IBM developsthe 704 Successor to the 701 “Speedcoding” FORTRAN I Introduction To Compilers 09/16/15 14
  • 15.
    The first compiler Hugeimpact on computer science Led to an enormous body of theoretical work Modern compilers preserve the outline of FORTRAN I Introduction To Compilers 09/16/15 15
  • 16.
    1. Lexical Analysis 2.Parsing 3. Semantic Analysis 4. Optimization 5. Code Generation Introduction To Compilers 09/16/15 16
  • 17.
     First step:recognize words.  Smallest unit above letters This is a sentence Introduction To Compilers 09/16/15 17
  • 18.
    ist his asente nce Introduction To Compilers 09/16/15 18
  • 19.
     Lexical analysisdivides program text into “words” or “tokens” if x == y then z = 1; else z = 2; Introduction To Compilers 09/16/15 19
  • 20.
     Lexical analysisdivides program text into “words” or “tokens” if x == y then z = 1; else z = 2; Introduction To Compilers 09/16/15 20
  • 21.
     Second Step:Once words are understood, the next step is to understand sentence structure  Parsing = Diagramming Sentences The diagram is a tree Introduction To Compilers 09/16/15 21
  • 22.
    This line isa longer sentence Introduction To Compilers 09/16/15 22
  • 23.
    if x ==y then z = 1; else z = 2; Introduction To Compilers 09/16/15 23
  • 24.
    Third Step: Once sentencestructure is understood, we can try to understand “meaning” This is hard! Compilers perform limited semantic analysis to catch inconsistencies Introduction To Compilers 09/16/15 24
  • 25.
    Programming languages define strict rulesto avoid such ambiguities Introduction To Compilers { int Jack = 3; { int Jack = 4; cout << Jack; } } { int Jack = 3; { int Jack = 4; cout << Jack; } } 09/16/15 25
  • 26.
    Compilers perform manysemantic checks besides variable bindings Example: Jack left her homework at home. A “type mismatch” between her and Jack; we know they are different people Introduction To Compilers 09/16/15 26
  • 27.
    Optimization has nostrong counterpart in English But a little bit like editing X = Y * 0 is the same as X = 0 Automatically modify programs so that they Run faster Use less memory Introduction To Compilers 09/16/15 27
  • 28.
    Produces assembly code(usually) A translation into another language Analogous to human translation Introduction To Compilers 09/16/15 28
  • 29.