SlideShare a Scribd company logo
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

PPT
Message passing interface
PPTX
Multiprocessor
PPT
Distributed Operating System
PPTX
Introduction to C Programming
PPTX
INSTRUCTION LEVEL PARALLALISM
PPTX
Ch 3 Assembler in System programming
PDF
Process scheduling (CPU Scheduling)
Message passing interface
Multiprocessor
Distributed Operating System
Introduction to C Programming
INSTRUCTION LEVEL PARALLALISM
Ch 3 Assembler in System programming
Process scheduling (CPU Scheduling)

What's hot (20)

PPTX
Csma cd and csma-ca
PDF
Memory consistency models and basics
PPT
Clock synchronization in distributed system
PPTX
Cache coherence ppt
PPT
Scheduling algorithms
PPTX
Dichotomy of parallel computing platforms
PDF
Assembly level language
PPTX
RPC: Remote procedure call
PPT
Inter process communication
PDF
CSI-503 - 11.Distributed Operating System
PPSX
Multiple access control protocol
PPTX
Compiler vs interpreter
PPT
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
PPTX
Multiprocessor Scheduling
PDF
Process Scheduling in OS
PPTX
Multi threading models
PPTX
Principal source of optimization in compiler design
PPT
program partitioning and scheduling IN Advanced Computer Architecture
PPT
Error detection and correction
PDF
Lecture 01 introduction to compiler
Csma cd and csma-ca
Memory consistency models and basics
Clock synchronization in distributed system
Cache coherence ppt
Scheduling algorithms
Dichotomy of parallel computing platforms
Assembly level language
RPC: Remote procedure call
Inter process communication
CSI-503 - 11.Distributed Operating System
Multiple access control protocol
Compiler vs interpreter
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
Multiprocessor Scheduling
Process Scheduling in OS
Multi threading models
Principal source of optimization in compiler design
program partitioning and scheduling IN Advanced Computer Architecture
Error detection and correction
Lecture 01 introduction to compiler
Ad

Similar to Compilers and interpreters (20)

PPTX
Computer ORGANIZATIONoh nannana FINAL (1).pptx
PPTX
Agro informatics centre up State of Lec 6.pptx
PPT
Introduction to C for Btech 1st year.ppt
PPTX
Insight into progam execution ppt
PPTX
Lecture 1 Introduction.pptx hfjsh huwhf uwej wiuehfi w
PPTX
introductiontocomputerprogramming.pptx
PPTX
lecture Slides - Week 1.programming fundamentals
PPTX
BCA FIT 105 PPT Unit 2.pptx
PPT
introduction computer programming languages
PPT
computer languages
PPTX
Compilers.pptx
PPTX
Presentation on computer software-system software.
PDF
CH-1SYSTEM PROGARMMING (1).pdf programing
PDF
Computer Software
DOCX
Computer software and operating system
PPTX
Introduction to Computer Softwares
PPTX
Computer Programming In C.pptx
PPT
Csphtp1 01
PPT
PPT
Introduction Computer programming and operating system
Computer ORGANIZATIONoh nannana FINAL (1).pptx
Agro informatics centre up State of Lec 6.pptx
Introduction to C for Btech 1st year.ppt
Insight into progam execution ppt
Lecture 1 Introduction.pptx hfjsh huwhf uwej wiuehfi w
introductiontocomputerprogramming.pptx
lecture Slides - Week 1.programming fundamentals
BCA FIT 105 PPT Unit 2.pptx
introduction computer programming languages
computer languages
Compilers.pptx
Presentation on computer software-system software.
CH-1SYSTEM PROGARMMING (1).pdf programing
Computer Software
Computer software and operating system
Introduction to Computer Softwares
Computer Programming In C.pptx
Csphtp1 01
Introduction Computer programming and operating system
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
Advanced methodologies resolving dimensionality complications for autism neur...
Mobile App Security Testing_ A Comprehensive Guide.pdf
MYSQL Presentation for SQL database connectivity
sap open course for s4hana steps from ECC to s4
Review of recent advances in non-invasive hemoglobin estimation
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The AUB Centre for AI in Media Proposal.docx
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectroscopy.pptx food analysis technology
Digital-Transformation-Roadmap-for-Companies.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
MIND Revenue Release Quarter 2 2025 Press Release

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.