Backpatching II - PowerPoint PPT Presentation

About This Presentation
Title:

Backpatching II

Description:

... We try to design the function Backpatch in such a way that Y is unique for every X Backpatching II Prepared by: Shreyas Ashok Karkhedkar Roll ... – PowerPoint PPT presentation

Number of Views:712
Avg rating:3.0/5.0
Slides: 14
Provided by: Shrey8
Category:

less

Transcript and Presenter's Notes

Title: Backpatching II


1
Backpatching II
  • Prepared by
  • Shreyas Ashok Karkhedkar
  • Roll Number 04CS3013

2
Backpatching II
  • Consider the following grammar
  • E ? E1 or ME2
  • E ? E1 and ME2
  • E ? not E1
  • E ? (E1)
  • E ? id1 relop id2
  • E ? false
  • E ? true
  • M ? e

3
Backpatching II
  • The corresponding semantic rules are given by
  • E ? E1 or ME2
  • Backpatch( E1.falselist,M.quad)
  • E.truelistmerge(E2.truelist,E1.truelist)
  • E.falselistE2.falselist

4
Backpatching II
  • E ? E1 and ME2
  • Backpatch(E1.truelist,M.quad)
  • E.falselistmerge(E1.falselist,E2.falselist)
  • E.truelistE2.truelist

5
Backpatching II
  • E ? not E1
  • E.truelist E1.falselist
  • E.falselist E1.truelist

6
Backpatching II
  • E ? (E1)
  • E.truelist E1.truelist

7
Backpatching II
  • E ? id1 relop id2
  • E.truelist makelist(nextquad)
  • E.falselist makelist(nextquad 1)
  • emit( if id1 relop id2 goto ____)
  • emit( goto ____)

8
Backpatching II
  • E ? false
  • E.falselist makelist(nextquad)
  • emit( goto ____)
  • E ? true
  • E.truelist makelist(nextquad)
  • emit( goto ____)

9
Backpatching II
  • M ? e
  • M.quad nextquad

10
Backpatching II
  • Example
  • Consider the string
  • altb or cltd and eltf
  • (Assuming that the grammar is left associative)

11
Backpatching II
  • The corresponding intermediate code is
  • 100 if ( altb ) goto L3
  • goto L1
  • 102 L1 if ( cltd ) goto L2
  • goto L4
  • 104 L2 if ( eltf ) goto L3
  • goto L4
  • L3 ..
  • ..
  • L4 ..
  • ..

12
Backpatching II
  • The code after backpatching becomes
  • 100 if ( altb ) goto ____
  • goto 102
  • 102 L1 if ( cltd ) goto 104
  • goto ____
  • 104 L2 if ( eltf ) goto ____
  • goto ____
  • L3 ..
  • ..
  • L4 ..
  • ..
  • This code is more similar to the machine code

13
Backpatching II
  • We define the function Backpatch (X , Y) as
    follows
  • Backpatch (X , Y) replace the line numbers
    listed in X with the value Y
  • Note We try to design the function Backpatch
    in such a way that Y is unique for every X
Write a Comment
User Comments (0)
About PowerShow.com