SlideShare une entreprise Scribd logo
1  sur  21
WELCOME TO A
JOURNEY TO
CS419

Dr. Hussien Sharaf
Computer Science Department

dr.sharaf@from-masr.com
LECTURE OUTLINE
 Grading

and policy
 Course outline and references
 Chapter one

Dr. Hussien M. Sharaf

2
GRADING AND POLICY
 Grades will be based on 100 possible points,

using the following distribution schedule:
 Assignments: 5%
 Mid-term Exam : 10%
 Group Project: 10%
 Practical: 10%
 Attendance: 5%
 Final Exam: 60%
Dr. Hussien M. Sharaf

3
COURSE OUTLINE AND REFERENCES
Chapter one – Introduction
 Chapter three- Lexical analysis definition using Regular Expression
 Chapter three- Lexical analysis using DFA
 Chapter three- Lexical analysis using NFA
and Transfer NFA to DFA.


Dr. Hussien M. Sharaf

4
COURSE OUTLINE AND REFERENCES
Chapter four- Syntax analysis using CFG.
 Chapter four- Syntax analysis, Parsing
trees and Ambiguity.
 Chapter four - Removing Left Recursion
and Left Factoring.
 Chapter four - Syntax analysis (CFG) using
Top-down parsing.


Dr. Hussien M. Sharaf

5
COURSE OUTLINE AND REFERENCES
Chapter four - First and Follow operators.
 Chapter four - Syntax analysis (CFG) using
Bottom-Up (predictive/LR) parsing.
 Chapter four - Construction of “LR Parsing
Tables” / “parsing Table LL1”
 Semantic analysis
 Intermediate code and code generation.


Dr. Hussien M. Sharaf

6
LECTURE1 OUTLINE



Introduction is split into two lectures:
Lec1: Overview
 What are compilers
 Phases ( architecture ) of a Compiler.
 Some Data structures that are required for
compiler’s work:
 Token
 Symbol table.
 Literal table
 Parse tree
Dr. Hussien M. Sharaf

7
LECTURE2 OUTLINE


Lec2: Overview


Phases of a Compiler:






Scanning.
Parsing.
Semantic analysis.
Intermediate code generation.
Code generation.

Dr. Hussien M. Sharaf

8
WHAT ARE COMPILERS?
A program that translates one
language to another.

Source
program

Responsibility:

Usually
High level
language

1. Accepts a source program

typically written in a high- level
language.

compiler

Target
program
Usually
machine
language

Error
message

2. Produces an equivalent target

program typically in assembly or
machine language.
3. Reports error messages as part

of the translation process.
Dr. Hussien M. Sharaf

9
COUSINS OF COMPILERS
1.

2.

3.

4.

Interpreter: is a program that ultimately performs the
same function as a compiler, but in a different manner.
It works by scanning through the source program
instruction by instruction. As each instruction is
encountered, the interpreter translates it into machine
code and executes it directly.
Assembler: is a program that automatically translates
the source program written in assembly language and
to produce as output an object code written in binary
machine code.
Linker: is a program that takes one or more objects
generated by compilers and assembles them into a
single executable program.
Loader: (is a routine that) loads an object program into
memory and prepares it for execution

Dr. Hussien M. Sharaf

10
DIFFERENT ARCHITECTURAL VIEWS
1.
2.

Functional view : 6 phases.
Logical view: the 6 phases are grouped into two main
categories
A.
B.

3.

Analysis VS synthesis.
Front end VS back end.

Operations view: execute one or more phase into one
pass. Each pass builds or updates the output of the
previous pass.
A.
B.
C.

Scanning & parsing.
Sematic analysis.
Code generation & optimization.

Dr. Hussien M. Sharaf

11
ARCHITECTURE/PHASES OF A COMPILER
Stream of
characters

Scanner/lexical analyzer
Stream of tokens

Parser/ syntax analyzer
Parse/syntax tree

Literal Table

Semantic analyzer
Annotated tree

Source Code optimization
Intermediate code

Symbol Table

Code generator
Target code

Target Code optimization
Target code

