SlideShare una empresa de Scribd logo
1 de 29
Chapter 10: Compilers and
Language Translation
Invitation to Computer Science,
Java Version, Third Edition
Invitation to Computer Science, Java Version, Third Edition 2
Objectives
In this chapter, you will learn about
 The compilation process
 Phase I: Lexical analysis
 Phase II: Parsing
 Phase III: Semantics and code generation
 Phase IV: Code optimization
Invitation to Computer Science, Java Version, Third Edition 3
Introduction
 High-level language instructions must be
translated into machine language prior to
execution
 Compiler
 A piece of system software that translates high-
level languages into machine language
Invitation to Computer Science, Java Version, Third Edition 4
Introduction (continued)
 Goals of a compiler when performing a
translation
 Correctness
 Producing a reasonably efficient and concise
machine language code
Invitation to Computer Science, Java Version, Third Edition 5
Figure 10.1
General Structure of a Compiler
Invitation to Computer Science, Java Version, Third Edition 6
The Compilation Process
 Phase I: Lexical analysis
 Compiler examines the individual characters in
the source program and groups them into
syntactical units called tokens
 Phase II: Parsing
 The sequence of tokens formed by the scanner is
checked to see whether it is syntactically correct
Invitation to Computer Science, Java Version, Third Edition 7
The Compilation Process (continued)
 Phase III: Semantic analysis and code
generation
 The compiler analyzes the meaning of the high-
level language statement and generates the
machine language instructions to carry out these
actions
 Phase IV: Code optimization
 The compiler takes the generated code and sees
whether it can be made more efficient
Invitation to Computer Science, Java Version, Third Edition 8
Figure 10.2
Overall Execution Sequence on a High-Level Language Program
Invitation to Computer Science, Java Version, Third Edition 9
The Compilation Process (continued)
 Final step
 Object program is written to an object file
 Source program
 Original high-level language program
 Object program
 Machine language translation of the source
program
Invitation to Computer Science, Java Version, Third Edition 10
Phase I: Lexical Analysis
 Lexical analyzer
 The program that performs lexical analysis
 More commonly called a scanner
 Job of lexical analyzer
 Group input characters into tokens
 Tokens: Syntactical units that are treated as single,
indivisible entities for the purposes of translation
 Classify tokens according to their type
Invitation to Computer Science, Java Version, Third Edition 11
Figure 10.3
Typical Token Classifications
Invitation to Computer Science, Java Version, Third Edition 12
Phase I: Lexical Analysis (continued)
 Input to a scanner
 A high-level language statement from the source
program
 Scanner’s output
 A list of all the tokens in that statement
 The classification number of each token found
Invitation to Computer Science, Java Version, Third Edition 13
Phase II: Parsing
Introduction
 Parsing phase
 A compiler determines whether the tokens
recognized by the scanner are a syntactically
legal statement
 Performed by a parser
Invitation to Computer Science, Java Version, Third Edition 14
Phase II: Parsing
Introduction (continued)
 Output of a parser
 A parse tree, if such a tree exists
 An error message, if a parse tree cannot be
constructed
 Successful construction of a parse tree is proof
that the statement is correctly formed
Invitation to Computer Science, Java Version, Third Edition 15
 Example
 High-level language statement: a = b + c
Invitation to Computer Science, Java Version, Third Edition 16
Grammars, Languages, and BNF
 Syntax
 The grammatical structure of the language
 The parser must be given the syntax of the
language
 BNF (Backus-Naur Form)
 Most widely used notation for representing the
syntax of a programming language
Invitation to Computer Science, Java Version, Third Edition 17
Grammars, Languages, and BNF
(continued)
 In BNF
 The syntax of a language is specified as a set of
rules (also called productions)
 A grammar
 The entire collection of rules for a language
 Structure of an individual BNF rule
left-hand side ::= “definition”
Invitation to Computer Science, Java Version, Third Edition 18
Grammars, Languages, and BNF
(continued)
 BNF rules use two types of objects on the right-
hand side of a production
 Terminals
 The actual tokens of the language
 Never appear on the left-hand side of a BNF rule
 Nonterminals
 Intermediate grammatical categories used to help
explain and organize the language
 Must appear on the left-hand side of one or more
rules
Invitation to Computer Science, Java Version, Third Edition 19
Grammars, Languages, and BNF
(continued)
 Goal symbol
 The highest-level nonterminal
 The nonterminal object that the parser is trying to
