0% found this document useful (0 votes)
2 views

01 Compiler _ Introduction

The document outlines the fundamentals of compiler engineering, detailing the role of compilers in translating programs between languages. It describes the phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. Additionally, it highlights the structure of a compiler, which consists of a front end for source language processing and a back end for target language processing.

Uploaded by

126003020
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

01 Compiler _ Introduction

The document outlines the fundamentals of compiler engineering, detailing the role of compilers in translating programs between languages. It describes the phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. Additionally, it highlights the structure of a compiler, which consists of a front end for source language processing and a back end for target language processing.

Uploaded by

126003020
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Compiler Engineering

Course Code: CSE402


• Syllabus
What is compiler
• Computer programs that translate a program
written in one language into a program
written in another language
A language Processing System
Type of translators
• COMPILER
• INTERPRETOR
List of Compiler
Types of Phases
• Analysis
(Machine Independent/Language Dependent)
• Synthesis
(Machine Dependent/Language independent)
Structure of Compiler

The compiler has a front end


to deal with the source
language. It has a back end
to deal with the target
language. Connecting the
front end and the back end,
it has a formal structure for
representing the program in
an intermediate form whose
meaning is largely
independent of either
language. To improve the
translation, a compiler often
includes an optimizer that
analyzes and rewrites that
intermediate form.
Phases of Compiler
Phases of Compiler
Lexical Analyzer (or) Scanner
LA or Scanners reads the source program one
character at a time, carving the source program into
a sequence of automatic units called tokens.

Example
Position:= initial + rate *60

id1 = id2 + id3 * id4

Type : variable, operator, keyword, constant


Syntax Analysis (or) parser
The second stage of translation is called Syntax analysis or
parsing. In this phase expressions, statements, declarations
etc… are identified by using the results of lexical analysis.
Syntax analysis is aided by using techniques based on formal
grammar of the programming language.

Example id1 = id2 + id3 * id4

A+/B id+/id
Semantic Analysis
a=a×2×b×c×d
b and d character string
Intermediate Code Generations
An intermediate representation of the final machine language
code is produced. This phase bridges the analysis and synthesis
phases of translation.
id1 = id2 + id3 * id4
Example
temp1:= int to real (60)
temp2:= id3 * temp1
temp3:= id2 + temp2
id1:= temp3.
Code Optimization
This is optional phase described to improve the intermediate
code so that the output runs faster and takes less space.

Example

temp1:= int to real (60)


temp2:= id3 * temp1 temp1:= id3 * 60.0
temp3:= id2 + temp2 Id1:= id2 +temp1
id1:= temp3.
Code Generation
The last phase of translation is code generation. A number of
optimizations to reduce the length of machine language
program are carried out during this phase. The output of the
code generator is the machine language program of the
specified computer.

Example
MOVF id3, r2
temp1:= id3 * 60.0 MULF *60.0, r2
Id1:= id2 +temp1 MOVF id2, r1
ADDF r2, r1
MOVF r1, id1
Compiler Example

You might also like