Download presentation

Presentation is loading. Please wait.

Published bySydnee Ramirez Modified over 3 years ago

1
Short circuit code for boolean expressions: Boolean expressions are typically used in the flow of control statements, such as if, while and for statements, the effect of such boolean expression can be represented by the position of the program after the expression is evaluated. Jump code can be directly generated without evaluating the expressions explicitly. The value of a boolean expression can sometimes be determined without evaluating the whole expression. Example: if (p && (p->next)) { p = p->next;}

2
Code generation for flow of control statements: S->if E then S S->if E then S else S S->while E do S –S -> if E then S1 Evaluate E into t If (t = true) goto ETRUE goto EFALSE ETRUE: code for S1 EFLASE:

3
Code generation for flow of control statements: –S -> if E then S1 else S2 ??? –S -> While E DO S1 ??? –How about these two? S -> Repeat S until E S -> For id := E1 to E2 do S1 endfor

4
Short circuit code for the control flow statements If E then S1 If E then S1 else S2

5
Short circuit code for the control flow statements

6
Code generation for flow of control statements: S->if E then S S->if E then S else S S->while E do S Attributes: E.true: the label to which control flows if E is true. E.false: the label to while control flows if E is false E/S.code: three-address code for E/S S.next: the next three-address code following the three address code of S. Functions to be used: || concatenate three address code

7
S->if E then S1 { E.true = newlabel; E.false = S.next; S1.next = S.next; S.code = E.code || gen(E.true, “:”) || S1.code; } S->if E then S1 else S2 { E.true = newlabel; E.false =newlabel;S1.next = S.next; S2.next = S.next; S.code = E.code || gen(E.true, “:”) ||S1.code|| gen(“goto” S.next) || gen(E.false ‘:’) || S2.code; } S->while E do S1 { S.begin = newlabel; E.true := newlabel; E.false = S.next; S1.next = S.begin; S.code = gen(S.begin ‘:’) || E.code || gen(E.true, ‘:’) || S1.code || gen(‘goto’ S.begin); }

8
–Control flow translation of boolean expressions: Basic idea: generate the jumping code without evaluating the whole boolean expression. Example: Let E = a < b, we will generate the code as (1) If a < b then goto E.true (2) Goto T.false Grammar: E->E or E | E and E | not E | (E) | id relop id | true | false.

9
E -> E1 or E2 { E1.true = E.true; E1.false = newlabel; E2.true = E.true; E2.false = E.false; E.code = E1.code || gen(E1.false ‘:’) || E2.code} E->E1 and E2 {E1.true = newlabel; E1.false = E.false; E2.true = E.true; E2.false = E.false; E.code = E1.code || gen(E1.true ‘:’) || E2.code} E->not E {E1.true = E.false; E1.false = E.true; E.code = E1.code} E->(E1) {E1.true = E.true; E1.false = E.false; E.code = E1.code;} E->id1 relop id2 {E.code = gen(‘if’ id1.place relop.op id2.place ‘goto’ E.true); gen (‘goto’ E.false);} E->true {gen(‘goto’ E.true);} E->false{gen(‘goto’ E.false);}

10
Example: a < b or (c < d and e < f) Example: while a< b do if c < d then x := y + z; else x: = y – z;

Similar presentations

OK

1 Structure of a Compiler Front end of a compiler is efficient and can be automated Back end is generally hard to automate and finding the optimum solution.

1 Structure of a Compiler Front end of a compiler is efficient and can be automated Back end is generally hard to automate and finding the optimum solution.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To ensure the functioning of the site, we use **cookies**. We share information about your activities on the site with our partners and Google partners: social networks and companies engaged in advertising and web analytics. For more information, see the Privacy Policy and Google Privacy & Terms.
Your consent to our cookies if you continue to use this website.

Ads by Google

Free download ppt on forest and wildlife Ppt on conservation of momentum example Ppt on diode as rectifier circuit Ppt on 2nd world war Ppt on barack obama leadership profile Ppt on bill gates life Ppt on db2 mainframes Ppt on ministry of corporate affairs company Bcd to 7 segment display ppt online Ppt on ideal gas laws