This lecture is a standard academic summary that prioritizes textbook definitions over the innovative realities of modern software engineering. It serves the syllabus well but remains safely confined within the limits of traditional pedagogy.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Introduction to Compiler DesignAdded:
Good afternoon dear students.
I am Dr. Sudasan Verha working as an assistant professor in the department of computer science and engineering in the school of computer science and artificial intelligence in SR University Warangal India.
Today we'll discuss we'll start the course compiler design.
Compiler design is a subject which plays very crucial role in uh crucial role for computer science and engineering students as well as the allied grants students.
compiler and these are the outlines of the subject I mean for today's lecturer these are the outlines here we will learn why compiler is required what is the necessity of compiler why not we can write the machine code directly What are the different types of compilers and what are the different works?
I mean there are different different roles. Why CS students should study compiler design?
Why it is important for them?
Then we will start introduction to compiler design, language processing system and phases of compiler.
Why compiler is necessary?
Actually the problem is computers understand machine languages. Machine language in the form of zero and one.
But we human beings or we are the programmer we write the program using highlevel programming languages like C, Java, Python, C++ where actually we mix some English text along with some mathematical symbols in order to formulate the program.
So there is a gap between what machine understanding and what we are writing.
So in order to f in order to minimize that gap or in order to eliminate that gap so a bridge is required that bridge is nothing but the compiler.
Okay.
So what it does a compiler it convert the higher level the source code or the program written in highle language into machine code that means it convert the program that we write using C, Java, C++, Python whatever the programming language we use.
So it convert that enter source code in the form into zero and one.
It act as a bridge or you may say it act as a translator because it translate the source code written in highle language into machine machine code.
So now from this particular uh slide we can uh understand that why compiler is necessary what are the advantage of uh I mean why why can't we write the machine code directly we can write the machine code in the form of zero and one we can write up to some extent but Not every time. Why? Because it is very difficult to remember every code or every syntax in the form of zero and one.
First thing then so that means it may lead to some error sometimes and it is time consuming approach. It is not portable. I mean it is machine dependent.
uh you cannot uh write the program in one machine in the form of zero and one and you cannot transfer to another machine because it is completely machine dependent if you write the code using zero and one only it is hard to debug and how hard to maintain too.
So that is why a compiler or a translator or a breeze is required which can convert the highle programming language that we use or the source code written in highle language to the machine code.
What is the necessity of a compiler? It enables the use of highle languages. It improves programming productivity. It provides error detection.
It also ensure efficient execution of the program and it also provide portability support. That means if you write a program using C language or Java language that source code that particular program if you run in your laptop it may run if you transfer that program in the form of a text file or in the form of any other file and you can execute in somebody else laptop then the program can also run. So that is called called as portability that is machine independent because machine does not know the source I mean the high level language. So you can write and you can take it into different machines and you can run there that is called as portal.
So from this uh what what are the takeaways uh what what we understood that without compilers it is difficult to execute modern programming languages and modern software development is impractical and compilers are core to all the programming systems.
So without compiler it is difficult to run a program.
So more or less now let us focus what a compiler actually does.
It reads the source code. The first step it reads the what program you write.
Once you click on the compile option then the compiler work starts.
So when it work start what it does it reads the source code it checks the uh I mean checks the error if any error is there then it returns back to us it translate the source code into machine then simultaneously it also optimizes the code.
If we wrote long very long code and the if some redundancy is there uh some kind of um lengthy code or complexity is there it also simultaneously uh take takes care of that it also convert that code into a optimized code. So that optimized code in the sense what the code which can takes less memory as well as it can execute uh with less time that code is called as optimized but not every time that code should execute with less time and consume less memory. Sometimes the code may consume more memory but it execute with less time because time is very important factor that is the time and space both are called as cost in computer science and engineering. Okay.
When we execute the program we tell them the what is the cost of the program that means how much memory it occupies and how much time it takes to execute.
Okay. Now see what are the different types of compilers available.
There are many variants of a compiler.
You may say one of them is cross compiler which compiles the code for different machine. That means compiles code on PC and run on embedded system.
I mean it it creates the executable code. I mean the machine code in the form of zero and one for one machine in one machine and that code can run in another machine that is called as comp cross compiler.
Then just type compiler which is used for Java language. Okay. It compiles the code during execution. It improves the runtime performance.
So runtime performance in the sense it improves it also perform optimization at the time of when the program runs.
Then another compiler is there another variant is single pass compiler. It scans the source code only once. Enter source code. It is scan at one time.
It is fast but limited optimization. It provides very less optimization.
On the other hand, another uh variant of the compiler is called as multipass compiler which processes the code in multiple times.
So it does not uh run the code I mean scan the code or process the code in one time rather it takes multiple time I mean uh it scan the code and process it in multiple attempts.
It provides better error checking and optimization.
Normally it used in modern compilers.
This type of compiler is called as multipass compiler.
Similarly another kind of compiler is there called as source to source compiler. It convert one highle language into another.
For example, TypeScript can be converted into JavaScript.
TypeScript is one language which can converted into JavaScript or you may say C language can be converted into C++.
Okay. So this type of compiler it convert the highle language written in one source code to another source not the machine code not in the form of zero and one it converts the highle code or the source code written in one language into the relative language another language.
Then another kind of compiler is called as ahead of time AOT compiler. It compiles the code before execution and it produces optimized code. So here this particular compiler it focus on how to optimize the code so that the code can uh run efficiently.
This is the primary moto of AOT compiler. So these are the different variants of compiler and they perform different task and they support different types of tech uh I mean uh user friendly technique also.
Now the question is why CSE or allied branch student should study compiler design because compiler is the backbone of the programming language.
So whenever you are writing a program in highle language on the other hand machine is understanding only zero and one. So you cannot convert the program into 0 and one.
So it will be difficult for the human being to convert the program into 0 and one. So a translator or compiler is required.
That is fine.
But now focus why CSE students or the CS allied grant student a IML data science IO I IOT embedded system why all those students should know about the computer because the fundamental to computer science there are few concept or the subjects one is the data structure one is automata theory one is programming These are the these are the major subjects in computer science and engineering or you may say the core subjects.
So when you discuss about the core subject data structure for uh to com to execute anything or to create a data structure you need to write the program to work with automata theory or to understand the principles of automata theory. Automata theory is a part of the compiler.
So you need to write the code. Then for any other programming language whenever you are learning without coding you are not learning the programming language.
So you need to write.
So whenever we are writing code we should know what is the syntax and what kind of errors are there and what is the what what type of how to execute the code and how whether whenever you wrote a code how can you know whether your code is efficient or not.
So, so for all these things it is essential to learn compiler DJ.
Understanding how programming language work. How code is converted internally.
What is the role of different phases of compiler?
Whether compiler perform the task within a single phase or there are different phases.
Okay. So for all these things it is very very essential to understand how what is a compiler and how it works.
How it convert the programming language written in uh highle language or the source code written in highle language to the machine.
Additionally some career opportunities are also there.
If you understand the concept of compiler properly perfectly, you can be a compiler developer. You can be a language developer.
Earlier we have seen C language. Next C++ came. Next Java came and now Python is running in the market.
So what who developed this languages like you and me like any other software I mean human being only software people software engineers or computer science engineers they only develop this.
So you can be a language designer. You can tomorrow you can come with a new language with a new compiler.
That compiler can only able to compile your language.
Then uh system programmer. You can be a system programmer because compiler is nothing but a system program. It is not an application program.
It is a system program. So there there are multiple career opportunities. If you learn the compiler subject perfect properly, it helps in competitive exams also like you can I mean most of the questions are coming from automata theory and compiler DJ in GA get in UGCNET you can also these are the competitive exams if you learn the subject in depth then you can easily easily attempt those questions.
And few real world applications are like programming languages, C, Java, Python, any ID I mean integrated uh development environment. Okay. error for error detection for autocompleteness all these things for game design for operating system you need compiler or to work with C Java Python you need to understand what is the purpose of compiling C language what is the purpose of compiling or interpreting Java what is the purpose of compiling Python what are the different syntax all those things so it also help you for problem solving like logical thinking, algorithm design and debug debugging ability.
If you knows the compiler properly, you can able to handle the debugging or you can able to handle the error in a programming language simultaneously. You need to also be perfect in you need to also be uh get expertise or proficiency in that programming language.
First you need to understand the syntax of every programming language. Then you need to understand before compilation how the compiler works.
Okay.
Now let us slowly go to the topic.
Now the question is what is a compiler?
Now you can say a s a compiler is nothing but a translator which convert or translate highle language into machine in into machine code or machine level language.
Here you can say the input is source the source code is written in C and the machine code is is in the form of binary. The output is binary. If you give the input as a program in C language then the output will be the machine code in the form of binary.
So when you write a program in C or Java, the computer cannot understand it directly. A compiler convert that program into machine language so that the system can execute it happily.
Okay. So for that a compiler is required.
So you can see one example present in the slide.
Int a= to 10. That means you declare a variable and you also initialize that variable a= to 10. Second statement int b = to 20.
There another variable you declared as well as initialize that is called as b.
The value you have given 20.
Now in the third statement what what is there the third statement int c another variable that c equals to a + b that means both the var the values of a and b as predefined the values of a and b b are added and placed in c.
So to the result will be 30. A = to 10, B = to 20. So and C carrying the result now. So the result will be 30.
Is it as we wrote it?
For our convenient we wrote it. Is the machine understanding this? No. So here the machine needs to convert entire thing int a equal symbol 10 semicolon everything it will convert to binary in the form of zero and the machine understand then whenever you print the or you ask the value of C the machine return you 30 okay now let's move to Another next slide.
Language levels.
There are many uh I mean many categories of language like highle language.
Normally you say C, C, C++, Java, Python. Then assembly language. It comes in the form of instruction. Okay. Add R R1, R2. There R1 R1 is a operand and R2 is another operand. Okay. Both of them added the values are I mean R2 value get added with R1 that is instruction.
Then machine code or the machine language it comes you see it comes in the form of 0 and 1 1 0 0 1 0 1 0 it comes in the form of them. So we need to spend more time to understand that machine code to find out the value human prefer highle language because that language we can easily remember because we knows English and we knows the mathematical symbol. So we are combining both of them the English text with the mathematical symbol in order to create the program.
Okay. Machine does not understand that machine need to understand only when that program get converted into in the form of 0 and one into the machine.
So it is not that much of simple that compiler converted easily. Okay, it passes through several pages.
Okay. So there is a system called as language processing system which combines or which consists many components or which has many components.
One is preprocessor. Second component is compiler. Third third third one is assembler. Next one is linker and next one is loader.
This is a complete journey of the program before it get executed.
Okay. So the language processing system the first one is prep-processor.
Okay. Preprocessor it reads the source code then compiler preprocessor it perform something. Okay.
It perform normally it remove the uh macros then it send the programs to the compiler. Then compiler translate the programs.
Sometimes it uh translate to the assembler I mean convert the program into assembly code and some compilers are there which can convert the code directly to the machine.
Okay.
So compiler then assembler linker then you get the executable files.
This is the overall view of a language processing system.
In this uh subject we are not going to discuss what is preprocessor in depth, what is assembler in depth, what is the role of linker loader in depth. We are not going we need to discuss what is the role of the major role which is played by compiler.
Okay. So let's move on.
See you see the pre-processor what it does it handles macros like whenever in C language you are writing no has include so it it removes them before sending the source code to the compiler or has defile. So it handles those macros.
Then compiler checks the syntax convert the code into machine code or assembly code. It also detect the error. If any error is there, it will not detect by the pre-processor rather the error get detected by the compiler.
Then compiler once it it detects the error and everything. If there will be nothing if the code is fine then it sometimes it produces assembly code then it send that assembly code as input to the assembler and assembler convert that assembly code to the machine.
As in the previous slide I told you assembly code there are three different levels of language. one is high level language then assembly language then machine level or machine code. Okay. So here assembler it convert that assembly code to the uh to the binary code or to the machine code.
Then linker what it does it combines multiple files. It links some libraries.
Okay. It establish the linking between libraries and the loader then loads the executable into memory. I mean executable code it place in the memory and then it runs the code.
So these are the overview of language processing system.
Now the major subject need to be study here is compiler or compiler DJ.
The this is the major thing we need to focus.
So now let us come to know what is a compiler. As I said before a compiler is nothing but a translator which translate highle I mean source code written in highle language into the target code or into the machine code.
Why I'm saying target code? As I said before, sometimes the compiler does not translate directly to the machine code.
Sometimes it translate to the assembly code. So either machine code or assembly code that can be called as target code.
So this do job is not performed in a single step rather it passes through several pages.
So now let us know what are the different phases available in compiler.
The major phases available or associated with with a compiler are first one is lexical analyzer.
Second one is syntax analysis or syntax analyzer. Third one is semantic analyzer or semantic analysis. Fourth one is intermediate code generation.
Fifth one is code optimization.
Sixth one is code generation.
These are the major major phases of compiler. Additionally two other phases are there. One is error handler and other one is symbol table.
Okay. error handler and symbol.
Let us know that.
So you can see you can see.
Yes, you can see here.
You can see here.
One one second.
Here we go.
These are the phases of compiler. You can see the block diagram or the phase diagram of compiler present in the left side of the slide.
The first phase known as lexical analysis or you may say lexical analyzer no problem.
Second what it does it is reads the source code the first phase then it perform some task and after that it is send the processed input to the syntax analysis. This is the second phase of the compiler. The third phase of the compiler is semantic analysis.
The fourth phase of the compiler is intermediate code generation.
The fifth phase of compiler is code optimization.
The next phase is the last phase you may say code generation.
But let me tell you this code generation sorry code optimization is again divided into two parts.
One kind of code optimization is carried out as you see as it is clearly visible in the PPT. Okay. One type of code optimization is just carried out before the code generation that is called as machine independent code optimization.
Then another kind of code optimization is carried out after the code generation that is called as machine dependent code optimization.
Okay, that we'll discuss when we go to the topic, we'll discuss that. And you see additionally two other pages are also there.
One is symbol table, other one is error handling.
We'll be discussing them each one of the phase one by one in depth.
Now just read uh just uh discuss it in brief.
Lexical analysis what or the lexical analyzer what it does it converts the input first of all it reads the input or the source code okay then it converts the input into tokens tokens in the sense sequence of words I mean characters not words characters it converts them into tokens it also remove the white space and comments from the One example is given. You see example int a = to 10. So here integer a equals to the value is 10.
The value 10 is assigned to a.
Now what what will be the tokens here?
If this is the source code then what will be the tokens? The tokens are first one is int. Second kind of token is a.
Third kind of token is equal symbol.
Fourth kind of token is 10. These are the four tokens available in that code.
So that is why we say we normally say what if somebody will ask you what is a program? What we say? A program is a collection of tokens. That is the perfect answer.
So each one of the symbol or word present in the program is known as a token.
So this lexical analyzer is normally perform tokenization.
What is tokenization? We'll be discussing when we'll start the discussion on lexical analyzer in depth.
we have to discuss.
Then the next phase is syntax analysis or you may say syntax analyzer. It is sometimes called as parser also.
It is checks the grammar rules.
It checks whether the syntax is correct or not. Whether a sentence is grammatically correct or not.
And it produces a grammar tree for the sentence.
If the sentence is correct, it produces the grammar tree for the sentence as output. Then it is the grammar tree also called as parse tree or syntax tree.
Then it pass that syntax tree as input to the semantic analyzer or the third page or semantic analysis.
What the semantic analysis does? It checks the meaning of the program.
Whether with a sentence is written, a sentence may be written correctly. But the eventual meaning of the sentence is correct or not. That is the role of semantic analysis or semantic analyzer.
Then semantic analyzer then after checking and everything it pass the code to the intermediate code generation.
Intermediate code generation what it does it convert the source code into a different form into another form I mean it breaks the ent program into intermediate form that intermediate form is called as three address code.
Or it can also be uh it can also be some other form like bag and others that we'll discuss. But now in brief you just try to know that it breaks the entire source code into another code.
That is the role of semantic uh role of this intermediate code generation.
And once the code is converted into IR intermediate code generation form then it trans send the code to the for the to the next phase code optimization.
Code optimization what it does it checks whether the code is uh I mean written correctly or not. I I mean uh if any redundancy is there it remove that. If uh any uh any other kind of I mean optimization is required it is perform that like if you are writing x = x + 0.
Otherwise you take suppose you are writing y = x into 1. What does it mean?
You can directly write y = x.
So that kind of optimization is performed by code optimization phase in order to improve the efficiency of the code. That's next finally it passes the code to the the optimized code optimize code to the code generation phase and the code generation it it perform or it creates the target code for the uh optimized code. This is the job of compiling and meanwhile the symbol table and error handling these two pages are associated with each and every page of the compiler. Symbol table it is a kind of storage unit. It stores the details of the identifiers or the details of the tokens and error handling. If any phase any kind of error is appeared then it that error is throw thrown to the error handler. Error handler that error handler it shows the error to us. That is the job of error handler. Okay. So symbol table is a data structure which stores the details of each and every identifiers or any other tokens identified in the program. and error handler it uh it checks the error if any error is there then it throw the error to the user for the corrective actions.
Suppose I am the programmer I wrote a program and there is a error this error is identify the error handler or any of the phases and that phes pass the error to the error handler. Finally, error handler will show us this is the error.
We already encountered many times while writing the programs.
If you have not done it, you can experience it when you write a program and compile. Then error will appear then definitely the compiler will show you the error.
That errors shows through the error handler page. error handling base.
Okay, next class we'll be uh learning in depth. These are the different phases we just more or less we identified. In the next class we'll be knowing in depth. We will take one for every uh for every phase we will take one or two examples to understand how exactly they are working. Okay. So this is uh for the today's lecture and in the next lecture we'll be learning what is the role of lexical analyzer, what is the role of syntax analyzer, what is the role of semantic analyzer, what is the role of intermediate code generation, what is the role of code optimization, what is the role of code generation, what is the role of symbol table and how error handling phases work phase works. Okay, in depth we with example we'll be learning them one by one. Okay, this compiler design it covers these phases are the entire syllabus of compiler design.
So from next class onward not we will be encountered them one by one. Okay, thank you all. Have a good day.
Thank you. Bye.
Take care.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 viewsβ’2026-05-28
How agent o11y differs from traditional o11y β Phil Hetzel, Braintrust
aiDotEngineer
450 viewsβ’2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanationπ―β
LearnwithSahera
1K viewsβ’2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 viewsβ’2026-05-29
Search Algorithms Explained in 60 Seconds! π€π¨
samarthtuliofficial
218 viewsβ’2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 viewsβ’2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 viewsβ’2026-05-29
π BCS613C Compiler Design | Module 1 to 5 Schema Evaluation π₯ | VTU 6th Sem π― #VTU #bcs613c #exam
Pranavaa-y4y
104 viewsβ’2026-06-02











