SlideShare a Scribd company logo
1 of 18
BACKPATCHING
SANTHIYA.T
BP150503
The easiest way to implement the syntax-
directed definitions in to use passes.
Frist, construct a syntax tree for the input
Then walk the tree in depth-first order, computing
the translations given in the definition.
The main problem with generating code for
Boolean expression and flow-of-control statement
is a singel pass is that during one single pass.
Statement will be put on a list of goto
statements whose labels will be filled in when
the proper label can be determine. We call this
subsequent filling in of labels backpatching.
Use three functions:
Makelist(i) creates a new list containing only i, an
index the array of quadruples;marklist returns a
pointer to the list it has made.
merge(p1,p2) concatenates the list pointed to
by p1 and p2, and returns a pointer to the
concatenated list.
backpatch(p,i) inserts I as the target label for
each of the statements on the list pointed to by
p.
Boolean Expressions
Construct a translation scheme suitable for
producing quadruples for boolean expressions
during bottom-up parsing.
We insert a marker nonterminal M into the
grammar to cause a semantic action to pick up,
the index of the next quadruple to be
generated.
E ->E1 or M E2
|E1 and M E2
|not E1
|(E1)
| id1 relop id2
| true
| false
M -> E
Consider the production E->E1 and E2.
If E1 is false, then W is also false, so the
statements on E1.false become part of E.false.
This target is obtained using the marker
nonterminal M.
Attribute M.quad records the number of the first
statement of E2.code.
With the production M->E we associate the
semantic action
{ M.quad := nextquad }
The variable nextquad holds the index of the
next quadruple to follow.
This value will be backpatched onto the
E1.truelist when we have seen the remainder
of the production E->E1 and M E2.
The translation scheme is as follows.
E->E1 or M E2 { backpatch(E1.falselist,M.quad);
E.truelist := merge(E1.truelist,E2.truelist);
E.falselist := E2.falselist }
E->E1 and M E2 { backpath (E1.treulist,M.quad);
E.truelist := E2.truelist;
E.falselist := merge(E1.false, E2falselist)}
E -> not E1 { E.truelist := E1.falselist;
E.falselist := E1.truelist}
E -> (E1) {E.truelist := E1.truelist;
E.falselist := E1.falselist}
E -> true {E.truelist := makelist(nextquad);
emit(‘goto_’)}
E -> false {E. false list := makelist(nextquad);
emit(‘goto_’)}
M -> e { M.quad := nextquad }
E -> id1 relop id2 { E.truelist := makelist(nextquad);
E.falselist := makelist(nextquad) +1 ;
emit(‘if’ id1.place relop.op id2.place
‘goto’_)
emit(‘goto_’)}
Flow-of-Control Statements
Backpatching can be used to translate flow-of-
control statements in one Pass.
We fix our attention on the generation of
quadruples, and the natation regarding
translation field names and list-handling
procedures from that section carries over to
this section as well.
Translation scheme grammar
S -> if E then S
| if E then S else S
| while L do S
| begin E end
| A
L –> L : S
| S
S  Statement,
L  Statement List
A  Assignment statement
E  Boolean Expression
A given statement in execution, it physically in
the quadruple array.
General approach will be to fill in the jumps
out of statements when their targets are found.
Not only do boolean expressions.
Scheme to Implement the Translation
A syntax-directed translation scheme to
generate translation for the flow-of-control.
The nonterminal E has two attributes E.truelist
and E.falselist.
L and S each also need a list of unfilled
quadruples that must eventually be completed
by backpatching.
Pointed to by the attributes L.nextlist and
S.listnext .
S.nextlist is a pointer to a list of all condition
and uncondition jumps and L.nextlist is
defined similarly.
The marker nonterminal M in the following
production record the quadruple numbers
S  while M1 do M2 S1
Labels and Gotos
Programming landuage construct for changing
the flow of control in a program is the label
and goto.
A compiler encounters a statement like goto L,
in must check that there is exactly one
statement with label L in the scope of this
goto statement.
The symbol table will have an entry giving the
compiler-generated label for the first three-
address instruction associated with the source
statement labeled L.
A label L is encountered for the first time in
the source program either in a declaration or as
the target of a forward goto, we enter L into
the symbol tabel and generate a symbolic label
for L.
THANK YOU

