0% found this document useful (0 votes)
51 views17 pages

A Program That Reads A Program Written in One Language and Translates It Into An Equivalent Program in Another Language

A compiler is a program that translates programs written in one language into an equivalent program in another language. It has two main phases: analysis and synthesis. Analysis breaks down the source program into pieces and creates an intermediate representation. Synthesis constructs the target program from the intermediate representation. The analysis phase includes lexical, syntax, and semantic analysis to validate the source program. An intermediate code is then generated before code optimization and final code generation produce the target program.

Uploaded by

yifru hail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views17 pages

A Program That Reads A Program Written in One Language and Translates It Into An Equivalent Program in Another Language

A compiler is a program that translates programs written in one language into an equivalent program in another language. It has two main phases: analysis and synthesis. Analysis breaks down the source program into pieces and creates an intermediate representation. Synthesis constructs the target program from the intermediate representation. The analysis phase includes lexical, syntax, and semantic analysis to validate the source program. An intermediate code is then generated before code optimization and final code generation produce the target program.

Uploaded by

yifru hail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

WHAT IS COMPILER

a program that reads a program written in one language


and translates it into an equivalent program in another
language.

1
LANGUAGE PROCESSING SYSTEM

2
PHASES OF A COMPILER
The two important parts in compilation are:
⚫ Analysis (Machine Independent/Language Dependent)
⚫ Synthesis (Machine Dependent/Language
independent)

3
4
ANALYSIS AND SYNTHESIS
Analysis:
⚫ breaks up the source program into pieces
⚫ creates an intermediate representation
Synthesis:
⚫ constructs the desired (target) program from the
intermediate representation.

5
ANALYSIS OF THE SOURCE PROGRAM
1. Lexical / Linear Analysis (scanning)
⚫ Scans the source code
⚫ Represents lexemes in the form of tokens as:
<token-name, attribute-value>
⚫ Token smallest meaningful element that a compiler
understands.
⚫ Example:
Identifiers, Keywords, Literals, Operators and Special
symbols.

6
7
2. Syntax / Hierarchical Analysis – Parsing
Tokens are grouped hierarchically
The result is generally a parse tree.
Expressions, statements, declarations etc... are identified
by using the results of lexical analysis.
Most syntactic errors in the source program are caught in
this phase.

8
9
3. Semantic Analysis
Checks for semantic errors in the source program
(e.g. type mismatch)
Stores type information in the symbol table or the
syntax tree.
Types of variables, function parameters, array
dimensions, etc.

10
11
INTERMEDIATE CODE GENERATION
While generating machine code directly from
source code is possible, it entails two problems:
⚫ With m languages and n target machines, we

need to write m × n compilers.


 The code optimizer cannot be reused.
A machine-independent code optimizer may be
written.

12
13
CODE OPTIMIZATION
Changes the IC by removing such inefficiencies
Improvement in time, space, or power
consumption.
It changes the structure of programs

14
15
CODE GENERATION
Converts IC to machine code.
Must handle all aspects of machine
architecture
Storage allocation decisions are made
here
 Register allocation and assignment are
the most important problems.

16
17

You might also like