Boolean Expressions, Backpatching - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Boolean Expressions, Backpatching, Quadruples, Recall, Reduction, Semantic Actions, Control Statements are basic concepts discussed of course.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekavia
ekavia 🇮🇳

4.3

(58)

241 documents

1 / 43

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Compiler
Construction
Lecture 40
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Partial preview of the text

Download Boolean Expressions, Backpatching - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 40

2

Boolean Expressions

E → E 1 and M E 2

{ backpatch(E1.truelist, M.quad); E.truelist = E 2 .truelist; E.falselist = merge(E 1 .falselist, E 2 .falselist);}

So the target for E 1 .truelist must be the beginning of code generated for E (^2)

4

Boolean Expressions

E → E 1 and M E 2

{ backpatch(E1.truelist, M.quad); E.truelist = E 2 .truelist; E.falselist = merge(E 1 .falselist, E 2 .falselist);}

M.quad records the number of the first statement of E 2 .code.

5

Boolean Expressions: OR

E → E 1 or M E 2

backpatch(E1.falselist, M.quad); E.truelist = merge(E 1 .truelist, E 2 .truelist); E.falselist = E 2 .falselist; } If E1 is false, need to test E 2

7

Boolean Experssions

E → ( E 1 ) { E.truelist = E 1 .truelist; E.falselist = E 1 .falselist; }

8

Boolean Experssions

E → id 1 relop id 2 { E.truelist = makelist(nextquad()); E.falselist = makelist(nextquad()+1); emit(‘if’ id 1 relop id 2 ‘goto _’) ; emit(‘goto _’ ); }

10

Boolean Experssions

E → false { E.falselist = makelist(nextquad()); emit(‘goto _’ ); }

11

Boolean Expressions

M → ε { M.quad = nextquad(); }

13

Backpatching

 In response to reduction of a < b to E, the two quadruples

100: if a < b goto _

101: goto _

are generated

14

Recall

E → id 1 relop id 2 { E.truelist = makelist(nextquad()); E.falselist = makelist(nextquad()+1); emit(‘if’ id 1 relop id 2 ‘goto _’) ; emit(‘goto _’ ); } View this in a parse tree

16

Backpatching

 The marker non-terminal M in the production

E → E 1 or M E 2

records the value of nextquad which at this time is 102.

17

E.t = {100} E.f = {101}

c < d

a < b

e < f

M.q = 102

or and

ε

19

E.t = {100} E.f = {101}

E.t = {102} E.f = {103} c < d

a < b

e < f

M.q = 102

or and

ε

20

Backpatching

 The marker non-terminal M in the production

E → E 1 and M E 2

records the value of nextquad which at this time is 104.