Dr. Hussien M.
Sharaf

12
SOME DATA STRUCTURES
1. Token
2. Symbol table
3. Literal table
4. Parse tree
5. Semantic parse tree
6. Intermediate code

Dr. Hussien M. Sharaf

13
Dr. Hussien M. Sharaf

1. TOKEN
Single Symbol ahead: In most languages the
scanner needs to generate only one token
ahead at a time.
 In this case you don’t need a collection/array
of tokens, only one global variable can be
used.

2. SYMBOL TABLE
1.

2.

Stores information associated with identifiers.
Information associated with variables like
[name, type, address, size (for array), etc.]
Stores Information associated with functions
like [name, type of return
value, parameters, address, etc.]
Sample
name
Type address size (for array)
code:
x
int
OxA300 n/a
y
int
OxA304 n/a
int x, y;
c
char OxA308 10
char c[10];
x = 5;

Dr. Hussien M. Sharaf

15
2. SYMBOL TABLE (CONT’D)
Use defined data types like structs, enums
and classes.
 The symbol table is modified by the scanner,
parser, and semantic analyzer.
3.





The information at the symbol table is used by
intermediate code generator phase and machine
code generator phase.
Mostly use hash table for efficiency Because
access time is O(k) and space consumption is
not a concern.

Dr. Hussien M. Sharaf

16
3. LITERAL TABLE


Store constants and strings used in program
 reduce

the memory size by reusing constants
and strings



Can be combined with symbol table in some
implementations.

Dr. Hussien M. Sharaf

17
4. PARSE TREE
Dynamically-allocated, pointer-based
TREE structure
 Sample code


Dr. Hussien M. Sharaf

18
5. SEMANTIC PARSE TREE


Usually the same parse tree is used and
annotations are added for each node.

Dr. Hussien M. Sharaf

19
6. INTERMEDIATE CODE
The structure of the code
is kept as simple as
possible usually threeaddress code.
 Each instruction is allows
only three addresses
(variables).
 Each instruction is added
as an entry into a linked
list that allows dynamic
growth.


Dr. Hussien M. Sharaf

Var1

Var2

op

Var3

Var1

Var2

op

Var3

….

….

op

…

NULL

20
http://tinyurl.com/mkwg48a

Dr. Hussien M. Sharaf

21

Contenu connexe

Tendances

Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointerNishant Munjal
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1tanmaymodi4
 
Cut and Goal on prolog
Cut and Goal on prologCut and Goal on prolog
Cut and Goal on prologchauhankapil
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++Muhammad Hammad Waseem
 
Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete  Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete Adnan abid
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]ecko_disasterz
 
C programming session 08
C programming session 08C programming session 08
C programming session 08Dushmanta Nath
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5Infinity Tech Solutions
 
Fundamentals of Computing and C Programming - Part 3
Fundamentals of Computing and C Programming - Part 3Fundamentals of Computing and C Programming - Part 3
Fundamentals of Computing and C Programming - Part 3Karthik Srini B R
 
programming fortran 77 Slide02
programming fortran 77 Slide02programming fortran 77 Slide02
programming fortran 77 Slide02Ahmed Gamal
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and reviewAbdullah Al-hazmy
 

Tendances (20)

Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
 
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C ProgrammingLecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
 
C programming part4
C programming part4C programming part4
C programming part4
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Cut and Goal on prolog
Cut and Goal on prologCut and Goal on prolog
Cut and Goal on prolog
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
 
Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete  Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Pointers - DataStructures
Pointers - DataStructuresPointers - DataStructures
Pointers - DataStructures
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
 
C# p8
C# p8C# p8
C# p8
 
Fundamentals of Computing and C Programming - Part 3
Fundamentals of Computing and C Programming - Part 3Fundamentals of Computing and C Programming - Part 3
Fundamentals of Computing and C Programming - Part 3
 
programming fortran 77 Slide02
programming fortran 77 Slide02programming fortran 77 Slide02
programming fortran 77 Slide02
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and review
 
Lecture 12 - Recursion
Lecture 12 - Recursion Lecture 12 - Recursion
Lecture 12 - Recursion
 