produce as it builds the parse tree
 All nonterminals are written inside angle
brackets
Invitation to Computer Science, Java Version, Third Edition 20
Parsing Concepts and Techniques
 Fundamental rule of parsing
 By repeated applications of the rules of the
grammar
 If the parser can convert the sequence of input
tokens into the goal symbol, the sequence of tokens
is a syntactically valid statement of the language
 If the parser cannot convert the input tokens into
the goal symbol, the sequence of tokens is not a
syntactically valid statement of the language
Invitation to Computer Science, Java Version, Third Edition 21
Parsing Concepts and Techniques
(continued)
 One of the biggest problems in building a
compiler is designing a grammar that
 Includes every valid statement that we want to be
in the language
 Excludes every invalid statement that we do not
want to be in the language
Invitation to Computer Science, Java Version, Third Edition 22
Parsing Concepts and Techniques
(continued)
 Another problem in constructing a compiler:
Designing a grammar that is not ambiguous
 An ambiguous grammar allows the construction of
two or more distinct parse trees for the same
statement
Invitation to Computer Science, Java Version, Third Edition 23
Phase III: Semantics and Code
Generation
 Semantic analysis
 The compiler makes a first pass over the parse
tree to determine whether all branches of the tree
are semantically valid
 If they are valid, the compiler can generate machine
language instructions
 If not, there is a semantic error; machine language
instructions are not generated
Invitation to Computer Science, Java Version, Third Edition 24
Phase III: Semantics and Code
Generation (continued)
 Code generation
 Compiler makes a second pass over the parse
tree to produce the translated code
Invitation to Computer Science, Java Version, Third Edition 25
Phase IV: Code Optimization
 Two types of optimization
 Local
 Global
 Local optimization
 The compiler looks at a very small block of
instructions and tries to determine how it can
improve the efficiency of this local code block
 Relatively easy; included as part of most
compilers
Invitation to Computer Science, Java Version, Third Edition 26
Phase IV: Code Optimization
(continued)
 Examples of possible local optimizations
 Constant evaluation
 Strength reduction
 Eliminating unnecessary operations
Invitation to Computer Science, Java Version, Third Edition 27
Phase IV: Code Optimization
(continued)
 Global optimization
 The compiler looks at large segments of the
program to decide how to improve performance
 Much more difficult; usually omitted from all but
the most sophisticated and expensive production-
level “optimizing compilers”
 Optimization cannot make an inefficient
algorithm efficient
Invitation to Computer Science, Java Version, Third Edition 28
Summary
 A compiler is a piece of system software that
translates high-level languages into machine
language
 Goals of a compiler: Correctness and the
production of efficient and concise code
 Source program: High-level language program
Invitation to Computer Science, Java Version, Third Edition 29
Summary (continued)
 Object program: The machine language
translation of the source program
 Phases of the compilation process
 Phase I: Lexical analysis
 Phase II: Parsing
 Phase III: Semantic analysis and code generation
 Phase IV: Code optimization

Más contenido relacionado

La actualidad más candente

Generation of computer languages
Generation of computer languagesGeneration of computer languages
Generation of computer languageskitturashmikittu
 
Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Languagefasihuddin90
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languageseducationfront
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1REHAN IJAZ
 
Generations of programming language
Generations of programming languageGenerations of programming language
Generations of programming languageJAIDEVPAUL
 
Programming languages
Programming languagesProgramming languages
Programming languagesSimon Mui
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in CompilerAkhil Kaushik
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Languagetahria123
 
Types of Programming Languages
Types of Programming LanguagesTypes of Programming Languages
Types of Programming LanguagesJuhi Bhoyar
 
Programming languages
Programming languagesProgramming languages
Programming languagesvito_carleone
 
Compilers and interpreters
Compilers and interpretersCompilers and interpreters
Compilers and interpretersRAJU KATHI
 
A History of Computer Programming Languages.pdf
A History of Computer Programming Languages.pdfA History of Computer Programming Languages.pdf
A History of Computer Programming Languages.pdfSohaib Roomi
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / TranslatorsProject Student
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 

La actualidad más candente (20)

Generation of computer languages
Generation of computer languagesGeneration of computer languages
Generation of computer languages
 
Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Language
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languages
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 
Generations of programming language
Generations of programming languageGenerations of programming language
Generations of programming language
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Language
 
