1 / 13

Backpatching II

Backpatching II. Prepared by: Shreyas Ashok Karkhedkar Roll Number: 04CS3013. Backpatching II. Consider the following grammar: E → E 1 or ME 2 E → E 1 and ME 2 E → not E 1 E → (E 1 ) E → id 1 relop id 2 E → false E → true M → ε. Backpatching II.

andra
Télécharger la présentation

Backpatching II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 → ε

  3. Backpatching II • The corresponding semantic rules are given by: E → E1 or ME2 { Backpatch( E1.falselist,M.quad) E.truelist=merge(E2.truelist,E1.truelist) E.falselist=E2.falselist }

  4. Backpatching II E → E1 and ME2 { Backpatch(E1.truelist,M.quad) E.falselist=merge(E1.falselist,E2.falselist) E.truelist=E2.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 → ε { M.quad = nextquad }

  10. Backpatching II • Example : Consider the string: a<b or c<d and e<f (Assuming that the grammar is left associative)

  11. Backpatching II • The corresponding intermediate code is: 100: if ( a<b ) goto L3 goto L1 102: L1: if ( c<d ) goto L2 goto L4 104: L2: if ( e<f ) goto L3 goto L4 L3: ….. ….. L4: ….. …..

  12. Backpatching II • The code after backpatching becomes: 100: if ( a<b ) goto ____ goto 102 102: L1: if ( c<d ) goto 104 goto ____ 104 L2: if ( e<f ) 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’

More Related