Monday, July 27, 2009

How do we make such compilers which can understand the c language and the computers work exactly the way we w

A compiler is designed to take a language, then break it down into simple pieces, examine it for correctness and then generate the base assembly code for the processor on which it is developed.





The first stage of the compiler is tokenizing, or breaking down each of the letters the compiler reads into groups of 'words' that make sense to the compiler. For example, the statement "int i = 10;" can be broken into 'int', 'i', '=', '10' and ';'.





Next, lexical analysis is done to ensure that the tokens read by the compiler fit the language. In the previous example, 'int' is seen as a keyword, 'i' recognized as a variable name, '=' as an operator, '10' as a literal constant, and ';' as a statement terminator.





Now, the compiler performs semantical analysis in order to make sure that the tokens it recognizes are in proper order and that they make sense. An example is a sentence like "going to the store are we", as opposed to "we are going to the store". In the code example above, "int i = 10;" is semantically correct, wherease "int 10 i =;" is not, even though the tokens are valid.





When the language is determined to be correct, the compiler goes into the "code generation" phase, which can consist of pseudo-code that is optimized, then converted into machine language that the computer can understand.





In a nutshell, language compilers usually understand the language by: a) breaking the language down into its individual 'pieces'; b) ensuring that all the pieces are in correct order according to the 'rules' of the language; and c) convert that language to the resulting native language of the machine.

How do we make such compilers which can understand the c language and the computers work exactly the way we w
To make compilers first we need to go thru the developing steps of the compiler.any compiler will have the same basic functionalities.So even if it is for C or Java or for .net or any other programming language the compiler functionalities will remain the same only with some specific modifications to the specified language.


Some of the important steps involved in making a basic compiler are:


1.Lexical analyzer.


2.Symantic analyzer.


3.Syntax analyzer.


4.Intermediate code generator.


5.Code optimizer.


6.Code generator.





Each stage refines the source code in order to generate the machine code which is understandable to the kernal.





It takes more text to explain each and every stages of the compiler.for further referance u can look out in the book "Compilers" by ullman and Ravi setty.Hope this might be of some help.


Best Regards.
Reply:Not real clear on what you are trying to do, "C" was the original cross platform language. Any machine with a "C" compiler should be able to compile most source code.

bottle palm

No comments:

Post a Comment