SlideShare uma empresa Scribd logo
1 de 10
Introduction to Compiler
              Construction
•   1
Objectives
• Be able to build a compiler for a (simplified)
  (programming) language
• Know how to use compiler construction tools,
  such as generators of scanners and parsers
• Be familiar with assembly code and virtual
  machines, such as the JVM, and bytecode
• Be able to define LL(1), LR(1), and LALR(1)
  grammars
• Be familiar with compiler analysis and
  optimization techniques
• … learn how to work on a larger software project!
                                                      2
Compilers and Interpreters
 • “Compilation”
    – Translation of a program written in a source
      language into a semantically equivalent
      program written in a target language
    – Oversimplified view:
                                                Input


 Source                                        Target
                      Compiler
Program                                       Program


                    Error messages             Output3
Compilers and Interpreters
              (cont’d)
 • “Interpretation”
    – Performing the operations implied by the
      source program
    – Oversimplified view:


 Source
Program
                      Interpreter           Output
  Input

                   Error messages                    4
The Analysis-Synthesis Model of
         Compilation

• There are two parts to compilation:
  – Analysis determines the operations implied by
    the source program which are recorded in a tree
    structure
  – Synthesis takes the tree structure and translates
    the operations therein into the target program



                                                    5
Other Tools that Use the
      Analysis-Synthesis Model
•   Editors (syntax highlighting)
•   Pretty printers (e.g. Doxygen)
•   Static checkers (e.g. Lint and Splint)
•   Interpreters
•   Text formatters (e.g. TeX and LaTeX)
•   Silicon compilers (e.g. VHDL)
•   Query interpreters/compilers (Databases)

                                               6
Preprocessors, Compilers,
          Assemblers, and Linkers
                        Skeletal Source Program

                             Preprocessor
                    Source Program
                                                    Try for example:
                               Compiler
                                                   gcc -v myprog.c
    Target Assembly Program
                        Assembler
   Relocatable Object Code
                          Linker                     Libraries and
                                                Relocatable Object Files
COP5621 Fall 2011                                                 7
                        Absolute Machine Code
The Grouping of Phases
• Compiler front and back ends:
   – Front end: analysis (machine independent)
   – Back end: synthesis (machine dependent)
• Compiler passes:
   – A collection of phases is done only once (single pass)
     or multiple times (multi pass)
      • Single pass: usually requires everything to be defined before
        being used in source program
      • Multi pass: compiler may have to keep entire program
        representation in memory



                                                                        8
Compiler-Construction Tools
• Software development tools are available to
  implement one or more compiler phases
  –   Scanner generators
  –   Parser generators
  –   Syntax-directed translation engines
  –   Automatic code generators
  –   Data-flow engines



                                                9
Outline
•   Introduction
•   A simple One-Pass Compiler for the JVM
•   Lexical Analysis and Lex/Flex
•   Syntax Analysis and Yacc/Bison
•   Syntax-Directed Translation
•   Static Semantics and Type Checking
•   Run-Time Environments
•   Intermediate Code Generation
•   Target Code Generation
•   Code Optimization
COP5621 Fall 2011                            10

Mais conteúdo relacionado

Mais procurados

Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
salmankhan570
 

Mais procurados (20)

1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Compilers
CompilersCompilers
Compilers
 
Software tools
Software toolsSoftware tools
Software tools
 
Language Translator ( Compiler)
Language Translator ( Compiler)Language Translator ( Compiler)
Language Translator ( Compiler)
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
structured programming
structured programmingstructured programming
structured programming
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Compiler type
Compiler typeCompiler type
Compiler type
 
basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler design
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 

Destaque

Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 

Destaque (20)

Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Compiler construction
Compiler constructionCompiler construction
Compiler construction
 
Compiler Design - Introduction to Compiler
Compiler Design - Introduction to CompilerCompiler Design - Introduction to Compiler
Compiler Design - Introduction to Compiler
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compiler
CompilerCompiler
Compiler
 
compiler and their types
compiler and their typescompiler and their types
compiler and their types
 
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
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Ktu - s1 me module 1 (Calculus Module 1)
Ktu  - s1 me module 1 (Calculus Module 1)Ktu  - s1 me module 1 (Calculus Module 1)
Ktu - s1 me module 1 (Calculus Module 1)
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 

Semelhante a Compiler Construction

Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
Mohd Arif
 
1 introduction to compiler
1 introduction to compiler1 introduction to compiler
1 introduction to compiler
BarwarBadradin
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 

Semelhante a Compiler Construction (20)

4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.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
 
Chap01-Intro.ppt
Chap01-Intro.pptChap01-Intro.ppt
Chap01-Intro.ppt
 
System software
System softwareSystem software
System software
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Cd unit i
Cd unit iCd unit i
Cd unit i
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
1 introduction to compiler
1 introduction to compiler1 introduction to compiler
1 introduction to compiler
 
Ch1 (1).ppt
Ch1 (1).pptCh1 (1).ppt
Ch1 (1).ppt
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Compiler design
Compiler designCompiler design
Compiler design
 
