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

Embedded Software
Embedded SoftwareEmbedded Software
Embedded SoftwareITz_1
 
debugging - system software
debugging - system softwaredebugging - system software
debugging - system softwareVicky Shan
 
Applying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine CodeApplying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine CodeTeodoro Cipresso
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language Mobio Solutions
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomeshpraveensomesh
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.pptRatnakar Mikkili
 
What is Software Quality and how to measure it?
What is Software Quality and how to measure it?What is Software Quality and how to measure it?
What is Software Quality and how to measure it?Denys Zaiats
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c languageIndia
 
Lecture 02 Software Process Model
Lecture 02 Software Process ModelLecture 02 Software Process Model
Lecture 02 Software Process ModelAchmad Solichin
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#Ali Hassan
 

What's hot (20)

Cocomo model
Cocomo modelCocomo model
Cocomo model
 
COCOMO model
COCOMO modelCOCOMO model
COCOMO model
 
Embedded Software
Embedded SoftwareEmbedded Software
Embedded Software
 
debugging - system software
debugging - system softwaredebugging - system software
debugging - system software
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Applying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine CodeApplying Anti-Reversing Techniques to Machine Code
Applying Anti-Reversing Techniques to Machine Code
 
C sharp
C sharpC sharp
C sharp
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
 
What is Software Quality and how to measure it?
What is Software Quality and how to measure it?What is Software Quality and how to measure it?
What is Software Quality and how to measure it?
 
Software engineering
Software engineering Software engineering
Software engineering
 
Software metrics
Software metricsSoftware metrics
Software metrics
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
Incremental Model
Incremental ModelIncremental Model
Incremental Model
 
C programming
C programmingC programming
C programming
 
Lecture 02 Software Process Model
Lecture 02 Software Process ModelLecture 02 Software Process Model
Lecture 02 Software Process Model
 
Input Validation
Input ValidationInput Validation
Input Validation
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#
 

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

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
 
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
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
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
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 

Recently uploaded (20)

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...
 
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...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
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...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 

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.