0% found this document useful (0 votes)
11 views5 pages

Unit-3-Boolean Expression

Compiler Design Boolean expression

Uploaded by

nihilsankarns
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Unit-3-Boolean Expression

Compiler Design Boolean expression

Uploaded by

nihilsankarns
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
‘CODE GENERATION By EXPRESSIONS - ; polean expressions have two primary purposes. They are used to compute s, but more often they are used as conditional expressions in statements ter the flow of control, such as if-then-else, or while-do statements. yolean expressions are composed of the boolean operators (and, or, and not) d to elements that are boolean variables or relational expressions. Relational ons are of the form £,relop£,, where E, and E, are arithmetic expressions. Here we consider boolean expressions generated by the following grammar: FE or E] E and E | not E | (E) | 1d relop id | true false hods of Translating Boolean Expressions: shods of representing the value of a boolean expression. There are two principal met pater! te a boolean expression se numerically and to evalua * To encode true and fal ften, 1 is used to denote true and 0 to analogously to an arithmetic expression. of denote false. ‘ontrol, that is, representing the * To imy t boolean expressions by. flow of : ne session by a position reached in a program. This method val boolean exp program. Th is ints convenient in implementing the boolean expressions in flow-of- control statements, such as the if-then and while-do statements. Representation — ce, Expressions will be evaluated completely Here, 1 denotes true and 0 denotes fals Toft to right, in a manner similar fo 2 thmetic expressions. For example: —_ { E.place : = newtemp; emit(E.place ': =’ 1’) } { E.place : = newtemp; emit(E place *; =’ 0’) } ‘ Short-Cireuit Code: We can also translate a boolean expression into three-address code seneratingcode for any of the boolean operators and without having the code ni evaluate the entireexpression. This style of evaluation is sometimes called “sb or “jumping” code, It ispossible to evaluate boolean expressions wit ing code for the boolean operators and,or, and not if we represent the v: ‘an expression by a position in the code sequence. ODL Translation of a to E.true to false (©) while-do "Fig. 6.7 Code for if-then, if-then-else, and while-do statements ed definition for flow-of-control statements SEMANTIC RULES E.true : Efalse : newlabel; = S.next; S.code : = E.code || gen(E.true ‘:’) || S,.code ll gen(‘goto’ S.next) || gen( Efalse ‘:') || S,code E.true : = newlabel; ‘Efalse : = Sinext; , wt S,.next : = S.begin; x S.code : = gen(S.begin ‘:)\| E.code || gen(E.true ‘:’) || S;-code || gen(‘goto’ S.begin)

You might also like