SlideShare a Scribd company logo
1 of 34
PROS AND CONS OF C AS A COMPILER LANGUAGE
AGENDA
● LANGUAGE PROCESSING SYSTEM
● WHAT IS A COMPILER ?
● WHY USE A COMPILER ?
● TYPES OF A COMPILER
● COMPILER DESIGN
● PROS AND CONS
LANGUAGE PROCESSING SYSTEM :
⮚ Computer system is made of hardware and software .
⮚ The hardware understands instructions in the form of electronic charge or
binary language in Software programming.
⮚ So the programs written in High Level Language are fed into a series of
tools and OS components to get the desired machine language.
⮚ This is known as Language Processing System.
PRE-PROCESSOR
● A special system software
● Performs preprocessing of High level language
● First step in language processing system
● Preprocessor mainly performs these tasks
i) Removing comments
ii) File inclusion
iii) Macro expansion.
ASSEMBLER
● Assembly language neither in binary form nor high level. It is an intermediate
state that is a combination of machine instructions and some other useful
data needed for execution.
● Assembler is a program that converts assembly language into machine code.
● Output of an assembler is an object file.
● Object file is a combination of machine instructions and the data required to
place these instructions in memory.
● Relocatable machine code can be loaded at any point and can be run. The
address within the program will be in such a way that it will cooperate for the
program movement.
LINKER
● Linker is a computer utility program that takes one or more object files
generated by the compiler and combines them into an single executable
object file.
● Linking is performed at both compile time and load time.
● It is performed at last step in compiling a program.
● Linking is of two types:
i) Static Linking
ii) Dynamic Linking
LOADER
● Loader is a part of a OS responsible for loading executable files into memory
and executes them by calculating the size of the program and creates
memory space for it.
● It initializes various registers to initiate execution.
● It converts the relocatable code into absolute code and tries to run the
program resulting in a running program or an error message (or sometimes
both can happen).
WHAT IS A COMPILER
● A compiler is a software program that transforms high-level source code that
is written by a developer in a high-level programming language into a low
level object code (binary code) in machine language, which is understood by
the processor.
● The process of converting high-level programming into machine language is
known as compilation.
● A compiler operates as a sequence of phases each of which transforms the
source program from one intermediate representation to another.
WHY USE A COMPILER?
● Verifies the entire program, so there are no syntax or semantic errors.
● The executable file is optimized by compiler, so it executes faster.
● Allows us to create an internal structure in memory.
● Allows the program to be machine independent if required(ie : no need to
execute the program on the same machine it was built).
● Helps in better understanding of language semantics and to handle language
performance issues.
● Translates entire program in other language and helps in checking for syntax
errors and data types .
Compiler Interpreter
Compiler generates an Intermediate Code. Interpreter generates Machine Code.
Compiler reads entire program for compilation.
Interpreter reads single statement at a time for
interpretation.
Compiler displays all errors and warning at time and
without fixing all errors program cannot be executed.
Since Interpreter reads single statement so an
interpreter display one error at a time and you have to
fix the error to interpret next statement.
Compiler needs more memory because of object (an
intermediate code) generation, every time when
program is being compiled an intermediate code
(object code) will be generated.
An Interpreter needs less memory to interpret the
program as interpreter does not generate any
intermediate code, it direct generates machine code.
Programming language like C, C++ use compilers.
Programming language like Python, Ruby use
interpreters.
Types of Compiler
• Native code compiler
• Cross compiler
• Source to source compiler
• One pass compiler
• Threaded code compiler
• Incremental compiler
• Source compiler
• Native code compiler:
• The compiler used to compile a source code for same type of platform only.
• The output generated by this type of compiler can only be run on the same type
of computer system and OS that the compiler itself runs on.
• Cross compiler:
• The compiler used to compile a source code for different kinds platform.
• Used in making software’s for embedded systems that can be used on multiple
platforms.
• Source to source compiler:
• Transcompiler or Transpier is a type of compiler that takes the source code of a
program written in one programming language as its input and produces the
equivalent source code in another programming language.
• One pass compiler:
• It is a type of compiler that compiles the whole process in only
one-pass.
• Threaded code compiler
• The compiler which simply replace a string by an appropriate binary
code.
• Incremental compiler:
• The compiler which compiles only the changed lines from the source
code and update the object code.
• Source compiler:
• The compiler which converts the source code high level language
code in to assembly language only.
STRUCTURE OF A COMPLIER
Two Phrase Complier
• Earlier, we depicted a compiler as a simple box that translates a source program into a target
program
• As the single-box model suggests, a compiler must both understand the source program that it
takes as input and map its functionality to the target machine.
• A design that decomposes compilation into two major pieces: a front end and a back end.
• The front end focuses on understanding the source-language program. The back end focuses on
mapping programs to the target machine.
• Intermediate representation (IR) becomes the compiler’s definitive representation for the code it
is translating
Three Phrase Complier
• The compiler writer can insert a third phase between the front end and the back end
• This middle section, or optimizer, takes an IR program as its input and produces a
semantically equivalent IR program as its output.
• This leads to the following compiler structure, termed a three-phase compiler.
• The optimizer may rewrite the IR in a way that is likely to produce a faster target program
from the back end or a smaller target program from the back end
• It may have other objectives, such as a program that produces fewer page faults or uses less
energy.
PHASES OF A COMPILER
• Any compiler must perform two major tasks
• Analysis of the source program
An intermediate representation is created from the give source code
• Synthesis of a machine-language program
Equivalent target program is created from the intermediate
representation.
• Lexical analysis is the first phase of compiler which is also termed as
scanning. This phase scans the source code as a stream of characters and
converts it into lexes or tokens
• Each token will have <token-name, attribute values>
• It deletes the blank spaces and comments. Once a token is generated the
corresponding entry is made in the symbol table.
• Input: stream of characters
• Output: Token
• Example:
c=a+b*5;
<id, 1> <=> < id, 2> < +> <id, 3 > < * > < 5>
Lexical Analysis
Syntax Analysis
• Syntax analysis is the second phase of compiler which is also called as parsing.
• Parser converts the tokens produced by lexical analyser into a tree like
representation called parse tree.
• A parse tree describes the syntactic structure of the input.
• It follows operator precedence. The root node will have the operators and the
child nodes will have operands.
• Input: Tokens
• Output: Syntax tree
Semantic Analysis
• It checks for the semantic consistency.
• Type information is gathered and stored in symbol table or in syntax
tree.
• Performs type checking.
Intermediate Code Generation
• Compiler generates an intermediate code of the source code for the
target machine.
• It generates abstract code. It is in between the high-level language and
the machine language.
• This intermediate code should be generated in such a way that it makes it
easier to be translated into the target machine code.
• It uses three address code and used some temporary variables.
t1 = int to float <5>
t2 = <id,3>* t1
t3 = <id,2> + t2
<id,1> = t3
Code Optimization
• Code optimization phase produces optimized intermediate code as output. It results in
faster running machine code.
• It can be done by reducing the number of lines of code for a program.
• During the code optimization, the result of the program is not affected.
• To improve the code generation, the optimization involves
⮚ Deduction and removal of dead code (unreachable code).
⮚ Calculation of constants in expressions and terms.
⮚ Collapsing of repeated expression into temporary string.
⮚ Moving code outside the loop.
⮚ Removal of unwanted temporary variables.
t1 = <id,3>* <5.0>
<id,1>= <id,2> + t1
Code Generation
• It gets input from code optimization phase and produces the target code or object code as result.
• Intermediate instructions are translated into a sequence of machine instructions that perform
the same task.
• The code generation involves
o Allocation of register and memory.
o Generation of correct references.
o Generation of correct data type.
o Generation of missing code.
MOV R1,<id,3>
MUL R1, #5.0
MOV R2<id,2>
ADD R1,R2
MOV <id,1>,R
Symbol Table Management
• The symbol table is a data structure containing a record of each variable name with fields
for the attributes of the name.
• The data structure should be designed to allow the complier to find the record for each
name quickly and to store or retrieve data from that record quickly.
• It is built in lexical and syntax analysis phases.
• The information is collected by the analysis phases of compiler and is used by synthesis
phases of compiler to generate code.
• It is used by compiler to achieve compile time efficiency.
Example
sum=old_sum+rate*50
<id,1>=<id,2>+<id,3><*><50>
Lexical
Analyzer
=
<id,1> +
<id,2> *
<id,3> 50
Syntax Analyzer
=
<id,1> +
<id,2> *
<id,3> inttofloat 50.0
Semantic
Analyzer
t1:=inttofloat 50.0
t2:=<id,3>*t1
t3:=<id,2>+t2
<id,1>:=t3
t1:=<id,3>*50.0
id1:=<id,2>+t1
Intermediate Code
Generator
Code Optimization
MOV R1 , <id,3>
MUL R1 , #50.0
ADD R1 , <id,2>
MOV <id,1> , R1
Code Generation
Pros and Cons of C for compiler
development
• Compiler uses methods like lexical analyzer which converts parsed
data into an executable binary code which when developed C could
construct a specialized and potentially more efficient processor for
the task.
• But additional runtime overhead is required to generate and debug
lexer table ,tokens.
• Many lexical tool applications are developed using C language.
Ex:lex
• In syntax analysis all types of syntax errors and position at which it
has occurred will be found
• The main feature of C is a simple set of keywords ,syntax and a clean
style which makes it suitable for this phase.
• The main drawback in syntax analysis phase is cannot determine
whether a token is valid or not.
• Code optimization is an approach for enhancing the performance of
the code when developed using C the compiler optimizes the code
for faster execution.
• C compiler produces the machine code very fast compared to other
language compilers.
• C compiler can compile around 1000 lines of code in a second or two.
• Low level access to memory.
• Tail call optimization is not supported.It is a method to avoid new
stack frame for a function because the calling function will simply
return a value that it gets from the called function.
• C language does not have an automatic garbage collection so code
optimization may have a little lack due to this.
• Efficient exception handling is not possible in C.
• THANK YOU

