SlideShare a Scribd company logo
1 of 19
Compilers and InterpretersCompilers and Interpreters
What's the difference?What's the difference?
• Computer programs are compiled or
interpreted. Languages like
Assembly Language, C, C++, Fortran,
Pascal were almost always compiled into
machine code. Languages like
Basic,VbScript and JavaScript were
usually interpreted.
• So what is the difference between a
compiled program and an Interpreted
one?
CompilingCompiling
• To write a program takes these steps:
1.Edit the Program
2.Compile the program into Machine
code files.
3.Link the Machine code files into a
runnable program (also known as an
exe).
4.Debug or Run the Program
With some languages like Turbo
Pascal and Delphi steps 2 and 3 are
combined
• Machine code files are self-contained
modules of machine code that require
linking together to build the final program.
The reason for having separate machine
code files is efficiency; compilers only
have to recompile source code that have
changed. The machine code files from the
unchanged modules are reused. This is
known as Making the application. If you
wish to recompile and rebuild all source
code then that is known as a Build.
• Linking is a technically complicated
process where all the function calls
between different modules are
hooked together, memory locations
are allocated for variables and all the
code is laid out in memory, then
written to disk as a complete
program. This is often a slower step
than compiling as all the machine
code files must be read into memory
and linked together.
InterpretingInterpreting
• The steps to run a program via an
interpreter are :
1. Edit the Program
2. Debug or Run the Program
3. This is a far faster process and it helps
novice programmers edit and test their
code quicker than using a compiler. The
disadvantage is that interpreted programs
run much slower than compiled programs.
As much as 5-10 times slower as every
line of code has to be re-read, then re-
processed.
Java and C#Java and C#
• Both of these languages are semi-compiled. They
generate an intermediate code that is optimized
for interpretation. This intermediate language is
independant of the underlying hardware and this
makes it easier to port programs written in either
to other processors, so long as an interpreter has
been written for that hardware.
• Java when compiled produces bytecode that is
interpreted at runtime by a Java Virtual Machine
(JVM). Many JVMs use a Just-In-Time compiler
that converts bytecode to native machine code
and then runs that code to increases the
interpretation speed. In effect the Java source
code is compiled in a two-stage process.
What is a Compiler?What is a Compiler?
• A compiler is a program that translates human
readable source code into computer executable
machine code. To do this successfully the human
readable code must comply with the syntax rules
of whichever programming language it is written
in. The compiler is only a program and cannot fix
your programs for you. If you make a mistake,
you have to correct the syntax or it won't
compile.
• What happens When You Compile Code?:
• A compiler's complexity depends on the syntax of
the language and how much abstraction that
programming language provides. A C compiler is
much simpler than
• C++ Compiler or a C# Compiler.
Here is what happens when you compile code.
• Lexical Analysis:
This is the first process where the compiler reads a stream
of characters (usually from a source code file) and
generates a stream of lexical tokens. For example the C++
code
• Next is Syntactical Analysis:
This output from Lexical Analyzer goes to the Syntactical
Analyzer part of the compiler. This uses the rules of
grammar to decide whether the input is valid or not. Unless
variables A and B had been previously declared and were in
scope, the compiler might say
• 'A' : undeclared identifier.
• Had they been declared but not initialized. the compiler
would issue a warning
• local variable 'A' used without been initialized.
• You should never ignore compiler warnings. They can break
your code in weird and unexpected ways.
• Always fix compiler warnings!
One Pass Or Two?:One Pass Or Two?:
• Some languages have been written so that
a compiler can get away with reading the
source code once and generating the
machine code. Pascal is one such
language. Many compilers require at least
two passes. Why is this?
• Sometimes it is because of
- Forward Declarations of functions or
classes.
- How much optimization you require of
the compiler.
• Assuming that the compiler has successfully
completed these stages
- Lexical Analysis.
- Syntactical Analysis.
• The final stage is generating machine code. This
can be an extremely complicated process,
especially with modern CPUs.
• The speed of the compiled executable should be
as fast as possible and can vary enormously
according to
• The quality of the generated code.
• How much optimization has been requested.
• Most compilers let you specify the amount of
optimization. Typically none for debugging
(quicker compiles!) and full optimization for the
released code.
• Code Generation Is Challenging!:
• The compiler writer faces challenges when
writing a code generator. Many processors
speed up processing by using
• Instruction Pipelining.
• Internal caches.
• If all of the instructions within a loop can
be held in the CPU cache then that loop
will run much faster than if the CPU has to
fetch instructions from main RAM. The
CPU cache is a block of memory built into
the CPU chip that is accessed much faster
than data in the main RAM.
Caches And Queues:Caches And Queues:
• Most CPUs have a prefetch queue where the CPU
reads in instructions into the cache prior to
executing them. If a conditional branch happens
then the CPU has to reload the queue. So code
should be generated to minimize this.
• Many CPUs have separate parts for
- Integer Arithmetic
- Floating Point Arithmetic
• So these operations can often run in parallel to
increase the speed.
• Compilers typically generate code into object files
which are then linked together by a Linker
program.
An introduction to
Operating Systems
What is an Operating System?What is an Operating System?
• An Operating system is a software
that controls a computer. This is not
the same as the applications that
you create - those are usually only
run when you want them. An OS
runs almost as soon as the computer
is turned on.
• Windows is an Operating System, as
is Linux and the Apple Mac OS X.
• Switching On
-When a computer is powered up, the CPU starts running
immediately. But what does it run? On most PCs, whether
Linux, Windows or Mac, there is a boot program stored
permanently in the ROM of the PC.
• Booting Up
- Each PC motherboard manufacturer writes a
boot program for their motherboard.
- This boot program is not an Operating System (OS), it is
there to load the OS. Its first job is the Power On Start-Up
Test (aka POST). This is a system test, first checking the
memory and flagging any errors. It will stop the system if
something is wrong. Next it resets and initializes any
devices plugged into the PC. This should result in the OS
being loaded from whichever device has been configured as
the boot device, be it Flash RAM, CD-Rom or hard disk.
Having successfully loaded the OS, the boot program hands
over control and the OS takes charge.
Managing the computerManaging the computer
• The job of an OS is to manage all the resources in
a computer. When user input is received from
mouse and keyboard it has to be handled in a
timely fashion. When you create or copy a file,
the OS takes care of it all behind the scenes. It
may store a file in a hundred different places on
disk but it keeps you well away from that level of
detail. You'll just see one file entry in a directory
listing.
• An OS is just a very complex collection of
programs and nowadays takes hundreds or
thousands of man hours to develop. We've come
along way since Dos 6.22 which fitted on a 720
Kb floppy and Vista promises to be very large- 9
or 10 Gigabytes
Protection and SecurityProtection and Security
• Modern CPUs have all sorts of tricks built into
their hardware - for example CPUs only permit
trusted programs to run with access to all of the
hardware facilities. This provides extra safety.
• In Ring 0 protection on Intel/AMD CPUs, the code
at the heart of the OS, usually called the Kernel
code, is protected against corruption or
overwriting by non Kernel applications - the kind
you and I write. Nowadays it is rare for a user
written program to crash a computer. The CPU
will stop any attempt to overwrite Kernel Code
• Also, the CPU has several privileged
instructions that can only be run by Kernel
Code. This enhances the robustness of the
OS and reduces the number of fatal
crashes, such as the infamous Windows
Blue Screen of death.
• The language C was developed to write
Operating Systems code and it is still
popular in this role mainly for Linux and
Unix systems. The Kernel part of Linux is
written in C.
• The operating system is arguably the most
important piece of software on your PC.