Types of Programming Languages
Types of Programming LanguagesTypes of Programming Languages
Types of Programming Languages
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Compilers
CompilersCompilers
Compilers
 
Compilers and interpreters
Compilers and interpretersCompilers and interpreters
Compilers and interpreters
 
A History of Computer Programming Languages.pdf
A History of Computer Programming Languages.pdfA History of Computer Programming Languages.pdf
A History of Computer Programming Languages.pdf
 
generation of programming language
generation of programming languagegeneration of programming language
generation of programming language
 
System software vs application software
System software vs application softwareSystem software vs application software
System software vs application software
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / Translators
 
Compilers
CompilersCompilers
Compilers
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Translators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreterTranslators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreter
 

Similar a Machine language

Chapter One
Chapter OneChapter One
Chapter Onebolovv
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdfAkarTaher
 
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
 
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...Prof Chethan Raj C
 
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
 
design intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdfdesign intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdfadvRajatSharma
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Tirumala Rao
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxdawod yimer
 
1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.pptRakesh Kumar
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORijistjournal
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docxvenkatapranaykumarGa
 

Similar a Machine language (20)

Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
3ss
3ss3ss
3ss
 
Compiler
Compiler Compiler
Compiler
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Chapter One
Chapter OneChapter One
Chapter One
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
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
 
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
 
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
 
design intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdfdesign intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdf
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
 
1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt
 
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
 
Assignment1
Assignment1Assignment1
Assignment1
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 

