Language Processing System in Compiler Design
The computer is an intelligent combination of software and hardware. Hardware is simply a piece of mechanical equipment and its functions are being compiled by the relevant software. The hardware considers instructions as electronic charge, which is equivalent to the binary language in software programming. The binary language has only 0s and 1s. To enlighten, the hardware code has to be written in binary format, which is just a series of 0s and 1s. Writing such code would be an inconvenient and complicated task for computer programmers, so we write programs in a high-level language, which is Convenient for us to comprehend and memorize. These programs are then fed into a series of devices and operating system (OS) components to obtain the desired code that can be used by the machine. This is known as a language processing system.
Components of Language processing system :
You have seen in the above diagram there are following components. Let’s discuss it one by one.
- Preprocessor –
The preprocessor includes all header files and also evaluates whether a macro(A macro is a piece of code that is given a name. Whenever the name is used, it is replaced by the contents of the macro by an interpreter or compiler. The purpose of macros is either to automate the frequency used for sequences or to enable more powerful abstraction) is included. It takes source code as input and produces modified source code as output. The preprocessor is also known as a macro evaluator, processing is optional that is if any language that does not support #include and macros processing is not required.
- Compiler –
The compiler takes the modified code as input and produces the target code as output.
- Assembler –
The assembler takes the target code as input and produces real locatable machine code as output.
- Linker –
A linker or link editor is a program that takes a collection of objects (created by assemblers and compilers) and combines them into an executable program.
- Loader –
The loader keeps the linked program in the main memory.
- Executable code –
It is the low level and machine specific code and machine can easily understand. Once the job of linker and loader is done then object code finally converted it into the executable code.
Differences between Linker/Loader :
The differences between linker and loader as follows.
Linker Loader The linker is part of the library files. The loader is part of an operating system. The linker performs the linking operation. The loader loads the program for execution. It also connects user-defined functions to user-defined libraries. Loading a program involves reading the contents of an executable file in memory.
Functions of loader :
- Allocation –
It is used to allocate space for memory in an object program. A translator cannot allocate space because there may be overlap or large wastage of memory.
- Linking –
It combines two or more different object programs and resolves the symbolic context between object decks. It also provides the necessary information to allow reference between them. Linking is of two types as follows.
Static Linking :
It copies all the library routines used in the program into an executable image. This requires more disk space and memory.
Dynamic Linking :
It resolves undefined symbols while a program is running. This means that executable code still has undefined symbols and a list of objects or libraries that will provide definitions for the same.
- Reallocation –
This object modifies the program so that it can be loaded to an address different from the originally specified location, and to accommodate all addresses between dependent locations.
- Loading –
Physically, it keeps machine instructions and data in memory for execution.
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.