Talk:CreditsPage

From C4swimmers

The compilation of C program is done in following 3 step which are explained below.

As you know that, Compilation is a process, where a language is translated into another language. So it need not have three steps.


Step I : Preprocessing First the source code passes through preprocessing step. -In which all the #define values are replaces. -May be if ur program contains #ifdef or #if than subject to the valildity of the expression the source code is modified. -If #include <xyz.h> is written, then this statement is replaced with the contents of the file 'xyz.h'

Preprocessing is done by a preprocessor. This is not part of compilation but part of preprocessing.

On a gcc compiler u can obtain the file after preprocessing by using -E option. Example : if you have temp.c as source file. just type the following cmd Prompt>gcc -E temp.c


Step II is Compilation. Once the source file is preprocecesed.Now ur file is converted to object file that is in machine language. In between there is intermediate assembly file is also created. Basically in this step an .o(Object) file is created. For creating a object file successfully make sure the fuction defination is same as fuction declaration. if there is a mismatch error message will be generated and object file wont be generated.

Usually, a compiler goes through a series of steps. Even here it is not mandatory that all steps must be followed.Some can even be combined to make it easier. It will be made clear in the subsequent texts.

1-> Lexical analysis. Here, all the valid tokens are recognized. This is done using a lexer. Some popular tools are LEX, FLEX.

Here is an example, if there is a declaration, int struct; we get three tokens here. i.e. 'int', 'struct' and ';'.

2-> Syntax analysis. Once we have got the tokens, we check if they are syntactically correct. This is done using a parser.

YACC, Bison are some of the popular parsers. Based on a grammar [something like Baskus-Naur Form], these grammars are evaluated.

If we take the above example, then 'int struct;' is a valid expression.

Or if we have a statement like int a; struct b; a == b; .This is a valid expression.

3-> Semantic analysis. At this stage, the meaning of the expression is evaluated. As we can see that both the examples mentioned are wrong.

These are sought here. As 'struct' is a keyword, it cannot be declared as a variable. And also 'a' cannot be compared with 'b'. So, the compiler generates error at this stage.

These three stages are called Analysis. Here the original code is not modified. All that is done is that, the code is analyzed as mentioned. Most compilers combine all these three stages into a single module.

4-> Intermediate code generation. A code generator converts a syntactically correct program into machine instructions. This takes the input from the Parse tree [forgot to mention that a parser generates this]. And this is not the final code still.

5-> Code Optimization. The above set of machine instructions are optimized for a particular target machine. Here optimization can be different for different users [i.e. with respect to Space and Time].

Some compiler repeat the above 2 stages more than once. The intermediate code is optimized to get another intermediate code. And so on. This is dependant on the implementation and the end user.

6-> Final Code Generation. Finally, we get the code that can be executed!

Or is it ?

A lot of optimization is required for the claims made above. [Serious] Like, generation of symbol table. Error handler.

On a gcc compiler u can obtain the objectfile by using -c option. example: if you have temp.c as source file. just type the following cmd Prompt>gcc -c temp.c You will get temp.o

similarly if u want Assembly file corresponding to your source file use -S option just type the following cmd Prompt>gcc -S temp.c You will get temp.s

Step II is divided into two part. First part generates Assembly file and Second part generates Object file.

Step III : Once you are through with Step I and II you link your files to create executable. Linking is the process of combining all required .o ( Object file) to form on executable ( .exe in DOS and a.out is Linux).

Personal tools