 Hello everyone, welcome to the session on Intermediate Code Generation in Compiler Design. Now, what is this Intermediate Code Generation? As we know that compiler is having many phases and every phases have given a task to perform this. When a source program is given to the compiler, it will convert that into a target program. Well, during the conversion of this source program to the target program, the source program is converted in many phases. Basically, compiler is divided in front end and the back end. So, output of the front end whatever is coming that is in some form that we can call it as Intermediate Code. So, let us see what this how the Intermediate Code Generation is generated in compiler design. Talking about the learning outcome of this session, at the end of this session you will be able to describe and differentiate the types of Intermediate Representations used for Intermediate Code Generation, it is considered as an Intermediate Language. So, you can differentiate them how many types are there and you can describe. And at the end of this session, you will be able to generate Intermediate Representation for a given arithmetic statement. As I told earlier that Intermediate Code is generated as an output of the front end. You can see in this diagram that so, this is the front end of the part of the front end of the compiler and this is the actual back end. What is the back end is doing? Back end is generating the target code target program which is done by the code generator. And in the front end there are many phases earlier to this also like syntax and semantic analysis and all. So, the output of the parser is given to the static checker and that is given as an Intermediate Code Generator and it is generating one form of the source program which is called as Intermediate Code. So, in the analysis and synthesis model of a compiler, the front end is translating source program into the independent Intermediate Code. What we can say is Intermediate Code is independent and the back end of the compiler is using this Intermediate Code to generate the target code which is machine dependent. So, Intermediate Code or you can say Intermediate Representation or you can say Intermediate Languages, these are machine independent. These are not dependent on the machine whereas, the target code is machine dependent code. Intermediate Code can be a language specific or it may be language independent. If we are talking about language specific, then it is a byte code you can take as an example in Java and language independent, it is in the one of the form called as 3 address code. We will be seeing soon that what are these codes and all. So, what is the advantage of machine independent Intermediate Code? Why this Intermediate Code is taken as machine independent? Because if it is machine independent, automatically the portability is enhanced because it is not dependent on the machine. Modifications of front end and back end are facilitated, so no dependency is there that if front end is changed then the back end has to be changed, no not necessary. So, separately we can do the modifications. Optimization can be applied to the Intermediate Code so that the performance can be increased. Overall, the compiler working of the performance can be increased. We can say the conversion of source program into target program process can be increased as a performance. Now, basically there are three types of Intermediate Code representation or you can say Intermediate Languages also. So, the first type is Syntax Tree which is in two forms one is called as Abstract Syntax Tree and another one directed as Cyclic Gram. The example given here is of Syntax Tree Abstract Syntax Tree. Second notation is a Post Fixed Notation in Polish Notation. So, any statement which is converted as a Post Fixed Notation is considered as an Intermediate Code and the third type of the statement or type of the representation is called as Three-Address Code which is into one of the two forms basically there are three forms, triples, quadruples or indirect triples also. So, this is one of the simple example the statement is A equal to B plus C this statement is converted as a tree which is in this form where this B plus C is first evaluated the output or the temporary result is stored here and this is given as an input to this and that is assigned to this A. So, the same statement if we are converting in Post Fixed you can see this is the Post Fixed Notation of A equal to B plus C where the first operation B is plus C is evaluated and then the A equal to whatever the result is storing. The same statement can be converted as Three-Address Code here we will see later on that why it is called as Three-Address Code in all. So, here T1 equal to B plus C is one of the operation and that operation the result of T1 is stored again in A. So, this form is called as Three-Address Code. So, basically this intermediate representation is having three forms Syntax Tree, Post Fixed Notation and Three-Address Code. Let us see one by one. So Syntax Tree as we have seen it is a tree representation of a Syntax Tree structure of a source code how the source code is executing what is the sequence of the code execution according to that the tree is generated and each node of the tree is denoting the construction which is occurring in a source code. So, every statement is converted a complete program can be converted as a tree and every part of sub tree is can be a statement also. So, here in the tree root node always represents an operation the basic operation and leaf nodes at the end whatever the leaf nodes are there those are representing the operands. So, you can see this example one of the statement is A multiplied by minus B plus C. So, here it is a unary minus operation. So, you can see that here that the first operation it is executing as it is a bracket. So, according to the precedence of operation B plus C is executing and that is now taken as a unary minus. So, it is negation operation will work here and then it is multiplied by A. So, this is what the syntax to example. Next one is postfix notation as earlier we talked about. So, it is a postfix notation basically in Polish notation there are three types of notations are there prefix postfix and the normal infix operation also infix means the normal operations whatever those are executing. So, in postfix operation what happens that the operands are first written and then the operator is written. If we are considering the binary operation then operand 1 is written and then operand 2 then the operator. Why it is postfix notation is used because it is easily implemented by stack we will see in the later videos how the postfix notation is implemented in stack and all. So, basically intermediate code one of the postfix notation is of this one. So, the same example another example we have taken that is A star B plus C minus D. So, this statement is converted in postfix notation like this. How it is converted like this because in postfix notation usually a tree form you can see that a tree is converted as a post order traversal of a tree is converted as a postfix notation of any statement. So, here you can see that first as this A is pushed into the stack B is pushed into the stack C is pushed into the stack whenever the operator comes the two operands are propped from the stack the result is stored again pushed into the stack and then again the next operation will work again the results is pushed into the stack and then the two results are again taken as in this operation. So, this is the postfix notation of this particular statement. Next form is a three address code the name itself is there here the three address why address are there because in this one whatever the operands are there the results are there the result wherever you are storing everything is considered as one of the address here. So, this form is called as a three address code basically this three address code is very close to assembly language we will see later that how this three address code can be converted into the assembly language. So, whenever assembly language conversion makes it easier it means that the machine code generation is becoming easier. So, it is having the three address code is having the statement in the form like this X assigns to Y operator Z. So, here what happens operand 1 the operate operator and then operand 2 and the result is stored in this one. So, how many addresses are there here X is one of the form of the address Y is one of the form of the address and Z is the one of the form of the address. So, hence it is called as your operate that is the three address code. So, the same statement is converted as three address code how many operations are there here the basic three operations are there. So, all individual operations are taken differently. So, the single statement is converted as three address codes in three statements. Let us see one example here the same example that is A plus B divided by C plus D. So, the syntax tree generated like this here in the postfix notation this is converted like this and the three address code is this form. Let us see another example A multiplied by B plus C multiplied by D. So, here the operation multiplication takes place first. So, therefore, these are the nodes and then finally the plus operation. So, the same can be converted as postfix notation here and then the three address code here. Another example your this is A divided by B multiplied by C plus D. So, how this operation takes place first A divided by B then the multiplication then the plus operation. So, accordingly the postfix notation accordingly the three address code. Now, the same thing one more example I have given here you can pause the video and represent the following statement in all three forms for the intermediate code. You have to generate the syntax tree you have to generate the postfix notation as well as the three address code. Let us see the answer of this one. This is the syntax tree. This is the postfix notation and this is the three address code. Now, the syntax tree can be represented at a directed acyclic graph also. What will happen here whatever the repetition is there you can see here that B star minus C B star minus C are the two operations here taken as a syntax tree, but the same operation can be taken once here. Therefore, in the directed acyclic graph once the operation takes place and if no changes are there in the result the same operation is again not considered here the same operation the same pointer is used for this. You can see the example of this how this is implemented as a data structure in this one. These are my references thank you.