SlideShare una empresa de Scribd logo
1 de 23
Compiler Construction
(Introduction)
Lecture-1
By
Shahid Akbar
MS (Computer Science)
Goals Of This Course
Know how to build a compiler for a (simplified) (programming)
language
Know how to use compiler construction tools, such as generators for
scanners (Lexical Analyzer) and parsers(Semantic Analyzer )
Be able to write LL(1), LR(1), and LALR(1) grammars (for new
languages)
Be familiar with compiler analysis and optimization techniques
8-Apr-17 2
Grading Policy
 Mid Term 20
 Final Term 60
 Quizzes / Assignments 20
Total 100
Note= 75% Attendance is compulsory for Exams
8-Apr-17
3
Textbook
Compilers: Principles, Techniques, and Tools, 2/E.
Alfred V. Aho, Columbia University
Monica S. Lam, Stanford University
Ravi Sethi, Avaya Labs
Jeffrey D. Ullman, Stanford University
Dragon
What is Compiler?
 The world as we know it depends on programming languages,
C, C++, Java, Web programming, and etc.
 All the software running on all the computers was written in some programming
language.
 Before a program can be run, it first must be translated into a form in which it
can be executed by a computer.
The software systems that do this translation are called compilers.
Different compilers
 VC, VC++ (visual compiler, Microsoft products)
 GCC
Dev C compiler , where Dev C is Integrated development environment (IDE)
 JavaC
Java compiler
 FORTRAN
 Pascal
 Visual Basic (internet programming)
Why Compilation?
The conversion of high level language into low level object code and
machine code.
High level language can be understandable by the human , contain
English words and phrases, but computer can only understand
machine language (Low level language), that’s we need compilation
for interaction between human and computer.
Computer Languages-1
 Machine language (Low Level Language)
 Only language computer directly understands
 Defined by hardware design
 Machine-dependent
 Generally consist of strings of numbers
 Ultimately 0s and 1s
 Instruct computers to perform elementary operations
 One at a time
 Cumbersome for humans
 Example:
+1300042774
+1400593419
+1200274027
8
Computer Languages-2
 Assembly language
 English-like abbreviations representing elementary
computer operations
 Clearer to humans
 Incomprehensible to computers
 Translator programs (assemblers)
 Convert to machine language
 Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
9
Computer Languages-3
 High-level languages
 Similar to everyday English, use common mathematical
notations
 Single statements accomplish substantial tasks
 Assembly language requires many instructions to
accomplish simple tasks
 Translator programs (compilers)
 Convert to machine language
 Interpreter programs
 Directly execute high-level language programs
 Example:
grossPay = basePay + overTimePay
10
A compiler is program that covert high level language to
Assembly languages , similarly an Assembler is a program that
convert the Assembly language to Machine Level language
Compiler Vs Assembler
Assembler VS Compiler
It is used to translate the program written in assembly language
into Machine language.
An assembler perform the translation process in the similar way
as compiler, but Assembler is a translator program for low
level programming language , while a compiler is the translator
program for high level languages
Compilers and Interpreters
“Compilation”
Translation of a program written in a source language into a
semantically equivalent program written in a target language.
An important role of the compiler is to report any errors in the
source program , errors are detected during the translation
process.
Compiler
Error messages
Source
Program
(HLL)
Target
Program
Input
Output
Execution
Compilation (Error Checking
(A L L)
Compilers and Interpreters (cont’d)
Interpreter
Source
Program
Input (Execution)
Output
Error messages
“Interpretation”
 Language processor
Performing the operations implied in the source program on
input supplied by users.
Complier Vs Interpreter
 In interpreter both execution and compilation process are combined ,At first a
statement is compiled and then executed.
 In compiler , A program is compiled one time and it can be execute again and
again until you need.
 While in interpreter A program/statement will be compiled and executed again
and again (depend on number of execution)
 e.g: if you need to execute a program 100 times, it requires 100 time compilation
and 100 times execution in interpreter
 Note : 1) Compiler is fast than interpreter (Why)
