Compiler Design - Introduction to Compiler

29
06/08/22 1

Transcript of Compiler Design - Introduction to Compiler

Page 1: Compiler Design - Introduction to Compiler

05/01/23 1

Page 2: Compiler Design - Introduction to Compiler

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

Page 3: Compiler Design - Introduction to Compiler

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

Page 4: Compiler Design - Introduction to Compiler

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

Page 5: Compiler Design - Introduction to Compiler

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

Page 6: Compiler Design - Introduction to Compiler

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

Page 7: Compiler Design - Introduction to Compiler

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

Page 8: Compiler Design - Introduction to Compiler

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

Page 9: Compiler Design - Introduction to Compiler

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

Page 10: Compiler Design - Introduction to Compiler

Aho, Lam, Sethi, Ullman:Compilers: Principles, Techniques, and Tools

(2nd Edition)

Recommended Books

05/01/23 10

Page 11: Compiler Design - Introduction to Compiler

Compiler Basics Lexical Analysis Syntax Analysis Semantic AnalysisRuntime environmentsCode GenerationCode Optimization

The Course covers

05/01/23 11

Page 12: Compiler Design - Introduction to Compiler

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

Page 13: Compiler Design - Introduction to Compiler

Interpreters:

Compilers:

Introduction To Compilers

05/01/23 13

Page 14: Compiler Design - Introduction to Compiler

1954 IBM develops the 704 Successor to the 701

“Speedcoding”

FORTRAN I

Introduction To Compilers

05/01/23 14

Page 15: Compiler Design - Introduction to Compiler

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

Page 16: Compiler Design - Introduction to Compiler

1. Lexical Analysis 2. Parsing 3. Semantic Analysis 4. Optimization 5. Code Generation

Introduction To Compilers

05/01/23 16

Page 17: Compiler Design - Introduction to Compiler

First step: recognize words. Smallest unit above letters

This is a sentence

Introduction To Compilers

05/01/23 17

Page 18: Compiler Design - Introduction to Compiler

ist his ase nte nce

Introduction To Compilers

05/01/23 18

Page 19: Compiler Design - Introduction to Compiler

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

Page 20: Compiler Design - Introduction to Compiler

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

Page 21: Compiler Design - Introduction to Compiler

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

Page 22: Compiler Design - Introduction to Compiler

This line is a longer sentence

Introduction To Compilers

05/01/23 22

Page 23: Compiler Design - Introduction to Compiler

if x == y then z = 1; else z = 2;

Introduction To Compilers

05/01/23 23

Page 24: Compiler Design - Introduction to Compiler

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

Page 25: Compiler Design - Introduction to Compiler

Programming languages define strict rules to avoid such ambiguities

Introduction To Compilers

{ int Jack = 3; {

int Jack = 4; cout << Jack;

} }

05/01/23 25

Page 26: Compiler Design - Introduction to Compiler

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

Page 27: Compiler Design - Introduction to Compiler

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

Page 28: Compiler Design - Introduction to Compiler

Produces assembly code (usually)

A translation into another language Analogous to human translation

Introduction To Compilers

05/01/23 28

Page 29: Compiler Design - Introduction to Compiler

Question?

05/01/23 29