Chapter One Update
Chapter One Update
o Introduction to Compiler
o Compiler Architecture / Structure
o Phases of Compiler
o Exercise
o What is Compiler ?
o What is the need of Compiler?
Introduction to Compiler
o Compiler : Simply stated, it is a language processer , a
compiler is a program that can read a program in one language
- the source language - and translate it into an equivalent
program in another language - the target language; see Fig.
below.
o An important role of the compiler is to report any errors in the
source program that it detects during the translation process.
Introduction to Compiler
o A compiler is a translator that converts the high-level
language into the machine language.
o High-level language is written by a developer and machine
language can be understood by the processor.
o Compiler is used to show errors to the programmer.
o The main purpose of compiler is to change the code written
in one language without changing the meaning of the
program.
Introduction to Compiler
o When you execute a program which is written in HLL
programming language then it executes into two parts.
o In the first part, the source program compiled and translated
into the object program (low level language).
o In the second part, object program translated into the target
program through the assembler.
objective(Compiler Design).
o Techniques used in a parser can be used in a query processing system such as SQL.
o Many software having a complex front-end may need techniques used in compiler design.
o Most of the techniques used in compiler design can be used in Natural Language
Prepared by Befkadu (MSc) : 2015 E.C 2022-2023 A.C in AASTU
Processing (NLP) systems.
Chapter One : An Overview of a Compiler
Introduction to Compiler
o An interpreter is another common kind of language processor that
instead of producing a target program as a translation, an interpreter
appears to directly execute the operations specified in the source
program on input supplied by the user.
Structure of a Compiler
There are two major parts of a compiler : Analysis and Synthesis . The analysis part
is often called the front end of the compiler; the synthesis part is the back end.
Analysis Part
o The analysis part breaks up the source program into constituent pieces and
imposes a grammatical structure on them.
o It then uses this structure to create an intermediate representation of the source
program.
o If the analysis part detects that the source program is either syntactically ill
formed or semantically unsound, then it must provide informative messages, so
the user can take corrective action.
o The analysis part also collects information about the source program and stores it
in a data structure called a symbol table, which is passed along with the
intermediate representation to the synthesis part.
o Lexical Analyzer, Syntax Analyzer and Semantic Analyzer are the phases in this
part.
Prepared by Befkadu (MSc) : 2015 E.C 2022-2023 A.C in AASTU
Chapter One : An Overview of a Compiler
Structure of a Compiler
Synthesis Part
o The synthesis part constructs the desired target program from the
intermediate representation and the information in the symbol
table.
o The symbol table, which stores information about the entire
source program, is used by all phases of the compiler.
o If we examine the compilation process in more detail, we see that
it operates as a sequence of phases, each of which transforms one
representation of the source program to another.
o Intermediate Code Generator, Code Generator, and Code
Optimizer are the phases in this part.
target-machine code
Prepared by Befkadu (MSc) : 2015 E.C 2022-2023 A.C in AASTU
Chapter One : An Overview of a
Compiler
The Phases of a Compiler
Lexical Analysis
o The first phase of a compiler is called lexical analysis or scanning.
The lexical analyzer reads the stream of characters making up the
source program and groups the characters into meaningful sequences
called lexemes.
o A token describes a pattern of characters having same meaning in the
source program. (such as identifiers, operators, keywords, numbers,
delimiters and so on)
o For each lexeme, the lexical analyzer produces as output a token of the
form that it passes on to the subsequent phase, syntax analysis .
<token- name, attribute-value>
• In the token, the first component token- name is an abstract symbol
that is used during syntax analysis , and the second component
attribute-value points to an entry in the symbol table for this token.
Information from the symbol-table entry 'is needed for semantic
analysis and code generation.
Prepared by Befkadu (MSc) : 2015 E.C 2022-2023 A.C in AASTU
Chapter One : An Overview of a
Compiler
The Phases of a Compiler
Lexical Analysis
o Puts information about
identifiers(token) into the symbol
table.
o Regular expressions are used to
describe tokens (lexical constructs).
o A (Deterministic) Finite State
Automaton can be used in the
implementation of a lexical
analyzer.
o position, =, initial , + , rate ,* and
60 are token