More Related Content

What's hot

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programmingTarun Sharma
 
Computer architecture register transfer languages rtl
Computer architecture register transfer languages rtlComputer architecture register transfer languages rtl
Computer architecture register transfer languages rtlMazin Alwaaly
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Files in C
Files in CFiles in C
Files in CPrabu U
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of cHarish Kumawat
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreterKamal Tamang
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-cteach4uin
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for universitySheikh Monirul Hasan
 

What's hot (20)

SPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in CSPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in C
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C function presentation
C function presentationC function presentation
C function presentation
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
 
Computer architecture register transfer languages rtl
Computer architecture register transfer languages rtlComputer architecture register transfer languages rtl
Computer architecture register transfer languages rtl
 
C tutorial
C tutorialC tutorial
C tutorial
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Files in C
Files in CFiles in C
Files in C
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
C functions
C functionsC functions
C functions
 
C notes
C notesC notes
C notes
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Function in c
Function in cFunction in c
Function in c
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for university
 

Similar to Pros and cons of c as a compiler language

Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in detailskazi_aihtesham
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfDrIsikoIsaac
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfDrIsikoIsaac
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compileradilmehmood93
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptxانشال عارف
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compilerAbha Damani
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialgadisaAdamu
 

Similar to Pros and cons of c as a compiler language (20)

Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdf
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Chap01-Intro.ppt
Chap01-Intro.pptChap01-Intro.ppt
Chap01-Intro.ppt
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptx
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course Material
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 