More Related Content

What's hot

Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler DesignShine Raj
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in CompilersMahbubur Rahman
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysisRicha Sharma
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Daniyal Mughal
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow GraphsJenny Galino
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical AnalysisMunni28
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler DesignKuppusamy P
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 

What's hot (20)

Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow Graphs
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
LR PARSE.pptx
LR PARSE.pptxLR PARSE.pptx
LR PARSE.pptx
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Module 11
Module 11Module 11
Module 11
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 

Viewers also liked

Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generationIffat Anjum
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocksShabeen Taj
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimizationWBUTTUTORIALS
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler designAnul Chaudhary
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation19magnet
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMSkoolkampus
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)bolovv
 
CBSE XII Boolean Algebra
CBSE XII Boolean AlgebraCBSE XII Boolean Algebra
CBSE XII Boolean AlgebraGuru Ji
 
Control Flow Analysis
Control Flow AnalysisControl Flow Analysis
Control Flow AnalysisEdgar Barbosa
 
Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)Tech_MX
 
Assignment statements
Assignment statementsAssignment statements
Assignment statementsDivya Devan
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generationrawan_z
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Iffat Anjum
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 

Viewers also liked (20)

Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
 
Code generation
Code generationCode generation
Code generation
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocks
 
Run time administration
Run time administrationRun time administration
Run time administration
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
 
CBSE XII Boolean Algebra
CBSE XII Boolean AlgebraCBSE XII Boolean Algebra
CBSE XII Boolean Algebra
 
Control Flow Analysis
Control Flow AnalysisControl Flow Analysis
Control Flow Analysis
 
Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)
 
Compiler Design QA
Compiler Design QACompiler Design QA
Compiler Design QA
 
Assignment statements
Assignment statementsAssignment statements
Assignment statements
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
Ch5a
Ch5aCh5a
Ch5a
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Optimisation
OptimisationOptimisation
Optimisation
 

Similar to Back patching

14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...venkatapranaykumarGa
 
In the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docxIn the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docxmecklenburgstrelitzh
 
Chapter -4.pptx
Chapter -4.pptxChapter -4.pptx
Chapter -4.pptxwoldu2
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design FileArchita Misra
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manualNitesh Dubey
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Keyappasami
 
Unit iv-syntax-directed-translation
Unit iv-syntax-directed-translationUnit iv-syntax-directed-translation
Unit iv-syntax-directed-translationAjith kumar M P
 
e computer notes - Reference variables
e computer notes - Reference variablese computer notes - Reference variables
e computer notes - Reference variablesecomputernotes
 
The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsMarkus Voelter
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptFamiDan
 
Excel Functions
Excel Functions Excel Functions
Excel Functions BHARAT JHA
 
33-Procedures-Switch Case Statements-27-03-2024.pdf
33-Procedures-Switch Case Statements-27-03-2024.pdf33-Procedures-Switch Case Statements-27-03-2024.pdf
33-Procedures-Switch Case Statements-27-03-2024.pdfYash218469
 

Similar to Back patching (20)

Compiler notes--unit-iii
Compiler notes--unit-iiiCompiler notes--unit-iii
Compiler notes--unit-iii
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
 
In the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docxIn the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docx
 
Ch1
Ch1Ch1
Ch1
 
Chapter -4.pptx
Chapter -4.pptxChapter -4.pptx
Chapter -4.pptx
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
 
Unit iv-syntax-directed-translation
Unit iv-syntax-directed-translationUnit iv-syntax-directed-translation
Unit iv-syntax-directed-translation
 
Ch8b
Ch8bCh8b
Ch8b
 
e computer notes - Reference variables
e computer notes - Reference variablese computer notes - Reference variables
e computer notes - Reference variables
 
The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methods
 
Assignment5
Assignment5Assignment5
Assignment5
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
Excel Functions
Excel Functions Excel Functions
Excel Functions
 
33-Procedures-Switch Case Statements-27-03-2024.pdf
33-Procedures-Switch Case Statements-27-03-2024.pdf33-Procedures-Switch Case Statements-27-03-2024.pdf
33-Procedures-Switch Case Statements-27-03-2024.pdf
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 

