The compiler is software that converts source code written in a high-level language into machine code. It works in two major phases - analysis and synthesis. The analysis phase performs lexical analysis, syntax analysis, and semantic analysis to generate an intermediate representation from the source code. The synthesis phase performs code optimization and code generation to create the target machine code from the intermediate representation. The compiler uses various components like a symbol table, parser, and code generator to perform this translation.
The document provides an introduction to compiler design, including:
- A compiler converts a program written in a high-level language into machine code. It can run on a different machine than the target.
- Language processing systems like compilers transform high-level code into a form usable by machines through a series of translations.
- A compiler analyzes source code in two main phases - analysis and synthesis. The analysis phase creates an intermediate representation, and the synthesis phase generates target code from that.
The document summarizes the key phases of a compiler:
1. The compiler takes source code as input and goes through several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation to produce machine code as output.
2. Lexical analysis converts the source code into tokens, syntax analysis checks the grammar and produces a parse tree, and semantic analysis validates meanings.
3. Code optimization improves the intermediate code before code generation translates it into machine instructions.
The document provides an introduction to compilers, including definitions of key terms like compiler, interpreter, assembler, translator, and phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also discusses compiler types like native compilers, cross compilers, source-to-source compilers, and just-in-time compilers. The phases of a compiler include breaking down a program, generating intermediate code, optimizing, and creating target code.
This document provides an introduction to compilers. It discusses how compilers bridge the gap between high-level programming languages that are easier for humans to write in and machine languages that computers can actually execute. It describes the various phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also compares compilers to interpreters and discusses different types of translators like compilers, interpreters, and assemblers.
This document provides an introduction to compilers, including definitions of key terms like translator, compiler, interpreter, and assembler. It describes the main phases of compilation as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also discusses related concepts like the front-end and back-end of a compiler, multi-pass compilation, and different types of compilers.
This document provides an overview of the key components and phases of a compiler. It discusses that a compiler translates a program written in a source language into an equivalent program in a target language. The main phases of a compiler are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and symbol table management. Each phase performs important processing that ultimately results in a program in the target language that is equivalent to the original source program.
This document provides an introduction to compilers and their construction. It defines a compiler as a program that translates a source program into target machine code. The compilation process involves several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation. An interpreter directly executes source code without compilation. The document also discusses compiler tools and intermediate representations used in the compilation process.
The document provides an overview of compilers and interpreters. It discusses that a compiler translates source code into machine code that can be executed, while an interpreter executes source code directly without compilation. The document then covers the typical phases of a compiler in more detail, including the front-end (lexical analysis, syntax analysis, semantic analysis), middle-end/optimizer, and back-end (code generation). It also discusses interpreters, intermediate code representation, symbol tables, and compiler construction tools.
The document provides an introduction to compiler design, including:
- A compiler converts a program written in a high-level language into machine code. It can run on a different machine than the target.
- Language processing systems like compilers transform high-level code into a form usable by machines through a series of translations.
- A compiler analyzes source code in two main phases - analysis and synthesis. The analysis phase creates an intermediate representation, and the synthesis phase generates target code from that.
The document summarizes the key phases of a compiler:
1. The compiler takes source code as input and goes through several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation to produce machine code as output.
2. Lexical analysis converts the source code into tokens, syntax analysis checks the grammar and produces a parse tree, and semantic analysis validates meanings.
3. Code optimization improves the intermediate code before code generation translates it into machine instructions.
The document provides an introduction to compilers, including definitions of key terms like compiler, interpreter, assembler, translator, and phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also discusses compiler types like native compilers, cross compilers, source-to-source compilers, and just-in-time compilers. The phases of a compiler include breaking down a program, generating intermediate code, optimizing, and creating target code.
This document provides an introduction to compilers. It discusses how compilers bridge the gap between high-level programming languages that are easier for humans to write in and machine languages that computers can actually execute. It describes the various phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also compares compilers to interpreters and discusses different types of translators like compilers, interpreters, and assemblers.
This document provides an introduction to compilers, including definitions of key terms like translator, compiler, interpreter, and assembler. It describes the main phases of compilation as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also discusses related concepts like the front-end and back-end of a compiler, multi-pass compilation, and different types of compilers.
This document provides an overview of the key components and phases of a compiler. It discusses that a compiler translates a program written in a source language into an equivalent program in a target language. The main phases of a compiler are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and symbol table management. Each phase performs important processing that ultimately results in a program in the target language that is equivalent to the original source program.
This document provides an introduction to compilers and their construction. It defines a compiler as a program that translates a source program into target machine code. The compilation process involves several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation. An interpreter directly executes source code without compilation. The document also discusses compiler tools and intermediate representations used in the compilation process.
The document provides an overview of compilers and interpreters. It discusses that a compiler translates source code into machine code that can be executed, while an interpreter executes source code directly without compilation. The document then covers the typical phases of a compiler in more detail, including the front-end (lexical analysis, syntax analysis, semantic analysis), middle-end/optimizer, and back-end (code generation). It also discusses interpreters, intermediate code representation, symbol tables, and compiler construction tools.
The document provides an introduction to compilers. It discusses that compilers are language translators that take source code as input and convert it to another language as output. The compilation process involves multiple phases including lexical analysis, syntax analysis, semantic analysis, code generation, and code optimization. It describes the different phases of compilation in detail and explains concepts like intermediate code representation, symbol tables, and grammars.
The document provides an overview of the compilation process and the different phases involved in compiler construction. It can be summarized as follows:
1. A compiler translates a program written in a source language into an equivalent program in a target language. It performs analysis, synthesis and error checking during this translation process.
2. The major phases of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation and linking. Tools like Lex and Yacc are commonly used to generate lexical and syntax analyzers.
3. Regular expressions are used to specify patterns for tokens during lexical analysis. A lexical analyzer reads the source program and generates a sequence of tokens by matching character sequences to patterns
This document provides an overview of compilers, including their structure and purpose. It discusses:
- What a compiler is and its main functions of analysis and synthesis.
- The history and need for compilers, from early assembly languages to modern high-level languages.
- The structure of a compiler, including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
- Different types of translators like interpreters, assemblers, and linkers.
- Tools that help in compiler construction like scanner generators, parser generators, and code generators.
Pros and cons of c as a compiler languageAshok Raj
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.
This document provides an overview of compiler design and the phases of a compiler. It discusses how compilers translate programs written in high-level languages into machine-executable code. The main phases of a compiler are lexical analysis, syntax analysis, code generation, and optional optimization phases. Lexical analysis breaks the source code into tokens. Syntax analysis checks for errors and determines the program structure. Code generation translates the program into machine code. Optimization aims to improve efficiency. Interpreters execute programs line-by-line rather than generating machine code.
The document discusses the phases of a compiler and their functions. It describes:
1) Lexical analysis converts the source code to tokens by recognizing patterns in the input. It identifies tokens like identifiers, keywords, and numbers.
2) Syntax analysis/parsing checks that tokens are arranged according to grammar rules by constructing a parse tree.
3) Semantic analysis validates the program semantics and performs type checking using the parse tree and symbol table.
The document discusses the phases of a compiler:
1) Lexical analysis scans the source code and converts it to tokens which are passed to the syntax analyzer.
2) Syntax analysis/parsing checks the token arrangements against the language grammar and generates a parse tree.
3) Semantic analysis checks that the parse tree follows the language rules by using the syntax tree and symbol table, performing type checking.
4) Intermediate code generation represents the program for an abstract machine in a machine-independent form like 3-address code.
Chapter 2 Program language translation.pptxdawod yimer
The document discusses the different phases of a compiler:
1. Lexical analysis scans the source code and groups characters into tokens like keywords, identifiers, and punctuation.
2. Syntax analysis checks that the tokens are combined according to the rules of the language.
3. Code generation translates the intermediate representation into the target machine code.
The document provides an overview of compilers by discussing:
1. Compilers translate source code into executable target code by going through several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
2. An interpreter directly executes source code statement by statement while a compiler produces target code as translation. Compiled code generally runs faster than interpreted code.
3. The phases of a compiler include a front end that analyzes the source code and produces intermediate code, and a back end that optimizes and generates the target code.
This document provides an overview of compiler design, including:
- The history and importance of compilers in translating high-level code to machine-level code.
- The main components of a compiler including the front-end (analysis), back-end (synthesis), and tools used in compiler construction.
- Key phases of compilation like lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
- Types of translators like interpreters, assemblers, cross-compilers and their functions.
- Compiler construction tools that help generate scanners, parsers, translation engines, code generators, and data flow analysis.
A compiler is a program that translates a program written in a source language into an equivalent program in a target language. It has two major phases: analysis and synthesis. The analysis phase creates an intermediate representation using tools like a lexical analyzer, syntax analyzer, and semantic analyzer. The synthesis phase creates the target program from this representation using tools like an intermediate code generator, code optimizer, and code generator. Techniques used in compiler design like lexical analysis, parsing, and code generation have applications in other areas like text editors, databases, and natural language processing.
The document summarizes key concepts about compiler design. It defines a compiler as a program that translates source code written in one language into an equivalent executable program in another language. Compilers are classified based on the number of passes, such as single-pass and multi-pass compilers. The document also discusses the analysis-synthesis model of compilation, which involves analyzing the source program to create an intermediate representation, then synthesizing target code from that representation. Major phases of a compiler include lexical analysis, parsing, semantic analysis, code generation, and optimization.
This document provides an overview of compiler design and the different phases involved in compiling a program. It begins with defining a compiler as a program that translates code written in one programming language into another target language to be executed by a computer. The major phases of a compiler are then described as the analysis phase (front-end) which breaks down and analyzes the source code, and the synthesis phase (back-end) which generates the target code. Key phases in the front-end include lexical analysis, syntax analysis, and semantic analysis, while the back-end includes code optimization and code generation. Different types of compilers such as single-pass, two-pass, and multi-pass compilers are also introduced based on how many times
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
The document summarizes key concepts about compiler design. It defines a compiler as a program that translates source code written in one language into an equivalent executable program in another language. Compilers are classified based on the number of passes they use, such as single-pass and multi-pass compilers. The analysis-synthesis model is described as the two-part process of compilation involving analysis of the source program and synthesis of the translated code. The phases of a compiler include lexical analysis, parsing, semantic analysis, code generation and optimization.
The document discusses the phases of a compiler. It describes the phases as:
1) Lexical analysis which converts source code into tokens.
2) Syntax analysis which checks the syntax is correct and builds a parse tree.
3) Semantic analysis which checks for semantic errors using symbol tables.
4) Intermediate code generation which converts the parse tree into an intermediate representation.
5) Optimization of the intermediate code.
6) Code generation which converts the optimized intermediate code into assembly code and then machine code.
The document describes the phases of a compiler. It discusses lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization and code generation.
Lexical analysis scans the source code and returns tokens. Syntax analysis builds an abstract syntax tree from tokens using a context-free grammar. Semantic analysis checks for semantic errors and annotates the tree with types. Intermediate code generation converts the syntax tree to an intermediate representation like 3-address code. Code generation outputs machine or assembly code from the intermediate code.
The phases of a compiler are:
1. Lexical analysis breaks the source code into tokens
2. Syntax analysis checks the token order and builds a parse tree
3. Semantic analysis checks for type errors and builds symbol tables
4. Code generation converts the parse tree into target code
This document provides an overview of compilers and their various phases. It begins by introducing compilers and their importance for increasing programmer productivity and enabling reverse engineering. It then covers the classification of programming languages and the history of compilers. The rest of the document details each phase of the compiler process, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and the role of the symbol table. It provides definitions and examples for each phase to explain how a source program is translated from a high-level language into executable machine code.
THIS PPT CONTAINS THE DETAILS ABOUT THE VARIOUS LANGUAGE PROCESSORS/LANGUAGE TRANSLATORS- THE COMPILER & THE INTERPRETER, OPERATING SYSTEMS & ITS FUNCTION, PARALLEL & CLOUD COMPUTING
The Science of Learning: implications for modern teachingDerek Wenmoth
Keynote presentation to the Educational Leaders hui Kōkiritia Marautanga held in Auckland on 26 June 2024. Provides a high level overview of the history and development of the science of learning, and implications for the design of learning in our modern schools and classrooms.
The document provides an introduction to compilers. It discusses that compilers are language translators that take source code as input and convert it to another language as output. The compilation process involves multiple phases including lexical analysis, syntax analysis, semantic analysis, code generation, and code optimization. It describes the different phases of compilation in detail and explains concepts like intermediate code representation, symbol tables, and grammars.
The document provides an overview of the compilation process and the different phases involved in compiler construction. It can be summarized as follows:
1. A compiler translates a program written in a source language into an equivalent program in a target language. It performs analysis, synthesis and error checking during this translation process.
2. The major phases of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation and linking. Tools like Lex and Yacc are commonly used to generate lexical and syntax analyzers.
3. Regular expressions are used to specify patterns for tokens during lexical analysis. A lexical analyzer reads the source program and generates a sequence of tokens by matching character sequences to patterns
This document provides an overview of compilers, including their structure and purpose. It discusses:
- What a compiler is and its main functions of analysis and synthesis.
- The history and need for compilers, from early assembly languages to modern high-level languages.
- The structure of a compiler, including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
- Different types of translators like interpreters, assemblers, and linkers.
- Tools that help in compiler construction like scanner generators, parser generators, and code generators.
Pros and cons of c as a compiler languageAshok Raj
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.
This document provides an overview of compiler design and the phases of a compiler. It discusses how compilers translate programs written in high-level languages into machine-executable code. The main phases of a compiler are lexical analysis, syntax analysis, code generation, and optional optimization phases. Lexical analysis breaks the source code into tokens. Syntax analysis checks for errors and determines the program structure. Code generation translates the program into machine code. Optimization aims to improve efficiency. Interpreters execute programs line-by-line rather than generating machine code.
The document discusses the phases of a compiler and their functions. It describes:
1) Lexical analysis converts the source code to tokens by recognizing patterns in the input. It identifies tokens like identifiers, keywords, and numbers.
2) Syntax analysis/parsing checks that tokens are arranged according to grammar rules by constructing a parse tree.
3) Semantic analysis validates the program semantics and performs type checking using the parse tree and symbol table.
The document discusses the phases of a compiler:
1) Lexical analysis scans the source code and converts it to tokens which are passed to the syntax analyzer.
2) Syntax analysis/parsing checks the token arrangements against the language grammar and generates a parse tree.
3) Semantic analysis checks that the parse tree follows the language rules by using the syntax tree and symbol table, performing type checking.
4) Intermediate code generation represents the program for an abstract machine in a machine-independent form like 3-address code.
Chapter 2 Program language translation.pptxdawod yimer
The document discusses the different phases of a compiler:
1. Lexical analysis scans the source code and groups characters into tokens like keywords, identifiers, and punctuation.
2. Syntax analysis checks that the tokens are combined according to the rules of the language.
3. Code generation translates the intermediate representation into the target machine code.
The document provides an overview of compilers by discussing:
1. Compilers translate source code into executable target code by going through several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
2. An interpreter directly executes source code statement by statement while a compiler produces target code as translation. Compiled code generally runs faster than interpreted code.
3. The phases of a compiler include a front end that analyzes the source code and produces intermediate code, and a back end that optimizes and generates the target code.
This document provides an overview of compiler design, including:
- The history and importance of compilers in translating high-level code to machine-level code.
- The main components of a compiler including the front-end (analysis), back-end (synthesis), and tools used in compiler construction.
- Key phases of compilation like lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation.
- Types of translators like interpreters, assemblers, cross-compilers and their functions.
- Compiler construction tools that help generate scanners, parsers, translation engines, code generators, and data flow analysis.
A compiler is a program that translates a program written in a source language into an equivalent program in a target language. It has two major phases: analysis and synthesis. The analysis phase creates an intermediate representation using tools like a lexical analyzer, syntax analyzer, and semantic analyzer. The synthesis phase creates the target program from this representation using tools like an intermediate code generator, code optimizer, and code generator. Techniques used in compiler design like lexical analysis, parsing, and code generation have applications in other areas like text editors, databases, and natural language processing.
The document summarizes key concepts about compiler design. It defines a compiler as a program that translates source code written in one language into an equivalent executable program in another language. Compilers are classified based on the number of passes, such as single-pass and multi-pass compilers. The document also discusses the analysis-synthesis model of compilation, which involves analyzing the source program to create an intermediate representation, then synthesizing target code from that representation. Major phases of a compiler include lexical analysis, parsing, semantic analysis, code generation, and optimization.
This document provides an overview of compiler design and the different phases involved in compiling a program. It begins with defining a compiler as a program that translates code written in one programming language into another target language to be executed by a computer. The major phases of a compiler are then described as the analysis phase (front-end) which breaks down and analyzes the source code, and the synthesis phase (back-end) which generates the target code. Key phases in the front-end include lexical analysis, syntax analysis, and semantic analysis, while the back-end includes code optimization and code generation. Different types of compilers such as single-pass, two-pass, and multi-pass compilers are also introduced based on how many times
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
The document summarizes key concepts about compiler design. It defines a compiler as a program that translates source code written in one language into an equivalent executable program in another language. Compilers are classified based on the number of passes they use, such as single-pass and multi-pass compilers. The analysis-synthesis model is described as the two-part process of compilation involving analysis of the source program and synthesis of the translated code. The phases of a compiler include lexical analysis, parsing, semantic analysis, code generation and optimization.
The document discusses the phases of a compiler. It describes the phases as:
1) Lexical analysis which converts source code into tokens.
2) Syntax analysis which checks the syntax is correct and builds a parse tree.
3) Semantic analysis which checks for semantic errors using symbol tables.
4) Intermediate code generation which converts the parse tree into an intermediate representation.
5) Optimization of the intermediate code.
6) Code generation which converts the optimized intermediate code into assembly code and then machine code.
The document describes the phases of a compiler. It discusses lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization and code generation.
Lexical analysis scans the source code and returns tokens. Syntax analysis builds an abstract syntax tree from tokens using a context-free grammar. Semantic analysis checks for semantic errors and annotates the tree with types. Intermediate code generation converts the syntax tree to an intermediate representation like 3-address code. Code generation outputs machine or assembly code from the intermediate code.
The phases of a compiler are:
1. Lexical analysis breaks the source code into tokens
2. Syntax analysis checks the token order and builds a parse tree
3. Semantic analysis checks for type errors and builds symbol tables
4. Code generation converts the parse tree into target code
This document provides an overview of compilers and their various phases. It begins by introducing compilers and their importance for increasing programmer productivity and enabling reverse engineering. It then covers the classification of programming languages and the history of compilers. The rest of the document details each phase of the compiler process, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and the role of the symbol table. It provides definitions and examples for each phase to explain how a source program is translated from a high-level language into executable machine code.
THIS PPT CONTAINS THE DETAILS ABOUT THE VARIOUS LANGUAGE PROCESSORS/LANGUAGE TRANSLATORS- THE COMPILER & THE INTERPRETER, OPERATING SYSTEMS & ITS FUNCTION, PARALLEL & CLOUD COMPUTING
The Science of Learning: implications for modern teachingDerek Wenmoth
Keynote presentation to the Educational Leaders hui Kōkiritia Marautanga held in Auckland on 26 June 2024. Provides a high level overview of the history and development of the science of learning, and implications for the design of learning in our modern schools and classrooms.
Creativity for Innovation and SpeechmakingMattVassar1
Tapping into the creative side of your brain to come up with truly innovative approaches. These strategies are based on original research from Stanford University lecturer Matt Vassar, where he discusses how you can use them to come up with truly innovative solutions, regardless of whether you're using to come up with a creative and memorable angle for a business pitch--or if you're coming up with business or technical innovations.
Post init hook in the odoo 17 ERP ModuleCeline George
In Odoo, hooks are functions that are presented as a string in the __init__ file of a module. They are the functions that can execute before and after the existing code.
How to Create User Notification in Odoo 17Celine George
This slide will represent how to create user notification in Odoo 17. Odoo allows us to create and send custom notifications on some events or actions. We have different types of notification such as sticky notification, rainbow man effect, alert and raise exception warning or validation.
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapitolTechU
Slides from a Capitol Technology University webinar held June 20, 2024. The webinar featured Dr. Donovan Wright, presenting on the Department of Defense Digital Transformation.
How to Download & Install Module From the Odoo App Store in Odoo 17Celine George
Custom modules offer the flexibility to extend Odoo's capabilities, address unique requirements, and optimize workflows to align seamlessly with your organization's processes. By leveraging custom modules, businesses can unlock greater efficiency, productivity, and innovation, empowering them to stay competitive in today's dynamic market landscape. In this tutorial, we'll guide you step by step on how to easily download and install modules from the Odoo App Store.
pol sci Election and Representation Class 11 Notes.pdf
Phases of Compiler.pptx
1.
2. BASIS OF COMPARISON ASSEMBLER COMPILER
Conversion
Assembler converts the assembly code
into the machine code.
Compiler converts the source
code written by the programmer
to a machine level language.
Input Assembler inputs source code.
Compiler inputs is preprocessed
source code.
The output The output of assembler is binary code.
The output of compiler is a
mnemonic version of machine
code.
Examples GAS, GNU C, C#, Java, C++
Debugging Debugging is difficult. Debugging is easy.
Working
Assembler converts source code to an
object code first then it converts the
object code to the machine language
with the help of linker programs.
Complier scans the entire
program first before translating
into machine code.
Intelligence
Assembler is less intelligent than a
compiler.
Compiler is more intelligent than
assembler.
Working Phases
Assembler makes works in two phases
over the given input. The phases are:
Pass I
Pass II
The compilation phases are:
Lexical analyzer
Syntax analyzer
Semantic analyzer
Code optimizer
Code generator
Error handler
4. BASIS OF
COMPARISON
COMPILER INTERPRETER
Function
A compiler converts high-level language
program code into machine language
and then executes it.
Interpreter converts source code
into the intermediate form and
then converts that intermediate
code into machine language
Scanning
Complier scans the entire program first
before translating into machine code.
Interpreter scans and translates
the program line by line to
equivalent machine code.
Working
Compiler takes entire program as
input.
Interpreter takes single
instruction as input.
Code Generation
Intermediate object code is generated
in case of compiler.
In case of interpreter, No
intermediate object code is
generated.
Execution Time
Compiler takes less execution time
when compared to interpreter.
Interpreter takes more
execution time when compared
to compiler.
Examples
C
COBOL
C#
C++, etc
Python
Perl
VB
PostScript
LISP etc.
5. BASIS OF COMPARISON COMPILER INTERPRETER
Memory Requirement
Compiler requires more memory than
interpreter.
Interpreter needs less memory
when compared to compiler.
Modification
If you happen to make any modification
in program you have to recompile entire
program i.e scan the whole program
every time after modification.
If you make any modification and
if that line has not been scanned
then no need to recompile entire
program.
Speed
Compiler is faster when compared to
interpreter.
Interpreter is slower when
compared to compiler.
At Execution
There is usually no need to compile
program every time (if not modified) at
execution time.
Every time program is scanned
and translated at execution time.
Error Detection
Compiler gives you the list of all errors
after compilation of whole program.
Interpreter stops the translation
at the error generation and will
continue when error get solved.
Machine Code
Compiler converts the entire program to
machine code when all errors are
removed execution takes place.
Each time the program is
executed; every line is checked for
error and then converted into
equivalent machine code.
Debugging
Compiler is slow for debugging because
errors are displayed after entire program
has been checked.
Interpreter is good for fast
debugging.
Code Version
The assembly code generated by the
compiler is a mnemonic version of
machine code.
At the output of assembler is re-
locatable machine code generated
by an assembler represented by
binary code.
6. compiler
• The compiler is software that converts a program written in a high-
level language (Source Language) to low-level language
(Object/Target/Machine Language).
7. • Cross Compiler that runs on a machine ‘A’ and produces a code for
another machine ‘B’. It is capable of creating code for a platform
other than the one on which the compiler is running.
• Source-to-source Compiler or transcompiler or transpiler is a
compiler that translates source code written in one programming
language into the source code of another programming language.
8. • Language processing systems (using Compiler) –
• The programs go through a series of transformations so that can
readily be used by machines.
• This is where language procedure systems come in handy.
9.
10. • High-Level Language – If a program contains
#define or #include directives such as
#include or #define it is called HLL. They are
closer to humans but far from machines.
These (#) tags are called preprocessor
directives. They direct the pre-processor
about what to do.
• Pre-Processor – The pre-processor removes
all the #include directives by including the
files called file inclusion and all the #define
directives using macro expansion. It performs
file inclusion, augmentation, macro-
processing, etc.
11. • Assembly Language – It’s 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 – For every platform (Hardware +
OS) we will have an assembler. They are not
universal since for each platform we have one.
The output of the assembler is called an object
file. Its translates assembly language to
machine code.
12. • Interpreter – An interpreter converts high-level
language into low-level machine language, just
like a compiler. But they are different in the way
they read the input. Interpreted programs are
usually slower with respect to compiled ones.
• Relocatable Machine Code – It 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 with the program movement.
13. • Loader/Linker – 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). Linker
loads a variety of object files into a single file to
make it executable. Then loader loads it in
memory and executes it.
14. Phases of a Compiler
• There are two major phases of compilation, which in turn have many
parts. Each of them takes input from the output of the previous level
and works in a coordinated way.
15.
16. • Analysis Phase – An intermediate representation is created from the
given source code :
• Lexical Analyzer
• Syntax Analyzer
• Semantic Analyzer
• Intermediate Code Generator
17. • Synthesis Phase – Equivalent target program is created from the
intermediate representation. It has two parts :
• Code Optimizer
• Code Generator
18. • Symbol Table – It is a data structure being used and maintained by
the compiler, consisting of all the identifier’s names along with their
types. It helps the compiler to function smoothly by finding the
identifiers quickly.
• The analysis of a source program is divided into mainly three phases.
They are:
• Linear Analysis-
This involves a scanning phase where the stream of characters is read
from left to right. It is then grouped into various tokens having a
collective meaning.
• Hierarchical Analysis-
In this analysis phase, based on a collective meaning, the tokens are
categorized hierarchically into nested groups.
• Semantic Analysis-
This phase is used to check whether the components of the source
program are meaningful or not.
19. • The compiler has two modules namely the front end and the back
end. Front-end constitutes the Lexical analyzer, semantic analyzer,
syntax analyzer, and intermediate code generator. And the rest are
assembled to form the back end.
20. Lexical Analyzer
• It is also called a scanner.
• It takes the output of the preprocessor (which performs file inclusion
and macro expansion) as the input which is in a pure high-level
language.
• It reads the characters from the source program and groups them
into lexemes (sequence of characters that “go together”). Each
lexeme corresponds to a token. Tokens are defined by regular
expressions which are understood by the lexical analyzer.
• It also removes lexical errors (e.g., erroneous characters), comments,
and white space.
21. Tokens
• Lexemes are said to be a sequence of characters (alphanumeric) in a
token.
• There are some predefined rules for every lexeme to be identified as
a valid token.
• These rules are defined by grammar rules, by means of a pattern.
• A pattern explains what can be a token, and these patterns are
defined by means of regular expressions.
22. int value = 100;
contains the tokens:
int (keyword), value (identifier), = (operator), 100
(constant) and ; (symbol).
In programming language, keywords, constants, identifiers, strings,
numbers, operators and punctuations symbols can be considered as
tokens.
For example, in C language, the variable declaration line
23. Specifications of Tokens
• Alphabets
Any finite set of symbols {0,1} is a set of binary alphabets,
{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} is a set of Hexadecimal alphabets, {a-z,
A-Z} is a set of English language alphabets.
• Strings
Any finite sequence of alphabets (characters) is called a string. Length
of the string is the total number of occurrence of alphabets, e.g., the
length of the string compilerdesign is 14 and is denoted by
|compilerdesign| = 14.
A string having no alphabets, i.e. a string of zero length is known as an
empty string and is denoted by ε (epsilon).
24. Arithmetic
Symbols
Addition(+), Subtraction(-), Modulo(%),
Multiplication(*), Division(/)
Punctuation Comma(,), Semicolon(;), Dot(.), Arrow(->)
Assignment =
Special
Assignment
+=, /=, *=, -=
Comparison ==, !=, <, <=, >, >=
Preprocessor #
Location
Specifier
&
Logical &, &&, |, ||, !
Shift Operator >>, >>>, <<, <<<
Special symbols
A typical high-level language contains the following symbols:-
25. Language
• A language is considered as a finite set of strings over some finite set
of alphabets.
• Computer languages are considered as finite sets, and
mathematically set operations can be performed on them.
• Finite languages can be described by means of regular expressions.
26. Regular Expressions
• The lexical analyzer needs to scan and identify only a finite set of
valid string/token/lexeme that belong to the language in hand. It
searches for the pattern defined by the language rules.
• Regular expressions have the capability to express finite languages by
defining a pattern for finite strings of symbols. The grammar defined
by regular expressions is known as regular grammar. The language
defined by regular grammar is known as regular language.
27. Operations
• The various operations on languages are:
• Union of two languages L and M is written as
• L U M = {s | s is in L or s is in M}
• Concatenation of two languages L and M is written as
• L∩M = {st | s is in L and t is in M}
• The Kleene Closure of a language L is written as
• L* = Zero or more occurrence of language L.
28. Notations
• If r and s are regular expressions denoting the languages L(r) and L(s),
then
• Union : (r)|(s) is a regular expression denoting L(r) U L(s)
• Concatenation : (r).(s) is a regular expression denoting L(r) ∩L(s)
• Kleene closure : (r)* is a regular expression denoting (L(r))*
• (r) is a regular expression denoting L(r)
29. Precedence and Associativity
• *, concatenation (.), and | (pipe sign) are left associative
• * has the highest precedence
• Concatenation (.) has the second highest precedence.
• | (pipe sign) has the lowest precedence of all.
30. Finite Automata
• Finite automata is a recognizer for regular expressions. When a
regular expression string is fed into finite automata, it changes its
state for each literal.
• The mathematical model of finite automata consists of:
• Finite set of states (Q)
• Finite set of input symbols (Σ)
• One Start state (q0)
• Set of final states (qf)
• Transition function (δ)
• The transition function (δ) maps the finite set of state (Q) to a finite
set of input symbols (Σ), Q × Σ ➔ Q
31. Finite Automata Construction
• Let L(r) be a regular language recognized by some finite
automata (FA).
• States :
• Start state
• Intermediate states
• Final state
• Transition
32. • States : States of FA are represented by circles. State names are of
the state is written inside the circle.
• Start state : The state from where the automata starts, is known as
start state. Start state has an arrow pointed towards it.
• Intermediate states : All intermediate states has at least two arrows;
one pointing to and another pointing out from them.
33. • Final state : If the input string is successfully parsed, the automata is
expected to be in this state. Final state is represented by double
circles.
• Transition : The transition from one state to another state happens
when a desired symbol in the input is found. Upon transition,
automata can either move to next state or stay in the same state.
Movement from one state to another is shown as a directed arrow,
where the arrows points to the destination state. If automata stays
on the same state, an arrow pointing from a state to itself is drawn.
• Example : We assume FA accepts any three digit binary value ending
in digit 1. FA = {Q(q0, qf), Σ(0,1), q0, qf, δ}
34. Longest Match Rule
• When the lexical analyzer read the source-code, it scans the code
letter by letter; and when a whitespace, operator symbol, or special
symbols occurs, it decides that a word is completed.
• For example:
• While scanning both lexemes till ‘int’, the lexical analyzer cannot
determine whether it is a keyword int or the initials of identifier int
value.
• The Longest Match Rule states that the lexeme scanned should be
determined based on the longest match among all the tokens
available.
int intvalue;
35.
36. Syntax Analyzer
• It is sometimes called a parser.
• It constructs the parse tree.
• It takes all the tokens one by one and uses Context-Free Grammar to
construct the parse tree.
There are certain rules associated with the derivation tree.
• Any identifier is an expression
• Any number can be called an expression
• Performing any operations in the given expression will always result in an
expression. For example, the sum of two expressions is also an expression.
• The parse tree can be compressed to form a syntax tree
• Syntax error can be detected at this level if the input is not in
accordance with the grammar.
37. Semantic Analyzer
• It verifies the parse tree, whether it’s meaningful or not.
• It furthermore produces a verified parse tree. It also does type
checking, Label checking, and Flow control checking.
38. Intermediate Code Generator
• It generates intermediate code, which is a form that can be readily
executed by a machine.
• Intermediate code is converted to machine language using the last
two phases which are platform dependent.
• Till intermediate code, it is the same for every compiler out there,
but after that, it depends on the platform. To build a new compiler
we don’t need to build it from scratch.
• We can take the intermediate code from the already existing
compiler and build the last two parts.
39. Code Optimizer
• It transforms the code so that it consumes fewer resources and
produces more speed.
• The meaning of the code being transformed is not altered.
Optimization can be categorized into two types: machine-dependent
and machine-independent.
40. Target Code Generator
• The main purpose of the Target Code generator is to write a code
that the machine can understand and also register allocation,
instruction selection, etc.
• The output is dependent on the type of assembler. This is the final
stage of compilation.
• The optimized code is converted into relocatable machine code
which then forms the input to the linker and loader.
• All these six phases are associated with the symbol table manager
and error handler as shown in the above block diagram.