More Related Content

What's hot

Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 
Kids computer-programming
Kids computer-programmingKids computer-programming
Kids computer-programmingEdward Burns
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming conceptssalmankhan570
 
High level and Low level Language
High level and Low level Language High level and Low level Language
High level and Low level Language adnan usmani
 
Presentation on computer language
Presentation on computer languagePresentation on computer language
Presentation on computer languageSwarnima Tiwari
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Languagetahria123
 
System software and application software
System software and application softwareSystem software and application software
System software and application softwareSanjay Vasava
 
Computer architecture
Computer architectureComputer architecture
Computer architectureZuhaib Zaroon
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languageseducationfront
 
software development and programming languages
software development and programming languages software development and programming languages
software development and programming languages PraShant Kumar
 
Basic computer organization
Basic computer organizationBasic computer organization
Basic computer organizationNitesh Singh
 
Programming Languages An Intro
Programming Languages An IntroProgramming Languages An Intro
Programming Languages An IntroKimberly De Guzman
 

What's hot (20)

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Computer Languages.
Computer Languages.Computer Languages.
Computer Languages.
 
Kids computer-programming
Kids computer-programmingKids computer-programming
Kids computer-programming
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
High level and Low level Language
High level and Low level Language High level and Low level Language
High level and Low level Language
 
Types of software
Types of softwareTypes of software
Types of software
 
Presentation on computer language
Presentation on computer languagePresentation on computer language
Presentation on computer language
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Language
 
System software and application software
System software and application softwareSystem software and application software
System software and application software
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languages
 