Similaire à Cs419 Compiler lec1&2 introduction

International journal of compiling
International journal of compilingInternational journal of compiling
International journal of compilingAndivann
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 
Chapter One
Chapter OneChapter One
Chapter Onebolovv
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxVigneshkumar Ponnusamy
 
A project on advanced C language
A project on advanced C languageA project on advanced C language
A project on advanced C languagesvrohith 9
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdfAkarTaher
 
Compiler Design.pptx
Compiler Design.pptxCompiler Design.pptx
Compiler Design.pptxSouvikRoy149
 
lec00-Introduction.pdf
lec00-Introduction.pdflec00-Introduction.pdf
lec00-Introduction.pdfwigewej294
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORijistjournal
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGEIJCI JOURNAL
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGEIJCI JOURNAL
 
Compiler design-lab-manual v-cse
Compiler design-lab-manual v-cseCompiler design-lab-manual v-cse
Compiler design-lab-manual v-cseravisharma159932
 

Similaire à Cs419 Compiler lec1&2 introduction (20)

International journal of compiling
International journal of compilingInternational journal of compiling
International journal of compiling
 
International journal of compiling
International journal of compilingInternational journal of compiling
International journal of compiling
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Chapter One
Chapter OneChapter One
Chapter One
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
A project on advanced C language
A project on advanced C languageA project on advanced C language
A project on advanced C language
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Mit gnu scheme reference manual
Mit gnu scheme reference manualMit gnu scheme reference manual
Mit gnu scheme reference manual
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Compiler Design.pptx
Compiler Design.pptxCompiler Design.pptx
Compiler Design.pptx
 
lec00-Introduction.pdf
lec00-Introduction.pdflec00-Introduction.pdf
lec00-Introduction.pdf
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Compiler design-lab-manual v-cse
Compiler design-lab-manual v-cseCompiler design-lab-manual v-cse
Compiler design-lab-manual v-cse
 
C language 3
C language 3C language 3
C language 3
 

Plus de Arab Open University and Cairo University

Plus de Arab Open University and Cairo University (20)

Infos2014
Infos2014Infos2014
Infos2014
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Lec4
Lec4Lec4
Lec4
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 

Dernier

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 

Dernier (20)

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 

