SlideShare a Scribd company logo
 STATEMENT OF PROBLEM
 A compiler accepts a program written in a higher
level language as input and produces its machine
language equivalent as output.
 Example:
WCM: PROCEDURE (RATE, START, FINISH);
DECLARE ( COST , RATE , START , FINISH) FIXED BINARY (31)
STATIC;
COST = RATE * (START – FINISH) + 2 * RATE * (START – FINISH –
100);
RETURN (COST) ;
END;
2jayashrisk
 Steps followed by compiler to produce machine code
 Recognize certain string as basic elements.
Ex: COST := variable , WCM := label, PROCEDURE : = keyword and
“=“ := operator
 Recognize combinations of elements as syntactic units and interpret
their meaning.
Ex: 1st statement is procedure name with three arguments
 Allocate storage and assign locations for all variables in this
program.
 Generate the appropriate object code.
3jayashrisk
 Problem No: 1 – Recognizing Basic Elements (lexical analysis)
 Uses conceptually simple string processing techniques.
 Source program is scanned sequentially
 Tokens (identifiers, literals or terminal symbols)are identified
 Basic elements(identifiers & literals) are placed into tables with basic
information
 Example:
WCM : PROCEDURE ( RATE , START , FINISH ) ;
(DECLARE COST , RATE , START , FINISH ) FIXED BINARY (
31 ) STATIC ;
COST = RATE * ( START - FINISH ) + 2 *
RATE * ( START - FINISH - 100 ) ;
RETURN ( COST ) ;
END ; 4jayashrisk
 Ways of lexical process
 Single continuous pass used to prepare a chain or table of
tokens
 Reduces the size of token table by only parsing tokens as
necessary.
 Discover and note lexical errors.
