Function Of Compiler

A compiler is a software translator which converts High level programming language to low level machine language. For example, the programmers write the code in C, C++, Java etc. and it is translated into machine code or assembly language. First the computer analyses the input one by one and generates an output, and when it’s done, the output is compiled in the form of object code. In earlier times binary data was used and with passage of time assembly language came into existence which was more reliable. Due to less memory in computers that time the compilation process was divided into smaller programs and it was troublesome. There are different types of compilers such as native code compiler, source to source compiler, cross compiler etc. The execution of a program with compiler is carried out in 3 ways including:

  1. Lexical Analysis: In the first step, the compiler combines the source codes that belong together and categorize them accordingly. It is also called scanning as it keeps record of the character present in each line. The output is in the form of tokens.
  2. Syntax Analyser: The second step involves checking whether the tokens created in the first step are in desired order. The syntax after correct rearrangement is analysed to gather the optimum result.
  3. Semantic Analysis: This step involves sorting of tokens in proper order and an object code is generated that has instructions to eliminate the unwanted programs and produce warnings in case of any discrepancy. The entire code is interpreted in the end and modified tokens are placed in object code.  
  4. Code optimization and Code generator: Optimization is achieved when unwanted codes are removed and ample memory is available for program. The final step is code generation which does the overall management and operations by providing object code and allocating to different locations of data.

The high level language is the one which humans can understand and the computer programs are written with this language. But the computer accepts binary data i.e. 0 and 1 so it is necessary that machine code is converted to source code and it is achieved using complier and interpreter. Both of them do same job but the only difference is that compiler converts before the program runs and interpreter converts when program is running. C, C++ languages uses compilers and Python, Ruby uses interpreters. Compilers display all the errors at the end once the program is finished but the interpreter display it one by one. Once the code is generated the compilers run the output program separately from the original one. Interpreters don’t have such thing they execute everything line to line. As compiler generates intermediate codes, so memory requirement is more. No such thing is present in interpreter and so it requires less memory. The functioning of compiler is fast as compared to interpreter. Error detection is easy in interpreter as compared to compiler. Despite having advantages and disadvantages complier and interpreter are vital parts of a computer program which ensures it smooth functioning.

Nick Willson

Hi, i am Nick Willson.welcome to my blog Article-Book.com. My keen interest in art, education, and technology. With a natural flair for making complex topics simple, Nick enjoys creating informative and engaging content that educates and inspires readers. His articles on books, health, and home appliances offer practical advice and valuable insights for everyday life. Stay tuned to Article-Book.com for more expert tips, thought-provoking ideas, and content that encourages you to explore, learn, and grow!