More from Ashok Raj

Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++Ashok Raj
 
How c++ stored in ram
How c++ stored in ramHow c++ stored in ram
How c++ stored in ramAshok Raj
 
Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
High Performance Computer
High Performance ComputerHigh Performance Computer
High Performance ComputerAshok Raj
 
Super computers
Super computersSuper computers
Super computersAshok Raj
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 
Printers and its types
Printers and its typesPrinters and its types
Printers and its typesAshok Raj
 
Microprocessor
MicroprocessorMicroprocessor
MicroprocessorAshok Raj
 
Mother board
Mother boardMother board
Mother boardAshok Raj
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systemsAshok Raj
 
FULL stack -> MEAN stack
FULL stack -> MEAN stackFULL stack -> MEAN stack
FULL stack -> MEAN stackAshok Raj
 

More from Ashok Raj (11)

Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
How c++ stored in ram
How c++ stored in ramHow c++ stored in ram
How c++ stored in ram
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
High Performance Computer
High Performance ComputerHigh Performance Computer
High Performance Computer
 
Super computers
Super computersSuper computers
Super computers
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 
Printers and its types
Printers and its typesPrinters and its types
Printers and its types
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
Mother board
Mother boardMother board
Mother board
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
FULL stack -> MEAN stack
FULL stack -> MEAN stackFULL stack -> MEAN stack
FULL stack -> MEAN stack
 

Recently uploaded

Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
1C_PNS.pdf Philippines National standard
1C_PNS.pdf Philippines National standard1C_PNS.pdf Philippines National standard
1C_PNS.pdf Philippines National standardraffietividad53
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 

Recently uploaded (20)

Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
1C_PNS.pdf Philippines National standard
1C_PNS.pdf Philippines National standard1C_PNS.pdf Philippines National standard
1C_PNS.pdf Philippines National standard
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 

