Introduction
As we all know, computers can only understand machine language, i.e., codes containing 0s and 1s. We in daily write many programming codes for various computer programs, and you may think about how the computer executes these codes. The answer is that our codes are converted to machine code by computer, and the compiler and preprocessors handle these translation processes. Let’s learn about these in detail.

This blog will explain the difference between compiler and preprocessor and how they execute codes.
Recommended Topic, loop and while loop
What is a Compiler?
A compiler translates a programming code into machine-readable code so that the computer can execute it. It converts all the files of a given task at once. The program code goes through various steps during the compiling process. Let's discuss these steps in detail.

-
Lexical Analysis
The Lexical Analysis is the first step. The compiler reads the source code and splits it into many meaningful units known as lexemes. These are then tokenized for further steps. It also removes comments and white spaces.
-
Syntax Analysis
The code goes through the next step, syntax analysis. As the name suggests, the compiler checks whether the code is valid according to the programming language's grammar. It verifies the syntax by creating a Parse tree. If the source can be produced with the help of the tree, then it is in the correct syntax.
-
Semantic Analysis
The next step is semantic analysis. During this, the compiler verifies whether the program makes sense and checks for errors. For example, if a variable is used before its declaration then the compiler will return an error message.
-
Intermediate Code Generation
After all the analyses, the compiler modifies the code. It translates the source code into an intermediate code.
-
Code Optimization
The intermediate code generated must be optimized before the final translation. This step improves intermediate code so the output machine code can be executed smoothly.
-
Code Generation
Code generation is the final step of compiling phase. In this step, the compiler generates the required machine-readable code for execution from the intermediate optimized code.
Let’s now see what the functioning of a preprocessor is and how it works. We will also discuss the difference between compiler and preprocessor.
Must Read Recursive Descent Parser , cousins of compiler and Cross Compiler