software development and programming languages
software development and programming languages software development and programming languages
software development and programming languages
 
Basic computer organization
Basic computer organizationBasic computer organization
Basic computer organization
 
Programming Languages An Intro
Programming Languages An IntroProgramming Languages An Intro
Programming Languages An Intro
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Types of software
Types of softwareTypes of software
Types of software
 

Similar to Compilers and interpreters

computer languages
computer languagescomputer languages
computer languagesRajendran
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterHossam Hassan
 
01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).pptx01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).pptxsarah380333
 
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
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxAliyahAli19
 
Embedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptxEmbedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptxlematadese670
 
Insight into progam execution ppt
Insight into progam execution pptInsight into progam execution ppt
Insight into progam execution pptKeerty Smile
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionKuppusamy P
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfAnonymousQ3EMYoWNS
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptxWildVenomOP
 
Introduction to Computer Softwares
Introduction to Computer SoftwaresIntroduction to Computer Softwares
Introduction to Computer SoftwaresNaresh Dubey
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingAkhil Kaushik
 

Similar to Compilers and interpreters (20)

computer languages
computer languagescomputer languages
computer languages
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
 
01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).pptx01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).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
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
 
Embedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptxEmbedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptx
 
Insight into progam execution ppt
Insight into progam execution pptInsight into progam execution ppt
Insight into progam execution ppt
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
compiler vs interpreter
compiler vs interpretercompiler vs interpreter
compiler vs interpreter
 
Compilers
CompilersCompilers
Compilers
 
E.s unit 6
E.s unit 6E.s unit 6
E.s unit 6
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdf
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptx
 
Introduction to Computer Softwares
Introduction to Computer SoftwaresIntroduction to Computer Softwares
Introduction to Computer Softwares
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Running a Program.pdf
Running a Program.pdfRunning a Program.pdf
Running a Program.pdf
 
Ic lecture8
Ic lecture8 Ic lecture8
Ic lecture8
 

