Compilation DefinitionIntroductionCompiling is the process computers use to translate high-level programming languages into computer-understandable machine language. A compiler is the name of the software that performs this conversion. Source code is the format in which programmers create their programs. Before a program can be executed, the source code should go through several steps. The source code must go through a compiler to convert the high-level language instruction into object code. When the compiler has generated object code, passing that code through a linker is the last step in creating an executable program. The linker creates machine code, integrating modules and assigning actual values to all symbolized addresses. The two components of compilation are analysis and synthesis. The analysis stage separates the source code into its constituent elements and produces an intermediate representation of the source program. The target program is created from the intermediate term by the synthesis component. Compilation ProcessCompiling a high-level program into binary low-level machine code is called compilation. The computer can execute only binary machine commands because of its hardware design. Thus, every program designed in a language other than machine code must first be translated into machine instructions. The compilation is a multi-stage process that transforms high-level computer programs that are understandable by humans into low-level, binary code that is readable by machines. Four steps convert a program's source code into an executable file. These four steps in the compilation process include preprocessing, the compiler, assembly, and linking. PreprocessorThe preprocessing stage is the initial step in the compilation process, and this stage is also known as the lexical analysis stage. The program source code file is entered into the preprocessing step, which outputs a file with the dot i(.i) extension that has been preprocessed. The compiler searches the source code file for any # include and # define class preprocessor directives. The entire header file set is processed at the preprocessing stage, and all macros are handled by replacing them with absolute values. But comments are not processed at this stage. CompilerThe second step in the compilation process is compilation itself. The compiler accepts the preprocessed file as input, producing an output file containing the assembly code containing the dot s(.s) extension. The compiler translates all high-level software instructions into their corresponding assembly code instructions. These instructions were built for a particular architecture and are platform-dependent. AssemblerThe third step in the compilation process is the assembler. The assembler translates basic computer commands into binary code for the computer's processor to perform its fundamental operations. These instructions are written in assembly language or assembler. An assembler is used to translate assembly code into object code. The name of the source file and the object file created by the assembler is the same. LinkerThe fourth and last step in the compilation process is linking. The primary purpose of linking is to combine all object code files into a single executable file (sourcefile.exe). Big computer programs are organized into a variety of manageable files. Separate files are used to store the user-defined functions. In the header section, these files are linked to the main program file like the C language's # included. Similarly, the programming language offers built-in standard library functions that programs can use immediately to simplify coding tasks. As the standard library code is in object code (a pre-compiled format), it may be immediately incorporated at the linking step by the linker while producing an executable file during the compilation process. Why are Computer Programs Compiled?The need to compile high-level programs is something that computer science students should understand fully. High-level programming languages like C, C++, Python, Dot Net, and Java are used to create high-level programs. Humans can understand high-level programs. Every high-level programming language has a unique syntax and reserved keywords instructing the machine to perform particular operations. The ease of programming is a special consideration in developing high-level programming languages. The majority of keywords in high-level programming languages are common English words. CompilerCompilers are pieces of software that change source code into object code. In other words, it transforms high-level language into machine/binary language. Also, carrying out this step is important to make the program executable, and this is because the computer understands only binary language. Some compilers translate the high-level language into an assembly language as an initial step. At the same time, others translate it into machine code. Compilation refers to the process of transforming source code into machine code. Types of compilerCompilers come in a variety of forms, including the following:
Phases/Structure Of CompilerThere are various phases in the compilation process. Also, the results of each stage serve as the input for the following step. The compilation process contains the following phases or structures: 1. Lexical Analyzer
2. Syntax Analyzer
3. Semantic Analyzer
4. Intermediate Code Generator (ICG)
5. Code Optimizer
6. Target Code Generator
Compiler OperationsThe compiler's crucial operations include the following:
Difference Between An Interpreter And A CompilerA compiler checks the entire program at once. Once the whole program has been reviewed, it displays all the errors in one location. Conversely, an interpreter goes through the program line by line, and the execution stops if an error is found. Next TopicCompound Definition |