Pros and cons of c as a compiler language

  • 1. PROS AND CONS OF C AS A COMPILER LANGUAGE
  • 2. AGENDA ● LANGUAGE PROCESSING SYSTEM ● WHAT IS A COMPILER ? ● WHY USE A COMPILER ? ● TYPES OF A COMPILER ● COMPILER DESIGN ● PROS AND CONS
  • 3. LANGUAGE PROCESSING SYSTEM : ⮚ Computer system is made of hardware and software . ⮚ The hardware understands instructions in the form of electronic charge or binary language in Software programming. ⮚ So the programs written in High Level Language are fed into a series of tools and OS components to get the desired machine language. ⮚ This is known as Language Processing System.
  • 4.
  • 5. PRE-PROCESSOR ● A special system software ● Performs preprocessing of High level language ● First step in language processing system ● Preprocessor mainly performs these tasks i) Removing comments ii) File inclusion iii) Macro expansion.
  • 6. ASSEMBLER ● Assembly language neither in binary form nor high level. It is an intermediate state that is a combination of machine instructions and some other useful data needed for execution. ● Assembler is a program that converts assembly language into machine code. ● Output of an assembler is an object file. ● Object file is a combination of machine instructions and the data required to place these instructions in memory. ● Relocatable machine code can be loaded at any point and can be run. The address within the program will be in such a way that it will cooperate for the program movement.
  • 7. LINKER ● Linker is a computer utility program that takes one or more object files generated by the compiler and combines them into an single executable object file. ● Linking is performed at both compile time and load time. ● It is performed at last step in compiling a program. ● Linking is of two types: i) Static Linking ii) Dynamic Linking
  • 8. LOADER ● Loader is a part of a OS responsible for loading executable files into memory and executes them by calculating the size of the program and creates memory space for it. ● It initializes various registers to initiate execution. ● It converts the relocatable code into absolute code and tries to run the program resulting in a running program or an error message (or sometimes both can happen).
  • 9. WHAT IS A COMPILER ● A compiler is a software program that transforms high-level source code that is written by a developer in a high-level programming language into a low level object code (binary code) in machine language, which is understood by the processor. ● The process of converting high-level programming into machine language is known as compilation. ● A compiler operates as a sequence of phases each of which transforms the source program from one intermediate representation to another.
  • 10. WHY USE A COMPILER? ● Verifies the entire program, so there are no syntax or semantic errors. ● The executable file is optimized by compiler, so it executes faster. ● Allows us to create an internal structure in memory. ● Allows the program to be machine independent if required(ie : no need to execute the program on the same machine it was built). ● Helps in better understanding of language semantics and to handle language performance issues. ● Translates entire program in other language and helps in checking for syntax errors and data types .
  • 11. Compiler Interpreter Compiler generates an Intermediate Code. Interpreter generates Machine Code. Compiler reads entire program for compilation. Interpreter reads single statement at a time for interpretation. Compiler displays all errors and warning at time and without fixing all errors program cannot be executed. Since Interpreter reads single statement so an interpreter display one error at a time and you have to fix the error to interpret next statement. Compiler needs more memory because of object (an intermediate code) generation, every time when program is being compiled an intermediate code (object code) will be generated. An Interpreter needs less memory to interpret the program as interpreter does not generate any intermediate code, it direct generates machine code. Programming language like C, C++ use compilers. Programming language like Python, Ruby use interpreters.
  • 12. Types of Compiler • Native code compiler • Cross compiler • Source to source compiler • One pass compiler • Threaded code compiler • Incremental compiler • Source compiler
  • 13. • Native code compiler: • The compiler used to compile a source code for same type of platform only. • The output generated by this type of compiler can only be run on the same type of computer system and OS that the compiler itself runs on. • Cross compiler: • The compiler used to compile a source code for different kinds platform. • Used in making software’s for embedded systems that can be used on multiple platforms. • Source to source compiler: • Transcompiler or Transpier is a type of compiler that takes the source code of a program written in one programming language as its input and produces the equivalent source code in another programming language.
  • 14. • One pass compiler: • It is a type of compiler that compiles the whole process in only one-pass. • Threaded code compiler • The compiler which simply replace a string by an appropriate binary code. • Incremental compiler: • The compiler which compiles only the changed lines from the source code and update the object code. • Source compiler: • The compiler which converts the source code high level language code in to assembly language only.
  • 15. STRUCTURE OF A COMPLIER Two Phrase Complier • Earlier, we depicted a compiler as a simple box that translates a source program into a target program • As the single-box model suggests, a compiler must both understand the source program that it takes as input and map its functionality to the target machine. • A design that decomposes compilation into two major pieces: a front end and a back end. • The front end focuses on understanding the source-language program. The back end focuses on mapping programs to the target machine. • Intermediate representation (IR) becomes the compiler’s definitive representation for the code it is translating
  • 16. Three Phrase Complier • The compiler writer can insert a third phase between the front end and the back end • This middle section, or optimizer, takes an IR program as its input and produces a semantically equivalent IR program as its output. • This leads to the following compiler structure, termed a three-phase compiler. • The optimizer may rewrite the IR in a way that is likely to produce a faster target program from the back end or a smaller target program from the back end • It may have other objectives, such as a program that produces fewer page faults or uses less energy.
  • 17. PHASES OF A COMPILER • Any compiler must perform two major tasks • Analysis of the source program An intermediate representation is created from the give source code • Synthesis of a machine-language program Equivalent target program is created from the intermediate representation.
  • 18.
  • 19. • Lexical analysis is the first phase of compiler which is also termed as scanning. This phase scans the source code as a stream of characters and converts it into lexes or tokens • Each token will have <token-name, attribute values> • It deletes the blank spaces and comments. Once a token is generated the corresponding entry is made in the symbol table. • Input: stream of characters • Output: Token • Example: c=a+b*5; <id, 1> <=> < id, 2> < +> <id, 3 > < * > < 5> Lexical Analysis
  • 20. Syntax Analysis • Syntax analysis is the second phase of compiler which is also called as parsing. • Parser converts the tokens produced by lexical analyser into a tree like representation called parse tree. • A parse tree describes the syntactic structure of the input. • It follows operator precedence. The root node will have the operators and the child nodes will have operands. • Input: Tokens • Output: Syntax tree
  • 21. Semantic Analysis • It checks for the semantic consistency. • Type information is gathered and stored in symbol table or in syntax tree. • Performs type checking.
  • 22. Intermediate Code Generation • Compiler generates an intermediate code of the source code for the target machine. • It generates abstract code. It is in between the high-level language and the machine language. • This intermediate code should be generated in such a way that it makes it easier to be translated into the target machine code. • It uses three address code and used some temporary variables. t1 = int to float <5> t2 = <id,3>* t1 t3 = <id,2> + t2 <id,1> = t3
  • 23. Code Optimization • Code optimization phase produces optimized intermediate code as output. It results in faster running machine code. • It can be done by reducing the number of lines of code for a program. • During the code optimization, the result of the program is not affected. • To improve the code generation, the optimization involves ⮚ Deduction and removal of dead code (unreachable code). ⮚ Calculation of constants in expressions and terms. ⮚ Collapsing of repeated expression into temporary string. ⮚ Moving code outside the loop. ⮚ Removal of unwanted temporary variables. t1 = <id,3>* <5.0> <id,1>= <id,2> + t1
  • 24. Code Generation • It gets input from code optimization phase and produces the target code or object code as result. • Intermediate instructions are translated into a sequence of machine instructions that perform the same task. • The code generation involves o Allocation of register and memory. o Generation of correct references. o Generation of correct data type. o Generation of missing code. MOV R1,<id,3> MUL R1, #5.0 MOV R2<id,2> ADD R1,R2 MOV <id,1>,R
  • 25. Symbol Table Management • The symbol table is a data structure containing a record of each variable name with fields for the attributes of the name. • The data structure should be designed to allow the complier to find the record for each name quickly and to store or retrieve data from that record quickly. • It is built in lexical and syntax analysis phases. • The information is collected by the analysis phases of compiler and is used by synthesis phases of compiler to generate code. • It is used by compiler to achieve compile time efficiency.
  • 27. = <id,1> + <id,2> * <id,3> 50 Syntax Analyzer
  • 28. = <id,1> + <id,2> * <id,3> inttofloat 50.0 Semantic Analyzer
  • 30. MOV R1 , <id,3> MUL R1 , #50.0 ADD R1 , <id,2> MOV <id,1> , R1 Code Generation
  • 31. Pros and Cons of C for compiler development • Compiler uses methods like lexical analyzer which converts parsed data into an executable binary code which when developed C could construct a specialized and potentially more efficient processor for the task. • But additional runtime overhead is required to generate and debug lexer table ,tokens. • Many lexical tool applications are developed using C language. Ex:lex
  • 32. • In syntax analysis all types of syntax errors and position at which it has occurred will be found • The main feature of C is a simple set of keywords ,syntax and a clean style which makes it suitable for this phase. • The main drawback in syntax analysis phase is cannot determine whether a token is valid or not. • Code optimization is an approach for enhancing the performance of the code when developed using C the compiler optimizes the code for faster execution. • C compiler produces the machine code very fast compared to other language compilers.
  • 33. • C compiler can compile around 1000 lines of code in a second or two. • Low level access to memory. • Tail call optimization is not supported.It is a method to avoid new stack frame for a function because the calling function will simply return a value that it gets from the called function. • C language does not have an automatic garbage collection so code optimization may have a little lack due to this. • Efficient exception handling is not possible in C.