Recently uploaded (20)

Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 

Back patching

  • 2. The easiest way to implement the syntax- directed definitions in to use passes. Frist, construct a syntax tree for the input Then walk the tree in depth-first order, computing the translations given in the definition. The main problem with generating code for Boolean expression and flow-of-control statement is a singel pass is that during one single pass.
  • 3. Statement will be put on a list of goto statements whose labels will be filled in when the proper label can be determine. We call this subsequent filling in of labels backpatching. Use three functions: Makelist(i) creates a new list containing only i, an index the array of quadruples;marklist returns a pointer to the list it has made.
  • 4. merge(p1,p2) concatenates the list pointed to by p1 and p2, and returns a pointer to the concatenated list. backpatch(p,i) inserts I as the target label for each of the statements on the list pointed to by p.
  • 5. Boolean Expressions Construct a translation scheme suitable for producing quadruples for boolean expressions during bottom-up parsing. We insert a marker nonterminal M into the grammar to cause a semantic action to pick up, the index of the next quadruple to be generated.
  • 6. E ->E1 or M E2 |E1 and M E2 |not E1 |(E1) | id1 relop id2 | true | false M -> E
  • 7. Consider the production E->E1 and E2. If E1 is false, then W is also false, so the statements on E1.false become part of E.false. This target is obtained using the marker nonterminal M. Attribute M.quad records the number of the first statement of E2.code. With the production M->E we associate the semantic action { M.quad := nextquad }
  • 8. The variable nextquad holds the index of the next quadruple to follow. This value will be backpatched onto the E1.truelist when we have seen the remainder of the production E->E1 and M E2. The translation scheme is as follows.
  • 9. E->E1 or M E2 { backpatch(E1.falselist,M.quad); E.truelist := merge(E1.truelist,E2.truelist); E.falselist := E2.falselist } E->E1 and M E2 { backpath (E1.treulist,M.quad); E.truelist := E2.truelist; E.falselist := merge(E1.false, E2falselist)} E -> not E1 { E.truelist := E1.falselist; E.falselist := E1.truelist} E -> (E1) {E.truelist := E1.truelist; E.falselist := E1.falselist}
  • 10. E -> true {E.truelist := makelist(nextquad); emit(‘goto_’)} E -> false {E. false list := makelist(nextquad); emit(‘goto_’)} M -> e { M.quad := nextquad } E -> id1 relop id2 { E.truelist := makelist(nextquad); E.falselist := makelist(nextquad) +1 ; emit(‘if’ id1.place relop.op id2.place ‘goto’_) emit(‘goto_’)}
  • 11. Flow-of-Control Statements Backpatching can be used to translate flow-of- control statements in one Pass. We fix our attention on the generation of quadruples, and the natation regarding translation field names and list-handling procedures from that section carries over to this section as well.
  • 12. Translation scheme grammar S -> if E then S | if E then S else S | while L do S | begin E end | A L –> L : S | S S  Statement, L  Statement List A  Assignment statement E  Boolean Expression
  • 13. A given statement in execution, it physically in the quadruple array. General approach will be to fill in the jumps out of statements when their targets are found. Not only do boolean expressions.
  • 14. Scheme to Implement the Translation A syntax-directed translation scheme to generate translation for the flow-of-control. The nonterminal E has two attributes E.truelist and E.falselist. L and S each also need a list of unfilled quadruples that must eventually be completed by backpatching.
  • 15. Pointed to by the attributes L.nextlist and S.listnext . S.nextlist is a pointer to a list of all condition and uncondition jumps and L.nextlist is defined similarly. The marker nonterminal M in the following production record the quadruple numbers S  while M1 do M2 S1
  • 16. Labels and Gotos Programming landuage construct for changing the flow of control in a program is the label and goto. A compiler encounters a statement like goto L, in must check that there is exactly one statement with label L in the scope of this goto statement.
  • 17. The symbol table will have an entry giving the compiler-generated label for the first three- address instruction associated with the source statement labeled L. A label L is encountered for the first time in the source program either in a declaration or as the target of a forward goto, we enter L into the symbol tabel and generate a symbolic label for L.