Cs419 Compiler lec1&2 introduction

  • 1. WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com
  • 2. LECTURE OUTLINE  Grading and policy  Course outline and references  Chapter one Dr. Hussien M. Sharaf 2
  • 3. GRADING AND POLICY  Grades will be based on 100 possible points, using the following distribution schedule:  Assignments: 5%  Mid-term Exam : 10%  Group Project: 10%  Practical: 10%  Attendance: 5%  Final Exam: 60% Dr. Hussien M. Sharaf 3
  • 4. COURSE OUTLINE AND REFERENCES Chapter one – Introduction  Chapter three- Lexical analysis definition using Regular Expression  Chapter three- Lexical analysis using DFA  Chapter three- Lexical analysis using NFA and Transfer NFA to DFA.  Dr. Hussien M. Sharaf 4
  • 5. COURSE OUTLINE AND REFERENCES Chapter four- Syntax analysis using CFG.  Chapter four- Syntax analysis, Parsing trees and Ambiguity.  Chapter four - Removing Left Recursion and Left Factoring.  Chapter four - Syntax analysis (CFG) using Top-down parsing.  Dr. Hussien M. Sharaf 5
  • 6. COURSE OUTLINE AND REFERENCES Chapter four - First and Follow operators.  Chapter four - Syntax analysis (CFG) using Bottom-Up (predictive/LR) parsing.  Chapter four - Construction of “LR Parsing Tables” / “parsing Table LL1”  Semantic analysis  Intermediate code and code generation.  Dr. Hussien M. Sharaf 6
  • 7. LECTURE1 OUTLINE   Introduction is split into two lectures: Lec1: Overview  What are compilers  Phases ( architecture ) of a Compiler.  Some Data structures that are required for compiler’s work:  Token  Symbol table.  Literal table  Parse tree Dr. Hussien M. Sharaf 7
  • 8. LECTURE2 OUTLINE  Lec2: Overview  Phases of a Compiler:      Scanning. Parsing. Semantic analysis. Intermediate code generation. Code generation. Dr. Hussien M. Sharaf 8
  • 9. WHAT ARE COMPILERS? A program that translates one language to another. Source program Responsibility: Usually High level language 1. Accepts a source program typically written in a high- level language. compiler Target program Usually machine language Error message 2. Produces an equivalent target program typically in assembly or machine language. 3. Reports error messages as part of the translation process. Dr. Hussien M. Sharaf 9
  • 10. COUSINS OF COMPILERS 1. 2. 3. 4. Interpreter: is a program that ultimately performs the same function as a compiler, but in a different manner. It works by scanning through the source program instruction by instruction. As each instruction is encountered, the interpreter translates it into machine code and executes it directly. Assembler: is a program that automatically translates the source program written in assembly language and to produce as output an object code written in binary machine code. Linker: is a program that takes one or more objects generated by compilers and assembles them into a single executable program. Loader: (is a routine that) loads an object program into memory and prepares it for execution Dr. Hussien M. Sharaf 10
  • 11. DIFFERENT ARCHITECTURAL VIEWS 1. 2. Functional view : 6 phases. Logical view: the 6 phases are grouped into two main categories A. B. 3. Analysis VS synthesis. Front end VS back end. Operations view: execute one or more phase into one pass. Each pass builds or updates the output of the previous pass. A. B. C. Scanning & parsing. Sematic analysis. Code generation & optimization. Dr. Hussien M. Sharaf 11
  • 12. ARCHITECTURE/PHASES OF A COMPILER Stream of characters Scanner/lexical analyzer Stream of tokens Parser/ syntax analyzer Parse/syntax tree Literal Table Semantic analyzer Annotated tree Source Code optimization Intermediate code Symbol Table Code generator Target code Target Code optimization Target code Dr. Hussien M. Sharaf 12
  • 13. SOME DATA STRUCTURES 1. Token 2. Symbol table 3. Literal table 4. Parse tree 5. Semantic parse tree 6. Intermediate code Dr. Hussien M. Sharaf 13
  • 14. Dr. Hussien M. Sharaf 1. TOKEN Single Symbol ahead: In most languages the scanner needs to generate only one token ahead at a time.  In this case you don’t need a collection/array of tokens, only one global variable can be used. 
  • 15. 2. SYMBOL TABLE 1. 2. Stores information associated with identifiers. Information associated with variables like [name, type, address, size (for array), etc.] Stores Information associated with functions like [name, type of return value, parameters, address, etc.] Sample name Type address size (for array) code: x int OxA300 n/a y int OxA304 n/a int x, y; c char OxA308 10 char c[10]; x = 5; Dr. Hussien M. Sharaf 15
  • 16. 2. SYMBOL TABLE (CONT’D) Use defined data types like structs, enums and classes.  The symbol table is modified by the scanner, parser, and semantic analyzer. 3.   The information at the symbol table is used by intermediate code generator phase and machine code generator phase. Mostly use hash table for efficiency Because access time is O(k) and space consumption is not a concern. Dr. Hussien M. Sharaf 16
  • 17. 3. LITERAL TABLE  Store constants and strings used in program  reduce the memory size by reusing constants and strings  Can be combined with symbol table in some implementations. Dr. Hussien M. Sharaf 17
  • 18. 4. PARSE TREE Dynamically-allocated, pointer-based TREE structure  Sample code  Dr. Hussien M. Sharaf 18
  • 19. 5. SEMANTIC PARSE TREE  Usually the same parse tree is used and annotations are added for each node. Dr. Hussien M. Sharaf 19
  • 20. 6. INTERMEDIATE CODE The structure of the code is kept as simple as possible usually threeaddress code.  Each instruction is allows only three addresses (variables).  Each instruction is added as an entry into a linked list that allows dynamic growth.  Dr. Hussien M. Sharaf Var1 Var2 op Var3 Var1 Var2 op Var3 …. …. op … NULL 20