2) Error diagnosis of interpreter is better than compiler
Interpreter Compiler
Translates program statement by statement at a
time.
Scans the entire program and translates it as a
whole into machine code
It takes less amount of time to analyze the
source code but the overall execution time is
slower.(Time consuming)
It takes large amount of time to analyze the
source code but the overall execution time is
comparatively faster.
Continues translating the program until the first
error is met, in which case it stops. Hence
debugging is easy.
It generates the error message only after
scanning the whole program. Hence debugging
is comparatively hard.
Programming language like Python, Ruby use
interpreters.
Programming language like C, C++ use
compilers.
Compiler History
1952: First compiler (linker/loader) written by Grace Hopper for A-0
programming language
1957: First complete compiler for FORTRAN by John Backus and team
1960: COBOL compilers for multiple architectures
1962: First self-hosting compiler for LISP
Compiler Construction requirements
Programming languages (parameter passing, variable scoping,
memory allocation, etc)
theory (automata, context-free languages, etc)
Algorithms and data structures (hash tables, graph algorithms,
dynamic programming, etc)
Computer architecture (assembly programming)
Software Engineering.
Compiler Qualities
Make the Code Accurate
Compiler runs fast
Compile time proportional to program size
Support for separate compilation
Efficient to check syntax errors
Works well with the debugger
Good diagnostics for flow anomalies
Cross language calls --- interface compatibilities
Consistent, predictable optimization
A General language processing System
Preprocessor
HLL
Pure HLL
Compiler
Assembler
Linker/Loader
Assembly Language
Relocatable machine Code
Target Machine Code
#include < ?? . h >
# define Const variable
File Inclusion
Macro Expansion
NO preprocessor Directives
MOV a, R1
ADD #2, R1
MOV R1, b
i.e. b:= a +2
0001 01 00 00000000
0011 01 10 00000010
0010 01 00 00000100
Loading the data(relocatable
machine Code) and instruction to the
proper locations
Phases of Compiler
Lexical Analyzer
Syntax Analyzer
Semantic Analyzer
Intermediate Code
Generator
Code Optimizer
Target Code Generator
Character Stream (H L L)
Token Stream
Syntax Tree
Syntax Tree
(semantically verified
meaningful)
3 Address Code
Assembly code
Symbol Table
Reduce size of program
(number of lines)
Error Handler
Phase Output Sample
Programmer Source string A=B+C;
Scanner (performs lexical
analysis)
Token string ‘A’, ‘=’, ‘B’, ‘+’, ‘C’, ‘;’
And symbol table for identifiers
Parser (performs syntax analysis
based on the grammar of the
programming language)
Parse tree or abstract syntax tree ;
|
=
/ 
A +
/ 
B C
Semantic analyzer (type
checking, etc)
Parse tree or abstract syntax tree
Intermediate code generator Three-address code int2fp B t1
+ t1 C t2
:= t2 A
Optimizer Three-address code int2fp B t1
+ t1 #2.3 A
Code generator Assembly code MOVF #2.3,r1
ADDF2 r1,r2
MOVF r2,A
Peephole optimizer Assembly code ADDF2 #2.3,r2
MOVF r2,A

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Compilers
CompilersCompilers
Compilers
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / Translators
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.
 
What is Compiler?
What is Compiler?What is Compiler?
What is Compiler?
 
Language translator
Language translatorLanguage translator
Language translator
 
Language Translator ( Compiler)
Language Translator ( Compiler)Language Translator ( Compiler)
Language Translator ( Compiler)
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Programming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwares
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
 
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorial
 
Cmp2412 programming principles
Cmp2412 programming principlesCmp2412 programming principles
Cmp2412 programming principles
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
Computer Language Translator
Computer Language TranslatorComputer Language Translator
Computer Language Translator
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
Computer
ComputerComputer
Computer
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
 
13 A Programing Languages (IT) Lecture Slide
13 A Programing Languages (IT) Lecture Slide13 A Programing Languages (IT) Lecture Slide
13 A Programing Languages (IT) Lecture Slide
 
df
dfdf
df
 

Similar a Lecture1 compilers

1.Overview of Programming.pptx
1.Overview of Programming.pptx1.Overview of Programming.pptx
1.Overview of Programming.pptxVishwas459764
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingNoel Malle
 
Compiler design slide share
Compiler design slide shareCompiler design slide share
Compiler design slide shareSudhaa Ravi
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Arslan Hussain
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programmingMukesh Tekwani
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
X-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfX-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfAlefya1
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxdawod yimer
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic conceptsAbdul Khan
 
