You can learn about Introduction to Programming Using Python Programs with Outputs helped you to understand the language better.
Introduction to Python Programming – Compiler
A program that translates a high-level language program into a machine language program is called a compiler. It checks all kinds of limits, ranges, errors, etc. But its program execution time is more and occupies a larger part of the memory. It has slow speed and low efficiency in memory utilization. If a compiler runs on a computer for which it produces the object code, then it is known as a self or resident compiler. If a compiler runs on a computer other than that for which it produces object code, then it is called a cross-compiler. The process of producing an object program using a compiler is called compilation.
After compilation, you get a file known as an object file which is in machine language. There are two steps in executing a program, the compilation phase and the execution phase. The compilation is required to detect syntax and semantic errors in a program. The compiler converts the program into machine language so that it can execute the program on the machine. (See Figure 1.4).
- Python Programming – Introduction to Programming
- Python Programming – Introduction to Python Interpreter and Program Execution
- Introduction to Python Programming – Interpreter
A compiler is nearly 5 to 25 times faster than an interpreter. An interpreter is a small program as compared to the compiler. The tasks performed by a compiler are shown in Figure 1.5. These may be divided into two main categories.
The compilation process consists of two steps:
(a) The Analysis Phase
(b) The Synthesis Phase
The Analysis phase consists of the following tasks:
(a) Lexical Analysis
(b) Syntax Analysis
(c) Semantic Analysis
The Synthesis Phase refers to the synthesis of the object program. It generates code and does optimi¬zation. This phase takes the parse tree and data type information as input and generates the object code as output. The object code can either be in machine language or in assembly language. The compiler writes machine or symbolic instructions for each HLL statement.
This phase is also concerned with code optimization for the generation of faster and more compact code. Unlike assemblers, compilers need multiple passes to translate the program. It needs to scan the program many times to generate an efficient code, in terms of both execution time and memory requirements.
Basic Flow of Compilation
The basic flow of program execution is as follows: Program (Source code) —> Binary —» Execution So, Source code is converted into the binary form using some special software known as a translator, and the computer executes the code.