CLASSES OF UNIFORM
SYMBOLS:
IDENTIFIER(IDN)
TERMINAL SYMBOL(TRM)
LITERAL(LIT)
CLASS PTR
IDN
TRM
TRM
TRM
IDN
WCM
:
PROCEDURE
(
RATE
5jayashrisk
 Problem No: 2 – Recognizing syntactic units
and Interpreting Meaning (syntactic
construction)
 Compiler must recognize the phrases &
interpret the meaning of the constructions.
 Note syntactic errors
 Some compiler guess what the programmer
did wrong & correct it.
6jayashrisk
Example:
WCM : PROCEDURE ( RATE , START , FINISH ) ;
DECLARE ( COST , RATE , START , FINISH ) FIXED BINARY ( 31 ) STATIC ;
COST = RATE * ( START – FINISH ) + 2 * RATE * ( START - FINISH - 100 ) ;
RETRUN ( COST ) ;
END ;
Valid
procedure
statement
Valid declare statement
Valid end statement
Valid assignment statement
Valid assignment statement
Basic syntactic constructs
Tokens
7jayashrisk
 INTERMEDIATE FORM
 Compiler creates an intermediate form of
source program.
 It facilitates optimization of object code
 It allows a logical separation between the
machine-independent phases & machine-
dependent phases
8jayashrisk
 ARITHMETIC STATEMENT
 Parse tree - form of an arithmetic statement
 Rules for converting an arithmetic statement
into a parse tree are:
 Any variable is a terminal node of the tree
 For every operator, construct a binary tree
whose left branch is the tree for operand 1 &
whose right branch is the tree for operand 2.
9jayashrisk
Example: parse tree
COST = RATE * ( START – FINISH ) + 2 * RATE * ( START - FINISH - 100 ) ;
=
+
* *
-
-
*
COST
RATE
-
START
FINISH 2 RATE
START FINISH
100
10jayashrisk
 MATRIX : Linear representation of the parse tree
 Operations are listed sequentially
 Each matrix entry has one operator and two operands.
 Operands are uniform symbols
Matrix line no. O8perator Operand1 Operand2
1 - START FINISH
2 * RATE M1
3 * 2 RATE
4 - START FINISH
5 - M4 100
6 * M3 M5
7 + M2 M6
8 = COST M7
matrix
11jayashrisk
 NONARITHMETIC STATEMENTS
 DO, IF GO TO ,etc replaced by sequential
ordering of individual matrix entries.
 Operators are defined in later phases of
compiler
Operator Operand1 Operand2
Return COST
End
RETURN ( COST) ;
END ;
Matrix for RETURN & END statement
12jayashrisk
 NONEXECUTABLE STATEMENTS
 No intermediate form for these statements
 Information of these statements is entered into
tables
Name Base Scale Precisio
n(bits)
Storage
class
location
COST BINARY FIXED 31 STATIC 0
RATE BINARY FIXED 31 STATIC 4
START BINARY FIXED 31 STATIC 8
FINISH BINARY FIXED 31 STATIC 12
13jayashrisk
 Problem no. 3 – Storage Allocation
 Storage allocation routine scans the identifier
table and assigns a location to each scalar.
 Absolute address is unknown at load time.
 Relative address format
 Temporary locations for intermediate results of
the matrix(M!,M2,etc)
Operand Sign bit(1) 31 binary
digit
COST S
RATE I
START G
FINISH N
14jayashrisk
 Problem no. 4 – Code Generation
 Based on matrix and table compiler generates object
code
 A table with matrix operation and associated matrix
code is used for creating object deck.
 Operators are treat as macro definition, operands as
arguments and production table as macro definition.
15jayashrisk
Standard code definition for -,*,+,=
- L 1,&OPERAND1
S 1,&OPERAND2
ST 1,M&N
-------------------------------
* L 1,&OPERAND1
S 1,&OPERAND2
ST 1,M&N
------------------------------------
+ L 1,&OPERAND1
S 1,&OPERAND2
ST 1,M&N
------------------------------------
= L 1,&OPERAND1
S 1,&OPERAND2
ST 1,M&N
----------------------------------
MATRIX GENERATED CODE
1 - START FINISH L 1,START
S 1,FINISH
ST 1,M1
2 * RATE M1 L 1,RATE
M 0,M1
ST 1,M2
3 * 2 RATE L 1,=F’2’
M 0,RATE
ST 1,M3
4 - START FINISH L 1,START
S 1,FINISH
ST 1,M4
5 - M4 100 L 1,M4
S 1,=F’100’
ST 1,M5
6 * M3 M5 L 1,M3
M 0,M5
ST 1,M6
7 + M2 M6 L 1,M2
A 1,M6
ST 1,M7
8 = COST M7 L 1,M7
ST 1,COST
Code definition
Code generation
16jayashrisk
 Questions
 Was it a good idea to generate code directly from the
matrix?
MACHINE INDEPENDENT OPTIMIZATION
 Have we made the best use of machine we have at
our disposal?
MACHINE DEPENDENT OPTIMIZATION
 Can we generate machine language directly?
17jayashrisk
 OPTIMIZATION(MACHINE-INDEPENDENT)
 Delete all duplicate matrix entries of sub expression occurs in the
same statement more than once(a common sub expression)
 Modify all references to the deleted entries
 Done before code generation
 Example
Matrix with common sub
expression
Matrix after elimination of common
sub expression
1 - START FINISH 1 - START FINISH
2 * RATE M1 2 * RATE M1
3 * 2 RATE 3 * 2 RATE
4 - START FINISH 4
5 - M4 100 5 - M1 100
6 * M3 M5 6 * M3 M5
7 + M2 M6 7 * M2 M6
8 = COST M7 8 = COST M7
18jayashrisk
 Other machine independent optimization steps
are:
 Compile time computation of operations, both of
whose operands are constants
 Movement of computations involving nonvarying
operands out of loops
 Use of the properties of Boolean expression to
minimize their computation.
19jayashrisk
 machine dependent optimization steps are:
 For temporary storage use registers, this reduce the
number of loads and stores from 14 to 5 in our
example
 Use shorter and faster instructions whenever
possible
 Advantages
 Reduces memory space needed for the program
 Execution time of the object program by factor of 2
20jayashrisk
 OPTIMIZATION(MACHINE-DEPENDENT)
 Done while generating code
Optimized matrix First try Improved code
1 - START FINISH L
S
ST
1,START
1,FINISH
1,M1
L 1,START
1,FINISH M1-> R1
2 * RATE M1 L
M
ST
1,RATE
0,M1
1,M2
L
MR
3,RATE
2,1 M2->R3
3 * 2 RATE L
M
ST
1,=F’2’
0,RATE
1,M3
L
M
5,=F’2’
4,RATE M3->R5
4
5 - M1 100 L
S
ST
1,M1
1,=F’100’
1,M5
S 1,=F’100’ M5->R1
6 * M3 M5 L
M
ST
1,M3
0,M5
1,M6
LR
MR
7,5
6,1
M6->M7
7 + M2 M6 L
A
ST
1,M2
1,M6
1,M7
AR 3,7 M7->R3
8 = M7 COST L
ST
1,M7
1,COST
ST 3,COST
21jayashrisk
 ASSEMBLY PHASE
 Assembly phase is similar to pass 2 of assembler
 Defines labels and resolves all references
22jayashrisk
23jayashrisk
 LEXICAL PHASE
 Task
 To parse the source program into basic elements or
tokens of the language
 Build literal table and an identifier table
 Build a uniform symbol table
 Database
 Source program(string of characters)
 Terminal table
Symbol Indicator precedence
; yes
Procedure no
24jayashrisk
 Database
 Literal table
 Identifier table
 Uniform symbol table
Literal Base Scale Precision Other information Address
31 Decimal Fixed 2
Name Data attribute Address
WCM Filled by later phases
Table Index
IDN 1(WCM)
25jayashrisk
 Algorithm
 Input string is separated into tokens by break
characters
 Tokens are checked with entries of terminal table
 If match then token is classified as terminal symbol and
an uniform symbol is created for type TRM
 If not matched then checked as identifier or literal
 If token start with alphabet and contain up to 30 more
characters or underscores. then classified as identifier
and an uniform symbol is created for type IDN
 If not then checked as literal
 If not fit into one of these categories, it is an error.
26jayashrisk
 SYNTAX PHASE
 TASK
 Recognize the major construct of the language and to
call the appropriate action routines that will generate
the intermediate from or matrix for these constructs.
 Databases
 Uniform symbol table
 stack
Table Index
27jayashrisk
 Algorithm
 Reduction are tested consecutively for match between old
top of stack field and the actual top of stack until match is
found.
 When matched is found, the action routines specified in
the action field are executed in order from left to right.
 When control returns to the syntax analyzer, it modifies
the top of stack to agree with the new top of stack field.
 Step 1 is then repeated starting with the reduction
specified in the next reduction field.
28jayashrisk
 Interpretation phase
 It is a collection of routines that are called when a
construct is recognized in the syntactic phase.
 Routines are used to create an intermediate form of
the source program and add information to the
identifier table.
29jayashrisk
 Databases
 Uniform symbol table
 Stack
 Identifier table
 Matrix
Name Base Scale Precision Storage
class
Array
bound
Structure
info
Literal
value
Block
info
other address
Uniform
symbol
Uniform
symbol
Uniform
symbol
chaining
Operator Operand1 operand2 30jayashrisk
 Temporary storage table
 Algorithm
 It contains collection of individual action routines
that accomplish specific tasks when invoked by the
syntax analysis phase
 Routines are
 Do any necessary additional parsing
 Create new entries in the matrix or add data attributes
to the identifier operator and operands and insert them
into the matrix.
MTXN Base Scale Precision Storage
class
Other address
31jayashrisk
 Optimization(machine independent
optimization)
 Databases
 Matrix
 Identifier table
 Literal table
Operator Operand1 Operand2 Forward pointer Backward pointer
32jayashrisk
 Algorithm
 Elimination of common sub expressions
 Common sub expression must be identical and must be in
same statement
1. Place the matrix in a form so that common sub expressions
can be recognized
2. Recognize two sub expressions as being equivalent
3. Eliminate one of them
4. Alter the rest of the matrix to reflect the elimination of this
entry
5. Rescan the matrix for possible crated common sub
expressions repeat 1 to 5 until no change occur
6. Eliminate from the temporary storage table any MTX
entries that are no longer needed
33jayashrisk
 Example
Source code
B=A
A=C*D*(D*C+B)
MATRIX BEFORE OPTIMIZATION
M line
no
Operator Operand1 Operand2 Backward forward
M1 = B A 0 2
M2 * C D 1 3
M3 * D C 2 4
M4 + M3 B 3 5
M5 * M2 M4 4 6
M6 = A M5 5 ?
MATRIX BEFORE OPTIMIZATION
M line
no
Operat
or
Operan
d1
Operan
d2
Backw
ard
forwar
d
M1 = B A 0 2
M2 * C D 1 3
M3 * C D 2 4
M4 + B M3 3 5
M5 * M2 M4 4 6
M6 = A M5 5 ?
MATRIX AFTER OPTIMIZATION
M line
no
Operat
or
Operan
d1
Operan
d2
Backwa
rd
forward
M1 = B A 0 2
M2 * C D 1 4
M3 * C D 2 4
M4 + B M2 2 5
M5 * M2 M4 4 6
M6 = A M5 5 ?
34jayashrisk
 Compile time compute
 Saves space and execution time for object program
 Used for arithmetic computation within loop
Example
A=2*276/92*B = (2*276/92)*B = 6*B
Before optimization
M1 * 2 276
M2 / M1 92
M3 * M2 B
M4 = A M3
After optimization
M1
M2
M3 * 6 B
M4 = A M3
35jayashrisk
 Boolean expression optimization
 Use properties of Boolean expression to shorten their
computation
 Example
If(a or b or c)
If a is true the no need to check b and c
So eliminate that part
36jayashrisk
 Move invariant computations outside of loops
 If the computation within a loop depends on a
variable that does not change within that loop, the
computation may be moved outside the loop
 Recognition of invariant computations
 Example
For(i=0;i<10;i++)
{
a=10;
i=i*2;
}
37jayashrisk
 Discovering where to move the invariant
computation
 Move the computation to a position directly
preceding the LOOP from which it comes
 Moving the invariant computation
 Delete the invariant computation from its original
position in the matrix and insert it into the
appropriate place
38jayashrisk

More Related Content

What's hot

Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
Arvind Kumar
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
Huawei Technologies
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
Tech_MX
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit I
Saranya1702
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
Satyamevjayte Haxor
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
Deepmala Sharma
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
PreethiSureshkumar1
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
Meghaj Mallick
 
Assembler design option
Assembler design optionAssembler design option
Assembler design option
Mohd Arif
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
Bhatt Balkrishna
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
Temesgen Molla
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
Bhavik Vashi
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
Dattatray Gandhmal
 
Assembler
AssemblerAssembler
Assembler
Maha Lakshmi
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil Kaushik
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
Darshan sai Reddy
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
Manoj Patil
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
Malek Sumaiya
 

What's hot (20)

Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit I
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Assembler design option
Assembler design optionAssembler design option
Assembler design option
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Assembler
AssemblerAssembler
Assembler
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 

Viewers also liked

Assembler1
Assembler1Assembler1
Assembler1
jayashri kolekar
 
Macro
MacroMacro
Loader
LoaderLoader
OMD chapter 2 Class modelling
 OMD  chapter 2 Class modelling OMD  chapter 2 Class modelling
OMD chapter 2 Class modelling
jayashri kolekar
 
Parsing
ParsingParsing
System programming
System programmingSystem programming
System programming
jayashri kolekar
 
Advanced behavioral modeling chapter 4 of omd
Advanced behavioral modeling chapter 4 of omdAdvanced behavioral modeling chapter 4 of omd
Advanced behavioral modeling chapter 4 of omd
jayashri kolekar
 
Architectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omdArchitectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omd
jayashri kolekar
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 

Viewers also liked (9)

Assembler1
Assembler1Assembler1
Assembler1
 
Macro
MacroMacro
Macro
 
Loader
LoaderLoader
Loader
 
OMD chapter 2 Class modelling
 OMD  chapter 2 Class modelling OMD  chapter 2 Class modelling
OMD chapter 2 Class modelling
 
Parsing
ParsingParsing
Parsing
 
System programming
System programmingSystem programming
System programming
 
Advanced behavioral modeling chapter 4 of omd
Advanced behavioral modeling chapter 4 of omdAdvanced behavioral modeling chapter 4 of omd
Advanced behavioral modeling chapter 4 of omd
 
Architectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omdArchitectural modeling chapter 5 of omd
Architectural modeling chapter 5 of omd
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 

Similar to Compilers

SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
venkatam
 
Building blocks 2
Building blocks 2Building blocks 2
Building blocks 2
NAZIRGUJJAR
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
SemsemSameer1
 
Power of call symput data
Power of call symput dataPower of call symput data
Power of call symput data
Yash Sharma
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
RaajTech
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
MugdhaSharma11
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
bolovv
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
Iffat Anjum
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Unit ii-111206004636-phpapp01
Unit ii-111206004636-phpapp01Unit ii-111206004636-phpapp01
Unit ii-111206004636-phpapp01
riddhi viradiya
 
Embedded programming u3 part 1
Embedded programming u3 part 1Embedded programming u3 part 1
Embedded programming u3 part 1
Karthik Vivek
 
C programming
C programmingC programming
C programming
ASHISH KUMAR
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Marina Kolpakova
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Franck Pachot
 
Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
Pantech ProLabs India Pvt Ltd
 
Unit i
Unit iUnit i
Assembler
AssemblerAssembler
Assembler
SheetalAwate2
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Dr. Jaydeep Patil
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
C++ Homework Help
 

Similar to Compilers (20)

SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
Building blocks 2
Building blocks 2Building blocks 2
Building blocks 2
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
 
Power of call symput data
Power of call symput dataPower of call symput data
Power of call symput data
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Unit ii-111206004636-phpapp01
Unit ii-111206004636-phpapp01Unit ii-111206004636-phpapp01
Unit ii-111206004636-phpapp01
 
Embedded programming u3 part 1
Embedded programming u3 part 1Embedded programming u3 part 1
Embedded programming u3 part 1
 
C programming
C programmingC programming
C programming
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
 
Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
 
Unit i
Unit iUnit i
Unit i
 
Assembler
AssemblerAssembler
Assembler
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 

Recently uploaded

Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 

Recently uploaded (20)

Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 

Compilers

  • 1.
  • 2.  STATEMENT OF PROBLEM  A compiler accepts a program written in a higher level language as input and produces its machine language equivalent as output.  Example: WCM: PROCEDURE (RATE, START, FINISH); DECLARE ( COST , RATE , START , FINISH) FIXED BINARY (31) STATIC; COST = RATE * (START – FINISH) + 2 * RATE * (START – FINISH – 100); RETURN (COST) ; END; 2jayashrisk
  • 3.  Steps followed by compiler to produce machine code  Recognize certain string as basic elements. Ex: COST := variable , WCM := label, PROCEDURE : = keyword and “=“ := operator  Recognize combinations of elements as syntactic units and interpret their meaning. Ex: 1st statement is procedure name with three arguments  Allocate storage and assign locations for all variables in this program.  Generate the appropriate object code. 3jayashrisk
  • 4.  Problem No: 1 – Recognizing Basic Elements (lexical analysis)  Uses conceptually simple string processing techniques.  Source program is scanned sequentially  Tokens (identifiers, literals or terminal symbols)are identified  Basic elements(identifiers & literals) are placed into tables with basic information  Example: WCM : PROCEDURE ( RATE , START , FINISH ) ; (DECLARE COST , RATE , START , FINISH ) FIXED BINARY ( 31 ) STATIC ; COST = RATE * ( START - FINISH ) + 2 * RATE * ( START - FINISH - 100 ) ; RETURN ( COST ) ; END ; 4jayashrisk
  • 5.  Ways of lexical process  Single continuous pass used to prepare a chain or table of tokens  Reduces the size of token table by only parsing tokens as necessary.  Discover and note lexical errors. CLASSES OF UNIFORM SYMBOLS: IDENTIFIER(IDN) TERMINAL SYMBOL(TRM) LITERAL(LIT) CLASS PTR IDN TRM TRM TRM IDN WCM : PROCEDURE ( RATE 5jayashrisk
  • 6.  Problem No: 2 – Recognizing syntactic units and Interpreting Meaning (syntactic construction)  Compiler must recognize the phrases & interpret the meaning of the constructions.  Note syntactic errors  Some compiler guess what the programmer did wrong & correct it. 6jayashrisk
  • 7. Example: WCM : PROCEDURE ( RATE , START , FINISH ) ; DECLARE ( COST , RATE , START , FINISH ) FIXED BINARY ( 31 ) STATIC ; COST = RATE * ( START – FINISH ) + 2 * RATE * ( START - FINISH - 100 ) ; RETRUN ( COST ) ; END ; Valid procedure statement Valid declare statement Valid end statement Valid assignment statement Valid assignment statement Basic syntactic constructs Tokens 7jayashrisk
  • 8.  INTERMEDIATE FORM  Compiler creates an intermediate form of source program.  It facilitates optimization of object code  It allows a logical separation between the machine-independent phases & machine- dependent phases 8jayashrisk
  • 9.  ARITHMETIC STATEMENT  Parse tree - form of an arithmetic statement  Rules for converting an arithmetic statement into a parse tree are:  Any variable is a terminal node of the tree  For every operator, construct a binary tree whose left branch is the tree for operand 1 & whose right branch is the tree for operand 2. 9jayashrisk
  • 10. Example: parse tree COST = RATE * ( START – FINISH ) + 2 * RATE * ( START - FINISH - 100 ) ; = + * * - - * COST RATE - START FINISH 2 RATE START FINISH 100 10jayashrisk
  • 11.  MATRIX : Linear representation of the parse tree  Operations are listed sequentially  Each matrix entry has one operator and two operands.  Operands are uniform symbols Matrix line no. O8perator Operand1 Operand2 1 - START FINISH 2 * RATE M1 3 * 2 RATE 4 - START FINISH 5 - M4 100 6 * M3 M5 7 + M2 M6 8 = COST M7 matrix 11jayashrisk
  • 12.  NONARITHMETIC STATEMENTS  DO, IF GO TO ,etc replaced by sequential ordering of individual matrix entries.  Operators are defined in later phases of compiler Operator Operand1 Operand2 Return COST End RETURN ( COST) ; END ; Matrix for RETURN & END statement 12jayashrisk
  • 13.  NONEXECUTABLE STATEMENTS  No intermediate form for these statements  Information of these statements is entered into tables Name Base Scale Precisio n(bits) Storage class location COST BINARY FIXED 31 STATIC 0 RATE BINARY FIXED 31 STATIC 4 START BINARY FIXED 31 STATIC 8 FINISH BINARY FIXED 31 STATIC 12 13jayashrisk
  • 14.  Problem no. 3 – Storage Allocation  Storage allocation routine scans the identifier table and assigns a location to each scalar.  Absolute address is unknown at load time.  Relative address format  Temporary locations for intermediate results of the matrix(M!,M2,etc) Operand Sign bit(1) 31 binary digit COST S RATE I START G FINISH N 14jayashrisk
  • 15.  Problem no. 4 – Code Generation  Based on matrix and table compiler generates object code  A table with matrix operation and associated matrix code is used for creating object deck.  Operators are treat as macro definition, operands as arguments and production table as macro definition. 15jayashrisk
  • 16. Standard code definition for -,*,+,= - L 1,&OPERAND1 S 1,&OPERAND2 ST 1,M&N ------------------------------- * L 1,&OPERAND1 S 1,&OPERAND2 ST 1,M&N ------------------------------------ + L 1,&OPERAND1 S 1,&OPERAND2 ST 1,M&N ------------------------------------ = L 1,&OPERAND1 S 1,&OPERAND2 ST 1,M&N ---------------------------------- MATRIX GENERATED CODE 1 - START FINISH L 1,START S 1,FINISH ST 1,M1 2 * RATE M1 L 1,RATE M 0,M1 ST 1,M2 3 * 2 RATE L 1,=F’2’ M 0,RATE ST 1,M3 4 - START FINISH L 1,START S 1,FINISH ST 1,M4 5 - M4 100 L 1,M4 S 1,=F’100’ ST 1,M5 6 * M3 M5 L 1,M3 M 0,M5 ST 1,M6 7 + M2 M6 L 1,M2 A 1,M6 ST 1,M7 8 = COST M7 L 1,M7 ST 1,COST Code definition Code generation 16jayashrisk
  • 17.  Questions  Was it a good idea to generate code directly from the matrix? MACHINE INDEPENDENT OPTIMIZATION  Have we made the best use of machine we have at our disposal? MACHINE DEPENDENT OPTIMIZATION  Can we generate machine language directly? 17jayashrisk
  • 18.  OPTIMIZATION(MACHINE-INDEPENDENT)  Delete all duplicate matrix entries of sub expression occurs in the same statement more than once(a common sub expression)  Modify all references to the deleted entries  Done before code generation  Example Matrix with common sub expression Matrix after elimination of common sub expression 1 - START FINISH 1 - START FINISH 2 * RATE M1 2 * RATE M1 3 * 2 RATE 3 * 2 RATE 4 - START FINISH 4 5 - M4 100 5 - M1 100 6 * M3 M5 6 * M3 M5 7 + M2 M6 7 * M2 M6 8 = COST M7 8 = COST M7 18jayashrisk
  • 19.  Other machine independent optimization steps are:  Compile time computation of operations, both of whose operands are constants  Movement of computations involving nonvarying operands out of loops  Use of the properties of Boolean expression to minimize their computation. 19jayashrisk
  • 20.  machine dependent optimization steps are:  For temporary storage use registers, this reduce the number of loads and stores from 14 to 5 in our example  Use shorter and faster instructions whenever possible  Advantages  Reduces memory space needed for the program  Execution time of the object program by factor of 2 20jayashrisk
  • 21.  OPTIMIZATION(MACHINE-DEPENDENT)  Done while generating code Optimized matrix First try Improved code 1 - START FINISH L S ST 1,START 1,FINISH 1,M1 L 1,START 1,FINISH M1-> R1 2 * RATE M1 L M ST 1,RATE 0,M1 1,M2 L MR 3,RATE 2,1 M2->R3 3 * 2 RATE L M ST 1,=F’2’ 0,RATE 1,M3 L M 5,=F’2’ 4,RATE M3->R5 4 5 - M1 100 L S ST 1,M1 1,=F’100’ 1,M5 S 1,=F’100’ M5->R1 6 * M3 M5 L M ST 1,M3 0,M5 1,M6 LR MR 7,5 6,1 M6->M7 7 + M2 M6 L A ST 1,M2 1,M6 1,M7 AR 3,7 M7->R3 8 = M7 COST L ST 1,M7 1,COST ST 3,COST 21jayashrisk
  • 22.  ASSEMBLY PHASE  Assembly phase is similar to pass 2 of assembler  Defines labels and resolves all references 22jayashrisk
  • 24.  LEXICAL PHASE  Task  To parse the source program into basic elements or tokens of the language  Build literal table and an identifier table  Build a uniform symbol table  Database  Source program(string of characters)  Terminal table Symbol Indicator precedence ; yes Procedure no 24jayashrisk
  • 25.  Database  Literal table  Identifier table  Uniform symbol table Literal Base Scale Precision Other information Address 31 Decimal Fixed 2 Name Data attribute Address WCM Filled by later phases Table Index IDN 1(WCM) 25jayashrisk
  • 26.  Algorithm  Input string is separated into tokens by break characters  Tokens are checked with entries of terminal table  If match then token is classified as terminal symbol and an uniform symbol is created for type TRM  If not matched then checked as identifier or literal  If token start with alphabet and contain up to 30 more characters or underscores. then classified as identifier and an uniform symbol is created for type IDN  If not then checked as literal  If not fit into one of these categories, it is an error. 26jayashrisk
  • 27.  SYNTAX PHASE  TASK  Recognize the major construct of the language and to call the appropriate action routines that will generate the intermediate from or matrix for these constructs.  Databases  Uniform symbol table  stack Table Index 27jayashrisk
  • 28.  Algorithm  Reduction are tested consecutively for match between old top of stack field and the actual top of stack until match is found.  When matched is found, the action routines specified in the action field are executed in order from left to right.  When control returns to the syntax analyzer, it modifies the top of stack to agree with the new top of stack field.  Step 1 is then repeated starting with the reduction specified in the next reduction field. 28jayashrisk
  • 29.  Interpretation phase  It is a collection of routines that are called when a construct is recognized in the syntactic phase.  Routines are used to create an intermediate form of the source program and add information to the identifier table. 29jayashrisk
  • 30.  Databases  Uniform symbol table  Stack  Identifier table  Matrix Name Base Scale Precision Storage class Array bound Structure info Literal value Block info other address Uniform symbol Uniform symbol Uniform symbol chaining Operator Operand1 operand2 30jayashrisk
  • 31.  Temporary storage table  Algorithm  It contains collection of individual action routines that accomplish specific tasks when invoked by the syntax analysis phase  Routines are  Do any necessary additional parsing  Create new entries in the matrix or add data attributes to the identifier operator and operands and insert them into the matrix. MTXN Base Scale Precision Storage class Other address 31jayashrisk
  • 32.  Optimization(machine independent optimization)  Databases  Matrix  Identifier table  Literal table Operator Operand1 Operand2 Forward pointer Backward pointer 32jayashrisk
  • 33.  Algorithm  Elimination of common sub expressions  Common sub expression must be identical and must be in same statement 1. Place the matrix in a form so that common sub expressions can be recognized 2. Recognize two sub expressions as being equivalent 3. Eliminate one of them 4. Alter the rest of the matrix to reflect the elimination of this entry 5. Rescan the matrix for possible crated common sub expressions repeat 1 to 5 until no change occur 6. Eliminate from the temporary storage table any MTX entries that are no longer needed 33jayashrisk
  • 34.  Example Source code B=A A=C*D*(D*C+B) MATRIX BEFORE OPTIMIZATION M line no Operator Operand1 Operand2 Backward forward M1 = B A 0 2 M2 * C D 1 3 M3 * D C 2 4 M4 + M3 B 3 5 M5 * M2 M4 4 6 M6 = A M5 5 ? MATRIX BEFORE OPTIMIZATION M line no Operat or Operan d1 Operan d2 Backw ard forwar d M1 = B A 0 2 M2 * C D 1 3 M3 * C D 2 4 M4 + B M3 3 5 M5 * M2 M4 4 6 M6 = A M5 5 ? MATRIX AFTER OPTIMIZATION M line no Operat or Operan d1 Operan d2 Backwa rd forward M1 = B A 0 2 M2 * C D 1 4 M3 * C D 2 4 M4 + B M2 2 5 M5 * M2 M4 4 6 M6 = A M5 5 ? 34jayashrisk
  • 35.  Compile time compute  Saves space and execution time for object program  Used for arithmetic computation within loop Example A=2*276/92*B = (2*276/92)*B = 6*B Before optimization M1 * 2 276 M2 / M1 92 M3 * M2 B M4 = A M3 After optimization M1 M2 M3 * 6 B M4 = A M3 35jayashrisk
  • 36.  Boolean expression optimization  Use properties of Boolean expression to shorten their computation  Example If(a or b or c) If a is true the no need to check b and c So eliminate that part 36jayashrisk
  • 37.  Move invariant computations outside of loops  If the computation within a loop depends on a variable that does not change within that loop, the computation may be moved outside the loop  Recognition of invariant computations  Example For(i=0;i<10;i++) { a=10; i=i*2; } 37jayashrisk
  • 38.  Discovering where to move the invariant computation  Move the computation to a position directly preceding the LOOP from which it comes  Moving the invariant computation  Delete the invariant computation from its original position in the matrix and insert it into the appropriate place 38jayashrisk