Introduction to Computer Programming (general background)
Introduction to Computer Programming (general background)Introduction to Computer Programming (general background)
Introduction to Computer Programming (general background)Chao-Lung Yang
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and developmentAli Raza
 
Computer program, computer languages, computer software
Computer program, computer languages, computer softwareComputer program, computer languages, computer software
Computer program, computer languages, computer softwareSweta Kumari Barnwal
 

Similar a Lecture1 compilers (20)

1.Overview of Programming.pptx
1.Overview of Programming.pptx1.Overview of Programming.pptx
1.Overview of Programming.pptx
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
COMPILER DESIGN.docx
COMPILER DESIGN.docxCOMPILER DESIGN.docx
COMPILER DESIGN.docx
 
Compiler design slide share
Compiler design slide shareCompiler design slide share
Compiler design slide share
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1
 
SS UI Lecture 1
SS UI Lecture 1SS UI Lecture 1
SS UI Lecture 1
 
Ss ui lecture 1
Ss ui lecture 1Ss ui lecture 1
Ss ui lecture 1
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Ic lecture8
Ic lecture8 Ic lecture8
Ic lecture8
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
X-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfX-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdf
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic concepts
 
Introduction to Computer Programming (general background)
Introduction to Computer Programming (general background)Introduction to Computer Programming (general background)
Introduction to Computer Programming (general background)
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
 
Ppt 1
Ppt 1Ppt 1
Ppt 1
 
Computer program, computer languages, computer software
Computer program, computer languages, computer softwareComputer program, computer languages, computer software
Computer program, computer languages, computer software
 

Último

Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxPurva Nikam
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 

Último (20)

Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 

