It is very popular question during the interviews either for fresher or lateral hiring. Compiler jobs is to take high level language program and convert into machine level. There are various phases of compiler and defined as follows:
1. Pre-processing:
In this phase, pre-processor expands the program by expanding the pre-processor directives. For example: #include<stdio.h>, #define X 5.
Compilation:
Now compiler takes expanded program and generates assembly program as output. There are various steps between input (expanded program) and output (assembly program). I would like to list down all those steps:
- lexical analysis
- syntax analysis
- semantic analysis
- generation of intermediate code
- optimization of intermediate code
- generation of pseudo code
Assembling:
In this steps, assembler takes assembly level code and generates object code (machine instruction)
Linker:
In this stage, generated object codes are linked to each other to generate a binary (executable)
Hope this will be very helpful.