 Hello everyone, welcome to the session on 3-address code generation for Boolean expression. In this session we will be discussing about the 3-address code generation for the Boolean expression considered for flow of control statement means here whatever the sequence of execution is there for the problem statement for them how the Boolean expressions are converted into the 3-address code we will be looking at that one. At the end of this session you will be able to generate the translation scheme of Boolean expressions for flow of control statements another learning outcome is convert a given control flow statements into its 3-address code. Let us move ahead to do these things basically there are two methods of translating the Boolean expression we have seen in the earlier video the first method that is numerical representation that how a normal Boolean expression is converted into a 3-address code for the numerical representation. Now in this video we will be looking at the second method that is the Boolean expressions which are used for controlling the flow of the execution of the program. So for this one for the second method we are representing the Boolean expression for the position of the execution of the statement. So after whenever a particular statement is checked by for a condition according to the Boolean expression based on the true and false value the control flow the execution flow of the program will be decided what to do next. So considering this one in this one usually the statements like if the L statements or loop statements you may say switch case statements these are used for these one. Let us look at the flow of control statements which are used for using the Boolean expressions. We know that the value of the Boolean expression is implicit that is the Boolean expression value is either true or false value and this value we will be representing we will be using for the flow of control. So consider this example here that if E then S so what is here if E is true then the statement S is executing. So therefore what we are saying here is E must be true if the statement S is reached. So indirectly S is executing when E is true right. Now let us see how it is executing we are talking about the grammar here we are considering the three things that is a normal if then statement and other type if then L statement or while do statement consider the grammar for it a statement S is there S is representing a statement here even S1 and S2 also. So the first statement we are representing is a simple if statement that is if the Boolean expression B if it is true then S1 is executing. The second type of expression is if and else so in this case what happens if this Boolean expression B is true then S1 is executing as S2 is executing. The third type of statement which we are considering here is while loop here in this one while the Boolean expression is true the statement S1 is executing and this loop is executing or repeating till this value of B a Boolean expression B is true once it is false it will come out of that loop. So here B is considered as a normal Boolean expression S1, S2, S these are the programming statements. So let us talk about the simple statement the first type of statement which we have considered so the type of statement is S representing producing if Boolean expression then else S1. So here we will be considering the two things here that is one is the code how the code is generated for the flow of control statement another one we will be looking at the syntax directed definitions. So in this one you can see that the first type that is this one is code for the control flow statement what is this code how it is executing what we are saying here that if the Boolean expression B is true then S1 is executing. So for this we require the thing that is the code for Boolean expression B has to be first generated ok whatever the expression for that Boolean expression is given that is executed after that it is generating two levels what are those two levels what will happen if the Boolean expression B is true what will happen if the Boolean expression is false. So for these two things the flow of the control execution is changing. So for this case we are creating two levels B dot true which is representing the statement which is executing when the Boolean expression value is true and B dot false this level is representing the statement where if the statement that is the Boolean expression B is false then it is executing. So in this case what happens if B code is generated after that the two levels are generated. So if that Boolean expression is true then S1 is executing else it is coming down that is else or if it is true it is executing S1 and again coming down. So this is what the flow of control statement which is the code is generating. So for this let us see what is the syntax record definition. So what we are doing for this one B dot true a new level we are creating for B dot false not necessary to create a new level why because B dot false this is representing the end of S1 that is S1's next code or you can say a statements next code directly S is our statement so that is the next code therefore we are saying here that B dot false is equal to S1's next equal to S next also it is representing the next of your current statement. So the code of S is generated as first B is code what we have seen here then the level B true is generated so this B true as it is it is writing here as a level and then S1's code is written and we are saying that we are not explicitly writing the false level for B because we are considering that as S1's next or S next. So that will be taken directly by this one let us see the example for this. So this is our example if the statement is if a less than B then S1. So what will happen here the Boolean expression B is considered as a less than B. So here we are assuming that the attributes true or false value those are existing as L true and L false. So these are the levels which are created for this one. So if this is the statement what will be the level created for this? This is the three address code if a less than B then go to L true. So that is what is L true? L true is the execution of S1's code. What is S1? S1 is the next statement which is executing when the Boolean expression B that is a less than B is true. So that is written here otherwise go to L false. What is L false? L false is the next statement after S1 or it is the next statement of your statement so that is L false. So this is what the three address code which is generated by the above example. Let us talk about another type of expression which is if and else. So if Boolean expression B is true then S1 is executing. If Boolean expression B is false then S2 is executing. So here also the same thing first we have to generate the code for B we have to see that we have to generate the three address code for Boolean expression B first. So that is generated then again we require two levels that is B true and B false. Why? Because what to execute if the Boolean expression B is true what to execute if the Boolean expression is false. So for both the things we have generated now what will happen if this is true then it is coming for S1's code and after that it has to go to the next of S. So that is directly given here otherwise if it is false then it is coming to false and it is executing this S2's code that is what the code which is generated for the flow of code control statement. Now the same thing we have represented that as a translation scheme here or a syntax directed definition so it is in this format. So what is happening here B is true label generating, B is false label generating. Now what do you mean by S1's next, S1's next is nothing but your S2's next that is equal to S next. So whatever this is there this is called as this statement. Next what is the sequence how the code is generating? First Boolean expression B's code is generating then the label true is written so that it generate written here and then we have to write S1's code so S1's 3 address code is generated and then it is generating one more string here that is go to S next. So here it is generating that go to the next one so that is written. So for that the code is generated next is the label that is B dot false so next label is this one and after that S2's code is generating and then it is coming down. So this is what the 3 address code generation which is presented as a syntax directed definition. Let us see the example for this the example is like this in this one if A less than B or C less than D then S1 else S2 so what will happen if A is less than B then it has to go to true so it is obviously or is there so true directly it will come to L true it will not go for the next statement but if it is false then it has to come to the next statement it has to check whether it is true if it is true it will come otherwise it will go for the false statement that is S2's execution otherwise it will execute the next code that is S1's code okay after the execution it will come out of it. Let us see another syntax directed definition for while it is same as you can see like if then else what will happen here this is the loop statement where it is beginning every time so what is there the S1 code is repeating till B is true so here B's code is executed first the 3 address code is generated again true and false values are there if the B's value is true then it is executing S1's code now here one more thing the difference here is it has to go to begin again so that is what it is going to loop back again and once the B's code is false then it will come out of this one so this is the flow of control statement for this while loop the same thing is represented as the syntax directed definition here so here the new label begin is created true label is created false label not to create not required because it is the next statement of your S so S1 dot next is again a begin one so that is given here and then what we are doing we are generating the begin label and then B's code then true label and then S1's code and then the statement what we are written that is go to begin. So you can see here this is our example while A less than B do this is the statement this is the statement so for this the 3 address code is generated using the above syntax related definition so you can see here if this is true then directly it is going to L2 so L2 is a loop where the statement is there so it will come here it will execute this part and again the repetition is go to L1 so every time it will go here once it is false it will come to else next that is down here like this the 3 address code is generated for the while statement pause the video and try to convert the given below expression into the 3 address code using the above translation schemes this is your example given for you now the answer is like this one it will generate the statement like this these are my references thank you.