Último

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Machine language

  • 1. Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition
  • 2. Invitation to Computer Science, Java Version, Third Edition 2 Objectives In this chapter, you will learn about  The compilation process  Phase I: Lexical analysis  Phase II: Parsing  Phase III: Semantics and code generation  Phase IV: Code optimization
  • 3. Invitation to Computer Science, Java Version, Third Edition 3 Introduction  High-level language instructions must be translated into machine language prior to execution  Compiler  A piece of system software that translates high- level languages into machine language
  • 4. Invitation to Computer Science, Java Version, Third Edition 4 Introduction (continued)  Goals of a compiler when performing a translation  Correctness  Producing a reasonably efficient and concise machine language code
  • 5. Invitation to Computer Science, Java Version, Third Edition 5 Figure 10.1 General Structure of a Compiler
  • 6. Invitation to Computer Science, Java Version, Third Edition 6 The Compilation Process  Phase I: Lexical analysis  Compiler examines the individual characters in the source program and groups them into syntactical units called tokens  Phase II: Parsing  The sequence of tokens formed by the scanner is checked to see whether it is syntactically correct
  • 7. Invitation to Computer Science, Java Version, Third Edition 7 The Compilation Process (continued)  Phase III: Semantic analysis and code generation  The compiler analyzes the meaning of the high- level language statement and generates the machine language instructions to carry out these actions  Phase IV: Code optimization  The compiler takes the generated code and sees whether it can be made more efficient
  • 8. Invitation to Computer Science, Java Version, Third Edition 8 Figure 10.2 Overall Execution Sequence on a High-Level Language Program
  • 9. Invitation to Computer Science, Java Version, Third Edition 9 The Compilation Process (continued)  Final step  Object program is written to an object file  Source program  Original high-level language program  Object program  Machine language translation of the source program
  • 10. Invitation to Computer Science, Java Version, Third Edition 10 Phase I: Lexical Analysis  Lexical analyzer  The program that performs lexical analysis  More commonly called a scanner  Job of lexical analyzer  Group input characters into tokens  Tokens: Syntactical units that are treated as single, indivisible entities for the purposes of translation  Classify tokens according to their type
  • 11. Invitation to Computer Science, Java Version, Third Edition 11 Figure 10.3 Typical Token Classifications
  • 12. Invitation to Computer Science, Java Version, Third Edition 12 Phase I: Lexical Analysis (continued)  Input to a scanner  A high-level language statement from the source program  Scanner’s output  A list of all the tokens in that statement  The classification number of each token found
  • 13. Invitation to Computer Science, Java Version, Third Edition 13 Phase II: Parsing Introduction  Parsing phase  A compiler determines whether the tokens recognized by the scanner are a syntactically legal statement  Performed by a parser
  • 14. Invitation to Computer Science, Java Version, Third Edition 14 Phase II: Parsing Introduction (continued)  Output of a parser  A parse tree, if such a tree exists  An error message, if a parse tree cannot be constructed  Successful construction of a parse tree is proof that the statement is correctly formed
  • 15. Invitation to Computer Science, Java Version, Third Edition 15  Example  High-level language statement: a = b + c
  • 16. Invitation to Computer Science, Java Version, Third Edition 16 Grammars, Languages, and BNF  Syntax  The grammatical structure of the language  The parser must be given the syntax of the language  BNF (Backus-Naur Form)  Most widely used notation for representing the syntax of a programming language
  • 17. Invitation to Computer Science, Java Version, Third Edition 17 Grammars, Languages, and BNF (continued)  In BNF  The syntax of a language is specified as a set of rules (also called productions)  A grammar  The entire collection of rules for a language  Structure of an individual BNF rule left-hand side ::= “definition”
  • 18. Invitation to Computer Science, Java Version, Third Edition 18 Grammars, Languages, and BNF (continued)  BNF rules use two types of objects on the right- hand side of a production  Terminals  The actual tokens of the language  Never appear on the left-hand side of a BNF rule  Nonterminals  Intermediate grammatical categories used to help explain and organize the language  Must appear on the left-hand side of one or more rules
  • 19. Invitation to Computer Science, Java Version, Third Edition 19 Grammars, Languages, and BNF (continued)  Goal symbol  The highest-level nonterminal  The nonterminal object that the parser is trying to produce as it builds the parse tree  All nonterminals are written inside angle brackets
  • 20. Invitation to Computer Science, Java Version, Third Edition 20 Parsing Concepts and Techniques  Fundamental rule of parsing  By repeated applications of the rules of the grammar  If the parser can convert the sequence of input tokens into the goal symbol, the sequence of tokens is a syntactically valid statement of the language  If the parser cannot convert the input tokens into the goal symbol, the sequence of tokens is not a syntactically valid statement of the language
  • 21. Invitation to Computer Science, Java Version, Third Edition 21 Parsing Concepts and Techniques (continued)  One of the biggest problems in building a compiler is designing a grammar that  Includes every valid statement that we want to be in the language  Excludes every invalid statement that we do not want to be in the language
  • 22. Invitation to Computer Science, Java Version, Third Edition 22 Parsing Concepts and Techniques (continued)  Another problem in constructing a compiler: Designing a grammar that is not ambiguous  An ambiguous grammar allows the construction of two or more distinct parse trees for the same statement
  • 23. Invitation to Computer Science, Java Version, Third Edition 23 Phase III: Semantics and Code Generation  Semantic analysis  The compiler makes a first pass over the parse tree to determine whether all branches of the tree are semantically valid  If they are valid, the compiler can generate machine language instructions  If not, there is a semantic error; machine language instructions are not generated
  • 24. Invitation to Computer Science, Java Version, Third Edition 24 Phase III: Semantics and Code Generation (continued)  Code generation  Compiler makes a second pass over the parse tree to produce the translated code
  • 25. Invitation to Computer Science, Java Version, Third Edition 25 Phase IV: Code Optimization  Two types of optimization  Local  Global  Local optimization  The compiler looks at a very small block of instructions and tries to determine how it can improve the efficiency of this local code block  Relatively easy; included as part of most compilers
  • 26. Invitation to Computer Science, Java Version, Third Edition 26 Phase IV: Code Optimization (continued)  Examples of possible local optimizations  Constant evaluation  Strength reduction  Eliminating unnecessary operations
  • 27. Invitation to Computer Science, Java Version, Third Edition 27 Phase IV: Code Optimization (continued)  Global optimization  The compiler looks at large segments of the program to decide how to improve performance  Much more difficult; usually omitted from all but the most sophisticated and expensive production- level “optimizing compilers”  Optimization cannot make an inefficient algorithm efficient
  • 28. Invitation to Computer Science, Java Version, Third Edition 28 Summary  A compiler is a piece of system software that translates high-level languages into machine language  Goals of a compiler: Correctness and the production of efficient and concise code  Source program: High-level language program
  • 29. Invitation to Computer Science, Java Version, Third Edition 29 Summary (continued)  Object program: The machine language translation of the source program  Phases of the compilation process  Phase I: Lexical analysis  Phase II: Parsing  Phase III: Semantic analysis and code generation  Phase IV: Code optimization