Explain the stages of compilation for a C Compiler?


Usually programs are stored in a disk. To compile a program, in standard integrated development environments we need to click at the compile button provided by the IDE. In places where IDE is not provided, the compiler may have to be explicitly involved at the command prompt. For example in UNIX system at shell prompt we must type CC filename C. This causes compiler to be called to primary memory and executed. When compiler is executed, it takes the given C file and translates it. A compiler uses two or more passes to compile the C program. The following activities are performed by a compiler.

1. Lexical analysis: In this process compiler recognize basic elements of program and create a uniform symbol rate.

2. Syntax analysis: In this process basic syntactic constructs are recognized by compiler and their validity is checked.

3. Interpretation: In this phase, exact meanings of syntactic units are determined and compiler creates certain data bases required for translation. It includes creation of tables.

4. Machine independent optimization: In this phase optimization of data bases is performed. This result in removing all redundancies during the code generation step.

5. Storage assignment: In this phase storage space is assigned for code, data etc.

6. Assembly and output: In this phase based, on data bases it created earlier, compiler generate machine code and resolve all symbolic addresses.

Post a Comment

0 Comments