Lecture1 compilers

  • 2. Goals Of This Course Know how to build a compiler for a (simplified) (programming) language Know how to use compiler construction tools, such as generators for scanners (Lexical Analyzer) and parsers(Semantic Analyzer ) Be able to write LL(1), LR(1), and LALR(1) grammars (for new languages) Be familiar with compiler analysis and optimization techniques 8-Apr-17 2
  • 3. Grading Policy  Mid Term 20  Final Term 60  Quizzes / Assignments 20 Total 100 Note= 75% Attendance is compulsory for Exams 8-Apr-17 3
  • 4. Textbook Compilers: Principles, Techniques, and Tools, 2/E. Alfred V. Aho, Columbia University Monica S. Lam, Stanford University Ravi Sethi, Avaya Labs Jeffrey D. Ullman, Stanford University Dragon
  • 5. What is Compiler?  The world as we know it depends on programming languages, C, C++, Java, Web programming, and etc.  All the software running on all the computers was written in some programming language.  Before a program can be run, it first must be translated into a form in which it can be executed by a computer. The software systems that do this translation are called compilers.
  • 6. Different compilers  VC, VC++ (visual compiler, Microsoft products)  GCC Dev C compiler , where Dev C is Integrated development environment (IDE)  JavaC Java compiler  FORTRAN  Pascal  Visual Basic (internet programming)
  • 7. Why Compilation? The conversion of high level language into low level object code and machine code. High level language can be understandable by the human , contain English words and phrases, but computer can only understand machine language (Low level language), that’s we need compilation for interaction between human and computer.
  • 8. Computer Languages-1  Machine language (Low Level Language)  Only language computer directly understands  Defined by hardware design  Machine-dependent  Generally consist of strings of numbers  Ultimately 0s and 1s  Instruct computers to perform elementary operations  One at a time  Cumbersome for humans  Example: +1300042774 +1400593419 +1200274027 8
  • 9. Computer Languages-2  Assembly language  English-like abbreviations representing elementary computer operations  Clearer to humans  Incomprehensible to computers  Translator programs (assemblers)  Convert to machine language  Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY 9
  • 10. Computer Languages-3  High-level languages  Similar to everyday English, use common mathematical notations  Single statements accomplish substantial tasks  Assembly language requires many instructions to accomplish simple tasks  Translator programs (compilers)  Convert to machine language  Interpreter programs  Directly execute high-level language programs  Example: grossPay = basePay + overTimePay 10
  • 11. A compiler is program that covert high level language to Assembly languages , similarly an Assembler is a program that convert the Assembly language to Machine Level language Compiler Vs Assembler
  • 12. Assembler VS Compiler It is used to translate the program written in assembly language into Machine language. An assembler perform the translation process in the similar way as compiler, but Assembler is a translator program for low level programming language , while a compiler is the translator program for high level languages
  • 13. Compilers and Interpreters “Compilation” Translation of a program written in a source language into a semantically equivalent program written in a target language. An important role of the compiler is to report any errors in the source program , errors are detected during the translation process. Compiler Error messages Source Program (HLL) Target Program Input Output Execution Compilation (Error Checking (A L L)
  • 14. Compilers and Interpreters (cont’d) Interpreter Source Program Input (Execution) Output Error messages “Interpretation”  Language processor Performing the operations implied in the source program on input supplied by users.
  • 15. Complier Vs Interpreter  In interpreter both execution and compilation process are combined ,At first a statement is compiled and then executed.  In compiler , A program is compiled one time and it can be execute again and again until you need.  While in interpreter A program/statement will be compiled and executed again and again (depend on number of execution)  e.g: if you need to execute a program 100 times, it requires 100 time compilation and 100 times execution in interpreter  Note : 1) Compiler is fast than interpreter (Why) 2) Error diagnosis of interpreter is better than compiler
  • 16. Interpreter Compiler Translates program statement by statement at a time. Scans the entire program and translates it as a whole into machine code It takes less amount of time to analyze the source code but the overall execution time is slower.(Time consuming) It takes large amount of time to analyze the source code but the overall execution time is comparatively faster. Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy. It generates the error message only after scanning the whole program. Hence debugging is comparatively hard. Programming language like Python, Ruby use interpreters. Programming language like C, C++ use compilers.
  • 17. Compiler History 1952: First compiler (linker/loader) written by Grace Hopper for A-0 programming language 1957: First complete compiler for FORTRAN by John Backus and team 1960: COBOL compilers for multiple architectures 1962: First self-hosting compiler for LISP
  • 18. Compiler Construction requirements Programming languages (parameter passing, variable scoping, memory allocation, etc) theory (automata, context-free languages, etc) Algorithms and data structures (hash tables, graph algorithms, dynamic programming, etc) Computer architecture (assembly programming) Software Engineering.
  • 19. Compiler Qualities Make the Code Accurate Compiler runs fast Compile time proportional to program size Support for separate compilation Efficient to check syntax errors Works well with the debugger Good diagnostics for flow anomalies Cross language calls --- interface compatibilities Consistent, predictable optimization
  • 20. A General language processing System Preprocessor HLL Pure HLL Compiler Assembler Linker/Loader Assembly Language Relocatable machine Code Target Machine Code #include < ?? . h > # define Const variable File Inclusion Macro Expansion NO preprocessor Directives MOV a, R1 ADD #2, R1 MOV R1, b i.e. b:= a +2 0001 01 00 00000000 0011 01 10 00000010 0010 01 00 00000100 Loading the data(relocatable machine Code) and instruction to the proper locations
  • 21. Phases of Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate Code Generator Code Optimizer Target Code Generator Character Stream (H L L) Token Stream Syntax Tree Syntax Tree (semantically verified meaningful) 3 Address Code Assembly code Symbol Table Reduce size of program (number of lines) Error Handler
  • 22.
  • 23. Phase Output Sample Programmer Source string A=B+C; Scanner (performs lexical analysis) Token string ‘A’, ‘=’, ‘B’, ‘+’, ‘C’, ‘;’ And symbol table for identifiers Parser (performs syntax analysis based on the grammar of the programming language) Parse tree or abstract syntax tree ; | = / A + / B C Semantic analyzer (type checking, etc) Parse tree or abstract syntax tree Intermediate code generator Three-address code int2fp B t1 + t1 C t2 := t2 A Optimizer Three-address code int2fp B t1 + t1 #2.3 A Code generator Assembly code MOVF #2.3,r1 ADDF2 r1,r2 MOVF r2,A Peephole optimizer Assembly code ADDF2 #2.3,r2 MOVF r2,A

Notas del editor

  1. 2
  2. 3