This document provides lecture notes on compiler design. It discusses the structure of a compiler including phases like lexical analysis, syntax analysis, intermediate code generation, code optimization, code generation, table management and error handling. It also discusses different types of translators like compilers, interpreters and preprocessors. Finally, it discusses the evolution of programming languages, classification of languages and applications of compiler technology.
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.
The document discusses the functions and purposes of translators in computing. It describes:
1) Interpreters and compilers translate programs from high-level languages to machine code. Compilers translate the entire program at once, while interpreters translate instructions one at a time as the program runs.
2) Translation from high-level languages to machine code involves multiple stages including lexical analysis, syntax analysis, code generation, and optimization.
3) Linkers and loaders are used to combine separately compiled modules into a complete executable program by resolving addresses and linking the modules together.
Language translators convert programming source code into machine language understood by computer processors. The three major types are compilers, assemblers, and interpreters. Compilers translate high-level languages into machine code in one or more passes, assemblers assemble assembly language into machine code, and interpreters analyze and execute each line of source code as the program runs without pre-translation.
This document provides an overview of compiler design and its various phases. It discusses the different phases of a compiler including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also describes the structure of a compiler and how it translates a source program through various representations and analyses until generating target code. Key concepts covered include context-free grammars, parsing techniques, symbol tables, intermediate representations, and code optimization.
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.
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 discusses the phases of a compiler including lexical analysis. It provides questions and answers related to compilers and lexical analysis. Specifically:
- It defines key terms related to compilers like translators, compilers, interpreters, and the phases of compilation.
- Questions cover topics like regular expressions, finite automata, lexical analysis issues, and the role of lexical analyzers.
- The role of the lexical analyzer is to read the source program and group it into tokens that are then passed to the parser.
- Regular expressions are used to specify patterns for tokens and can be represented by finite automata like NFAs and DFAs.
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
Introduction: Language Processors, the structure of a compiler, the science of building a compiler, programming language basics.
Lexical Analysis: The Role of the Lexical Analyzer, Input Buffering, Recognition of Tokens, The Lexical-Analyzer Generator Lex, Finite Automata, From Regular Expressions to Automata, Design of a Lexical-Analyzer Generator, Optimization of DFA-Based Pattern Matchers
Systems programming involves developing programs that interface computer systems with users and other programs. These programs include compilers, interpreters, and I/O routines. Systems programs must handle unpredictable events like errors and coordinate asynchronously executing programs. The document introduces concepts like syntax, semantics, domains, semantic gaps, and language processors like compilers and interpreters. It discusses how programming languages bridge gaps between application and execution domains.
This document provides an overview of compiler design and the different phases involved in compilation. It discusses the following:
1. The main types of language translators - assemblers, interpreters, and compilers - and the differences between compilation and interpretation.
2. The typical phases of a compiler - lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It provides examples to illustrate each phase.
3. Other components involved in compilation like preprocessors, linkers, loaders, symbol tables, and error handling.
4. The types of errors that can occur during different compiler phases like lexical analysis, syntax analysis, and semantic analysis.
So in summary
A programming language is a vocabulary and set of rules that instructs a computer to perform tasks. High-level languages like BASIC, C, Java, and Pascal are easier for humans than machine language but still need to be converted. Conversion can be done through compiling, which directly translates to machine language, or interpreting, which executes instructions without compilation. Popular languages today include Python, C, Java, and C++.
The document discusses the basics of compiler construction. It begins by defining key terms like compilers, source and target languages. It then describes the main phases of compilation as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization and machine code generation. It also discusses symbol tables, compiler tools and generations of programming languages.
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 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.
Introduction to high level Computer programmingbilalchuddher
I have formulated three objectives that I hope this book will achieve for the reader.
These objectives are based on long experience teaching a course in multivariate
methods, consulting on multivariate problems with researchers in many fields, and
guiding statistics graduate students as they consulted with similar clients.
The first objective is to gain a thorough understanding of the details of various
multivariate techniques, their purposes, their assumptions, their limitations, and so
on. Many of these techniques are related; yet they differ in some essential ways. We
emphasize these similarities and differences.
The second objective is to be able to select one or more appropriate techniques for
a given multivariate data set. Recognizing the essential nature of a multivariate data
set is the first step in a meaningful analysis. We introduce basic types of multivariate
data in Section 1.4.
The third objective is to be able to interpret the results of a computer analysis
of a multivariate data set. Reading the manual for a particular program package is
not enough to make an intelligent appraisal of the output. Achievement of the first
objective and practice on data sets in the text should help achieve the third objective.
This chapter introduces the basic elements of matrix algebra used in the remainder
of this book. It is essentially a review of the requisite matrix tools and is not intended
to be a complete development. However, it is sufficiently self-contained so that those
with no previous exposure to the subject should need no other reference. Anyone
unfamiliar with matrix algebra should plan to work most of the problems entailing
numerical illustrations. It would also be helpful to explore some of the problems
involving general matrix manipulation.
With the exception of a few derivations that seemed instructive, most of the results
are given without proof. Some additional proofs are requested in the problems. For
the remaining proofs, see any general text on matrix theory or one of the specialized
matrix texts oriented to statistics, such as Graybill (1969), Searle (1982), or Harville
(1997) The transpose operation does not change a scalar, since it has only one row and
one column.
If the transpose operator is applied twice to any matrix, the result is the original
matrix: Informally, a random variable may be defined as a variable whose value depends on
the outcome of a chance experiment. Generally, we will consider only continuous
random variables. Some types of multivariate data are only approximations to this
ideal, such as test scores or a seven-point semantic differential (Likert) scale consisting of ordered responses ranging from strongly disagree to strongly agree. Special
techniques have been developed for such data, but in many cases, the usual methods
designed for continuous data work almost as well.a single observation y. The variance σ2 is defined shortly. The notation E(y)
indicates the mean of all possible values of y; that
COMPILER DESIGN IS A COURSE IN THE COMPUTER SCIENCE DEPARTMENT THAT DEALS WITH THE CONVERSION OF PROGRAMMING WRITTEN IN HIGH-LEVEL LANGUAGE INTO MACHINE LANGUAGE, IT INVOLVES MANY PHASES
A compiler is a translator that converts a high-level language program into a low-level language program. There are four main types of translators: compilers, interpreters, assemblers, and preprocessors. Compilers translate source code into machine code in multiple phases including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. High-level languages are used because they are more readable, portable, general, brief, and easier for error checking than low-level languages.
The document discusses the phases of a compiler:
- Lexical analysis breaks the source code into tokens by grouping characters into lexemes. Each lexeme is mapped to a token with an abstract symbol and attribute value.
- Syntax analysis (parsing) uses the tokens to build a syntax tree that represents the grammatical structure.
- Semantic analysis checks the syntax tree and symbol table for semantic consistency with the language definition and gathers type information.
- Later phases include intermediate code generation, optimization, and code generation to produce the target code.
The document discusses compiler design options and the differences between compilers and interpreters. It states that a compiler converts a high-level language program into machine code all at once, while an interpreter converts the program line-by-line at runtime. Compilers generally execute programs faster but take longer to compile, while interpreters execute more slowly but can compile incrementally and debug line-by-line. The document also covers pure and impure interpreters, p-code compilers, and the roles of compilers and interpreters.
This Slide will clear all the Question Regarding compiler development and will also help to understand how a compiler works and how the phases are connected to each one
What is the Philosophy of Statistics? (and how I was drawn to it)jemille6
What is the Philosophy of Statistics? (and how I was drawn to it)
Deborah G Mayo
At Dept of Philosophy, Virginia Tech
April 30, 2025
ABSTRACT: I give an introductory discussion of two key philosophical controversies in statistics in relation to today’s "replication crisis" in science: the role of probability, and the nature of evidence, in error-prone inference. I begin with a simple principle: We don’t have evidence for a claim C if little, if anything, has been done that would have found C false (or specifically flawed), even if it is. Along the way, I’ll sprinkle in some autobiographical reflections.
Rock Art As a Source of Ancient Indian HistoryVirag Sontakke
This Presentation is prepared for Graduate Students. A presentation that provides basic information about the topic. Students should seek further information from the recommended books and articles. This presentation is only for students and purely for academic purposes. I took/copied the pictures/maps included in the presentation are from the internet. The presenter is thankful to them and herewith courtesy is given to all. This presentation is only for academic purposes.
Ad
More Related Content
Similar to Compiler design lecture 1 introduction computer science (20)
The document discusses the phases of a compiler including lexical analysis. It provides questions and answers related to compilers and lexical analysis. Specifically:
- It defines key terms related to compilers like translators, compilers, interpreters, and the phases of compilation.
- Questions cover topics like regular expressions, finite automata, lexical analysis issues, and the role of lexical analyzers.
- The role of the lexical analyzer is to read the source program and group it into tokens that are then passed to the parser.
- Regular expressions are used to specify patterns for tokens and can be represented by finite automata like NFAs and DFAs.
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
Introduction: Language Processors, the structure of a compiler, the science of building a compiler, programming language basics.
Lexical Analysis: The Role of the Lexical Analyzer, Input Buffering, Recognition of Tokens, The Lexical-Analyzer Generator Lex, Finite Automata, From Regular Expressions to Automata, Design of a Lexical-Analyzer Generator, Optimization of DFA-Based Pattern Matchers
Systems programming involves developing programs that interface computer systems with users and other programs. These programs include compilers, interpreters, and I/O routines. Systems programs must handle unpredictable events like errors and coordinate asynchronously executing programs. The document introduces concepts like syntax, semantics, domains, semantic gaps, and language processors like compilers and interpreters. It discusses how programming languages bridge gaps between application and execution domains.
This document provides an overview of compiler design and the different phases involved in compilation. It discusses the following:
1. The main types of language translators - assemblers, interpreters, and compilers - and the differences between compilation and interpretation.
2. The typical phases of a compiler - lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It provides examples to illustrate each phase.
3. Other components involved in compilation like preprocessors, linkers, loaders, symbol tables, and error handling.
4. The types of errors that can occur during different compiler phases like lexical analysis, syntax analysis, and semantic analysis.
So in summary
A programming language is a vocabulary and set of rules that instructs a computer to perform tasks. High-level languages like BASIC, C, Java, and Pascal are easier for humans than machine language but still need to be converted. Conversion can be done through compiling, which directly translates to machine language, or interpreting, which executes instructions without compilation. Popular languages today include Python, C, Java, and C++.
The document discusses the basics of compiler construction. It begins by defining key terms like compilers, source and target languages. It then describes the main phases of compilation as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization and machine code generation. It also discusses symbol tables, compiler tools and generations of programming languages.
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 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.
Introduction to high level Computer programmingbilalchuddher
I have formulated three objectives that I hope this book will achieve for the reader.
These objectives are based on long experience teaching a course in multivariate
methods, consulting on multivariate problems with researchers in many fields, and
guiding statistics graduate students as they consulted with similar clients.
The first objective is to gain a thorough understanding of the details of various
multivariate techniques, their purposes, their assumptions, their limitations, and so
on. Many of these techniques are related; yet they differ in some essential ways. We
emphasize these similarities and differences.
The second objective is to be able to select one or more appropriate techniques for
a given multivariate data set. Recognizing the essential nature of a multivariate data
set is the first step in a meaningful analysis. We introduce basic types of multivariate
data in Section 1.4.
The third objective is to be able to interpret the results of a computer analysis
of a multivariate data set. Reading the manual for a particular program package is
not enough to make an intelligent appraisal of the output. Achievement of the first
objective and practice on data sets in the text should help achieve the third objective.
This chapter introduces the basic elements of matrix algebra used in the remainder
of this book. It is essentially a review of the requisite matrix tools and is not intended
to be a complete development. However, it is sufficiently self-contained so that those
with no previous exposure to the subject should need no other reference. Anyone
unfamiliar with matrix algebra should plan to work most of the problems entailing
numerical illustrations. It would also be helpful to explore some of the problems
involving general matrix manipulation.
With the exception of a few derivations that seemed instructive, most of the results
are given without proof. Some additional proofs are requested in the problems. For
the remaining proofs, see any general text on matrix theory or one of the specialized
matrix texts oriented to statistics, such as Graybill (1969), Searle (1982), or Harville
(1997) The transpose operation does not change a scalar, since it has only one row and
one column.
If the transpose operator is applied twice to any matrix, the result is the original
matrix: Informally, a random variable may be defined as a variable whose value depends on
the outcome of a chance experiment. Generally, we will consider only continuous
random variables. Some types of multivariate data are only approximations to this
ideal, such as test scores or a seven-point semantic differential (Likert) scale consisting of ordered responses ranging from strongly disagree to strongly agree. Special
techniques have been developed for such data, but in many cases, the usual methods
designed for continuous data work almost as well.a single observation y. The variance σ2 is defined shortly. The notation E(y)
indicates the mean of all possible values of y; that
COMPILER DESIGN IS A COURSE IN THE COMPUTER SCIENCE DEPARTMENT THAT DEALS WITH THE CONVERSION OF PROGRAMMING WRITTEN IN HIGH-LEVEL LANGUAGE INTO MACHINE LANGUAGE, IT INVOLVES MANY PHASES
A compiler is a translator that converts a high-level language program into a low-level language program. There are four main types of translators: compilers, interpreters, assemblers, and preprocessors. Compilers translate source code into machine code in multiple phases including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. High-level languages are used because they are more readable, portable, general, brief, and easier for error checking than low-level languages.
The document discusses the phases of a compiler:
- Lexical analysis breaks the source code into tokens by grouping characters into lexemes. Each lexeme is mapped to a token with an abstract symbol and attribute value.
- Syntax analysis (parsing) uses the tokens to build a syntax tree that represents the grammatical structure.
- Semantic analysis checks the syntax tree and symbol table for semantic consistency with the language definition and gathers type information.
- Later phases include intermediate code generation, optimization, and code generation to produce the target code.
The document discusses compiler design options and the differences between compilers and interpreters. It states that a compiler converts a high-level language program into machine code all at once, while an interpreter converts the program line-by-line at runtime. Compilers generally execute programs faster but take longer to compile, while interpreters execute more slowly but can compile incrementally and debug line-by-line. The document also covers pure and impure interpreters, p-code compilers, and the roles of compilers and interpreters.
This Slide will clear all the Question Regarding compiler development and will also help to understand how a compiler works and how the phases are connected to each one
What is the Philosophy of Statistics? (and how I was drawn to it)jemille6
What is the Philosophy of Statistics? (and how I was drawn to it)
Deborah G Mayo
At Dept of Philosophy, Virginia Tech
April 30, 2025
ABSTRACT: I give an introductory discussion of two key philosophical controversies in statistics in relation to today’s "replication crisis" in science: the role of probability, and the nature of evidence, in error-prone inference. I begin with a simple principle: We don’t have evidence for a claim C if little, if anything, has been done that would have found C false (or specifically flawed), even if it is. Along the way, I’ll sprinkle in some autobiographical reflections.
Rock Art As a Source of Ancient Indian HistoryVirag Sontakke
This Presentation is prepared for Graduate Students. A presentation that provides basic information about the topic. Students should seek further information from the recommended books and articles. This presentation is only for students and purely for academic purposes. I took/copied the pictures/maps included in the presentation are from the internet. The presenter is thankful to them and herewith courtesy is given to all. This presentation is only for academic purposes.
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18Celine George
In this slide, we’ll discuss on how to clean your contacts using the Deduplication Menu in Odoo 18. Maintaining a clean and organized contact database is essential for effective business operations.
Learn about the APGAR SCORE , a simple yet effective method to evaluate a newborn's physical condition immediately after birth ....this presentation covers .....
what is apgar score ?
Components of apgar score.
Scoring system
Indications of apgar score........
Form View Attributes in Odoo 18 - Odoo SlidesCeline George
Odoo is a versatile and powerful open-source business management software, allows users to customize their interfaces for an enhanced user experience. A key element of this customization is the utilization of Form View attributes.
This slide is an exercise for the inquisitive students preparing for the competitive examinations of the undergraduate and postgraduate students. An attempt is being made to present the slide keeping in mind the New Education Policy (NEP). An attempt has been made to give the references of the facts at the end of the slide. If new facts are discovered in the near future, this slide will be revised.
This presentation is related to the brief History of Kashmir (Part-I) with special reference to Karkota Dynasty. In the seventh century a person named Durlabhvardhan founded the Karkot dynasty in Kashmir. He was a functionary of Baladitya, the last king of the Gonanda dynasty. This dynasty ruled Kashmir before the Karkot dynasty. He was a powerful king. Huansang tells us that in his time Taxila, Singhpur, Ursha, Punch and Rajputana were parts of the Kashmir state.
How to Manage Purchase Alternatives in Odoo 18Celine George
Managing purchase alternatives is crucial for ensuring a smooth and cost-effective procurement process. Odoo 18 provides robust tools to handle alternative vendors and products, enabling businesses to maintain flexibility and mitigate supply chain disruptions.
Computer crime and Legal issues Computer crime and Legal issuesAbhijit Bodhe
• Computer crime and Legal issues: Intellectual property.
• privacy issues.
• Criminal Justice system for forensic.
• audit/investigative.
• situations and digital crime procedure/standards for extraction,
preservation, and deposition of legal evidence in a court of law.
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Leonel Morgado
Slides used at the Invited Talk at the Harvard - Education University of Hong Kong - Stanford Joint Symposium, "Emerging Technologies and Future Talents", 2025-05-10, Hong Kong, China.
1. Introduction to Compiler
الجامع
ة
المستنصريه
-
1
References
"Compilers Principles, techniques, & tools", by Alfred Aho,
second edition, Pearson Addison Wesley, 2007.
Compiler and Translators
Translator is a program that takes as input a program written in one
programming language (the source language) and produces as output
a program in another language (the object or target language).
Types of translator
There are four types of translator according to the source
language as well as target language:
Compiler is a translator that translates a high-level language
program such as FORTRAN, PASCAL, C++
, to low-level language
program such as an assembly language or machine language.
Note: The translation process should also report the presence of
errors in the source program.
Translator
Source
Program
Object
Program
Compiler
High-level
language
Low-level
language
(machine 01)
2. Introduction to Compiler
الجامع
ة
المستنصريه
-
2
Others Translators:
Interpreters are another kind of translators. An Interpreter is a
translator that effectively accepts a source program and executes it
directly, without, producing any object code first. It does this by
fetching the source program instructions one by one, analyzing them
one by one, and then "executing" them one by one.
1- Smaller ( advantage)
2- Slower (disadvantage)
An Assembler is a translator that translates the assembly language
program (mnemonic program) to machine language program.
Pre-processor: is a Translator Translate program written by H.L.L
Into an equivalent program in H.L.L.
Why do we Need Translations?
If there are no translators then we must programming in machine
language. With machine language we must be communicate directly
with a computer in terms of bits, registers, and very primitive
machine operations. Since a machine language program is nothing
more than a sequence of 0's and 1's, programming a complex
Assembler
Assembly
Program
Machine
Program
Low-level language Low-level language
Interpreter
High-level
language
Intermediate code
(
directly execution
)
Pre-processor
High-level
language
High-level
Language
3. Introduction to Compiler
الجامع
ة
المستنصريه
-
3
algorithm in such a language is terribly tedious and fraught with
mistakes.
Why we Write Programs in High-Level Language?
We write programs in high-level language (advantages of high-level
language) because it is:
1) Readability: high-level language will allow programs to be
written in the same ways that used in description of the
algorithms.
2) Portability: High-level languages can be run without
changing on a variety of different computers.
3) Generality: Most high-level languages allow the writing of a
wide variety of programs, thus relieving the programmer of the
need to become expert in many languages.
4) Brevity: Programs expressed in high-level languages are often
considerably shorter (in terms of their number of source lines)
than their low-level equivalents.
5) It's easy in the Error checking process.
The Structure of a Compiler
The process of compilation is so complex to be achieved in
one single step, either from a logical point of view or from an
implementation point of view. For this reason it is partition into a
series of subprocesses called Phases. The typical compiler consists
of several phases each of which passes its output to the next phase
plus symbol table manager and an error handler as shown below:
4. Introduction to Compiler
الجامع
ة
المستنصريه
-
4
Lexical Analyzer (Scanner): It is the first phase of the complier
and also called scanner, which represent the interface between
source program and the compiler. where the Lexical will read the
source program by one letter at a time and decomposed it into group
of letters called TOKEN that is logically interrelated between them.
Phases of a Compiler.
Target Program
Symbol Table
management
Lexical
Analysis
Syntax
Analysis
Semantic
Analysis
Intermediate
Code Generating
Code
Optimization
Code
Generating
Source Program
Error
Handler
5. Introduction to Compiler
الجامع
ة
المستنصريه
-
5
This token represent string of characters that can be processed
together as a logical input.
In others words, lexical Separates characters of the source language
program into groups (sets) that logically belong together. These
groups are called Tokens.
Tokens are Keywords, Identifiers, Operator Symbols, and
Punctuation Symbols. The output of the analyzer is stream of tokens,
which is passed to the syntax analyzer.
Tokens: groups of characters of source language program logically
belong together. For example:
Syntax Analyzer (Parser): Groups tokens together into syntactic
structures called Expressions. Expressions might further be
combined to form Statements. Often the syntactic structure can be
regarded as a Tree (parse tree) whose leaves are the tokens. The
interior nodes of the tree represent strings of tokens that logically
belong together.
Every programming language has rules that prescribe the syntactic
structure of well –formed programs. Syntax analysis takes an out of
lexical analyzer and produce a large tree call parse tree
Semantics:. is a term used to describe "meaning", and so the
constraint analyzer is often called the static semantic analyzer, or
simply the semantic analyzer. Semantic analyzer takes the output of
For, If, Do {Keyword}
X, A1, Num {Identifiers}
3, 44.2,-53 {Constants}
>, +, = {Operator Symbols}
; , . ,' {Punctuation Symbols}
Tokens =
6. Introduction to Compiler
الجامع
ة
المستنصريه
-
6
syntax analyzer and produces another tree.The output of the syntax
analyzer and semantic analyzer phases is sometimes expressed in the
form of a Abstract Syntax Tree (AST). This is a very useful
representation, as it can be used in clever ways to optimize code
generation at a later phase.
It is Recently added a stage to analyze in terms of sentence
meaning, in other words, will reject the sentence in the case of the
discovery of the meaning of error (Note: The sentence can be true in
terms of the syntax but have no meaning).
For example the English sentence : "The man eat the house " This is
in the natural language, put in programming languages can either
write inter correct the hand, but wrong in the sense rules .
Intermediate Code Generator: Create a stream of simple
instructions. Many style of intermediate code are possible. One
common style uses instructions with one operator and a small
number of operands.
This phase is used structures built in the previous stages and convert
them into intermediate codes by using a most famous meta language
such as:
- Postfix notation
- Polish notation
In some versions be enforceable as is the case in the interpreter for
the BASIC language and commands interpreter of the DOS
operating system.
7. Introduction to Compiler
الجامع
ة
المستنصريه
-
7
Code Optimization: Is an optional phase designed to improve the
intermediate code so that the ultimate object program runs faster
and/or takes less space.
Code Generation: In a real compiler this phase takes the output
from the previous phase and produces the object code, by deciding
on the memory locations for data, generating code to access such
locations, selecting registers for intermediate calculations and
indexing, and so on.
Table Management: Portion of the compiler keeps tracks of the
name used by the program and records essential information about
each, such as its type integer, real, … etc. the data structure used to
record this information is called a Symbolic Table.
Error Handler: One of the most important functions of a compiler
is the detection and reporting of errors in the source program. The
error messages should allow the programmer to determine exactly
where the errors have occurred. Whenever a phase of the compiler
discovers an error, it must report the error to the error handler, which
issues an appropriate diagnostic message.
Passes of Compiler
The previous phases showing the main parts of the compiler
theoretically, either in the case of the application must merge
combine more than one phase in round one and this is called one
pass. Each pass will read the output of the previous pass ( except for
the first pass ) that reads the source program.
8. Introduction to Compiler
الجامع
ة
المستنصريه
-
8
In the case of integrating more than one stage in one round will lead
to interference in the work of these stages through the control
structure between these stages.
The influential factor in the number of stages per pass depends on
the structure of the source language , the translator , who owns
multi-pass uses less memory space of a translator who is in round
one single pass. On the other hand , the multi-pass type slower than
the another because each stage reads and writes in the intermediate
file leads to the slow work of the translator . Must be a balance
between the number of stages in a single pass and between the speed
of the compiler. And on this basis can be lexical in one pass with
syntax or separated .
When a lexical phase are separate from syntax pass there are four
pros :
1 - the design of each model separately and thus achieved simplicity.
2 - be efficiency translator largest so that you can manipulate each
part in order to achieve the desired efficiency .
3 - including that the lexical is the interface for that is change when
you change the language and vocabulary development process.
4 – can make symbol table more structure in which we can use it as
input and output in the same time.
Notice: If phase lexical built with syntax In this case, the Lexical in
the form of a subroutine assistant called from the phase of syntax
that followed , and if their separation will store the results of
intermediate file, this file is called symbol table.
12. Introduction to Compiler
الجامع
ة
المستنصريه
-
12
How Lexical Work
Input Buffering:
The lexical analyzer scans the characters of the source
program one at a time to discover tokens; it is desirable for the
lexical analyzer to read its input from an input buffer.
We have two pointers one marks to the beginning of the token
begin discovered. A look-ahead pointer scans a head of the
beginning point, until the token is discovered
For example, if we have the following statement written by HLL
program