SlideShare a Scribd company logo
1 of 38
 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 (20)

Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
 
Design of a two pass assembler
Design of a two pass assemblerDesign of a two pass assembler
Design of a two pass assembler
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assembler
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Unit 2
Unit 2Unit 2
Unit 2
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compiler design
Compiler designCompiler design
Compiler design
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Macro Processor
Macro ProcessorMacro Processor
Macro Processor
 
Loaders
LoadersLoaders
Loaders
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 

Viewers also liked

Viewers also liked (8)

Assembler1
Assembler1Assembler1
Assembler1
 
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 1venkatam
 
Building blocks 2
Building blocks 2Building blocks 2
Building blocks 2NAZIRGUJJAR
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdfSemsemSameer1
 
Power of call symput data
Power of call symput dataPower of call symput data
Power of call symput dataYash Sharma
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answerRaajTech
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMugdhaSharma11
 
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-generationIffat Anjum
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationAkhil Kaushik
 
Unit ii-111206004636-phpapp01
Unit ii-111206004636-phpapp01Unit ii-111206004636-phpapp01
Unit ii-111206004636-phpapp01riddhi viradiya
 
Embedded programming u3 part 1
Embedded programming u3 part 1Embedded programming u3 part 1
Embedded programming u3 part 1Karthik Vivek
 
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 CompilerMarina 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.docxvenkatapranaykumarGa
 
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 optionFranck Pachot
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework HelpC++ Homework Help
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 

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
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 

Recently uploaded

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 

Recently uploaded (20)

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

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