SlideShare a Scribd company logo
1 of 36
PCSG Computer Science Unit 1
– Lecture 2
COMPILATION, INTERPRETING, LINKERS,
PREPROCESSORS AND VIRTUAL MACHINES
FEBRUARY 17, 2023
STUDENT-HOST: JOSHUA LAYNE
Agenda:
• What are compilers vs interpreters?
• What are the steps of the code translation process?
• What are linkers?
• What are pre-processors?
• What are virtual machines?
What are compilers vs
interpreters?
TOPIC 1
Definitions:
• A compiler is a program that translates a computer program written
in a computer language to another. A compiler is primarily used for
programs that translate source code from a high level language to a
lower level, like assembly or machine language.
• [NB: A decompiler would be a program that translates from a lower
level language to a higher level language.]
• However, an interpreter is also a program that translates an
instruction into a machine language and executes it before
proceeding to the next instruction.
Compare and Contrast:
• These are usually slower than their compiler counterparts as they
translate each line, check for errors and then execute it and then
do the same for the rest, whereas with a compiler, it translates the
whole program, then check the whole program for errors before it
is executed and run.
• However, because of their different approaches, interpreters
require less memory while compilers require more memory as
more of the program is being held, then translated, then checked,
then executed; while an interpreter lets go of each instruction once
it’s done executing it.
• As well, the compiler and the interpreter both, in their translation
of the code, must look up each word of your programming language
in a kind of dictionary and then in a series of steps, translate it into
machine code.
• Due to the nature of interpreters, debugging and testing is relatively
fast and easy in interpreted languages as the entire program does
not need to be reprocessed each time a change is made. In fact,
programmers usually use interpreters to test and debug their code
and then use a compiler for production.
• An interpreter, in its translation, translates high-level instructions
into an intermediate form, which it then executes; whereas a
compiler translates high-level instructions directly into machine
language.
• This gives an advantage to interpreters as, if the program is long,
the interpreter can run it immediately, while for a compiler, it would
be time consuming as all needs to be translated to machine
language all at once.
How do compilers work?
TOPIC 1
How the Compiler Works
• As stated, most compilers convert programs in three steps, each
one called a “pass”.
• A compiler may have one program per pass, or may combine two or
three of those steps into a single program. Regardless of how much
passes or programs are require, the compiler performs only three
main functions:
1. Lexical Analysis
2. Syntax Analysis
3. Code Generation
Lexical Analysis
• This is the first pass of the compiler. Here, the source code is passed
through a lexical analyser, which would convert the source code to
a set of tokens.
• A token is the basic component of a source code, e.g., keywords,
operators, punctuation, individual words etc., and are usually
represented by a unique number. Numbers itself are represented by
a token that indicates that what follows it should be interpreted as
a number.
• These token put the programming language into a form that can be
checked for proper structure and order.
Lexical Anaysis
• An other important task of the lexical analyser is to build a symbol
table, which is a table of all identifiers (variable names, procedures
and constants) used in the program.
• When one identifier is first recognised by the analyser, it is inserted
into the symbol table, along with information about its type, where
it is to be stored and so forth.
Syntax Analysis
• This is the second stage of the compilation process and it
determines whether the string of input tokens form valid
sentences. That is, it checks the grammar to see if all of the rules of
syntax are being followed.
• At this stage, the structure of the source program is analysed to see
if it conforms to the context free grammar for the particular
language that is being compiled.
• It basically breaks up the statements into smaller, identifiable
chunks that can be acted upon by the computer when it executes
the final program.
Syntax Analysis
• At this stage, it is passed to a parser, which checks to be sure that all
the rules were followed and to see if the program was written
correctly.
• It reads those tokens generated and compares them to the set
grammar of the language and would issue a warning or an error
once it encounters a mistake, then continues to search the rest of
the program. Some parsers may attempt to correct a faulty program
while others do not.
• When it finishes, it will either tell the compiler if the program is
grammatically correct and compiling can continue, or if the program
contains too much errors that must be corrected
Semantic Analysis
• So, once the program is grammatically correct, the parser will call
for semantic routines.
• We then have the semantic analysis where first, each series of
tokens are checked to make sure that each series of tokens would
be understood by the computer once it fully translated to machine
code and then after that, convert those tokens one step closer to
machine code.
• At the first stage, a set of tokens, called a “production” is taken and
checked to see if it makes sense.
Semantic Analysis
• For instance, whereas, it may make sense to the parser
grammatically, the semantic routines check to see whether
variables are declared or if they’re the right type.
• If it makes sense, then it would be reduced in preparation for the
next stage of compilation, code generation.
• This is the largest stage in the compilation process and takes the
most amount of time.
Intermediate Code Generation
• This process takes the intermediate code produced by the semantic
routines (or the optimizer if the compiler has one) and generates
virtual machine code.
• It is the part of the process that is the most machine dependent as
the choice of instructions for the fastest execution and smallest
code size is made at this point according to the computer’s
operating system which processes the virtual machine code.
• Note that the code generator is made specifically for the machine
and operating system the final code will run on.
Intermediate Code Generation
• If the code were free of syntax errors, then code generation should
take place without a problem.
• When the code generator is finished, the code produced will be in
machine code, but the format of the code is not yet executable. It is
in a format (sometimes an .obj file) that is ready to got to a linker
which will create an executable .exe or .com file from the machine
code the compiler generated.
Code Optimization
• In this step, the compiler tries to make the intermediate code
generated by the semantic routines more efficient. This process can
be very slow and may not be able to improve the code
meaningfully.
• Due to this, most compilers don’t include optimizers, and, if they
do, they only look for areas that are easy to optimise.
Code Generation
• This is the last phase of the compilation process where the code
specific to the target machine is generated.
• The code generation process determines how fast the code will run
and how large it will be.
• Here, the linker would produce the executable file and the program
will be ready to run.
Linkers
TOPIC 3
Definition
• A linker is a computer program that takes one or more objects
generated by a compiler and combines them into a single
executable program.
• It uses the object files created by the compiler and then uses the
predefined library objects to create an executable. For more
modular programs, it combines the separate object modules in
order to create this executable.
• This is the file seen by the common user.
Pre-Processor
TOPIC 4
Definition
• A pre-processor is used to modify your program according to the
pre-processor directives in your source code. Examples of pre-
processor directives are “#include” or “#define”. These give the pre-
processor specific instructions on how to modify your source code.
• It reads in all the include files and the source code you are
compiling and creates a pre-processed version of that code which
has all the macros, and constants replaced by their corresponding
code and value assignments.
• If your source code contains any conditional preprocessor directives
(such as #if), the preprocessor evaluates the condition and modifies
your source code accordingly.
Pre-Processors
• The preprocessor contains many features that are powerful to use,
such as creating macros, performing conditional compilation,
inserting predefined environment variables into your code, and
turning compiler features on and off. For the professional
programmer, in-depth knowledge of the features of the
preprocessor can be one of the keys to creating fast, efficient
programs.
Virtual Machines
TOPIC 5
Definition
• A virtual machine is a lightly isolated software container that can
run on its own operating systems and applications as if it were a
physical computer and contains its own virtual CPU, RAM, hard disk
and network interfaced card (all software based).
• As well, virtual machines may also be a group of computers that
work together to create a more powerful machine. In this type of
virtual machine, the software makes it possible for one
environment to be formed throughout several computers. This
makes it appear to the end user as if he or she is using a single
computer, when there are actually numerous computers at work.
Definition:
• An operating system can’t tell the difference between a virtual
machine and a physical machine, nor can applications or other
computers on a network. Even the virtual machine thinks it is a
“real” computer. Nevertheless, a virtual machine is composed
entirely of software and contains no hardware components
whatsoever. As a result, virtual machines offer a few distinct
advantages over physical hardware.
Advantages
• In general, virtual machines possess three key characteristics that
benefit the user:
1. Isolation: machines being isolated from each other as if they were
physically separated
2. Encapsulation: machines encapsulating a whole complete computing
environment
3. Hardware independence: machines run independently of underlying
hardware.
Isolation
• While virtual machines can share the physical resources of a single
computer, they remain completely isolated from each other as if
they were separate physical machines.
• If, for example, there are four virtual machines on a single physical
server and one of the virtual machines crash, the other three virtual
machines remain available.
• Isolation is an important reason why the availability and security of
applications running in a virtual environment is far superior to
applications running in a traditional, non-virtualized system.
Encapsulation
• A virtual machine is essentially a software container that bundles or
“encapsulates” a complete set of virtual hardware resources, as
well as an operating system and all its applications, inside a
software package.
• Encapsulation makes virtual machines incredibly portable and easy
to manage.
Encapsulation
• For example, you can move and copy a virtual machine from one
location to another just like any other software file or save a virtual
machine on any standard data storage medium, from a pocket-sized
USB flash memory card to an enterprise storage area network,
which is an architecture that attaches remote storage computer
storage devices, tape libraries, and optical jukeboxes to servers in
such a way that the devices appear as locally attached to the
operating system.
Hardware Independence
• Virtual machines are completely independent from their underlying
physical hardware.
• For example, you can configure a virtual machine with virtual
components (eg, CPU, network card, SCSI controller) that are
completely different from the physical components that are present
on the underlying hardware.
Hardware Independence
• Virtual machines on the same physical server can even run different
kinds of operating systems (Windows, Linux, etc).
• Hardware independence also means that you can run a
heterogeneous mixture of operating systems and applications on a
single physical computer.
Uses for Virtual Machines
• Set up an office quickly: Imagine you’re gearing up for a political
campaign, or you’re going to build a retail store in a new town. You
need an office with a mail server, a print server, a file server, and
some desktop systems. You could have your people on the ground
go buy a server from the local computer store (or ship one,
whatever), and ship them the DVD with your images on it (or a hard
drive). About a half hour later, you could have everything
configured and running.
• Emulators: Virtual machines can also perform the role of an
emulator, allowing software applications and operating systems
written for another computer processor architecture to be run.
List of Advantages
• The main advantages of system VMs are:
• multiple OS environments can co-exist on the same computer, in strong
isolation from each other
• application provisioning - the process of providing users with access to data
and technology resources.; maintenance, high availability and disaster
recovery
• Increase the hardware utilization
• Decrease the capital and operating cost by sharing in number of VM
• High availability and Secure
• VM can be used from anywhere in the intranet
List of Disadvantages
• The main disadvantage of system VMs is:
• a virtual machine is less efficient than a real machine when it accesses the
hardware indirectly
• since it is all software based, if server is shutdown, we cannot access the VM

More Related Content

Similar to PCSG_Computer_Science_Unit_1_Lecture_2.pptx

4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
computer languages
computer languagescomputer languages
computer languagesRajendran
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 
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
 
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
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction Sarmad Ali
 
Compilers and interpreters
Compilers and interpretersCompilers and interpreters
Compilers and interpretersRAJU KATHI
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdfRakibRahman19
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Mca i-fundamental of computer-u-2- application and system software
Mca  i-fundamental of  computer-u-2- application and system softwareMca  i-fundamental of  computer-u-2- application and system software
Mca i-fundamental of computer-u-2- application and system softwareRai University
 
Unit 2 computer software
Unit 2 computer softwareUnit 2 computer software
Unit 2 computer softwareHardik Patel
 
Bba i-introduction to computer-u-2- application and system software
Bba  i-introduction to computer-u-2- application and system softwareBba  i-introduction to computer-u-2- application and system software
Bba i-introduction to computer-u-2- application and system softwareRai University
 

Similar to PCSG_Computer_Science_Unit_1_Lecture_2.pptx (20)

4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
computer languages
computer languagescomputer languages
computer languages
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
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
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Insight into progam execution ppt
Insight into progam execution pptInsight into progam execution ppt
Insight into progam execution ppt
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Compilers and interpreters
Compilers and interpretersCompilers and interpreters
Compilers and interpreters
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdf
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Mca i-fundamental of computer-u-2- application and system software
Mca  i-fundamental of  computer-u-2- application and system softwareMca  i-fundamental of  computer-u-2- application and system software
Mca i-fundamental of computer-u-2- application and system software
 
Unit 2 computer software
Unit 2 computer softwareUnit 2 computer software
Unit 2 computer software
 
Bba i-introduction to computer-u-2- application and system software
Bba  i-introduction to computer-u-2- application and system softwareBba  i-introduction to computer-u-2- application and system software
Bba i-introduction to computer-u-2- application and system software
 

Recently uploaded

Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

PCSG_Computer_Science_Unit_1_Lecture_2.pptx

  • 1. PCSG Computer Science Unit 1 – Lecture 2 COMPILATION, INTERPRETING, LINKERS, PREPROCESSORS AND VIRTUAL MACHINES FEBRUARY 17, 2023 STUDENT-HOST: JOSHUA LAYNE
  • 2. Agenda: • What are compilers vs interpreters? • What are the steps of the code translation process? • What are linkers? • What are pre-processors? • What are virtual machines?
  • 3. What are compilers vs interpreters? TOPIC 1
  • 4. Definitions: • A compiler is a program that translates a computer program written in a computer language to another. A compiler is primarily used for programs that translate source code from a high level language to a lower level, like assembly or machine language. • [NB: A decompiler would be a program that translates from a lower level language to a higher level language.] • However, an interpreter is also a program that translates an instruction into a machine language and executes it before proceeding to the next instruction.
  • 5. Compare and Contrast: • These are usually slower than their compiler counterparts as they translate each line, check for errors and then execute it and then do the same for the rest, whereas with a compiler, it translates the whole program, then check the whole program for errors before it is executed and run. • However, because of their different approaches, interpreters require less memory while compilers require more memory as more of the program is being held, then translated, then checked, then executed; while an interpreter lets go of each instruction once it’s done executing it.
  • 6. • As well, the compiler and the interpreter both, in their translation of the code, must look up each word of your programming language in a kind of dictionary and then in a series of steps, translate it into machine code. • Due to the nature of interpreters, debugging and testing is relatively fast and easy in interpreted languages as the entire program does not need to be reprocessed each time a change is made. In fact, programmers usually use interpreters to test and debug their code and then use a compiler for production.
  • 7. • An interpreter, in its translation, translates high-level instructions into an intermediate form, which it then executes; whereas a compiler translates high-level instructions directly into machine language. • This gives an advantage to interpreters as, if the program is long, the interpreter can run it immediately, while for a compiler, it would be time consuming as all needs to be translated to machine language all at once.
  • 8. How do compilers work? TOPIC 1
  • 9. How the Compiler Works • As stated, most compilers convert programs in three steps, each one called a “pass”. • A compiler may have one program per pass, or may combine two or three of those steps into a single program. Regardless of how much passes or programs are require, the compiler performs only three main functions: 1. Lexical Analysis 2. Syntax Analysis 3. Code Generation
  • 10. Lexical Analysis • This is the first pass of the compiler. Here, the source code is passed through a lexical analyser, which would convert the source code to a set of tokens. • A token is the basic component of a source code, e.g., keywords, operators, punctuation, individual words etc., and are usually represented by a unique number. Numbers itself are represented by a token that indicates that what follows it should be interpreted as a number. • These token put the programming language into a form that can be checked for proper structure and order.
  • 11. Lexical Anaysis • An other important task of the lexical analyser is to build a symbol table, which is a table of all identifiers (variable names, procedures and constants) used in the program. • When one identifier is first recognised by the analyser, it is inserted into the symbol table, along with information about its type, where it is to be stored and so forth.
  • 12. Syntax Analysis • This is the second stage of the compilation process and it determines whether the string of input tokens form valid sentences. That is, it checks the grammar to see if all of the rules of syntax are being followed. • At this stage, the structure of the source program is analysed to see if it conforms to the context free grammar for the particular language that is being compiled. • It basically breaks up the statements into smaller, identifiable chunks that can be acted upon by the computer when it executes the final program.
  • 13. Syntax Analysis • At this stage, it is passed to a parser, which checks to be sure that all the rules were followed and to see if the program was written correctly. • It reads those tokens generated and compares them to the set grammar of the language and would issue a warning or an error once it encounters a mistake, then continues to search the rest of the program. Some parsers may attempt to correct a faulty program while others do not. • When it finishes, it will either tell the compiler if the program is grammatically correct and compiling can continue, or if the program contains too much errors that must be corrected
  • 14. Semantic Analysis • So, once the program is grammatically correct, the parser will call for semantic routines. • We then have the semantic analysis where first, each series of tokens are checked to make sure that each series of tokens would be understood by the computer once it fully translated to machine code and then after that, convert those tokens one step closer to machine code. • At the first stage, a set of tokens, called a “production” is taken and checked to see if it makes sense.
  • 15. Semantic Analysis • For instance, whereas, it may make sense to the parser grammatically, the semantic routines check to see whether variables are declared or if they’re the right type. • If it makes sense, then it would be reduced in preparation for the next stage of compilation, code generation. • This is the largest stage in the compilation process and takes the most amount of time.
  • 16. Intermediate Code Generation • This process takes the intermediate code produced by the semantic routines (or the optimizer if the compiler has one) and generates virtual machine code. • It is the part of the process that is the most machine dependent as the choice of instructions for the fastest execution and smallest code size is made at this point according to the computer’s operating system which processes the virtual machine code. • Note that the code generator is made specifically for the machine and operating system the final code will run on.
  • 17. Intermediate Code Generation • If the code were free of syntax errors, then code generation should take place without a problem. • When the code generator is finished, the code produced will be in machine code, but the format of the code is not yet executable. It is in a format (sometimes an .obj file) that is ready to got to a linker which will create an executable .exe or .com file from the machine code the compiler generated.
  • 18. Code Optimization • In this step, the compiler tries to make the intermediate code generated by the semantic routines more efficient. This process can be very slow and may not be able to improve the code meaningfully. • Due to this, most compilers don’t include optimizers, and, if they do, they only look for areas that are easy to optimise.
  • 19. Code Generation • This is the last phase of the compilation process where the code specific to the target machine is generated. • The code generation process determines how fast the code will run and how large it will be. • Here, the linker would produce the executable file and the program will be ready to run.
  • 21. Definition • A linker is a computer program that takes one or more objects generated by a compiler and combines them into a single executable program. • It uses the object files created by the compiler and then uses the predefined library objects to create an executable. For more modular programs, it combines the separate object modules in order to create this executable. • This is the file seen by the common user.
  • 23. Definition • A pre-processor is used to modify your program according to the pre-processor directives in your source code. Examples of pre- processor directives are “#include” or “#define”. These give the pre- processor specific instructions on how to modify your source code. • It reads in all the include files and the source code you are compiling and creates a pre-processed version of that code which has all the macros, and constants replaced by their corresponding code and value assignments. • If your source code contains any conditional preprocessor directives (such as #if), the preprocessor evaluates the condition and modifies your source code accordingly.
  • 24. Pre-Processors • The preprocessor contains many features that are powerful to use, such as creating macros, performing conditional compilation, inserting predefined environment variables into your code, and turning compiler features on and off. For the professional programmer, in-depth knowledge of the features of the preprocessor can be one of the keys to creating fast, efficient programs.
  • 26. Definition • A virtual machine is a lightly isolated software container that can run on its own operating systems and applications as if it were a physical computer and contains its own virtual CPU, RAM, hard disk and network interfaced card (all software based). • As well, virtual machines may also be a group of computers that work together to create a more powerful machine. In this type of virtual machine, the software makes it possible for one environment to be formed throughout several computers. This makes it appear to the end user as if he or she is using a single computer, when there are actually numerous computers at work.
  • 27. Definition: • An operating system can’t tell the difference between a virtual machine and a physical machine, nor can applications or other computers on a network. Even the virtual machine thinks it is a “real” computer. Nevertheless, a virtual machine is composed entirely of software and contains no hardware components whatsoever. As a result, virtual machines offer a few distinct advantages over physical hardware.
  • 28. Advantages • In general, virtual machines possess three key characteristics that benefit the user: 1. Isolation: machines being isolated from each other as if they were physically separated 2. Encapsulation: machines encapsulating a whole complete computing environment 3. Hardware independence: machines run independently of underlying hardware.
  • 29. Isolation • While virtual machines can share the physical resources of a single computer, they remain completely isolated from each other as if they were separate physical machines. • If, for example, there are four virtual machines on a single physical server and one of the virtual machines crash, the other three virtual machines remain available. • Isolation is an important reason why the availability and security of applications running in a virtual environment is far superior to applications running in a traditional, non-virtualized system.
  • 30. Encapsulation • A virtual machine is essentially a software container that bundles or “encapsulates” a complete set of virtual hardware resources, as well as an operating system and all its applications, inside a software package. • Encapsulation makes virtual machines incredibly portable and easy to manage.
  • 31. Encapsulation • For example, you can move and copy a virtual machine from one location to another just like any other software file or save a virtual machine on any standard data storage medium, from a pocket-sized USB flash memory card to an enterprise storage area network, which is an architecture that attaches remote storage computer storage devices, tape libraries, and optical jukeboxes to servers in such a way that the devices appear as locally attached to the operating system.
  • 32. Hardware Independence • Virtual machines are completely independent from their underlying physical hardware. • For example, you can configure a virtual machine with virtual components (eg, CPU, network card, SCSI controller) that are completely different from the physical components that are present on the underlying hardware.
  • 33. Hardware Independence • Virtual machines on the same physical server can even run different kinds of operating systems (Windows, Linux, etc). • Hardware independence also means that you can run a heterogeneous mixture of operating systems and applications on a single physical computer.
  • 34. Uses for Virtual Machines • Set up an office quickly: Imagine you’re gearing up for a political campaign, or you’re going to build a retail store in a new town. You need an office with a mail server, a print server, a file server, and some desktop systems. You could have your people on the ground go buy a server from the local computer store (or ship one, whatever), and ship them the DVD with your images on it (or a hard drive). About a half hour later, you could have everything configured and running. • Emulators: Virtual machines can also perform the role of an emulator, allowing software applications and operating systems written for another computer processor architecture to be run.
  • 35. List of Advantages • The main advantages of system VMs are: • multiple OS environments can co-exist on the same computer, in strong isolation from each other • application provisioning - the process of providing users with access to data and technology resources.; maintenance, high availability and disaster recovery • Increase the hardware utilization • Decrease the capital and operating cost by sharing in number of VM • High availability and Secure • VM can be used from anywhere in the intranet
  • 36. List of Disadvantages • The main disadvantage of system VMs is: • a virtual machine is less efficient than a real machine when it accesses the hardware indirectly • since it is all software based, if server is shutdown, we cannot access the VM