Cd econtent link1
Cd econtent link1Cd econtent link1
Cd econtent link1
 
Compiler1
Compiler1Compiler1
Compiler1
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course Material
 

Mais de Army Public School and College -Faisal

Mais de Army Public School and College -Faisal (20)

SENSOR WHITEBOARDS
SENSOR WHITEBOARDSSENSOR WHITEBOARDS
SENSOR WHITEBOARDS
 
INPUT AND OUTPUT DEVICES
INPUT AND OUTPUT DEVICESINPUT AND OUTPUT DEVICES
INPUT AND OUTPUT DEVICES
 
INPUT AND OUTPUT DEVICES
INPUT AND OUTPUT DEVICESINPUT AND OUTPUT DEVICES
INPUT AND OUTPUT DEVICES
 
2d and 3d cutters
2d and 3d cutters 2d and 3d cutters
2d and 3d cutters
 
SCANNERS /BARCODE
SCANNERS /BARCODE SCANNERS /BARCODE
SCANNERS /BARCODE
 
3D PRINTERS
3D PRINTERS3D PRINTERS
3D PRINTERS
 
Operaing system
Operaing systemOperaing system
Operaing system
 
Module 2 handouts part 2
Module 2 handouts part 2Module 2 handouts part 2
Module 2 handouts part 2
 
Module 2 handouts part 1
Module 2 handouts part 1Module 2 handouts part 1
Module 2 handouts part 1
 
Module 1 ELECTRONICS
Module 1  ELECTRONICSModule 1  ELECTRONICS
Module 1 ELECTRONICS
 
Module 1
Module 1 Module 1
Module 1
 
Cookies may be set by the website you are visiting
Cookies may be set by the website you are visitingCookies may be set by the website you are visiting
Cookies may be set by the website you are visiting
 
Css
CssCss
Css
 
python 1
python 1python 1
python 1
 
Boolean and comparison_instructions
Boolean and comparison_instructionsBoolean and comparison_instructions
Boolean and comparison_instructions
 
hadoop_module
hadoop_modulehadoop_module
hadoop_module
 
Polymorphism (2)
Polymorphism (2)Polymorphism (2)
Polymorphism (2)
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Presentation 2
Presentation 2Presentation 2
Presentation 2
 
Lecture 1 progrmming with C
Lecture 1 progrmming with C Lecture 1 progrmming with C
Lecture 1 progrmming with C
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Último (20)

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Compiler Construction

  • 1. Introduction to Compiler Construction • 1
  • 2. Objectives • Be able to build a compiler for a (simplified) (programming) language • Know how to use compiler construction tools, such as generators of scanners and parsers • Be familiar with assembly code and virtual machines, such as the JVM, and bytecode • Be able to define LL(1), LR(1), and LALR(1) grammars • Be familiar with compiler analysis and optimization techniques • … learn how to work on a larger software project! 2
  • 3. Compilers and Interpreters • “Compilation” – Translation of a program written in a source language into a semantically equivalent program written in a target language – Oversimplified view: Input Source Target Compiler Program Program Error messages Output3
  • 4. Compilers and Interpreters (cont’d) • “Interpretation” – Performing the operations implied by the source program – Oversimplified view: Source Program Interpreter Output Input Error messages 4
  • 5. The Analysis-Synthesis Model of Compilation • There are two parts to compilation: – Analysis determines the operations implied by the source program which are recorded in a tree structure – Synthesis takes the tree structure and translates the operations therein into the target program 5
  • 6. Other Tools that Use the Analysis-Synthesis Model • Editors (syntax highlighting) • Pretty printers (e.g. Doxygen) • Static checkers (e.g. Lint and Splint) • Interpreters • Text formatters (e.g. TeX and LaTeX) • Silicon compilers (e.g. VHDL) • Query interpreters/compilers (Databases) 6
  • 7. Preprocessors, Compilers, Assemblers, and Linkers Skeletal Source Program Preprocessor Source Program Try for example: Compiler gcc -v myprog.c Target Assembly Program Assembler Relocatable Object Code Linker Libraries and Relocatable Object Files COP5621 Fall 2011 7 Absolute Machine Code
  • 8. The Grouping of Phases • Compiler front and back ends: – Front end: analysis (machine independent) – Back end: synthesis (machine dependent) • Compiler passes: – A collection of phases is done only once (single pass) or multiple times (multi pass) • Single pass: usually requires everything to be defined before being used in source program • Multi pass: compiler may have to keep entire program representation in memory 8
  • 9. Compiler-Construction Tools • Software development tools are available to implement one or more compiler phases – Scanner generators – Parser generators – Syntax-directed translation engines – Automatic code generators – Data-flow engines 9
  • 10. Outline • Introduction • A simple One-Pass Compiler for the JVM • Lexical Analysis and Lex/Flex • Syntax Analysis and Yacc/Bison • Syntax-Directed Translation • Static Semantics and Type Checking • Run-Time Environments • Intermediate Code Generation • Target Code Generation • Code Optimization COP5621 Fall 2011 10