SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de Arab Open University and Cairo University

Mais 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
 

Último

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Último (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

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