A compiler is a language translator that converts high-level source code into executable machine code through six distinct phases: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and target code generation; the first three phases constitute the analysis phase (front end) while the last three form the synthesis phase (back end), with the symbol table manager and error handler serving as supporting components throughout the compilation process.
Compiler Design Introduction: Phases & Architecture Explained
Added:hello everyone welcome to the first lecture of compiler design the course compiler design deals with the study of compilers and in this particular session we will first learn about the emergence of compilers followed by the different phases of it also by the end of this lecture we will see the course plan prerequisites and the target audience for this particular course so without any further ado let's get to learning now we all know computers are electronic machines or in other words they understand only zeros and ones therefore in early days of computation instructions to a computer were given using perforated paper tapes and punch cards in these the presence of a hole is representation of zero and absence means one now writing down instructions in the form of ones and zeros is pretty hectic let me show you how let's take this word punched card if we convert this into its equivalent binary using ascii standard now ascii stands for american standard code for information interchange it becomes this now this is the format which computers can process directly but for us it is almost impossible even if it becomes possible for any human to encode instructions like this it is undoubtedly time consuming now think about the situation carefully at one hand we have a machine that has immense potential we can employ it to solve many of our problems but on the other hand we are facing an awful lot of trouble while communicating with it so what is the solution since we are facing a communication barrier we need language translator in simpler terms we will say punch cards and the middleman that is the language translator will convert that into the strings of ones and zeroes over the time computer scientists came up with various language translators the first one was the assembler debuted in the late 1948 these language translators could translate assembly language into its machine code that is streams of ones and zeros now assembly language has a very strong correspondence between the instructions of it and the architectural specification of the computer that means in order to write instructions for the computer in assembly language the coder needs to have a proper knowledge about the computer's architecture first it seems tedious too doesn't it so in the 50s two new language translators the interpreter and the compiler came into picture php ruby python javascript are some examples of interpreted languages that is when we write programs in this the respective interpreters run through the programs one line at a time and finally convert the programs into machine codes on the other hand c c plus plus erlang etc are some common examples of purely compiled languages that is programs written in these are converted directly to the machine codes compilers tend to be faster and more efficient than interpreters so this is how compilers came into picture now many of us know about the c programming language right although nowadays it is classified as a middle level language because of various features like direct memory access through pointers bit manipulation using bitwise operators and the ability to embed assembly code within c programs however originally it was classified as high level language because syntactically c codes are almost like the english language let's consider this piece of c code now it is a very basic program code this hash include stdio.h is actually a preprocessor directive which specifies the standard input output header file should be included in this program now coming to the next portion it is the definition of the main function in c the default written type of main is int now here we have four integer variables x a b and c now apart from x a has been initialized with the value 2 b with 3 and c is initialized with 5.
coming to the next statement it's actually an arithmetic expression here first b is multiplied with c and thereafter the result is added with a and finally it is assigned to the variable x and here we are printing the calculated value of x on the screen using this printf function by the way we have to include the standard input output header file because we are using the printf function if we don't want to print the value of x on the screen we need not write this line now finally here we are returning 0 because this function main is not supposed to return anything under error free execution now if you observe this piece of code is close to english right header file is being included using hash include preprocessor directive the main function is actually the main part of the code integers are given the data type named int and finally printing is happening through the printf function so it is in human readable form but the machine cannot understand it we usually call it the source code or high level language code and the job of the language translator is to convert this high-level language code into executable machine code now let me walk you through the internal architecture of the language translator specifically for c language the language translator has four different phases the first one is the preprocessor this preprocessor will resolve all the preprocessor directives as for this particular code reading the hash include preprocessor directive it will append the standard input output header file to the high level language code removing the preprocessor directive also it will remove all the comments so now the high level language becomes a pure high level language the next one is the compiler this phase will generate the equivalent assembly language code as you can see this is the assembly code of this pure high level language code and the compiler is responsible for this translation thereafter this assembler will generate the relocatable machine code now relocatable machine code is actually streams of ones and zeros which is actually the machine code however this is relocatable ok let me put it to you this way a program turns into a process during execution right and only during execution it is allocated to the main memory so before execution we cannot know where exactly in the ram the process will be located so for that time being the sequence of the machine code instructions is given a relocatable address as you can see here the first instruction has the address i plus 0 and then the successive ones have i plus 1 i plus 2 and so on basically these are sequential here i is the variable which signifies the relocatability finally the last one that is the linker and loader these generate the absolute machine code that is actually the executable machine code this one is basically the process which has been loaded into the ram and is ready for execution see these are some sequential absolute addresses so this is the underlying architecture of the c language translator now from all these the second one that is the compiler is what we are going to focus on in this compiler design course now coming to compilers it has six different phases these are lexical analysis syntax analysis then the semantic analysis phase after that the intermediate code generation phase the code optimization phase and last but not the least the target code generation phase now phase wise the first three phases are called analysis phase whereas the remaining three are known as synthesis phase however from a software's perspective the first four phases that is the lexical syntax and semantic analysis phases and along with that the intermediate code generation phase these four are called the front end and the remaining two that is the code optimization and the target code generation phase are called the backend and why so suppose we have an existing c compiler for windows platform now we would like to build a c compiler for a mac operating system for this we can modify the back end that is these two phases according to the max specification and have those newly created backend phases merged with the existing front end and it will we now have the c compiler for the mac os now alongside these six phases there are two more components of the compiler the symbol table manager and the error handler informations gathered from analysis phase are stored in the symbol table and used by the synthesis phase and the error handler deals with there are detection and recovery so these two are used by all the six phases now in a nutshell this is exactly the compiler design course now if we talk about the course plan that is the syllabus it is as follows chapter 1 will be the introduction here we will cover the symbol table and the lexical analyzer chapter 2 will be the syntax analyzer in this chapter we will get to know about different classifications of context free grammars next up is the top down pursers here we will mainly focus on the recursive decent and ll1 parsers also while covering ll1 persons we will learn about first and follow in chapter 4 we will learn about various bottom-up parsers in details first we will study the most unique parser that is the operator precedence parser and thereafter we will learn about various lr parsers next up is the sdts or syntax directed translation schemes this is basically the semantic analysis phase here we will learn how the compiler looks for meaningfulness in our code now chapter 6 will be all about intermediate code generation phase intermediate codes can either have a linear form or a tree form we will observe the very popular three address codes and the directed acyclic graphs there finally chapter seven will be all about runtime environment and code optimization phase in runtime environment we will get to know about the process structure in details and in code optimization phase we will observe various machine independent and dependent code optimization techniques so basically our proposed syllabus will have seven different chapters now since it is not a basic course in order to study compiler design the learners need to have a basic understanding of the subject theory of computation so i strongly recommend you all to go through our beautifully presented theory of computation course now coming to the audience whom keeping in mind this course has been designed all the college and university students can take this course because this course will be taught comprehensively next any aspirant willing to take part in any competitive exam will be able to lucidly understand many numerical problems along with the most apt illustration of the theory involved in those finally any computer science admirer who just wants to get wise in this subject or anyone who wants a quick detailed recall about any topic of compiler design can refer to the lectures all right people that will be all for this session in the next session we will observe all the phases of compiler with the help of a proper illustration so i hope to see you in the next one thank you all for watching [Music] [Applause] [Music] you
Up Next

Writing a Custom Language Parser in Golang: Tokenization
@tylerlaceby
32.5K views•2024-04-02

BitTorrent Protocol Explained: Piece Selection & Peer Choking
@StevenGordonAU
481 views•2013-02-22

Hamming Code Error Detection Explained | Digital Electronics Tutorial
@nesoacademy
2.4M views•2015-01-20

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science












