Recently uploaded

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Compilers and interpreters

  • 2. What's the difference?What's the difference? • Computer programs are compiled or interpreted. Languages like Assembly Language, C, C++, Fortran, Pascal were almost always compiled into machine code. Languages like Basic,VbScript and JavaScript were usually interpreted. • So what is the difference between a compiled program and an Interpreted one?
  • 3. CompilingCompiling • To write a program takes these steps: 1.Edit the Program 2.Compile the program into Machine code files. 3.Link the Machine code files into a runnable program (also known as an exe). 4.Debug or Run the Program With some languages like Turbo Pascal and Delphi steps 2 and 3 are combined
  • 4. • Machine code files are self-contained modules of machine code that require linking together to build the final program. The reason for having separate machine code files is efficiency; compilers only have to recompile source code that have changed. The machine code files from the unchanged modules are reused. This is known as Making the application. If you wish to recompile and rebuild all source code then that is known as a Build.
  • 5. • Linking is a technically complicated process where all the function calls between different modules are hooked together, memory locations are allocated for variables and all the code is laid out in memory, then written to disk as a complete program. This is often a slower step than compiling as all the machine code files must be read into memory and linked together.
  • 6. InterpretingInterpreting • The steps to run a program via an interpreter are : 1. Edit the Program 2. Debug or Run the Program 3. This is a far faster process and it helps novice programmers edit and test their code quicker than using a compiler. The disadvantage is that interpreted programs run much slower than compiled programs. As much as 5-10 times slower as every line of code has to be re-read, then re- processed.
  • 7. Java and C#Java and C# • Both of these languages are semi-compiled. They generate an intermediate code that is optimized for interpretation. This intermediate language is independant of the underlying hardware and this makes it easier to port programs written in either to other processors, so long as an interpreter has been written for that hardware. • Java when compiled produces bytecode that is interpreted at runtime by a Java Virtual Machine (JVM). Many JVMs use a Just-In-Time compiler that converts bytecode to native machine code and then runs that code to increases the interpretation speed. In effect the Java source code is compiled in a two-stage process.
  • 8. What is a Compiler?What is a Compiler? • A compiler is a program that translates human readable source code into computer executable machine code. To do this successfully the human readable code must comply with the syntax rules of whichever programming language it is written in. The compiler is only a program and cannot fix your programs for you. If you make a mistake, you have to correct the syntax or it won't compile. • What happens When You Compile Code?: • A compiler's complexity depends on the syntax of the language and how much abstraction that programming language provides. A C compiler is much simpler than • C++ Compiler or a C# Compiler.
  • 9. Here is what happens when you compile code. • Lexical Analysis: This is the first process where the compiler reads a stream of characters (usually from a source code file) and generates a stream of lexical tokens. For example the C++ code • Next is Syntactical Analysis: This output from Lexical Analyzer goes to the Syntactical Analyzer part of the compiler. This uses the rules of grammar to decide whether the input is valid or not. Unless variables A and B had been previously declared and were in scope, the compiler might say • 'A' : undeclared identifier. • Had they been declared but not initialized. the compiler would issue a warning • local variable 'A' used without been initialized. • You should never ignore compiler warnings. They can break your code in weird and unexpected ways. • Always fix compiler warnings!
  • 10. One Pass Or Two?:One Pass Or Two?: • Some languages have been written so that a compiler can get away with reading the source code once and generating the machine code. Pascal is one such language. Many compilers require at least two passes. Why is this? • Sometimes it is because of - Forward Declarations of functions or classes. - How much optimization you require of the compiler.
  • 11. • Assuming that the compiler has successfully completed these stages - Lexical Analysis. - Syntactical Analysis. • The final stage is generating machine code. This can be an extremely complicated process, especially with modern CPUs. • The speed of the compiled executable should be as fast as possible and can vary enormously according to • The quality of the generated code. • How much optimization has been requested. • Most compilers let you specify the amount of optimization. Typically none for debugging (quicker compiles!) and full optimization for the released code. • Code Generation Is Challenging!:
  • 12. • The compiler writer faces challenges when writing a code generator. Many processors speed up processing by using • Instruction Pipelining. • Internal caches. • If all of the instructions within a loop can be held in the CPU cache then that loop will run much faster than if the CPU has to fetch instructions from main RAM. The CPU cache is a block of memory built into the CPU chip that is accessed much faster than data in the main RAM.
  • 13. Caches And Queues:Caches And Queues: • Most CPUs have a prefetch queue where the CPU reads in instructions into the cache prior to executing them. If a conditional branch happens then the CPU has to reload the queue. So code should be generated to minimize this. • Many CPUs have separate parts for - Integer Arithmetic - Floating Point Arithmetic • So these operations can often run in parallel to increase the speed. • Compilers typically generate code into object files which are then linked together by a Linker program.
  • 15. What is an Operating System?What is an Operating System? • An Operating system is a software that controls a computer. This is not the same as the applications that you create - those are usually only run when you want them. An OS runs almost as soon as the computer is turned on. • Windows is an Operating System, as is Linux and the Apple Mac OS X.
  • 16. • Switching On -When a computer is powered up, the CPU starts running immediately. But what does it run? On most PCs, whether Linux, Windows or Mac, there is a boot program stored permanently in the ROM of the PC. • Booting Up - Each PC motherboard manufacturer writes a boot program for their motherboard. - This boot program is not an Operating System (OS), it is there to load the OS. Its first job is the Power On Start-Up Test (aka POST). This is a system test, first checking the memory and flagging any errors. It will stop the system if something is wrong. Next it resets and initializes any devices plugged into the PC. This should result in the OS being loaded from whichever device has been configured as the boot device, be it Flash RAM, CD-Rom or hard disk. Having successfully loaded the OS, the boot program hands over control and the OS takes charge.
  • 17. Managing the computerManaging the computer • The job of an OS is to manage all the resources in a computer. When user input is received from mouse and keyboard it has to be handled in a timely fashion. When you create or copy a file, the OS takes care of it all behind the scenes. It may store a file in a hundred different places on disk but it keeps you well away from that level of detail. You'll just see one file entry in a directory listing. • An OS is just a very complex collection of programs and nowadays takes hundreds or thousands of man hours to develop. We've come along way since Dos 6.22 which fitted on a 720 Kb floppy and Vista promises to be very large- 9 or 10 Gigabytes
  • 18. Protection and SecurityProtection and Security • Modern CPUs have all sorts of tricks built into their hardware - for example CPUs only permit trusted programs to run with access to all of the hardware facilities. This provides extra safety. • In Ring 0 protection on Intel/AMD CPUs, the code at the heart of the OS, usually called the Kernel code, is protected against corruption or overwriting by non Kernel applications - the kind you and I write. Nowadays it is rare for a user written program to crash a computer. The CPU will stop any attempt to overwrite Kernel Code
  • 19. • Also, the CPU has several privileged instructions that can only be run by Kernel Code. This enhances the robustness of the OS and reduces the number of fatal crashes, such as the infamous Windows Blue Screen of death. • The language C was developed to write Operating Systems code and it is still popular in this role mainly for Linux and Unix systems. The Kernel part of Linux is written in C. • The operating system is arguably the most important piece of software on your PC.