SlideShare a Scribd company logo
1 of 33
Lectured by Rebaz Najeeb
Compilers (CPL5316)
Software Engineering
Koya university
2015-2016
e-mail: rebaz.najeeb at koyauniversity dot org
Lecture 1 :
Introduction to language processors
Outline
Overview
 Introduction to compiler
 The Architecture of a Compiler
 Lexical analysis (Scanning)
 Syntax Analysis (Parsing)
 Semantic Analysis
 Intermediate Code Generation
 Code Optimization
 Code Generation
What to know?
The essential knowledge in Computation Theory RE, FSA, and CFG.
The essential skills of a Java developer.
The Dragon book
Why compilers?
• Increase productivity
• Low level programming languages are harder to write , less portable , error-prone area, harder to
maintain.
• Hardware synthesis :
Verilog , VHDL to describe high-level hardware description language.
Register Transfer Language (RTL)  gates  transistors  physical layout.
• Reverse engineering eg. (Executble applications .exe )
runtime (0100101100)  assembly code  high level language.
Understanding binary language is hard
• 01000101 01110110 01100101 01110010 01111001 01101111 01101110
01100101 00100000 01100011 01100001 01101110 00100000 01110000
01100001 01110011 01110011 00101100 00100000 01110101 01101110
01101100 01100101 01110011 01110011 00100000 01010011 00101111
01101000 01100101 00100000 01100100 01101111 01100101 01110011
01101110 00100111 01110100 00100000 01110111 01100001 01101110
01110100 00100000 01110100 01101111 00101110
• What does that mean ?
Programming language classification (Levels)
• Low-level language
Assembly language
Machine language
• High-level language
C, C++, java, Pascal, Prolog, Scheme
• Natural language
English, Kurdish.
* There is also a classification by programming language generations.
Who is that girl? Tell me what is her name?
History of compilers
• Grace Hopper, in 1952 ,A-0 System .
• Alick Glennie in 1952, Autocode.
• John W. Backus
Speedcoding , 1953 .
- More productive , but 10-20 slower in execution.
- took 300 bytes of memory (30% memory)
• Fortran, first complete compiler, in 1954-1957 (18 yrs)
%50 code were in Fortran.
• 1960 Cobol, lisp
• 1970 Pascal , C
• 1980 OOP Ada , smalltalk , C++ .
• 1990 Java , script , Perl
• 2000 language specifications
Compilers
• A compiler translates the code written in one language (HLL) to some other language (LLL) without changing the
meaning of the program.
• It is also expected that a compiler should make the target code efficient and optimized in terms of time and space.
• Compiler design covers basic translation mechanism and error detection & recovery.
• Fortran , Ada, C, C++ , C# , Cobol.
Source program Compiler Output (result)
Error/ Warning
Executable program
Executable program
Input(data)
interpreters
• Interpreter is a type of language processor that directly executes the operations specified in the source program on
inputs supplied by the user.
• Python , Perl , Basic , Ruby, AWK.
Source program Interpreter Output (result)
Error/ Warning
Input(data)
Compilers vs interpreters
•No Compiler Interpreter
1 Compiler Takes Entire program as input Interpreter Takes Single instruction as input .
2 Intermediate Object Code is Generated No Intermediate Object Code isGenerated
3 Conditional Control Statements are Executes faster Conditional Control Statements are Executes slower
4
Memory Requirement : More(Since Object Code is
Generated)
Memory Requirement is Less
5 Program need not be compiled every time
Every time higher level program is converted into
lower level program
6 Errors are displayed after entire program is checked
Errors are displayed for every instruction interpreted
(if any)
7 Example : C Compiler Example : BASIC
http://www.c4learn.com/c-programming/compiler-vs-interpreter/
Java Virtual Machine
• Why Java machine independent ?
• Tools to view and edit bytecodes
- ASM (http://asm.ow2.org)
- Jasmin (http://jasmin.sourceforge.net)
• Show demo by CMD
Java compilers
List of compilers
https://en.wikipedia.org/wiki/List_of_compilers
Language processing phases?
Source Program
Preprocessor
Compiler
Assembler
Linker/Loader
Target machine code
Modified source program
Target assembly language
Relocatable machine code
Library files
Relocatable object
files
Memory
Language processing phases?
Source Program
Preprocessor
Compiler
Assembler
Linker/Loader
Target machine code
Modified source program
Target assembly language
Relocatable machine code
Compiler
Analysis
Synthesis
Library files
Relocatable object
files
Memory
Analysis and Synthesis
Compiler
Analysis
Synthesis
Lexical analysis
Syntax analysis
Semantic analysis
Intermediate code generation
Front-end
Code optimization
Code Generation
Back-end
Analysis VS Synthesis
Analysis part
Breaks up the source program into constituent pieces and create an intermediate representation of the source
program. It is often called the front end of the compiler.
The analysis part can be divided along the following phases:
Lexical analysis , syntax analysis , semantic analysis and intermediate code generation (optional)
Synthesis part
Construct the desired target program from the intermediate representation and the information of the symbol table. It
is often called the back end.
The Synthesis part can be divided along the following phases:
Intermediate code generator, code optimizer, code generator
Compiler phases
Lexical analysis Syntax analysis Semantic analysis
Intermediate code generation
Machine-independent
Code optimization
Code Generator
Character
stream
Token
stream
Syntax
tree
Syntax tree
Intermediate code
representation
Intermediate code
representation
Target machine
code
Machine-independent
Code optimization
Target
machine code
Symbol table
Compiler phases
Target code
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Code optimization
5. Code Generation
http://www.tutorialspoint.com/compiler_design/i
mages/compiler_phases.jpg
Lexical analysis (Scanning)
• How do we understand English ?
• Break up sentence and recognize words
Iamasmartstudent. I am a smart student.
Separator
Noun
Lexical analysis (Scanning)
lexical analysis is the process of converting a sequence of characters (such as
a computer program or web page) into a sequence of tokens (strings with an
identified "meaning").
Syntax analysis
• How do we understand English?
The Smart students never ever give up.
S Adv V
Sentence
Syntax analysis (Parsing)
A Parser reads a stream of tokens from scanner, and determines if the syntax of the
program is correct according to the context-free grammar (CFG) of the source language.
Then, Tokens are grouped into grammatical phrases represented by a Parse Tree or an
abstract syntax tree, which gives a hierarchical structure to the source program.
Syntax analysis example
Semantic analysis
For example :
A woman without her man is nothing. Vs A woman: without her, man is nothing
Semantic analysis
The Semantic Analysis phase checks the (meaning of) source program for semantic errors
(Type Checking) and gathers type information for the successive phases.
Semantic analysis is the heart of compiler. Also, type checking is the important part in this phase.
Check language requirements like proper declarations.
Semantic analysis catches inconsistencies for instance mismatching datatypes.
Intermediate code generation
After syntax and semantic analysis of the source program , many compilers generate an explicit low-level
or machine-like intermediate code.
In some compilers, a source program is translated into an intermediate code first and then translated into
the target language. In other compilers, translated directly into the target language.
One of the popular intermediate code is three-address code.
Example:
temp1 = int_to_float(60)
temp2 = id3 ∗ temp1
temp3 = id2 + temp2
id1 = temp3
Optimization
This phase attempts to improve the intermediate code, which is produced. So that faster-running
machine code can be achieved in the term of time and space.
The optimized code MUST be CORRECT
Run Faster (time)
Minimize power consumption (Mobile devices)
Use less memory
Shorter is better
Consider network, database access.
Optimize this code
Code Generation
The code generator takes as input an intermediate code representation of
the source program and maps it into the target language.
If the target language is machine code , registers or memory locations are
selected for each of the variables used by the program.
Symbol table
• A symbol table is a data structure containing a record for each variable name, with fields for the
attributes of the name.
• Symbol table should allow find the record for each name quickly and to store and retrieve data from that
record quickly.
• Attributes may provide information about storage allocation, type , scope , number and type of
arguments , method of passing, the type returned.
All phases in one example
Lecture 1  introduction to language processors

More Related Content

What's hot

basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler designPreeti Katiyar
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1Manoj Patil
 
System programming note
System programming noteSystem programming note
System programming noteSANTOSH RATH
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Chap 1-language processor
Chap 1-language processorChap 1-language processor
Chap 1-language processorshindept123
 
5 Names, bindings,Typechecking and Scopes
5 Names, bindings,Typechecking and Scopes5 Names, bindings,Typechecking and Scopes
5 Names, bindings,Typechecking and ScopesMunawar Ahmed
 
Toy compiler
Toy compilerToy compiler
Toy compilerhome
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1REHAN IJAZ
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / TranslatorsProject Student
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 
Introduction to system programming
Introduction to system programmingIntroduction to system programming
Introduction to system programmingsonalikharade3
 
Programming languages
Programming languagesProgramming languages
Programming languagesvito_carleone
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction Sarmad Ali
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdfRakibRahman19
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Bhavin Darji
 

What's hot (20)

basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler design
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
System programming note
System programming noteSystem programming note
System programming note
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Chap 1-language processor
Chap 1-language processorChap 1-language processor
Chap 1-language processor
 
5 Names, bindings,Typechecking and Scopes
5 Names, bindings,Typechecking and Scopes5 Names, bindings,Typechecking and Scopes
5 Names, bindings,Typechecking and Scopes
 
Toy compiler
Toy compilerToy compiler
Toy compiler
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / Translators
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Introduction to system programming
Introduction to system programmingIntroduction to system programming
Introduction to system programming
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Design of a two pass assembler
Design of a two pass assemblerDesign of a two pass assembler
Design of a two pass assembler
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdf
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
 

Viewers also liked

Viewers also liked (14)

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Syntax directed-translation
Syntax directed-translationSyntax directed-translation
Syntax directed-translation
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Ch5a
Ch5aCh5a
Ch5a
 
History of computers - Modern
History of computers - ModernHistory of computers - Modern
History of computers - Modern
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Analysis of the source program
Analysis of the source programAnalysis of the source program
Analysis of the source program
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 

Similar to Lecture 1 introduction to language processors

Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdfAkarTaher
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Language translators
Language translatorsLanguage translators
Language translatorsAditya Sharat
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfDrIsikoIsaac
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introductionmengistu23
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxdawod yimer
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterHossam Hassan
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfDrIsikoIsaac
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Rebaz Najeeb
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 

Similar to Lecture 1 introduction to language processors (20)

Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Language translators
Language translatorsLanguage translators
Language translators
 
Cd unit i
Cd unit iCd unit i
Cd unit i
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdf
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Compilers.pptx
Compilers.pptxCompilers.pptx
Compilers.pptx
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 

Recently uploaded

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Recently uploaded (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 

Lecture 1 introduction to language processors

  • 1. Lectured by Rebaz Najeeb Compilers (CPL5316) Software Engineering Koya university 2015-2016 e-mail: rebaz.najeeb at koyauniversity dot org Lecture 1 : Introduction to language processors
  • 2. Outline Overview  Introduction to compiler  The Architecture of a Compiler  Lexical analysis (Scanning)  Syntax Analysis (Parsing)  Semantic Analysis  Intermediate Code Generation  Code Optimization  Code Generation
  • 3. What to know? The essential knowledge in Computation Theory RE, FSA, and CFG. The essential skills of a Java developer. The Dragon book
  • 4. Why compilers? • Increase productivity • Low level programming languages are harder to write , less portable , error-prone area, harder to maintain. • Hardware synthesis : Verilog , VHDL to describe high-level hardware description language. Register Transfer Language (RTL)  gates  transistors  physical layout. • Reverse engineering eg. (Executble applications .exe ) runtime (0100101100)  assembly code  high level language.
  • 5. Understanding binary language is hard • 01000101 01110110 01100101 01110010 01111001 01101111 01101110 01100101 00100000 01100011 01100001 01101110 00100000 01110000 01100001 01110011 01110011 00101100 00100000 01110101 01101110 01101100 01100101 01110011 01110011 00100000 01010011 00101111 01101000 01100101 00100000 01100100 01101111 01100101 01110011 01101110 00100111 01110100 00100000 01110111 01100001 01101110 01110100 00100000 01110100 01101111 00101110 • What does that mean ?
  • 6. Programming language classification (Levels) • Low-level language Assembly language Machine language • High-level language C, C++, java, Pascal, Prolog, Scheme • Natural language English, Kurdish. * There is also a classification by programming language generations.
  • 7. Who is that girl? Tell me what is her name?
  • 8. History of compilers • Grace Hopper, in 1952 ,A-0 System . • Alick Glennie in 1952, Autocode. • John W. Backus Speedcoding , 1953 . - More productive , but 10-20 slower in execution. - took 300 bytes of memory (30% memory) • Fortran, first complete compiler, in 1954-1957 (18 yrs) %50 code were in Fortran. • 1960 Cobol, lisp • 1970 Pascal , C • 1980 OOP Ada , smalltalk , C++ . • 1990 Java , script , Perl • 2000 language specifications
  • 9. Compilers • A compiler translates the code written in one language (HLL) to some other language (LLL) without changing the meaning of the program. • It is also expected that a compiler should make the target code efficient and optimized in terms of time and space. • Compiler design covers basic translation mechanism and error detection & recovery. • Fortran , Ada, C, C++ , C# , Cobol. Source program Compiler Output (result) Error/ Warning Executable program Executable program Input(data)
  • 10. interpreters • Interpreter is a type of language processor that directly executes the operations specified in the source program on inputs supplied by the user. • Python , Perl , Basic , Ruby, AWK. Source program Interpreter Output (result) Error/ Warning Input(data)
  • 11. Compilers vs interpreters •No Compiler Interpreter 1 Compiler Takes Entire program as input Interpreter Takes Single instruction as input . 2 Intermediate Object Code is Generated No Intermediate Object Code isGenerated 3 Conditional Control Statements are Executes faster Conditional Control Statements are Executes slower 4 Memory Requirement : More(Since Object Code is Generated) Memory Requirement is Less 5 Program need not be compiled every time Every time higher level program is converted into lower level program 6 Errors are displayed after entire program is checked Errors are displayed for every instruction interpreted (if any) 7 Example : C Compiler Example : BASIC http://www.c4learn.com/c-programming/compiler-vs-interpreter/
  • 12. Java Virtual Machine • Why Java machine independent ? • Tools to view and edit bytecodes - ASM (http://asm.ow2.org) - Jasmin (http://jasmin.sourceforge.net) • Show demo by CMD
  • 13. Java compilers List of compilers https://en.wikipedia.org/wiki/List_of_compilers
  • 14. Language processing phases? Source Program Preprocessor Compiler Assembler Linker/Loader Target machine code Modified source program Target assembly language Relocatable machine code Library files Relocatable object files Memory
  • 15. Language processing phases? Source Program Preprocessor Compiler Assembler Linker/Loader Target machine code Modified source program Target assembly language Relocatable machine code Compiler Analysis Synthesis Library files Relocatable object files Memory
  • 16. Analysis and Synthesis Compiler Analysis Synthesis Lexical analysis Syntax analysis Semantic analysis Intermediate code generation Front-end Code optimization Code Generation Back-end
  • 17. Analysis VS Synthesis Analysis part Breaks up the source program into constituent pieces and create an intermediate representation of the source program. It is often called the front end of the compiler. The analysis part can be divided along the following phases: Lexical analysis , syntax analysis , semantic analysis and intermediate code generation (optional) Synthesis part Construct the desired target program from the intermediate representation and the information of the symbol table. It is often called the back end. The Synthesis part can be divided along the following phases: Intermediate code generator, code optimizer, code generator
  • 18. Compiler phases Lexical analysis Syntax analysis Semantic analysis Intermediate code generation Machine-independent Code optimization Code Generator Character stream Token stream Syntax tree Syntax tree Intermediate code representation Intermediate code representation Target machine code Machine-independent Code optimization Target machine code Symbol table
  • 19. Compiler phases Target code 1. Lexical analysis 2. Syntax analysis 3. Semantic analysis 4. Code optimization 5. Code Generation http://www.tutorialspoint.com/compiler_design/i mages/compiler_phases.jpg
  • 20. Lexical analysis (Scanning) • How do we understand English ? • Break up sentence and recognize words Iamasmartstudent. I am a smart student. Separator Noun
  • 21. Lexical analysis (Scanning) lexical analysis is the process of converting a sequence of characters (such as a computer program or web page) into a sequence of tokens (strings with an identified "meaning").
  • 22. Syntax analysis • How do we understand English? The Smart students never ever give up. S Adv V Sentence
  • 23. Syntax analysis (Parsing) A Parser reads a stream of tokens from scanner, and determines if the syntax of the program is correct according to the context-free grammar (CFG) of the source language. Then, Tokens are grouped into grammatical phrases represented by a Parse Tree or an abstract syntax tree, which gives a hierarchical structure to the source program.
  • 25. Semantic analysis For example : A woman without her man is nothing. Vs A woman: without her, man is nothing
  • 26. Semantic analysis The Semantic Analysis phase checks the (meaning of) source program for semantic errors (Type Checking) and gathers type information for the successive phases. Semantic analysis is the heart of compiler. Also, type checking is the important part in this phase. Check language requirements like proper declarations. Semantic analysis catches inconsistencies for instance mismatching datatypes.
  • 27. Intermediate code generation After syntax and semantic analysis of the source program , many compilers generate an explicit low-level or machine-like intermediate code. In some compilers, a source program is translated into an intermediate code first and then translated into the target language. In other compilers, translated directly into the target language. One of the popular intermediate code is three-address code. Example: temp1 = int_to_float(60) temp2 = id3 ∗ temp1 temp3 = id2 + temp2 id1 = temp3
  • 28. Optimization This phase attempts to improve the intermediate code, which is produced. So that faster-running machine code can be achieved in the term of time and space. The optimized code MUST be CORRECT Run Faster (time) Minimize power consumption (Mobile devices) Use less memory Shorter is better Consider network, database access.
  • 30. Code Generation The code generator takes as input an intermediate code representation of the source program and maps it into the target language. If the target language is machine code , registers or memory locations are selected for each of the variables used by the program.
  • 31. Symbol table • A symbol table is a data structure containing a record for each variable name, with fields for the attributes of the name. • Symbol table should allow find the record for each name quickly and to store and retrieve data from that record quickly. • Attributes may provide information about storage allocation, type , scope , number and type of arguments , method of passing, the type returned.
  • 32. All phases in one example