Transcript for:
Understanding Compiler Phases and Structure

hi students welcome back coming to the next topic in the compiler design was faces of compiler so in this thesis of compiler we are going to learn about the structure exactly the structure of the compiler so in the previous video I explained about the language processing system so whatever the program you are taking how that program is internally convert mean internal what operations it is going to be done means whatever the high level language program you are returning that program is converted into come a similar low-level language that is assembly language and that to machine code okay now let's take only the compiler part and what are the phrases that are present in the compiler actually the compiler operates interfaces they compel us having different faces so what exactly a face is a face is a logical let me write the face okay what do you call the face a face easy logically interrelated so whatever the face you are taking that face is logically interrelated operations that takes source program that takes the source program and one representation one representation and produce output and another representation so that is a phase so phase is going to take input and gives output another so source program in one representation produce output in another representation that represents the face so in the compilers also define the compiler there are different phases or existence each phase input will gives output to another phase okay so whenever whatever the input it is taking that input is going to be converted and gives output in an another format that is a freeze okay so let me clearly show you how the phrases there are different phases that are exist in the compiler actually that there are the complete compiler is divided into two major phases there are two major phases again these major phases will be divided in two sub phrases so there are two major phases of compilation so what are those two major phases of compilation one is analysis space analysis phase and another is synthesis phase so the total compilation process is divided into two major phases one is analysis phase and another is a synthesis phase so what analysis phase consists of analysis phase starting it is machine independent it doesn't know what type of machine you are using but the analysis phase is machine independent but language dependent what language you are using okay so analysis phase is machine independent and language dependent next phase is a synthesis phase the synthesis phase is machine dependent machine dependent and language independent so from this word you understand analysis phase only concentrated on language whereas a synthesis phase is concentrating on the machine okay machine level language so it is concentrating on the languages that is a high-level language assembly language and synthesis phase II is concentrating on the machine level language now let's see what are the different phases that are present in the compiler okay so let's take these are the different phases this is structure of the compiler different phases are present first the source program whatever the program that you are written in high-level language there the source program that's source program enter into the compilation phase so what the camp will do the compiler will convert the high-level language into target program what is a target program of the compiler that is the low-level language okay then what are the different phases that are present in between the high level and the can't be in the conversion conversion process so these are all the different phases lexical analyzer syntax analyzer semantic analyzer intermediate code generator code optimizer and code generator total six phases are there okay total six phases lexical syntax semantics intermediate code code optimizer and code generator so here you have all these phases are managed by with the help of symbol table manager so it's having all the symbol related information will be stored in the symbol table manager and if any error is occur in between these pieces that error handles is going to handle that error okay so this is the phases of compiler or the structure of the compiler source program target program lexical analyzer syntax analyzer semantics intermediate code and the code optimizer code generator symbol table manager error handler now let's discuss one by one phase 1 phase 2 phase 3 5 6 and like that ok so let me explain each phase clearly so what is the phase 1 the phase 1 you call it as a little analyzer so whatever the source code that that source code is entering to the phase 1 that is lexical analysis ok so what does lexical analysis will do the lexical analysis reads a stream of characters so it's first read ste read ste streamer characters making up the source program and group the characters into meaningful sequence call let's see me okay let me write lexical analysis reads this stream of characters making up making up the source program and group the characters whatever the stream of characters it is reading so that it group the characters into meaningful sequence meaningful sequences call let's see okay so that whatever the group of characters that is reading that are call it doesn't see mixing so here the lexical another an liar analyzer represents these legs seems in the form of tokens okay lexical analyzer represents these leg seems in the form of tokens in the form of tokens so what do you understand from this whatever the high-level language that for the in the first phase it reads the character sequence of characters and group them and that leg seems you call it as a tokens okay let me show show you simple example the lexical analyzer in the form of token name token name and attribute values okay so let me take one simple example of lexical analyzer how the program is converted into tokens let's take the example let's take new value is equal to old value plus 12 so this is a simple example now this statement whatever the statement is statement consisting of group of characters this statement is converted into tokens in lexical analysis so what are the tokens that are present how the tokens are represented so new valve is identifiers new valve is identifier and equal to is one token that you call it as assignment operator assignment operator next token is old value old value is another identifier and plus plus is add operator add operator and 1212 is number so the statement whatever the statement that we are represented so this lexical analyzer is converted that statement into tokens so each one is represented as a token so here the lexical analyzer truncates the white spaces and also removes the errors so this is a phrase one okay let's continue in the second video in that video I will explain the different phases that are present in the compilation thank you