compiler design - introduction to compiler
TRANSCRIPT
05/01/23 1
Iffat Anjum (IFF)
Formal Email: [email protected]@gmail.com
Submission Email: [email protected]: 01814928290
Google Group:CompilerDesignBRACUhttps://groups.google.com/forum/#!forum/compilerdesignbracu
05/01/23 2
Theory Class Schedule: Section 01: (UB30503)
Sunday, Monday11.00 am - 12.20 pm
Section 02: (UB30501)Sunday, Monday08.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 05/01/23 3
35% - Final Examination25% - LAB performance20% - MID Examination8% - Assignment & Surprise Quizzes7% - Declared Quizzes5% - 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
05/01/23 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
05/01/23 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
05/01/23 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
05/01/23 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
05/01/23 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
05/01/23 9
Aho, Lam, Sethi, Ullman:Compilers: Principles, Techniques, and Tools
(2nd Edition)
Recommended Books
05/01/23 10
Compiler Basics Lexical Analysis Syntax Analysis Semantic AnalysisRuntime environmentsCode GenerationCode Optimization
The Course covers
05/01/23 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?
05/01/23 12
Interpreters:
Compilers:
Introduction To Compilers
05/01/23 13
1954 IBM develops the 704 Successor to the 701
“Speedcoding”
FORTRAN I
Introduction To Compilers
05/01/23 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
05/01/23 15
1. Lexical Analysis 2. Parsing 3. Semantic Analysis 4. Optimization 5. Code Generation
Introduction To Compilers
05/01/23 16
First step: recognize words. Smallest unit above letters
This is a sentence
Introduction To Compilers
05/01/23 17
ist his ase nte nce
Introduction To Compilers
05/01/23 18
Lexical analysis divides program text into “words” or “tokens”
if x == y then z = 1; else z = 2;
Introduction To Compilers
05/01/23 19
Lexical analysis divides program text into “words” or “tokens”
if x == y then z = 1; else z = 2;
Introduction To Compilers
05/01/23 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
05/01/23 21
This line is a longer sentence
Introduction To Compilers
05/01/23 22
if x == y then z = 1; else z = 2;
Introduction To Compilers
05/01/23 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
05/01/23 24
Programming languages define strict rules to avoid such ambiguities
Introduction To Compilers
{ int Jack = 3; {
int Jack = 4; cout << Jack;
} }
05/01/23 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
05/01/23 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
05/01/23 27
Produces assembly code (usually)
A translation into another language Analogous to human translation
Introduction To Compilers
05/01/23 28
Question?
05/01/23 29